/*---------------------------------------------------------------------------*\
  ==  == ====== ====   ====    |
                    \\     ||  | Multiphase Code Repository by HZDR
  ======   //   ||  || ===//   | Website: https://doi.org/10.14278/rodare.767
  ||  ||  //    ||  // || \\   | License: GPL-3.0-or-later
  ==  == ====== ====   ==  ==  |
-------------------------------------------------------------------------------
License
    This file is part of the Multiphase Code Repository by HZDR.

    Copyright (C) 2025 by Helmholtz-Zentrum Dresden-Rossendorf e.V. (HZDR),
    Website: https://hzdr.de

    Multiphase Code Repository by HZDR is based on the free software for
    computational fluid dynamics (CFD) from the OpenFOAM Foundation.
    Copyright (C) 2025 by OpenFOAM Foundation, Website: https://openfoam.org

    If you are interested in which files are original OpenFOAM Foundation
    files, which OpenFOAM Foundation files were modified, and which files were
    newly created, see FILES.md.

    Multiphase Code Repository by HZDR is free software: you can redistribute
    it and/or modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    Multiphase Code Repository by HZDR is distributed in the hope that it will
    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
    Public License for more details.

    You should have received a copy of the GNU General Public License along
    with the Multiphase Code Repository by HZDR. If not, see
    <http://www.gnu.org/licenses/>.

Class
    Foam::functionObjects::addonCourantNo

Description
    Calculates the CourantNo in the same way, the original
    functionObject "CourantNo" does. Additionally to writing out at defined
    times, the CourantNo field is written out whenever the maximum CourantNo
    exceeds the criterion CourantNo.

    Example of function object specification:
    \verbatim
    ConditionalCourantNumber
    {
        type addonCourantNo;
        libs ("libaddonFieldFunctionObjects.so");
        log             true;
        writeControl    none;
        ...
        field           "phi.air";
        critWrite       true;
        criterion       0.5;
    }
    \endverbatim

Usage
    \table
        Property     | Description                    | Required| Default value
        type         | type name: addonCourantNo      | yes     |
        field        | flux field: phi or phi.*       | no      | "phi"
        rho          | density field                  | no      | "rho"
        critWrite    | switch for conditional write   | no      | false
        criterion    | critical value for writing out | no      | 0.5
        writeControl | writeControl options           | no      |
        result       | Name of the resulting field    | no    | derived from phi
    \endtable

See also
    Foam::functionObjects::CourantNo
    Foam::functionObject::fieldExpression
    Foam::functionObject

SourceFiles
    addonCourantNo.C

\*---------------------------------------------------------------------------*/

#ifndef functionObjects_addonCourantNo_H
#define functionObjects_addonCourantNo_H

#include "fieldExpression.H"
#include "volFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                        Class addonCourantNo Declaration
\*---------------------------------------------------------------------------*/

class addonCourantNo
:
    public fieldExpression
{
    // Private Data

        //- Name of density field (according to flux field)
        word rhoName_;

        //- Switch for autowrite according to Co criterion "critCo"
        bool critWrite_;

        //- CourantNo criterion, save conditionalCo if maximum is above critCo
        scalar critCo_;


    // Private Member Functions

        //- Divide the Courant number by rho if required
        tmp<volScalarField::Internal> byRho
        (
            const tmp<volScalarField::Internal>& Co
        ) const;

        //- Calculate the Courant number field and return true if successful
        virtual bool calc();


public:

    //- Runtime type information
    TypeName("addonCourantNo");


    // Constructors

        //- Construct from Time and dictionary
        addonCourantNo
        (
            const word& name,
            const Time&,
            const dictionary&
        );


    //- Destructor
    virtual ~addonCourantNo();


    // Member Functions

        //- Read the CourantNo data
        virtual bool read(const dictionary&);
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace functionObjects
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
