RASModel.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) 2013-2026 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 "RASModel.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class BasicMomentumTransportModel>
33 (
34  const word& type,
35  const alphaField& alpha,
36  const rhoField& rho,
37  const volVectorField& U,
38  const surfaceScalarField& alphaRhoPhi,
39  const surfaceScalarField& phi,
40  const viscosity& viscosity
41 )
42 :
43  BasicMomentumTransportModel
44  (
45  type,
46  alpha,
47  rho,
48  U,
49  alphaRhoPhi,
50  phi,
51  viscosity
52  ),
53 
54  turbulence_(RASDict().template lookupOrDefault<Switch>("turbulence", true)),
55  kMin_("kMin", sqr(dimVelocity), RASDict(), small),
56  nutMaxCoeff_("nutMaxCoeff", dimless, RASDict(), 1e5),
57 
58  viscosityModel_
59  (
60  typeDict(type).found("viscosityModel")
61  ? laminarModels::generalisedNewtonianViscosityModel::New
62  (
63  typeDict(type),
64  viscosity,
65  U
66  )
67  : autoPtr<laminarModels::generalisedNewtonianViscosityModel>
68  (
69  new laminarModels::generalisedNewtonianViscosityModels::Newtonian
70  (
71  typeDict(type),
72  viscosity,
73  U
74  )
75  )
76  )
77 {
78  // Force the construction of the mesh deltaCoeffs which may be needed
79  // for the construction of the derived models and BCs
80  this->mesh_.deltaCoeffs();
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
85 
86 template<class BasicMomentumTransportModel>
89 (
90  const alphaField& alpha,
91  const rhoField& rho,
92  const volVectorField& U,
93  const surfaceScalarField& alphaRhoPhi,
94  const surfaceScalarField& phi,
95  const viscosity& viscosity
96 )
97 {
98  const IOdictionary dict
99  (
101  (
102  U.db(),
103  alphaRhoPhi.group()
104  )
105  );
106 
107  const dictionary& RASdict(dict.subDict("RAS"));
108 
109  const word modelType = RASdict.lookupBackwardsCompatible<word>
110  (
111  {"model", "RASModel"}
112  );
113 
114  Info<< indentOrNl
115  << "Selecting RAS turbulence model " << modelType << endl;
116 
117  libs.open(RASdict, "libs", dictionaryConstructorTablePtr_);
118 
119  typename dictionaryConstructorTable::iterator cstrIter =
120  dictionaryConstructorTablePtr_->find(modelType);
121 
122  if (cstrIter == dictionaryConstructorTablePtr_->end())
123  {
125  << "Unknown RASModel type "
126  << modelType << nl << nl
127  << "Valid RASModel types:" << endl
128  << dictionaryConstructorTablePtr_->sortedToc()
129  << exit(FatalError);
130  }
131 
132  printDictionary print
133  (
134  RASdict.name(),
135  RASdict.optionalTypeDict(modelType).name()
136  );
137 
138  return cstrIter()(alpha, rho, U, alphaRhoPhi, phi, viscosity);
139 }
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
144 template<class BasicMomentumTransportModel>
145 const Foam::dictionary&
147 {
148  return this->subDict("RAS");
149 }
150 
151 
152 template<class BasicMomentumTransportModel>
153 const Foam::dictionary&
155 {
156  return typeDict(this->type());
157 }
158 
159 
160 template<class BasicMomentumTransportModel>
161 const Foam::dictionary&
163 {
164  return this->RASDict().optionalTypeDict(type);
165 }
166 
167 
168 template<class BasicMomentumTransportModel>
170 {
172  {
173  turbulence_.readIfPresent("turbulence", RASDict());
174  kMin_.readIfPresent(RASDict());
175  nutMaxCoeff_.readIfPresent(RASDict());
176 
177  return true;
178  }
179  else
180  {
181  return false;
182  }
183 }
184 
185 
186 template<class BasicMomentumTransportModel>
188 {
189  viscosityModel_->correct();
191 }
192 
193 
194 // ************************************************************************* //
bool found
Generic GeometricField class.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
static word group(const word &name)
Return group (extension part of name)
Definition: IOobject.C:131
BasicMomentumTransportModel::alphaField alphaField
Definition: RASModel.H:90
static autoPtr< RASModel > New(const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const viscosity &viscosity)
Return a reference to the selected RAS model.
Definition: RASModel.C:89
virtual void correct()
Solve the turbulence equations and correct the turbulence viscosity.
Definition: RASModel.C:187
const dictionary & typeDict() const
Const access to the coefficients dictionary.
Definition: RASModel.C:154
RASModel(const word &type, const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const viscosity &viscosity)
Construct from components.
Definition: RASModel.C:33
const dictionary & RASDict() const
Const access to the RAS dictionary.
Definition: RASModel.C:146
virtual bool read()
Read model coefficients if they have changed.
Definition: RASModel.C:169
BasicMomentumTransportModel::rhoField rhoField
Definition: RASModel.H:91
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:778
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:680
const dictionary & optionalTypeDict(const word &typeName) const
Find and return an optional type sub-dictionary.
Definition: dictionary.C:921
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
static typeIOobject< IOdictionary > readModelDict(const objectRegistry &obr, const word &group, bool registerObject=false)
Enables the printing of a dictionary and subsequently looked-up defaulted entries.
Abstract base class for all fluid physical properties.
Definition: viscosity.H:50
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
U
Definition: pEqn.H:72
rho
Definition: pEqn.H:1
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
void correct(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiCorr, const SpType &Sp)
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
const dimensionSet dimless
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
const dimensionSet & dimVelocity
Definition: dimensions.C:154
Ostream & indentOrNl(Ostream &os)
Indent stream or add newline if indent level == 0.
Definition: Ostream.H:250
error FatalError
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
Info<< "Reading field U\n"<< endl;volVectorField U(IOobject("U", runTime.name(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);Info<< "Creating face flux\n"<< endl;surfaceScalarField phi(IOobject("phi", runTime.name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), mesh, dimensionedScalar(mesh.Sf().dimensions() *U.dimensions(), 0));autoPtr< viscosityModel > viscosity(viscosityModel::New(mesh))