/*---------------------------------------------------------------------------*\
  ==  == ====== ====   ====    |
                    \\     ||  | 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::fv::addonPhaseTurbulenceStabilisation

Description
    Phase turbulence stabilisation

    In contrast to the original implementation of phase turbulence
    stabilisation, the field contribution is not derived from momentum transport
    models of foreign phases but instead a residual contribution is added to
    the according turbulence fields in case of phase inversion.

Usage
    Example usage:
    \verbatim
    addonPhaseTurbulenceStabilisation
    {
        type    addonPhaseTurbulenceStabilisation;

        libs    ("libaddonMultiphaseEulerFvModels.so");

        phase   air;
    }
    \endverbatim

SourceFiles
    addonPhaseTurbulenceStabilisation.C

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

#ifndef addonPhaseTurbulenceStabilisation_H
#define addonPhaseTurbulenceStabilisation_H

#include "fvModel.H"
#include "phaseModel.H"
#include "phaseCompressibleMomentumTransportModel.H"

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

namespace Foam
{
namespace fv
{

/*---------------------------------------------------------------------------*\
              Class addonPhaseTurbulenceStabilisation Declaration
\*---------------------------------------------------------------------------*/

class addonPhaseTurbulenceStabilisation
:
    public fvModel
{
    // Private Data

        //- The name of the phase
        word phaseName_;

        //- Field names
        wordList fieldNames_;

        //- Reference to the phase
        const phaseModel& phase_;

        //- Reference to the mixture turbulence model
        const phaseCompressible::momentumTransportModel& turbulence_;


    // Private Member Functions

        //- Add contribution to phase psi equation
        template<class Type>
        void addAlphaRhoSup
        (
            const volScalarField& alpha,
            const volScalarField& rho,
            const VolField<Type>& field,
            fvMatrix<Type>& eqn,
            tmp<VolField<Type>>
            (phaseCompressible::momentumTransportModel::*psi)() const
        ) const;


public:

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


    // Constructors

        //- Construct from explicit source name and mesh
        addonPhaseTurbulenceStabilisation
        (
            const word& sourceName,
            const word& modelType,
            const fvMesh& mesh,
            const dictionary& dict
        );

        //- Disallow default bitwise copy construction
        addonPhaseTurbulenceStabilisation
        (
            const addonPhaseTurbulenceStabilisation&
        ) = delete;


    // Member Functions

        // Checks

            //- Return the list of fields for which the option adds source term
            //  to the transport equation
            virtual wordList addSupFields() const;


        // Sources

            //- Add contribution to phase k, epsilon or omega equation
            virtual void addSup
            (
                const volScalarField& alpha,
                const volScalarField& rho,
                const volScalarField& field,
                fvMatrix<scalar>& eqn
            ) const;

            //- Add contribution to phase R equation
            virtual void addSup
            (
                const volScalarField& alpha,
                const volScalarField& rho,
                const volSymmTensorField& field,
                fvMatrix<symmTensor>& eqn
            ) const;


        // Mesh changes

            //- Update topology using the given map
            virtual void topoChange(const polyTopoChangeMap&);

            //- Update from another mesh using the given map
            virtual void mapMesh(const polyMeshMap&);

            //- Redistribute or update using the given distribution map
            virtual void distribute(const polyDistributionMap&);

            //- Update for mesh motion
            virtual bool movePoints();


    // Member Operators

        //- Disallow default bitwise assignment
        void operator=(const addonPhaseTurbulenceStabilisation&) = delete;
};


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

} // End namespace fv
} // End namespace Foam

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

#endif

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