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

Description
    Modification of the k-omega-SST turbulence model to account for
    low-Reynolds number incompressible flows according to Langtry &
    Sjolander (2002).

    \verbatim
        Langtry, R., & Sjolander, S. (2002).
        Prediction of transition for attached and separated shear layers in
        turbomachinery.
        In 38th AIAA/ASME/SAE/ASEE Joint Propulsion Conference & Exhibit
        (p. 3641).
    \endverbatim

    Note that equations (10) onwards are not considered in this
    implementation. A factor alphaStarOne() was identified to be missing in
    equation (8) and has been included from reference 9.

    The default model coefficients are
    \verbatim
        kOmegaSSTLangtrySjolanderCoeffs
        {
            alphaK1     0.85;
            alphaK2     1.0;
            alphaOmega1 0.5;
            alphaOmega2 0.856;
            alpha0      0.1;
            alphaStar0  0.025;
            alpha2      0.4404;
            beta1       0.075;
            beta2       0.0828;
            betaStar2   0.09;
            alphaStar2  1.0;
            RBeta       8.0;
            RK          6.0;
            ROmega      2.7;
            a1          0.31;
            b1          1.0;
            c1          10.0;
            F3          no;
        }
    \endverbatim

SeeAlso
    Foam::kOmegaSSTBase

SourceFiles
    kOmegaSSTLangtrySjolander.C

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

#ifndef kOmegaSSTLangtrySjolanderBase_H
#define kOmegaSSTLangtrySjolanderBase_H

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

