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

Description
    Nicoud's sigma model.

    Reference:
    \verbatim
        Nicoud, F., Toda, H. B., Cabrit, O., Bose, S., & Lee, J. (2011).
        Using singular values to build a subgrid-scale model for large eddy
        simulations.
        Physics of Fluids, 23(8), 085106.
    \endverbatim

    The sub-grid turbulence kinetic energy is computed from the assumption of
    local equilibrium. From this a cubic equation arises. This one is solved
    under the assumption of incompressibility.

    \f[
        \mathbf{B} =
          \frac{2}{3}k\mathbf{I}
        - 2\,\nu_\mathrm{SGS}\,\mathit{dev}(\mathbf{D}) ,
    \f]
    where
    \f[
        \mathbf{D} =
          \frac{1}{2}
          \left(\nabla\cdot\mathbf{u} + (\nabla\cdot\mathbf{u})^T\right)
    \f]
    and
    \f[
        \nu_t = (C_\sigma \Delta)^2 D_\sigma ,
    \f]
    with
    \f[
        D_\sigma =
          \frac{\sigma_3(\sigma_1 - \sigma_2)(\sigma_2 - \sigma_3)}
               {\sigma_1^2} ,
    \f]
    \f[
        \sigma_1 \geq \sigma_2 \geq \sigma_3 = \sqrt{\mathit{Eig}(\mathbf{G})} ,
    \f]
    and
    \f[
        \mathbf{G} = (\nabla\cdot\mathbf{u})\cdot(\nabla\cdot\mathbf{u})^T .
    \f]

    Sub-grid scale turbulence dissipation rate and sub-grid scale turbulence
    kinetic energy are calculated as follows:
    \f[
        \varepsilon_\mathrm{SGS} = 2\nu_t \mathbf{D}^2 ,
    \f]
    \f[
        k_\mathrm{SGS} = \sqrt{\nu_t\frac{\varepsilon}{C_\varepsilon C_k}} .
    \f]

    The default model coefficients are
    \verbatim
        NicoudSigmaCoeffs
        {
            Ce                  1.048;
            Csigma              1.5;
            Ck                  0.094;
        }
    \endverbatim

SourceFiles
    NicoudSigma.C

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

#ifndef NicoudSigma_H
#define NicoudSigma_H

#include "LESModel.H"
#include "LESeddyViscosity.H"

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

namespace Foam
{
namespace LESModels
{

/*---------------------------------------------------------------------------*\
                         Class NicoudSigma Declaration
\*---------------------------------------------------------------------------*/

template<class BasicMomentumTransportModel>
class NicoudSigma
:
    public LESeddyViscosity<BasicMomentumTransportModel>
{
    // Private Member Functions

        // Disallow default bitwise copy construct and assignment
        NicoudSigma(const NicoudSigma&);
        void operator=(const NicoudSigma&);

        //- Return model specific shear velocity tensor
        //  calculated from the given velocity gradient
        tmp<volSymmTensorField> G(const tmp<volTensorField>& gradU) const;

        //- Return model specific shear velocity tensor
        tmp<volSymmTensorField> G() const
        {
            return G(fvc::grad(this->U_));
        }

        //- Return model specific differential operator
        //  calculated from the given shear velocity tensor
        tmp<volScalarField> Dsigma(const tmp<volSymmTensorField>& tG) const;

        //- Return model specific differential operator
        tmp<volScalarField> Dsigma() const
        {
            return Dsigma(G());
        }


protected:

    // Protected data

        dimensionedScalar Csigma_;


    // Protected Member Functions

        //- Update the SGS eddy viscosity
        virtual void correctNut();


public:

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


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


    // Constructors

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


    //- Destructor
    virtual ~NicoudSigma()
    {}


    // Member Functions

        //- Return SGS kinetic energy
        virtual tmp<volScalarField> k() const;

        //- Return sub-grid dissipation rate
        virtual tmp<volScalarField> epsilon() const;

        //- Return the turbulence specific dissipation rate
        virtual tmp<volScalarField> omega() const;

        //- Correct Eddy-Viscosity and related properties
        virtual void correct();

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


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

} // End namespace LESModels
} // End namespace Foam

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

#ifdef NoRepository
    #include "NicoudSigma.C"
#endif

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

#endif

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