multiphaseStabilizedTurbulence.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "fvMatrices.H"
31 #include "gravityMeshObject.H"
33 
34 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace fv
39 {
40  defineTypeNameAndDebug(multiphaseStabilizedTurbulence, 0);
42  (
43  option,
44  multiphaseStabilizedTurbulence,
45  dictionary
46  );
47 }
48 }
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const word& sourceName,
55  const word& modelType,
56  const dictionary& dict,
57  const fvMesh& mesh
58 )
59 :
60  fv::option(sourceName, modelType, dict, mesh),
61  rhoName_(coeffs_.getOrDefault<word>("rho", "rho")),
62  Cmu_
63  (
64  dimensionedScalar::getOrAddToDict
65  (
66  "Cmu",
67  coeffs_,
68  0.09
69  )
70  ),
71  C_
72  (
73  dimensionedScalar::getOrAddToDict
74  (
75  "C",
76  coeffs_,
77  1.51
78  )
79  ),
80  lambda2_
81  (
82  dimensionedScalar::getOrAddToDict
83  (
84  "lambda2",
85  coeffs_,
86  0.1
87  )
88  ),
89  alpha_
90  (
91  dimensionedScalar::getOrAddToDict
92  (
93  "alpha",
94  coeffs_,
95  1.36
96  )
97  )
98 {
99  fieldNames_.resize(2);
100 
101  // Note: incompressible only
102  const auto* turbPtr =
103  mesh_.findObject<incompressible::turbulenceModel>
104  (
105  turbulenceModel::propertiesName
106  );
107 
108  if (turbPtr)
109  {
110  const tmp<volScalarField>& tk = turbPtr->k();
111  fieldNames_[0] = tk().name();
112 
113  const tmp<volScalarField>& tnut = turbPtr->nut();
114  fieldNames_[1] = tnut().name();
115 
116  Log << " Applying model to " << fieldNames_[0]
117  << " and " << fieldNames_[1] << endl;
118  }
119  else
120  {
122  << "Unable to find incompressible turbulence model"
123  << exit(FatalError);
124  }
125 
126  fv::option::resetApplied();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 (
134  const volScalarField& rho,
135  fvMatrix<scalar>& eqn,
136  const label fieldi
137 )
138 {
139  // Not applicable to compressible cases
141 }
142 
143 
145 (
146  fvMatrix<scalar>& eqn,
147  const label fieldi
148 )
149 {
150  if (fieldi != 0)
151  {
152  return;
153  }
154 
155  Log << this->name() << ": applying buoyancy production term to "
156  << eqn.psi().name() << endl;
157 
158  // Buoyancy production in k eqn
159 
160  const auto* turbPtr =
161  mesh_.findObject<incompressible::turbulenceModel>
162  (
163  turbulenceModel::propertiesName
164  );
165 
166  if (!turbPtr)
167  {
169  << "Unable to find incompressible turbulence model"
170  << exit(FatalError);
171  }
172 
173 
174  tmp<volScalarField> tepsilon = turbPtr->epsilon();
175  const volScalarField& epsilon = tepsilon();
176  const volScalarField& k = eqn.psi();
177 
178  // Note: using solver density field for incompressible multiphase cases
179  const auto& rho = mesh_.lookupObject<volScalarField>(rhoName_);
180 
181  const auto& g = meshObjects::gravity::New(mesh_.time());
182 
183  const dimensionedScalar eps0("eps0", epsilon.dimensions(), SMALL);
184 
185  // Note: differing from reference by replacing nut/k by Cmu*k/epsilon
186  const volScalarField GbyK
187  (
188  "GbyK",
189  Cmu_*k/(epsilon + eps0)*alpha_*(g & fvc::grad(rho))/rho
190  );
191 
192  return eqn -= fvm::SuSp(GbyK, k);
193 }
194 
195 
197 {
198  if (field.name() != fieldNames_[1])
199  {
200  return;
201  }
202 
203  Log << this->name() << ": correcting " << field.name() << endl;
204 
205  const auto* turbPtr =
207  (
209  );
210 
211  // nut correction
212  const auto& U = turbPtr->U();
213  tmp<volScalarField> tepsilon = turbPtr->epsilon();
214  const auto& epsilon = tepsilon();
215  tmp<volScalarField> tk = turbPtr->k();
216  const auto& k = tk();
217 
218  tmp<volTensorField> tgradU = fvc::grad(U);
219  const auto& gradU = tgradU();
220  const dimensionedScalar pSmall("pSmall", dimless/sqr(dimTime), SMALL);
221  const volScalarField pRat
222  (
223  magSqr(symm(gradU))/(magSqr(skew(gradU)) + pSmall)
224  );
225 
226  const volScalarField epsilonTilde
227  (
228  max
229  (
230  epsilon,
231  lambda2_*C_*pRat*epsilon
232  )
233  );
234 
235  field = Cmu_*sqr(k)/epsilonTilde;
236  field.correctBoundaryConditions();
237 }
238 
239 
240 // ************************************************************************* //
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:84
Foam::fv::option::name
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:31
Log
#define Log
Definition: PDRblock.C:35
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::skew
dimensionedTensor skew(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:138
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
turbulentTransportModel.H
gravityMeshObject.H
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
Foam::fac::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:56
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
rho
rho
Definition: readInitialConditions.H:88
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:139
Foam::fam::SuSp
tmp< faMatrix< Type > > SuSp(const areaScalarField &sp, const GeometricField< Type, faPatchField, areaMesh > &vf)
Definition: famSup.C:151
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:126
Foam::fv::option::fieldNames_
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:148
Foam::fv::multiphaseStabilizedTurbulence::multiphaseStabilizedTurbulence
multiphaseStabilizedTurbulence(const word &sourceName, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from explicit source name and mesh.
Definition: multiphaseStabilizedTurbulence.C:53
field
rDeltaTY field()
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fvMatrix::psi
const GeometricField< Type, fvPatchField, volMesh > & psi(const label i=0) const
Return psi.
Definition: fvMatrix.H:399
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::fv::multiphaseStabilizedTurbulence::correct
virtual void correct(volScalarField &field)
Correct the turbulent viscosity.
Definition: multiphaseStabilizedTurbulence.C:196
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned< scalar >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:26
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
fv
labelList fv(nPoints)
U
U
Definition: pEqn.H:72
Foam::fv::multiphaseStabilizedTurbulence::addSup
virtual void addSup(const volScalarField &rho, fvMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible k equation.
Definition: multiphaseStabilizedTurbulence.C:133
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::objectRegistry::findObject
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:401
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:55
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
epsilon
scalar epsilon
Definition: evaluateNearWall.H:7
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField< scalar, fvPatchField, volMesh >
multiphaseStabilizedTurbulence.H
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189