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

Description
    Film-Euler transfer model

    FvModel for transferring mass, momentum and energy from the film region
    to a continuous phase in the multiphaseEuler region, based on local
    morphology criteria.

    The transfer occurs over a user-defined time scale and is triggered by
    a set of threshold parameters, including:
    - Maximum film thickness in the film region.
    - Minimum volume fraction of the target phase in the multiphaseEuler region.
    - Minimum combined film thickness (in film and multiphaseEuler regions).

Usage
    Example usage:
    \verbatim
    filmEulerTransfer
    {
        type    filmEulerTransfer;
        libs    ("libaddonFilmEulerTransfer.so");

        morphologyTransfer
        {
            timeScale              0.1;
            deltaFactorToEuler     1.5;
            alphaToEuler           0.9;
            totalDeltaToEuler      1.0;
        }
    }
    \endverbatim

Usage
    \table
        Property              | Description               | Required | Default
        type               | Type name: filmEulerTransfer | yes      |
        timeScale             | Transfer timescale        | yes      |
        deltaFactorToEuler    | Film thickness threshold  | no       | great
        alphaToEuler          | Volume fraction threshold | no       | great
        totalDeltaToEuler  | Combined thickness threshold | no       | great
    \endtable

SourceFiles
    filmEulerTransfer.C

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

#ifndef filmEulerTransfer_H
#define filmEulerTransfer_H

#include "fvModel.H"
#include "isothermalFilm.H"

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

namespace Foam
{
namespace fv
{

class EulerFilmTransfer;

/*---------------------------------------------------------------------------*\
                      Class filmEulerTransfer Declaration
\*---------------------------------------------------------------------------*/

class filmEulerTransfer
:
    public fvModel
{
    // Private Data

        //- The film model
        const solvers::isothermalFilm& film_;

        //- Current time index (used for updating)
        mutable label curTimeIndex_;

        //- Optional morphology transfer dictionary
        dictionary morphologyTransferDict_;

        //- Cached transfer rate
        volScalarField::Internal transferRate_;


    // Private Member Functions

        const EulerFilmTransfer& EulerFilm(const fvModels&) const;

        //- Return the transfer rate from the Euler transferRateFunc
        template<class Type, class TransferRateFunc>
        inline tmp<VolInternalField<Type>> EulerToFilmTransferRate
        (
            TransferRateFunc transferRateFunc,
            const dimensionSet& dimProp
        ) const;

        //- Return the transfer rate of field f
        template<class Type, class FieldType>
        inline tmp<Field<Type>> TransferRate(const FieldType& f) const;


public:

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


    // Constructors

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

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


    // Member Functions

        // Checks

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


        // Correct

            //- Solve the film and update the sources
            virtual void correct();


        // Sources

            //- Add source to phase continuity equation
            virtual void addSup
            (
                const volScalarField& rho,
                const volScalarField& alpha,
                fvMatrix<scalar>& eqn
            ) const;

            //- Add source to phase energy equation
            virtual void addSup
            (
                const volScalarField& alpha,
                const volScalarField& rho,
                const volScalarField& he,
                fvMatrix<scalar>& eqn
            ) const;

            //- Add source to mixture momentum equation
            virtual void addSup
            (
                const volScalarField& alpha,
                const volScalarField& rho,
                const volVectorField& U,
                fvMatrix<vector>& eqn
            ) const;


        // Transfer to Euler

            //- Return the volume transfer rate
            tmp<scalarField> transferRate() const;

            //- Return the mass transfer rate
            tmp<scalarField> rhoTransferRate() const;

            //- Return the energy transfer rate
            tmp<scalarField> heTransferRate() const;

            //- Return the momentum transfer rate
            tmp<vectorField> UTransferRate() 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 filmEulerTransfer&) = delete;
};


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

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

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

#endif

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