RASModelVariables.H
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) 2007-2019, 2022-2023 PCOpt/NTUA
9  Copyright (C) 2013-2019, 2022-2023 FOSS GP
10  Copyright (C) 2019-2020 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 Class
29  Foam::incompressible::RASModelVariables
30 
31 Description
32  Abstract base class for objective functions. No point in making this
33  runTime selectable since its children will have different constructors.
34 
35 SourceFiles
36  RASModelVariables.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef RASModelVariables_H
41 #define RASModelVariables_H
42 
43 #include "solverControl.H"
46 #include "runTimeSelectionTables.H"
47 #include "refPtr.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 namespace incompressible
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class RASModelVariables Declaration
58 \*---------------------------------------------------------------------------*/
59 
61 {
62 protected:
63 
64  // Protected Data
65 
66  const fvMesh& mesh_;
68 
69  // Base names of the turbulent fields
73 
78 
79  // Initial values (demand-driven)
80  // For finite differences and optimisation runs
84 
85  // Mean values (demand-driven)
89 
90 
91  // Protected Member functions
92 
93  virtual void allocateInitValues();
94  virtual void allocateMeanFields();
95 
97  cloneRefPtr(const refPtr<volScalarField>& obj) const;
98 
100 
101  //- No copy assignment
102  void operator=(const RASModelVariables&) = delete;
103 
104 
105 public:
106 
107 
108  //- Runtime type information
109  TypeName("RASModelVariables");
110 
111  // Declare run-time constructor selection table
112 
114  (
115  autoPtr,
117  dictionary,
118  (
119  const fvMesh& mesh,
120  const solverControl& SolverControl
121  ),
122  (mesh, SolverControl)
123  );
124 
125 
126  // Constructors
127 
128  //- Construct from components
130  (
131  const fvMesh& mesh,
132  const solverControl& SolverControl
133  );
134 
135  //- Copy constructor
136  // Will allocate new fields (instead of referencing the ones in the
137  // turbulence model), so cannot be used directly to access the fields
138  // of the turbulence model.
139  // Mainly used for checkpointing in unsteady adjoint
141  (
142  const RASModelVariables& rmv
143  );
144 
145  //- Clone
146  // Will allocate new fields (instead of referencing the ones in the
147  // turbulence model), so cannot be used directly to access the fields
148  // of the turbulence model.
149  // Mainly used for checkpointing in unsteady adjoint
151 
152 
153  // Selectors
154 
155  //- Return a reference to the selected turbulence model
157  (
158  const fvMesh& mesh,
159  const solverControl& SolverControl
160  );
161 
162 
163  // Destructor
164 
165  // Destructor does nothing on base since depending on the case new
166  // fields might be allocated
167  // MUST be overloaded in inherited classes
168  virtual ~RASModelVariables() = default;
169 
170 
171  // Member Functions
172 
173  //- Turbulence field names
174  inline const word& TMVar1BaseName() const;
175  inline const word& TMVar2BaseName() const;
176  inline const word& nutBaseName() const;
177 
178  //- Bools to identify which turbulent fields are present
179  inline virtual bool hasTMVar1() const;
180  inline virtual bool hasTMVar2() const;
181  inline virtual bool hasNut() const;
182  inline bool hasDist() const;
183 
184  //- Return references to turbulence fields
185  // will return the mean field if it exists, otherwise the
186  // instantaneous one
187  inline const volScalarField& TMVar1() const;
188  inline volScalarField& TMVar1();
189  inline const volScalarField& TMVar2() const;
190  inline volScalarField& TMVar2();
191  inline const volScalarField& nutRef() const;
192  inline volScalarField& nutRef();
193  inline tmp<volScalarField> nut() const;
194  inline const volScalarField& d() const;
195  inline volScalarField& d();
196 
197  inline tmp<scalarField> TMVar1(const label patchi) const;
198  inline tmp<scalarField> TMVar2(const label patchi) const;
199  inline tmp<scalarField> nut(const label patchi) const;
200  inline tmp<fvPatchScalarField> nutPatchField(const label patchi) const;
201 
202  //- Return references to instantaneous turbulence fields
203  inline const volScalarField& TMVar1Inst() const;
204  inline volScalarField& TMVar1Inst();
205  inline const volScalarField& TMVar2Inst() const;
206  inline volScalarField& TMVar2Inst();
207  inline const volScalarField& nutRefInst() const;
208  inline volScalarField& nutRefInst();
209 
210 
211  //- Return nut Jacobian wrt the TM vars
213  (
215  ) const;
216 
218  (
220  ) const;
221 
222  //- Return the turbulence production term
224  {
226  return nullptr;
227  }
228 
229  //- Restore turbulent fields to their initial values
230  void restoreInitValues();
231 
232  //- Reset mean fields to zero
233  void resetMeanFields();
234 
235  //- Compute mean fields on the fly
236  virtual void computeMeanFields();
237 
238  //- Return stress tensor based on the mean flow variables
240  (
242  const volVectorField& U
243  ) const;
244 
245  //- correct bounday conditions of turbulent fields
246  virtual void correctBoundaryConditions
247  (
249  );
250 
251  //- Transfer turbulence fields from an another object
252  // Copies values since the ownership of the original fields is held
253  // by the turbulence model
254  virtual void transfer(RASModelVariables& rmv);
255 };
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace incompressible
261 } // End namespace Foam
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #include "RASModelVariablesI.H"
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************************************************************* //
TypeName("RASModelVariables")
Runtime type information.
void operator=(const RASModelVariables &)=delete
No copy assignment.
refPtr< volScalarField > cloneRefPtr(const refPtr< volScalarField > &obj) const
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const volScalarField & TMVar1Inst() const
Return references to instantaneous turbulence fields.
virtual tmp< volScalarField > nutJacobianVar2(const singlePhaseTransportModel &laminarTransport) const
virtual tmp< volScalarField > nutJacobianVar1(const singlePhaseTransportModel &laminarTransport) const
Return nut Jacobian wrt the TM vars.
const volScalarField & TMVar2() const
const volScalarField & d() const
virtual void transfer(RASModelVariables &rmv)
Transfer turbulence fields from an another object.
const volScalarField & nutRef() const
virtual bool hasTMVar1() const
Bools to identify which turbulent fields are present.
tmp< fvPatchScalarField > nutPatchField(const label patchi) const
virtual tmp< volScalarField::Internal > G()
Return the turbulence production term.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
static autoPtr< RASModelVariables > New(const fvMesh &mesh, const solverControl &SolverControl)
Return a reference to the selected turbulence model.
Templated abstract base class for single-phase incompressible turbulence models.
singlePhaseTransportModel laminarTransport(U, phi)
dynamicFvMesh & mesh
declareRunTimeSelectionTable(autoPtr, RASModelVariables, dictionary,(const fvMesh &mesh, const solverControl &SolverControl),(mesh, SolverControl))
RASModelVariables(const fvMesh &mesh, const solverControl &SolverControl)
Construct from components.
A class for handling words, derived from Foam::string.
Definition: word.H:63
void resetMeanFields()
Reset mean fields to zero.
Base class for solver control classes.
Definition: solverControl.H:45
const volScalarField & TMVar1() const
Return references to turbulence fields.
void restoreInitValues()
Restore turbulent fields to their initial values.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
const word & TMVar1BaseName() const
Turbulence field names.
void copyAndRename(volScalarField &f1, volScalarField &f2)
Info<< "Reading field U\"<< endl;volVectorField U(IOobject("U", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);volScalarField rho(IOobject("rho", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), thermo.rho());volVectorField rhoU(IOobject("rhoU", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), rho *U);volScalarField rhoE(IOobject("rhoE", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), rho *(e+0.5 *magSqr(U)));surfaceScalarField pos(IOobject("pos", runTime.timeName(), mesh), mesh, dimensionedScalar("pos", dimless, 1.0));surfaceScalarField neg(IOobject("neg", runTime.timeName(), mesh), mesh, dimensionedScalar("neg", dimless, -1.0));surfaceScalarField phi("phi", fvc::flux(rhoU));Info<< "Creating turbulence model\"<< endl;autoPtr< compressible::turbulenceModel > turbulence(compressible::turbulenceModel::New(rho, U, phi, thermo))
Definition: createFields.H:94
const volScalarField & TMVar2Inst() const
const volScalarField & nutRefInst() const
U
Definition: pEqn.H:72
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
autoPtr< RASModelVariables > clone() const
Clone.
tmp< volSymmTensorField > devReff(const singlePhaseTransportModel &laminarTransport, const volVectorField &U) const
Return stress tensor based on the mean flow variables.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A simple single-phase transport model based on viscosityModel.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
virtual void correctBoundaryConditions(const incompressible::turbulenceModel &turbulence)
correct bounday conditions of turbulent fields
Namespace for OpenFOAM.
virtual void computeMeanFields()
Compute mean fields on the fly.