variablesSet.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 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019 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::variablesSet
30 
31 Description
32  Base class for creating a set of variables
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef variablesSet_H
37 #define variablesSet_H
38 
39 #include "fvMesh.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class variablesSet Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class variablesSet
51 {
52 private:
53 
54  // Private Member Functions
55 
56  //- No copy construct
57  variablesSet(const variablesSet&) = delete;
58 
59  //- No copy assignment
60  void operator=(const variablesSet&) = delete;
61 
62  //- Add the solverName to every patch entry read from the boundaryField
63  //- of the IOobject and allocate the corresponding GeometricField.
64  //- Used to pass the adjoint solver name to the adjoint boundary
65  //- conditions.
66  // Returns naked pointer but used only to feed autoPtrs and tmps,
67  // so memory handling shouldn't be an issue
68  template<class Type, template<class> class PatchField, class GeoMesh>
69  static GeometricField<Type, PatchField, GeoMesh>* allocateNamedField
70  (
71  const fvMesh& mesh,
72  const IOobject& io,
73  const word& solverName
74  );
75 
76  //- Read field with base or custom field name
77  template<class Type, template<class> class PatchField, class GeoMesh>
78  static bool readFieldOK
79  (
81  const fvMesh& mesh,
82  const word& baseName,
83  const word& solverName,
84  const bool useSolverNameForFields
85  );
86 
87 
88 protected:
89 
90  // Protected data
91 
92  //- Reference to the mesh database
93  fvMesh& mesh_;
94 
95  //- Solver name owning the variables set
97 
98  //- Append the solver name to the variables names?
100 
101 
102  // Protected Member Functions
103 
104  template<class Type, template<class> class PatchField, class GeoMesh>
106  (
108  );
109 
110  //- Swap autoPtrs and rename managed fields
111  template<class Type, template<class> class PatchField, class GeoMesh>
112  void swapAndRename
113  (
116  );
117 
118 
119 public:
120 
121 
122  // Static Data Members
123 
124  //- Run-time type information
125  TypeName("variablesSet");
126 
127 
128  // Constructors
129 
130  //- Construct from mesh and solver name
132  (
133  fvMesh& mesh,
134  const dictionary& dict
135  );
136 
137  //- Clone the variablesSet
138  // Not implemented in base. Should be overloaded in derived classes
139  virtual autoPtr<variablesSet> clone() const;
140 
141 
142  //- Destructor
143  virtual ~variablesSet() = default;
144 
145 
146  // Member Functions
147 
148  // Access
149 
150  //- Return solver name
151  const word& solverName() const;
152 
153  //- Append solver name to fields?
154  bool useSolverNameForFields() const;
155 
156  // Set functions. Static in order to be used by other classes as well
157 
158  //- Read vol fields
159  template<class Type>
160  static void setField
161  (
163  const fvMesh& mesh,
164  const word& baseName,
165  const word& solverName,
166  const bool useSolverNameForFields
167  );
168 
169  template<class Type>
171  (
172  const fvMesh& mesh,
173  const word& baseName,
174  const word& solverName,
175  const bool useSolverNameForFields
176  );
177 
178  //- Turbulence model always reads fields with the prescribed name
179  //- If a custom name is supplied, check whether this field exists,
180  //- copy it to the field known by the turbulence model
181  //- and re-name the latter
182  template<class Type>
184  (
186  const word& solverName
187  );
188 
189  //- Set flux field
190  static void setFluxField
191  (
192  autoPtr<surfaceScalarField>& fieldPtr,
193  const fvMesh& mesh,
194  const volVectorField& velocity,
195  const word& baseName,
196  const word& solverName,
197  const bool useSolverNameForFields
198  );
199 
201  (
202  const fvMesh& mesh,
203  const volVectorField& velocity,
204  const word& baseName,
205  const word& solverName,
206  const bool useSolverNameForFields
207  );
208 
209  //- Auto create variable for mesh movement
211  (
212  const fvMesh& mesh,
213  const word& name,
214  const dimensionSet& dims
215  );
216 
217  //- Nullify field and old times, if present
218  template<class Type, template<class> class PatchField, class GeoMesh>
219  static void nullifyField
220  (
222  );
223 
224  //- Transfer the fields of another variablesSet to this
225  virtual void transfer(variablesSet& vars);
226 };
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #ifdef NoRepository
236  #include "variablesSetTemplates.C"
237 #endif
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #endif
242 
243 // ************************************************************************* //
Foam::variablesSet::useSolverNameForFields
bool useSolverNameForFields() const
Append solver name to fields?
Definition: variablesSet.C:90
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::variablesSet::solverName
const word & solverName() const
Return solver name.
Definition: variablesSet.C:84
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::variablesSet::allocateFluxField
tmp< surfaceScalarField > allocateFluxField(const fvMesh &mesh, const volVectorField &velocity, const word &baseName, const word &solverName, const bool useSolverNameForFields)
Definition: variablesSet.C:149
Foam::variablesSet::allocateField
tmp< GeometricField< Type, fvPatchField, volMesh > > allocateField(const fvMesh &mesh, const word &baseName, const word &solverName, const bool useSolverNameForFields)
Definition: variablesSetTemplates.C:257
Foam::variablesSet::TypeName
TypeName("variablesSet")
Run-time type information.
Foam::variablesSet::setFluxField
static void setFluxField(autoPtr< surfaceScalarField > &fieldPtr, const fvMesh &mesh, const volVectorField &velocity, const word &baseName, const word &solverName, const bool useSolverNameForFields)
Set flux field.
Definition: variablesSet.C:97
Foam::variablesSet::swapAndRename
void swapAndRename(autoPtr< GeometricField< Type, PatchField, GeoMesh >> &p1, autoPtr< GeometricField< Type, PatchField, GeoMesh >> &p2)
Swap autoPtrs and rename managed fields.
Definition: variablesSetTemplates.C:191
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
Foam::variablesSet::clone
virtual autoPtr< variablesSet > clone() const
Clone the variablesSet.
Definition: variablesSet.C:75
Foam::variablesSet
Base class for creating a set of variables.
Definition: variablesSet.H:49
Foam::variablesSet::nullifyField
static void nullifyField(GeometricField< Type, PatchField, GeoMesh > &fieldPtr)
Nullify field and old times, if present.
Definition: variablesSetTemplates.C:347
Foam::variablesSet::transfer
virtual void transfer(variablesSet &vars)
Transfer the fields of another variablesSet to this.
Definition: variablesSet.C:196
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::variablesSet::autoCreateMeshMovementField
static tmp< volVectorField > autoCreateMeshMovementField(const fvMesh &mesh, const word &name, const dimensionSet &dims)
Auto create variable for mesh movement.
Definition: variablesSet.C:173
Foam::variablesSet::solverName_
word solverName_
Solver name owning the variables set.
Definition: variablesSet.H:95
Foam::variablesSet::setField
static void setField(autoPtr< GeometricField< Type, fvPatchField, volMesh >> &fieldPtr, const fvMesh &mesh, const word &baseName, const word &solverName, const bool useSolverNameForFields)
Read vol fields.
Definition: variablesSetTemplates.C:222
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::variablesSet::mesh_
fvMesh & mesh_
Reference to the mesh database.
Definition: variablesSet.H:92
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::GeoMesh
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:48
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
variablesSetTemplates.C
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::variablesSet::allocateRenamedField
autoPtr< GeometricField< Type, PatchField, GeoMesh > > allocateRenamedField(const autoPtr< GeometricField< Type, PatchField, GeoMesh >> &bf)
Definition: variablesSetTemplates.C:167
Foam::variablesSet::~variablesSet
virtual ~variablesSet()=default
Destructor.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::variablesSet::renameTurbulenceField
void renameTurbulenceField(GeometricField< Type, fvPatchField, volMesh > &baseField, const word &solverName)
Definition: variablesSetTemplates.C:275
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::variablesSet::useSolverNameForFields_
bool useSolverNameForFields_
Append the solver name to the variables names?
Definition: variablesSet.H:98