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

Description
    Calculates and applies source terms for turbulent kinetic energy or Reynolds
    stress tensor and dissipation rate or eddy frequency according to the
    selected momentum transport model. When applied to a momentum transport
    model of Reynolds stress transport type, the switch
    'isotropicReynoldsStress' (default true) controls, if the source is added in
    an isotropic or and anisotropic manner.

Usage
    Example usage:
    \verbatim
    inducedTurbulence
    {
        type                    inducedTurbulence;

        libs                    ("libaddonMultiphaseEulerFvModels.so");

        phase                   water;
        dispersedPhases         ( air );
        isotropicReynoldsStress true;
        model                   Ma;
    }
    \endverbatim

SourceFiles
    inducedTurbulence.C

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

#ifndef inducedTurbulence_H
#define inducedTurbulence_H

#include "fvModel.H"
#include "inducedTurbulenceModel.H"
#include "dispersedPhaseInterface.H"
#include "blendingMethod.H"

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

namespace Foam
{
namespace fv
{

/*---------------------------------------------------------------------------*\
                    Class inducedTurbulence Declaration
\*---------------------------------------------------------------------------*/

class inducedTurbulence
:
    public fvModel
{
    // Private data

        //- The name of the phase
        word phaseName_;

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

        //- List of dispersed phases
        const wordList dispersedPhaseNames_;

        //- List of dispersed phase interfaces
        UPtrList<dispersedPhaseInterface> interfaces_;

        //- Blending methods
        PtrList<blendingMethod> blendingMethods_;

        //- List of induced turbulence models
        UPtrList<inducedTurbulenceModel> inducedTurbulenceModels_;

        //- List of phase fraction field combinations for blending
        UPtrList<const volScalarField> alphas_;

        //- Field names
        wordList fieldNames_;

        //- Isotropic Reynolds stress switch
        const Switch isotropicRSource_;

        //- Reference to continuous phase turbulence model
        const phaseCompressible::momentumTransportModel& turbulence_;


public:

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


    // Constructors

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

        //- Disallow default bitwise copy construction
        inducedTurbulence
        (
            const inducedTurbulence&
        ) = 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 volScalarField& field,
                fvMatrix<symmTensor>& eqn
            ) const;

            // Blending

                //- Compute blending factor taking phase order into account
                virtual tmp<volScalarField> blendingFactor
                (
                    label
                ) 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();
};


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

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

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

#endif

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