namespace Foam
{

/*---------------------------------------------------------------------------*\
                  Class kOmegaSSTLangtrySjolander Declaration
\*---------------------------------------------------------------------------*/

template<class MomentumTransportModel, class BasicMomentumTransportModel>
class kOmegaSSTLangtrySjolander
:
    public MomentumTransportModel
{
protected:

    // Protected data

        // Model coefficients

            dimensionedScalar alphaK1_;
            dimensionedScalar alphaK2_;

            dimensionedScalar alphaOmega1_;
            dimensionedScalar alphaOmega2_;

            dimensionedScalar alpha0_;
            dimensionedScalar alphaStar0_;
            dimensionedScalar alpha2_;

            dimensionedScalar beta1_;
            dimensionedScalar beta2_;

            dimensionedScalar betaStar2_;
            dimensionedScalar alphaStar2_;

            dimensionedScalar RBeta_;
            dimensionedScalar RK_;
            dimensionedScalar ROmega_;

            dimensionedScalar a1_;
            dimensionedScalar b1_;
            dimensionedScalar c1_;

            Switch F3_;


        // Fields

            //- Wall distance
            //  Note: different to wall distance in parent RASModel
            //  which is for near-wall cells only
            const volScalarField& y_;

            volScalarField k_;
            volScalarField omega_;


    // Protected Member Functions

        virtual tmp<volScalarField> ReT() const;
        virtual tmp<volScalarField> alphaStarOne() const;
        virtual tmp<volScalarField> alphaOne() const;
        virtual tmp<volScalarField> betaStarOne() const;

        virtual tmp<volScalarField> F1(const volScalarField& CDkOmega) const;
        virtual tmp<volScalarField> F2() const;
        virtual tmp<volScalarField> F3() const;
        virtual tmp<volScalarField> F23() const;

        tmp<volScalarField> blend
        (
            const volScalarField& F1,
            const dimensionedScalar& psi1,
            const dimensionedScalar& psi2
        ) const
        {
            return F1*(psi1 - psi2) + psi2;
        }

        tmp<volScalarField::Internal> blend
        (
            const volScalarField::Internal& F1,
            const dimensionedScalar& psi1,
            const dimensionedScalar& psi2
        ) const
        {
            return F1*(psi1 - psi2) + psi2;
        }

        tmp<volScalarField> blend
        (
            const volScalarField& F1,
            const volScalarField& psi1,
            const dimensionedScalar& psi2
        ) const
        {
            return F1*(psi1 - psi2) + psi2;
        }

        tmp<volScalarField::Internal> blend
        (
            const volScalarField::Internal& F1,
            const volScalarField::Internal& psi1,
            const dimensionedScalar& psi2
        ) const
        {
            return F1*(psi1 - psi2) + psi2;
        }

        tmp<volScalarField> alphaK(const volScalarField& F1) const
        {
            return blend(F1, alphaK1_, alphaK2_);
        }

        tmp<volScalarField> alphaOmega(const volScalarField& F1) const
        {
            return blend(F1, alphaOmega1_, alphaOmega2_);
        }

        tmp<volScalarField::Internal> beta
        (
            const volScalarField::Internal& F1
        ) const
        {
            return blend(F1, beta1_, beta2_);
        }

        tmp<volScalarField::Internal> betaStar
        (
            const volScalarField::Internal& F1
        ) const
        {
            return blend(F1, betaStarOne(), betaStar2_);
        }

        tmp<volScalarField> alphaStar
        (
            const volScalarField& F1
        ) const
        {
            return blend(F1, alphaStarOne(), alphaStar2_);
        }

        tmp<volScalarField> gamma
        (
            const volScalarField& F1
        ) const
        {
            return blend(F1, alphaOne(), alpha2_);
        }

        //- Bound omega
        void boundOmega();

        virtual void correctNut
        (
            const volScalarField& S2,
            const volScalarField& F2,
            const volScalarField& F1
        );

        virtual void correctNut();

        //- Return k production rate
        virtual tmp<volScalarField::Internal> Pk
        (
            const volScalarField::Internal& G,
            const volScalarField::Internal& F1
        ) const;

        //- Return epsilon/k which for standard RAS is betaStar*omega
        virtual tmp<volScalarField::Internal> epsilonByk
        (
            const volScalarField::Internal& F1,
            const volScalarField::Internal& F2
        ) const;

        virtual tmp<fvScalarMatrix> kSource() const;

        virtual tmp<fvScalarMatrix> omegaSource() const;

        virtual tmp<fvScalarMatrix> Qsas
        (
            const volScalarField::Internal& S2,
            const volScalarField::Internal& gamma,
            const volScalarField::Internal& beta
        ) const;


public:

    typedef typename BasicMomentumTransportModel::alphaField alphaField;
    typedef typename BasicMomentumTransportModel::rhoField rhoField;


    // Constructors

        //- Construct from components
        kOmegaSSTLangtrySjolander
        (
            const word& type,
            const alphaField& alpha,
            const rhoField& rho,
            const volVectorField& U,
            const surfaceScalarField& alphaRhoPhi,
            const surfaceScalarField& phi,
            const viscosity& viscosity
        );

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


    //- Destructor
    virtual ~kOmegaSSTLangtrySjolander()
    {}


    // Member Functions

        //- Re-read model coefficients if they have changed
        virtual bool read();

        //- Return the effective diffusivity for k
        tmp<volScalarField> DkEff(const volScalarField& F1) const
        {
            return volScalarField::New
            (
                "DkEff",
                alphaK(F1)*this->nut_ + this->nu()
            );
        }

        //- Return the effective diffusivity for omega
        tmp<volScalarField> DomegaEff(const volScalarField& F1) const
        {
            return volScalarField::New
            (
                "DomegaEff",
                alphaOmega(F1)*this->nut_ + this->nu()
            );
        }

        //- Return the turbulence kinetic energy
        virtual tmp<volScalarField> k() const
        {
            return k_;
        }

        //- Return the turbulence kinetic energy dissipation rate
        virtual tmp<volScalarField> epsilon() const;

        //- Return the turbulence eddy frequency
        virtual tmp<volScalarField> omega() const
        {
            return omega_;
        }

        //- Solve the turbulence equations and correct the turbulence viscosity
        virtual void correct();


    // Member Operators

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


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

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
    #include "kOmegaSSTLangtrySjolanderBase.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

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