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

Description
    Kobayashi's methodology applied to structural sub-grid scale models.

    Reference
    \verbatim
        Kobayashi, H. (2018).
        Improvement of the SGS model by using a scale-similarity model based on
        the analysis of SGS force and SGS energy transfer.
        International Journal of Heat and Fluid Flow, 72, 329-336.
    \endverbatim

    Originally this methodology was applied to Clark's gradient model but can be
    applied to any structural LES model (struct).

    No equation for kSGS is solved. The prefactor of the second term is set to a
    constant value, Fk, which is zero by default. With Fk=0, the present model
    is identical as the one referred to as "LS" in the original reference. In
    contrast to the original formulation, the full sub-grid stress tensor of the
    underlying structural model is utilised including it's isotropical part.

    With Fk=1, the modified version of Klein et al. (2020), KKK1, is recovered.

    Reference:
    \verbatim
        Klein, M., Ketterl, S., Engelmann, L., Kempf, A., Kobayashi, H. (2020).
        Regularized, parameter free scale similarity type models for Large Eddy
        Simulation.
        International Journal of Heat and Fluid Flow, 81, 108496.
    \endverbatim

    The modeled sub-grid scale tensor is formulated as follows:
    \f[
        \mathbf{B} =
            F \mathbf{B}^\mathrm{struct}
          + F_k
            \left(
                \mathbf{B}^\mathrm{struct}
              + \frac{-\mathbf{B}^\mathrm{struct}:\mathbf{D}}
                {\mathbf{D} : \mathbf{D}} \mathbf{D}
            \right)
    \f]
    with
    \f[
        F =
        \begin{cases}
            2, \text{if}\ (- \mathbf{B}^{\mathrm{struct}} : \mathbf{D}) > 0 \\
            0, \text{otherwise}
        \end{cases} ,
    \f]
    \f[
        \mathbf{D} =
          \frac{1}{2}
          \left(\nabla\cdot\mathbf{u} + (\nabla\cdot\mathbf{u})^T\right) .
    \f]

SourceFiles
    KobayashiStructuralModel.C

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

#ifndef KobayashiStructuralModel_H
#define KobayashiStructuralModel_H

#include "typeInfo.H"
#include "volFieldsFwd.H"
#include "tmp.H"
#include "pureStructuralModel.H"

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

namespace Foam
{
namespace LESModels
{

/*---------------------------------------------------------------------------*\
                  Class KobayashiStructuralModel Declaration
\*---------------------------------------------------------------------------*/

template
<
    class BasicMomentumTransportModel,
    template<class> class StructuralMomentumTransportModel
>
class KobayashiStructuralModel
:
    public StructuralMomentumTransportModel<BasicMomentumTransportModel>
{
    // Private Data

        // Weighting factor for second term of model
        dimensionedScalar kFactor_;

        // Model constant for calculating nuSgs
        dimensionedScalar Ck_;


public:

    typedef BasicMomentumTransportModel BasicLinearViscousStress;
    typedef StructuralMomentumTransportModel<BasicLinearViscousStress>
        BasicStructural;

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


private:

    // Private Member Functions

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

        //- Getter for model coefficient
        virtual dimensionedScalar Ck() const
        {
            return Ck_;
        }


protected:

        //- Return the sub-grid stress tensor
        virtual tmp<volSymmTensorField> B
        (
            const rhoField& rho,
            const volVectorField& U
        ) const;


public:

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


    // Constructors

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


    //- Destructor
    virtual ~KobayashiStructuralModel()
    {}


    // Member Functions

        //- Return the effective stress
        virtual tmp<surfaceVectorField> devTau() const;

        //- Return the source term for the momentum equation
        virtual tmp<fvVectorMatrix> divDevTau(volVectorField& U) const;

        //- Return the source term for the momentum equation
        virtual tmp<fvVectorMatrix> divDevTau
        (
            const volScalarField& rho,
            volVectorField& U
        ) const;

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

        //- Read model coefficient
        virtual bool read();
};


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

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

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

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

#endif

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