dynamicKEqn.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "dynamicKEqn.H"
27 #include "fvModels.H"
28 #include "fvConstraints.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace LESModels
35 {
36 
37 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
38 
39 template<class BasicMomentumTransportModel>
42 {
43  return max
44  (
45  0.5*(filter_(magSqr(this->U_)) - magSqr(filter_(this->U_))),
47  );
48 }
49 
50 
51 template<class BasicMomentumTransportModel>
53 (
54  const volSymmTensorField& D,
55  const volScalarField& KK
56 ) const
57 {
58  const volSymmTensorField LL
59  (
60  simpleFilter_(dev(filter_(sqr(this->U_)) - (sqr(filter_(this->U_)))))
61  );
62 
63  const volSymmTensorField MM
64  (
65  simpleFilter_(-2.0*this->delta()*sqrt(KK)*filter_(D))
66  );
67 
68  const volScalarField Ck
69  (
70  simpleFilter_(0.5*(LL && MM))
71  /(
72  simpleFilter_(magSqr(MM))
73  + dimensionedScalar(sqr(MM.dimensions()), vSmall)
74  )
75  );
76 
77  tmp<volScalarField> tfld = 0.5*(mag(Ck) + Ck);
78  return tfld();
79 }
80 
81 
82 template<class BasicMomentumTransportModel>
84 (
85  const volSymmTensorField& D,
86  const volScalarField& KK
87 ) const
88 {
89  const volScalarField Ce
90  (
91  simpleFilter_(this->nuEff()*(filter_(magSqr(D)) - magSqr(filter_(D))))
92  /simpleFilter_(pow(KK, 1.5)/(2.0*this->delta()))
93  );
94 
95  tmp<volScalarField> tfld = 0.5*(mag(Ce) + Ce);
96  return tfld();
97 }
98 
99 
100 template<class BasicMomentumTransportModel>
102 {
103  const volSymmTensorField D(dev(symm(fvc::grad(this->U_))));
104  return Ce(D, KK());
105 }
106 
107 
108 template<class BasicMomentumTransportModel>
110 (
111  const volSymmTensorField& D,
112  const volScalarField& KK
113 )
114 {
115  this->nut_ = Ck(D, KK)*sqrt(k_)*this->delta();
116  this->nut_.correctBoundaryConditions();
117  fvConstraints::New(this->mesh_).constrain(this->nut_);
118 }
119 
120 
121 template<class BasicMomentumTransportModel>
123 {
124  correctNut(symm(fvc::grad(this->U_)), KK());
125 }
126 
127 
128 template<class BasicMomentumTransportModel>
130 {
131  return tmp<fvScalarMatrix>
132  (
133  new fvScalarMatrix
134  (
135  k_,
136  dimVolume*this->rho_.dimensions()*k_.dimensions()
137  /dimTime
138  )
139  );
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
144 
145 template<class BasicMomentumTransportModel>
147 (
148  const alphaField& alpha,
149  const rhoField& rho,
150  const volVectorField& U,
151  const surfaceScalarField& alphaRhoPhi,
152  const surfaceScalarField& phi,
153  const viscosity& viscosity,
154  const word& type
155 )
156 :
157  LESeddyViscosity<BasicMomentumTransportModel>
158  (
159  type,
160  alpha,
161  rho,
162  U,
163  alphaRhoPhi,
164  phi,
165  viscosity
166  ),
167 
168  k_
169  (
170  IOobject
171  (
172  this->groupName("k"),
173  this->runTime_.name(),
174  this->mesh_,
175  IOobject::MUST_READ,
176  IOobject::AUTO_WRITE
177  ),
178  this->mesh_
179  ),
180 
181  simpleFilter_(this->mesh_),
182  filterPtr_(LESfilter::New(this->mesh_, this->coeffDict())),
183  filter_(filterPtr_())
184 {
185  bound(k_, this->kMin_);
186 }
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
191 template<class BasicMomentumTransportModel>
193 {
195  {
196  filter_.read(this->coeffDict());
197 
198  return true;
199  }
200  else
201  {
202  return false;
203  }
204 }
205 
206 
207 template<class BasicMomentumTransportModel>
209 {
210  return volScalarField::New
211  (
212  this->groupName("epsilon"),
213  Ce()*k()*sqrt(k())/this->delta()
214  );
215 }
216 
217 
218 template<class BasicMomentumTransportModel>
220 {
221  if (!this->turbulence_)
222  {
223  return;
224  }
225 
226  // Local references
227  const alphaField& alpha = this->alpha_;
228  const rhoField& rho = this->rho_;
229  const surfaceScalarField& alphaRhoPhi = this->alphaRhoPhi_;
230  const volVectorField& U = this->U_;
231  volScalarField& nut = this->nut_;
232  const Foam::fvModels& fvModels(Foam::fvModels::New(this->mesh_));
234  (
235  Foam::fvConstraints::New(this->mesh_)
236  );
237 
239 
240  volScalarField divU(fvc::div(fvc::absolute(this->phi(), U)));
241 
243  const volSymmTensorField D(dev(symm(tgradU())));
244  const volScalarField G(this->GName(), 2.0*nut*(tgradU() && D));
245  tgradU.clear();
246 
247  const volScalarField KK(this->KK());
248 
250  (
251  fvm::ddt(alpha, rho, k_)
252  + fvm::div(alphaRhoPhi, k_)
253  - fvm::laplacian(alpha*rho*DkEff(), k_)
254  ==
255  alpha*rho*G
256  - fvm::SuSp((2.0/3.0)*alpha*rho*divU, k_)
257  - fvm::Sp(Ce(D, KK)*alpha*rho*sqrt(k_)/this->delta(), k_)
258  + kSource()
259  + fvModels.source(alpha, rho, k_)
260  );
261 
262  kEqn.ref().relax();
264  solve(kEqn);
266  bound(k_, this->kMin_);
267 
268  correctNut(D, KK);
269 }
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 } // End namespace LESModels
275 } // End namespace Foam
276 
277 // ************************************************************************* //
label k
scalar delta
const dimensionSet & dimensions() const
Return dimensions.
Generic GeometricField class.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Eddy viscosity LES SGS model base class.
BasicMomentumTransportModel::alphaField alphaField
Definition: dynamicKEqn.H:128
volScalarField Ce() const
Definition: dynamicKEqn.C:101
volScalarField Ck(const volSymmTensorField &D, const volScalarField &KK) const
Calculate Ck by filtering the velocity field U.
Definition: dynamicKEqn.C:53
virtual void correct()
Correct Eddy-Viscosity and related properties.
Definition: dynamicKEqn.C:219
virtual tmp< volScalarField > epsilon() const
Return sub-grid disipation rate.
Definition: dynamicKEqn.C:208
virtual tmp< fvScalarMatrix > kSource() const
Definition: dynamicKEqn.C:129
tmp< volScalarField > KK() const
Return the KK field obtained by filtering the velocity field U.
Definition: dynamicKEqn.C:41
dynamicKEqn(const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const viscosity &viscosity, const word &type=typeName)
Construct from components.
Definition: dynamicKEqn.C:147
virtual bool read()
Read model coefficients if they have changed.
Definition: dynamicKEqn.C:192
BasicMomentumTransportModel::rhoField rhoField
Definition: dynamicKEqn.H:129
One equation eddy-viscosity model.
Definition: kEqn.H:74
Abstract class for LES filters.
Definition: LESfilter.H:55
static autoPtr< dictionary > New(Istream &)
Construct top-level dictionary on freestore from Istream.
Definition: dictionaryIO.C:103
virtual void correct()=0
Solve the turbulence equations and correct the turbulence viscosity.
Finite volume constraints.
Definition: fvConstraints.H:67
bool constrain(fvMatrix< Type > &eqn) const
Apply constraints to an equation.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Finite volume models.
Definition: fvModels.H:65
tmp< fvMatrix< Type > > source(const VolField< Type > &field) const
Return source for an equation.
A class for managing temporary objects.
Definition: tmp.H:55
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:253
Abstract base class for all fluid physical properties.
Definition: viscosity.H:50
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvConstraints & fvConstraints(Foam::fvConstraints::New(mesh))
Foam::fvModels & fvModels(Foam::fvModels::New(mesh))
const scalar nut
const scalar nuEff
U
Definition: pEqn.H:72
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
const dimensionedScalar G
Newtonian constant of gravitation.
tmp< VolField< typename outerProduct< vector, Type >::type > > grad(const SurfaceField< Type > &ssf)
Definition: fvcGrad.C:46
tmp< VolField< Type > > div(const SurfaceField< Type > &ssf)
Definition: fvcDiv.C:47
tmp< surfaceScalarField > absolute(const tmp< surfaceScalarField > &tphi, const volVectorField &U)
Return the given relative flux in absolute form.
Definition: fvcMeshPhi.C:202
tmp< fvMatrix< Type > > laplacian(const VolField< Type > &vf, const word &name)
Definition: fvmLaplacian.C:47
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const VolField< Type > &vf, const word &name)
Definition: fvmDiv.C:48
tmp< fvMatrix< Type > > Sp(const volScalarField::Internal &, const VolField< Type > &)
tmp< fvMatrix< Type > > SuSp(const volScalarField::Internal &, const VolField< Type > &)
tmp< fvMatrix< Type > > ddt(const VolField< Type > &vf)
Definition: fvmDdt.C:46
static const coefficient D("D", dimTemperature, 257.14)
Namespace for OpenFOAM.
void dev(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
const dimensionSet dimTime
void symm(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
void pow(LagrangianPatchField< typename powProduct< Type, r >::type > &f, const LagrangianPatchField< Type > &f1)
const dimensionSet dimVolume
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
bool bound(volScalarField &, const dimensionedScalar &min)
Bound the given scalar field where it is below the specified min value.
Definition: bound.C:31
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const dimensionSet dimVelocity
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
SolverPerformance< Type > solve(fvMatrix< Type > &, const word &)
Solve returning the solution statistics given convergence tolerance.