GeometricField.H
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 Class
25  Foam::GeometricField
26 
27 Description
28  Generic GeometricField class.
29 
30 SourceFiles
31  GeometricFieldI.H
32  GeometricField.C
33  GeometricFieldFunctions.H
34  GeometricFieldFunctions.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef GeometricField_H
39 #define GeometricField_H
40 
43 #include "GeometricBoundaryField.H"
44 #include "GeometricFieldSources.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 class dictionary;
52 
53 // Forward declaration of friend functions and operators
54 
55 template<class Type, template<class> class PatchField, class GeoMesh>
56 class GeometricField;
57 
58 template<class Type, template<class> class PatchField, class GeoMesh>
59 Ostream& operator<<
60 (
61  Ostream&,
63 );
64 
65 template<class Type, template<class> class PatchField, class GeoMesh>
66 Ostream& operator<<
67 (
68  Ostream&,
70 );
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class GeometricField Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<class Type, template<class> class PatchField, class GeoMesh>
78 class GeometricField
79 :
80  public DimensionedField<Type, GeoMesh>,
81  public OldTimeField<GeometricField<Type, PatchField, GeoMesh>>
82 {
83  // Private Member Functions
84 
85  //- Read from file if it is present
86  bool readIfPresent();
87 
88 
89 public:
90 
91  // Public Typedefs
92 
93  //- Type of mesh on which this GeometricField is instantiated
94  typedef typename GeoMesh::Mesh Mesh;
95 
96  //- Type of the internal field from which this GeometricField is derived
98 
99  //- Type of the field from which this GeometricField is derived
101 
102  //- Type of the patch field of which the Boundary is composed
103  typedef PatchField<Type> Patch;
104 
105  //- Type of the boundary field
107 
108  //- Type of the field source of which the Sources is composed
109  typedef typename GeoMesh::template FieldSource<Type> Source;
110 
111  //- Type of the field sources
113 
114  //- Component type of the elements of the field
115  typedef typename Field<Type>::cmptType cmptType;
116 
117 
118 private:
119 
120  // Private Data
121 
122  //- Pointer to previous iteration (used for under-relaxation)
123  mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
124 
125  //- Boundary Type field containing boundary field values
126  Boundary boundaryField_;
127 
128  //- Type field sources containing field source values
129  Sources sources_;
130 
131 
132  // Private Member Functions
133 
134  //- Read the field from the dictionary
135  void readFields(const dictionary&);
136 
137  //- Read the field - create the field dictionary on-the-fly
138  void readFields();
139 
140 
141 public:
142 
143  //- Runtime type information
144  TypeName("GeometricField");
145 
146 
147  // Static Member Functions
148 
149  //- Return a null geometric field
150  inline static const GeometricField<Type, PatchField, GeoMesh>& null();
151 
152 
153  // Constructors
154 
155  //- Constructor given IOobject, mesh, dimensions and patch field type.
156  // This allocates storage for the field but not values.
157  // Used only within this class to create TEMPORARY variables
159  (
160  const IOobject&,
161  const Mesh&,
162  const dimensionSet&,
163  const word& patchFieldType = PatchField<Type>::calculatedType()
164  );
165 
166  //- Constructor given IOobject, mesh, dimensions and patch field types.
167  // This allocates storage for the field but not values.
168  // Used only within this class to create TEMPORARY variables
170  (
171  const IOobject&,
172  const Mesh&,
173  const dimensionSet&,
174  const wordList& wantedPatchTypes,
175  const wordList& actualPatchTypes = wordList(),
176  const HashTable<word>& fieldSourceTypes = HashTable<word>()
177  );
178 
179  //- Constructor given IOobject, mesh, dimensioned<Type>
180  // and patch field type.
182  (
183  const IOobject&,
184  const Mesh&,
185  const dimensioned<Type>&,
186  const word& patchFieldType = PatchField<Type>::calculatedType()
187  );
188 
189  //- Constructor given IOobject, mesh, dimensioned<Type>
190  // and patch field types.
192  (
193  const IOobject&,
194  const Mesh&,
195  const dimensioned<Type>&,
196  const wordList& wantedPatchTypes,
197  const wordList& actualPatchTypes = wordList(),
198  const HashTable<word>& fieldSourceTypes = HashTable<word>()
199  );
200 
201  //- Constructor from components
203  (
204  const IOobject&,
205  const Internal&,
206  const PtrList<PatchField<Type>>&,
208  );
209 
210  //- Constructor from components
212  (
213  const IOobject&,
214  const Mesh&,
215  const dimensionSet&,
216  const Field<Type>&,
217  const PtrList<PatchField<Type>>&,
219  );
220 
221  //- Construct and read given IOobject
223  (
224  const IOobject&,
225  const Mesh&
226  );
227 
228  //- Construct from dictionary
230  (
231  const IOobject&,
232  const Mesh&,
233  const dictionary&
234  );
235 
236  //- Copy constructor
238 
239  //- Move constructor
241 
242  //- Construct as copy of tmp
244 
245  //- Construct as copy resetting IO parameters
247  (
248  const IOobject&,
250  );
251 
252  //- Construct as copy of tmp resetting IO parameters
254  (
255  const IOobject&,
257  );
258 
259  //- Construct as copy resetting name
261  (
262  const word& newName,
264  );
265 
266  //- Construct as copy of tmp resetting name
268  (
269  const word& newName,
271  );
272 
273  //- Construct as copy resetting IO parameters and patch field type
275  (
276  const IOobject&,
278  const word& patchFieldType
279  );
280 
281  //- Construct as copy resetting IO parameters and boundary types
283  (
284  const IOobject&,
286  const wordList& patchFieldTypes,
287  const wordList& actualPatchTypes = wordList(),
288  const HashTable<word>& fieldSourceTypes = HashTable<word>()
289  );
290 
291  //- Construct as copy of tmp resetting IO parameters and boundary types
293  (
294  const IOobject&,
296  const wordList& patchFieldTypes,
297  const wordList& actualPatchTypes = wordList(),
298  const HashTable<word>& fieldSourceTypes = HashTable<word>()
299  );
300 
301  //- Clone
303 
304  //- Clone un-sliced
306 
307  //- Return a temporary field constructed from name,
308  // internal field and list of patch fields
310  (
311  const word& name,
312  const Internal&,
313  const PtrList<PatchField<Type>>&,
315  );
316 
317  //- Return a temporary field constructed from name, mesh, dimensionSet
318  // and patch field type.
320  (
321  const word& name,
322  const Mesh&,
323  const dimensionSet&,
324  const word& patchFieldType = PatchField<Type>::calculatedType()
325  );
326 
327  //- Return a temporary field constructed from mesh, dimensioned<Type>
328  // and patch field type.
330  (
331  const word& name,
332  const Mesh&,
333  const dimensioned<Type>&,
334  const word& patchFieldType = PatchField<Type>::calculatedType()
335  );
336 
337  //- Return a temporary field constructed from mesh, dimensioned<Type>
338  // and patch field types.
340  (
341  const word& name,
342  const Mesh&,
343  const dimensioned<Type>&,
344  const wordList& patchFieldTypes,
345  const wordList& actualPatchTypes = wordList(),
346  const HashTable<word>& fieldSourceTypes = HashTable<word>()
347  );
348 
349  //- Rename temporary field and return
351  (
352  const word& newName,
354  );
355 
356  //- Rename temporary field, reset patch field type and return
358  (
359  const word& newName,
361  const word& patchFieldType
362  );
363 
364  //- Rename and reset patch fields types of temporary field and return
366  (
367  const word& newName,
369  const wordList& patchFieldTypes,
370  const wordList& actualPatchTypes = wordList(),
371  const HashTable<word>& fieldSourceTypes = HashTable<word>()
372  );
373 
374 
375  //- Destructor
376  virtual ~GeometricField();
377 
378 
379  // Member Functions
380 
381  //- Return a reference to the dimensioned internal field
382  // Note: this increments the event counter and checks the
383  // old-time fields; avoid in loops.
385 
386  //- Return a const-reference to the dimensioned internal field
387  inline const Internal& internalField() const;
388 
389  //- Return a const-reference to the dimensioned internal field
390  // of a "vol" field. Useful in the formulation of source-terms
391  // for FV equations
392  inline const Internal& v() const;
393 
394  //- Return a reference to the primitive field
395  // Note: this increments the event counter and checks the
396  // old-time fields; avoid in loops.
398 
399  //- Return a const-reference to the primitive field
400  inline const typename Internal::FieldType& primitiveField() const;
401 
402  //- Return a reference to the boundary field
403  // Note: this increments the event counter and checks the
404  // old-time fields; avoid in loops.
406 
407  //- Return const-reference to the boundary field
408  inline const Boundary& boundaryField() const;
409 
410  //- Return const-reference to the sources
411  inline const Sources& sources() const;
412 
413  //- Store the field as the previous iteration value
414  void storePrevIter() const;
415 
416  //- Delete the previous iteration field
417  void clearPrevIter();
418 
419  //- Return previous iteration field
421 
422  //- Use old-time methods from the base class
424 
425  //- Correct boundary field
427 
428  //- Reset the field contents to the given field
429  // Used for mesh to mesh mapping
431 
432  //- Does the field need a reference level for solution
433  bool needReference() const;
434 
435  //- Return a component of the field
437  (
438  const direction
439  ) const;
440 
441  //- WriteData member function required by regIOobject
442  bool writeData(Ostream&) const;
443 
444  //- Return transpose (only if it is a tensor field)
446 
447  //- Relax field (for steady-state solution).
448  // alpha >= 1 : no relaxation
449  // alpha < 1 : relaxation
450  void relax(const scalar alpha);
451 
452  //- Return the field relaxation factor read from fvSolution
453  // or 1 if not specified
454  scalar relaxationFactor() const;
455 
456  //- Relax current field with respect to the cached previous iteration.
457  // Relaxation factor is read from fvSolution
458  void relax();
459 
460  //- Relax given field with respect to the current field
461  // and reset the field to the result
462  void relax
463  (
465  const scalar alpha
466  );
467 
468  //- Relax given field with respect to the current field
469  // and reset the field to the result
470  // Relaxation factor is read from fvSolution
472 
473  //- Select the final iteration parameters if `final' is true
474  // by returning the field name + "Final"
475  // otherwise the standard parameters by returning the field name
476  word select(bool final) const;
477 
478  //- Helper function to write the min and max to an Ostream
479  void writeMinMax(Ostream& os) const;
480 
481 
482  // Member function *this operators
483 
484  void negate();
485 
486  void replace
487  (
488  const direction,
490  );
491 
492  void replace
493  (
494  const direction,
495  const dimensioned<cmptType>&
496  );
497 
498  void max(const dimensioned<Type>&);
499 
500  void min(const dimensioned<Type>&);
501 
502  void maxMin
503  (
504  const dimensioned<Type>& minDt,
505  const dimensioned<Type>& maxDt
506  );
507 
508 
509  // Member Operators
510 
511  //- Return a const-reference to the dimensioned internal field
512  // Useful in the formulation of source-terms for FV equations
513  inline const Internal& operator()() const;
514 
518  void operator=(const dimensioned<Type>&);
519  void operator=(const zero&);
520 
522  void operator==(const dimensioned<Type>&);
523  void operator==(const zero&);
524 
527 
530 
533 
536 
537  void operator+=(const dimensioned<Type>&);
538  void operator-=(const dimensioned<Type>&);
539 
540  void operator*=(const dimensioned<scalar>&);
541  void operator/=(const dimensioned<scalar>&);
542 
543 
544  // Ostream operators
545 
546  friend Ostream& operator<< <Type, PatchField, GeoMesh>
547  (
548  Ostream&,
550  );
551 
552  friend Ostream& operator<< <Type, PatchField, GeoMesh>
553  (
554  Ostream&,
556  );
557 };
558 
559 
560 template<class Type, template<class> class PatchField, class GeoMesh>
561 Ostream& operator<<
562 (
563  Ostream&,
565 );
566 
567 
568 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
569 
570 } // End namespace Foam
571 
572 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
573 
574 #include "GeometricFieldI.H"
575 
576 #ifdef NoRepository
577  #include "GeometricField.C"
578 #endif
579 
580 #include "GeometricFieldFunctions.H"
581 
582 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
583 
584 #endif
585 
586 // ************************************************************************* //
List of coupled interface fields to be used in coupling.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
Pre-declare SubField and related Field type.
Definition: Field.H:83
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:98
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:47
MESH Mesh
Definition: GeoMesh.H:61
Generic GeometricBoundaryField class.
Part of a geometric field used for setting the values associated with optional sources.
Generic GeometricField class.
void max(const dimensioned< Type > &)
Internal & internalFieldRef()
Return a reference to the dimensioned internal field.
Internal::FieldType & primitiveFieldRef()
Return a reference to the primitive field.
DimensionedField< Type, GeoMesh > Internal
Type of the internal field from which this GeometricField is derived.
const Sources & sources() const
Return const-reference to the sources.
bool writeData(Ostream &) const
WriteData member function required by regIOobject.
void writeMinMax(Ostream &os) const
Helper function to write the min and max to an Ostream.
void relax()
Relax current field with respect to the cached previous iteration.
TypeName("GeometricField")
Runtime type information.
void operator/=(const GeometricField< scalar, PatchField, GeoMesh > &)
void maxMin(const dimensioned< Type > &minDt, const dimensioned< Type > &maxDt)
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Return transpose (only if it is a tensor field)
GeoMesh::Mesh Mesh
Type of mesh on which this GeometricField is instantiated.
void operator==(const tmp< GeometricField< Type, PatchField, GeoMesh >> &)
void operator-=(const GeometricField< Type, PatchField, GeoMesh > &)
tmp< GeometricField< Type, PatchField, GeoMesh > > cloneUnSliced() const
Clone un-sliced.
void operator*=(const GeometricField< scalar, PatchField, GeoMesh > &)
void min(const dimensioned< Type > &)
void operator+=(const GeometricField< Type, PatchField, GeoMesh > &)
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of the boundary field.
GeoMesh::template FieldSource< Type > Source
Type of the field source of which the Sources is composed.
const Internal & v() const
Return a const-reference to the dimensioned internal field.
Definition: volFieldsI.H:31
PatchField< Type > Patch
Type of the patch field of which the Boundary is composed.
Field< Type >::cmptType cmptType
Component type of the elements of the field.
GeometricFieldSources< Type, GeoMesh > Sources
Type of the field sources.
void replace(const direction, const GeometricField< cmptType, PatchField, GeoMesh > &)
const Boundary & boundaryField() const
Return const-reference to the boundary field.
GeometricField(const IOobject &, const Mesh &, const dimensionSet &, const word &patchFieldType=PatchField< Type >::calculatedType())
Constructor given IOobject, mesh, dimensions and patch field type.
const GeometricField< Type, PatchField, GeoMesh > & prevIter() const
Return previous iteration field.
bool needReference() const
Does the field need a reference level for solution.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
virtual ~GeometricField()
Destructor.
scalar relaxationFactor() const
Return the field relaxation factor read from fvSolution.
void clearPrevIter()
Delete the previous iteration field.
void storePrevIter() const
Store the field as the previous iteration value.
word select(bool final) const
Select the final iteration parameters if `final' is true.
void correctBoundaryConditions()
Correct boundary field.
void reset(const tmp< GeometricField< Type, PatchField, GeoMesh >> &)
Reset the field contents to the given field.
const Internal & operator()() const
Return a const-reference to the dimensioned internal field.
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
USING_OLD_TIME_FIELD(GeometricField)
Use old-time methods from the base class.
void operator=(const GeometricField< Type, PatchField, GeoMesh > &)
tmp< GeometricField< Type, PatchField, GeoMesh > > clone() const
Clone.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
DimensionedField< Type, GeoMesh > Base
Type of the field from which this GeometricField is derived.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Internal &, const PtrList< PatchField< Type >> &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
An STL-conforming hash table.
Definition: HashTable.H:127
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:310
Class to add into field types to provide old-time storage and retrieval.
Definition: OldTimeField.H:93
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Generic dimensioned Type class.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
word patchFieldType(const PatchField &pf)
uint8_t direction
Definition: direction.H:45