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-2020 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  Boundary.C
34  GeometricFieldFunctions.H
35  GeometricFieldFunctions.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef GeometricField_H
40 #define GeometricField_H
41 
42 #include "regIOobject.H"
43 #include "dimensionedTypes.H"
44 #include "DimensionedField.H"
45 #include "FieldField.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 class dictionary;
55 
56 // Forward declaration of friend functions and operators
57 
58 template<class Type, template<class> class PatchField, class GeoMesh>
59 class GeometricField;
60 
61 template<class Type, template<class> class PatchField, class GeoMesh>
62 Ostream& operator<<
63 (
64  Ostream&,
65  const GeometricField<Type, PatchField, GeoMesh>&
66 );
67 
68 template<class Type, template<class> class PatchField, class GeoMesh>
69 Ostream& operator<<
70 (
71  Ostream&,
72  const tmp<GeometricField<Type, PatchField, GeoMesh>>&
73 );
74 
75 
76 /*---------------------------------------------------------------------------*\
77  Class GeometricField Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 template<class Type, template<class> class PatchField, class GeoMesh>
81 class GeometricField
82 :
83  public DimensionedField<Type, GeoMesh>
84 {
85  // Private Member Functions
86 
87  //- Read from file if it is present
88  bool readIfPresent();
89 
90  //- Read old time field from file if it is present
91  bool readOldTimeIfPresent();
92 
93 
94 public:
95 
96  // Public Typedefs
97 
98  //- Type of mesh on which this GeometricField is instantiated
99  typedef typename GeoMesh::Mesh Mesh;
100 
101  //- Type of boundary mesh on which this
102  // GeometricField::Boundary is instantiated
103  typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
104 
105  //- Type of the internal field from which this GeometricField is derived
107 
108  //- Type of the patch field of which the
109  // GeometricField::Boundary is composed
110  typedef PatchField<Type> Patch;
111 
113  class Boundary
114  :
115  public FieldField<PatchField, Type>
116  {
117  // Private Data
118 
119  //- Reference to BoundaryMesh for which this field is defined
120  const BoundaryMesh& bmesh_;
121 
122 
123  public:
124 
125  // Constructors
126 
127  //- Construct from a BoundaryMesh
128  Boundary(const BoundaryMesh&);
129 
130  //- Construct from a BoundaryMesh,
131  // reference to the internal field
132  // and a patch field type
133  Boundary(const BoundaryMesh&, const Internal&, const word&);
134 
135  //- Construct from a BoundaryMesh,
136  // reference to the internal field
137  // and a wordList of patch field types and optionally
138  // the actual patch types (to override constraint patches)
139  Boundary
140  (
141  const BoundaryMesh&,
142  const Internal&,
143  const wordList& wantedPatchTypes,
144  const wordList& actualPatchTypes = wordList()
145  );
146 
147  //- Construct from a BoundaryMesh,
148  // reference to the internal field
149  // and a PtrList<PatchField<Type>>
150  Boundary
151  (
152  const BoundaryMesh&,
153  const Internal&,
154  const PtrList<PatchField<Type>>&
155  );
156 
157  //- Construct as copy setting the reference to the internal field
158  Boundary(const Internal&, const Boundary&);
159 
160  //- Copy constructor deleted
161  // as it would not set the internalField reference correctly
162  Boundary(const Boundary&) = delete;
163 
164  //- Move constructor deleted
165  // as it would not set the internalField reference correctly
166  Boundary(Boundary&&) = delete;
167 
168  //- Construct from dictionary
169  Boundary(const BoundaryMesh&, const Internal&, const dictionary&);
170 
171 
172  // Member Functions
173 
174  //- Read the boundary field
175  void readField(const Internal& field, const dictionary& dict);
176 
177  //- Update the boundary condition coefficients
178  void updateCoeffs();
179 
180  //- Evaluate boundary conditions
181  void evaluate();
182 
183  //- Return a list of the patch field types
184  wordList types() const;
185 
186  //- Return BoundaryField of the cell values neighbouring
187  // the boundary
189 
190  //- Return a list of pointers for each patch field with only those
191  // pointing to interfaces being set
193 
194  //- Return a list of pointers for each patch field with only those
195  // pointing to interfaces being set
197 
198  //- Write boundary field as dictionary entry
199  void writeEntry(const word& keyword, Ostream& os) const;
200 
201 
202  // Member Operators
203 
204  //- Assignment operator
205  void operator=(const Boundary&);
206 
207  //- Move assignment operator
208  void operator=(Boundary&&);
209 
210  //- Assignment to FieldField<PatchField, Type>
212 
213  //- Assignment to Type
214  void operator=(const Type&);
215 
216 
217  //- Forced assignment to
218  // BoundaryField<Type, PatchField, BoundaryMesh>
219  void operator==(const Boundary&);
220 
221  //- Forced assignment to FieldField<PatchField, Type>
223 
224  //- Forced assignment to Type
225  void operator==(const Type&);
226  };
227 
228 
229 private:
230 
231  // Private Data
232 
233  //- Current time index.
234  // Used to trigger the storing of the old-time value
235  mutable label timeIndex_;
236 
237  //- Pointer to old time field
238  mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
239 
240  //- Pointer to previous iteration (used for under-relaxation)
241  mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
242 
243  //- Boundary Type field containing boundary field values
244  Boundary boundaryField_;
245 
246 
247  // Private Member Functions
248 
249  //- Read the field from the dictionary
250  void readFields(const dictionary&);
251 
252  //- Read the field - create the field dictionary on-the-fly
253  void readFields();
254 
255 
256 public:
257 
258  //- Runtime type information
259  TypeName("GeometricField");
260 
261 
262  // Public Typedefs
264  typedef typename Field<Type>::cmptType cmptType;
265 
266  // Static Member Functions
267 
268  //- Return a null geometric field
269  inline static const GeometricField<Type, PatchField, GeoMesh>& null();
270 
271 
272  // Constructors
273 
274  //- Constructor given IOobject, mesh, dimensions and patch field type.
275  // This allocates storage for the field but not values.
276  // Used only within this class to create TEMPORARY variables
278  (
279  const IOobject&,
280  const Mesh&,
281  const dimensionSet&,
282  const word& patchFieldType=PatchField<Type>::calculatedType()
283  );
284 
285  //- Constructor given IOobject, mesh, dimensions and patch field types.
286  // This allocates storage for the field but not values.
287  // Used only within this class to create TEMPORARY variables
289  (
290  const IOobject&,
291  const Mesh&,
292  const dimensionSet&,
293  const wordList& wantedPatchTypes,
294  const wordList& actualPatchTypes = wordList()
295  );
296 
297  //- Constructor given IOobject, mesh, dimensioned<Type>
298  // and patch field type.
300  (
301  const IOobject&,
302  const Mesh&,
303  const dimensioned<Type>&,
304  const word& patchFieldType=PatchField<Type>::calculatedType()
305  );
306 
307  //- Constructor given IOobject, mesh, dimensioned<Type>
308  // and patch field types.
310  (
311  const IOobject&,
312  const Mesh&,
313  const dimensioned<Type>&,
314  const wordList& wantedPatchTypes,
315  const wordList& actualPatchTypes = wordList()
316  );
317 
318  //- Constructor from components
320  (
321  const IOobject&,
322  const Internal&,
323  const PtrList<PatchField<Type>>&
324  );
325 
326  //- Constructor from components
328  (
329  const IOobject&,
330  const Mesh&,
331  const dimensionSet&,
332  const Field<Type>&,
333  const PtrList<PatchField<Type>>&
334  );
335 
336  //- Construct and read given IOobject
338  (
339  const IOobject&,
340  const Mesh&
341  );
342 
343  //- Construct from dictionary
345  (
346  const IOobject&,
347  const Mesh&,
348  const dictionary&
349  );
350 
351  //- Copy constructor
353 
354  //- Move constructor
356 
357  //- Construct as copy of tmp<GeometricField> deleting argument
359 
360  //- Construct as copy resetting IO parameters
362  (
363  const IOobject&,
365  );
366 
367  //- Construct as copy of tmp<GeometricField> resetting IO parameters
369  (
370  const IOobject&,
372  );
373 
374  //- Construct as copy resetting name
376  (
377  const word& newName,
379  );
380 
381  //- Construct as copy resetting name
383  (
384  const word& newName,
386  );
387 
388  //- Construct as copy resetting IO parameters and patch field type
390  (
391  const IOobject&,
393  const word& patchFieldType
394  );
395 
396  //- Construct as copy resetting IO parameters and boundary types
398  (
399  const IOobject&,
401  const wordList& patchFieldTypes,
402  const wordList& actualPatchTypes = wordList()
403  );
404 
405  //- Construct as copy resetting IO parameters and boundary types
407  (
408  const IOobject&,
410  const wordList& patchFieldTypes,
411  const wordList& actualPatchTypes = wordList()
412  );
413 
414  //- Clone
416 
417  //- Return a temporary field constructed from name,
418  // internal field and list of patch fields
420  (
421  const word& name,
422  const Internal&,
423  const PtrList<PatchField<Type>>&
424  );
425 
426  //- Return a temporary field constructed from name, mesh, dimensionSet
427  // and patch field type.
429  (
430  const word& name,
431  const Mesh&,
432  const dimensionSet&,
433  const word& patchFieldType=PatchField<Type>::calculatedType()
434  );
435 
436  //- Return a temporary field constructed from mesh, dimensioned<Type>
437  // and patch field type.
439  (
440  const word& name,
441  const Mesh&,
442  const dimensioned<Type>&,
443  const word& patchFieldType=PatchField<Type>::calculatedType()
444  );
445 
446  //- Return a temporary field constructed from mesh, dimensioned<Type>
447  // and patch field types.
449  (
450  const word& name,
451  const Mesh&,
452  const dimensioned<Type>&,
453  const wordList& patchFieldTypes,
454  const wordList& actualPatchTypes = wordList()
455  );
456 
457  //- Rename temporary field and return
459  (
460  const word& newName,
462  );
463 
464  //- Rename temporary field, reset patch field type and return
466  (
467  const word& newName,
469  const word&
470  );
471 
472  //- Rename and reset patch fields types of temporary field and return
474  (
475  const word& newName,
477  const wordList& patchFieldTypes,
478  const wordList& actualPatchTypes = wordList()
479  );
480 
481 
482  //- Destructor
483  virtual ~GeometricField();
484 
485 
486  // Member Functions
487 
488  //- Return a reference to the dimensioned internal field
489  // Note: this increments the event counter and checks the
490  // old-time fields; avoid in loops.
491  Internal& ref();
492 
493  //- Return a const-reference to the dimensioned internal field
494  inline const Internal& internalField() const;
495 
496  //- Return a const-reference to the dimensioned internal field
497  // of a "vol" field. Useful in the formulation of source-terms
498  // for FV equations
499  inline const Internal& v() const;
500 
501  //- Return a reference to the internal field
502  // Note: this increments the event counter and checks the
503  // old-time fields; avoid in loops.
505 
506  //- Return a const-reference to the internal field
507  inline const typename Internal::FieldType& primitiveField() const;
508 
509  //- Return a reference to the boundary field
510  // Note: this increments the event counter and checks the
511  // old-time fields; avoid in loops.
513 
514  //- Return const-reference to the boundary field
515  inline const Boundary& boundaryField() const;
516 
517  //- Return the time index of the field
518  inline label timeIndex() const;
519 
520  //- Return the time index of the field
521  inline label& timeIndex();
522 
523  //- Store the old-time fields
524  void storeOldTimes() const;
525 
526  //- Store the old-time field
527  void storeOldTime() const;
528 
529  //- Return the number of old time fields stored
530  label nOldTimes() const;
531 
532  //- Return old time field
534 
535  //- Return non-const old time field
536  // (Not a good idea but it is used for sub-cycling)
538 
539  //- Store the field as the previous iteration value
540  void storePrevIter() const;
541 
542  //- Return previous iteration field
544 
545  //- Correct boundary field
547 
548  //- Does the field need a reference level for solution
549  bool needReference() const;
550 
551  //- Return a component of the field
553  (
554  const direction
555  ) const;
556 
557  //- WriteData member function required by regIOobject
558  bool writeData(Ostream&) const;
559 
560  //- Return transpose (only if it is a tensor field)
562 
563  //- Relax field (for steady-state solution).
564  // alpha = 1 : no relaxation
565  // alpha < 1 : relaxation
566  // alpha = 0 : do nothing
567  void relax(const scalar alpha);
568 
569  //- Relax field (for steady-state solution).
570  // alpha is read from controlDict
571  void relax();
572 
573  //- Select the final iteration parameters if `final' is true
574  // by returning the field name + "Final"
575  // otherwise the standard parameters by returning the field name
576  word select(bool final) const;
577 
578  //- Helper function to write the min and max to an Ostream
579  void writeMinMax(Ostream& os) const;
580 
581 
582  // Member function *this operators
583 
584  void negate();
585 
586  void replace
587  (
588  const direction,
590  );
591 
592  void replace
593  (
594  const direction,
595  const dimensioned<cmptType>&
596  );
597 
598  void max(const dimensioned<Type>&);
599 
600  void min(const dimensioned<Type>&);
601 
602  void maxMin
603  (
604  const dimensioned<Type>& minDt,
605  const dimensioned<Type>& maxDt
606  );
607 
608 
609  // Member Operators
610 
611  //- Return a const-reference to the dimensioned internal field
612  // Useful in the formulation of source-terms for FV equations
613  inline const Internal& operator()() const;
614 
618  void operator=(const dimensioned<Type>&);
619  void operator=(const zero&);
620 
622  void operator==(const dimensioned<Type>&);
623  void operator==(const zero&);
624 
627 
630 
633 
636 
637  void operator+=(const dimensioned<Type>&);
638  void operator-=(const dimensioned<Type>&);
639 
640  void operator*=(const dimensioned<scalar>&);
641  void operator/=(const dimensioned<scalar>&);
642 
643 
644  // Ostream operators
645 
646  friend Ostream& operator<< <Type, PatchField, GeoMesh>
647  (
648  Ostream&,
650  );
651 
652  friend Ostream& operator<< <Type, PatchField, GeoMesh>
653  (
654  Ostream&,
656  );
657 };
658 
659 
660 template<class Type, template<class> class PatchField, class GeoMesh>
661 Ostream& operator<<
662 (
663  Ostream&,
665  Boundary&
666 );
667 
668 
669 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
670 
671 } // End namespace Foam
672 
673 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
674 
675 #include "GeometricFieldI.H"
676 
677 #ifdef NoRepository
678  #include "GeometricField.C"
679 #endif
680 
681 #include "GeometricFieldFunctions.H"
682 
683 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
684 
685 #endif
686 
687 // ************************************************************************* //
void operator=(const Boundary &)
Assignment operator.
dictionary dict
const GeometricField< Type, PatchField, GeoMesh > & oldTime() const
Return old time field.
Boundary(const BoundaryMesh &)
Construct from a BoundaryMesh.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
GeoMesh::BoundaryMesh BoundaryMesh
Type of boundary mesh on which this.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
void writeEntry(const word &keyword, Ostream &os) const
Write boundary field as dictionary entry.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
bool writeData(Ostream &) const
WriteData member function required by regIOobject.
MESH::BoundaryMesh BoundaryMesh
Definition: GeoMesh.H:62
uint8_t direction
Definition: direction.H:45
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:97
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Internal &, const PtrList< PatchField< Type >> &)
Return a temporary field constructed from name,.
void evaluate()
Evaluate boundary conditions.
GeoMesh::Mesh Mesh
Type of mesh on which this GeometricField is instantiated.
TypeName("GeometricField")
Runtime type information.
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Generic GeometricField class.
Generic dimensioned Type class.
LduInterfaceFieldPtrsList< Type > interfaces() const
Return a list of pointers for each patch field with only those.
label nOldTimes() const
Return the number of old time fields stored.
void operator==(const Boundary &)
Forced assignment to.
void maxMin(const dimensioned< Type > &minDt, const dimensioned< Type > &maxDt)
DimensionedField< Type, GeoMesh > Internal
Type of the internal field from which this GeometricField is derived.
word select(bool final) const
Select the final iteration parameters if `final&#39; is true.
Generic field type.
Definition: FieldField.H:51
wordList types() const
Return a list of the patch field types.
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
void readField(const Internal &field, const dictionary &dict)
Read the boundary field.
void updateCoeffs()
Update the boundary condition coefficients.
bool needReference() const
Does the field need a reference level for solution.
Dimension set for the base types.
Definition: dimensionSet.H:120
const Internal & v() const
Return a const-reference to the dimensioned internal field.
Definition: volFieldsI.H:31
void negate()
Negate this field.
Definition: FieldField.C:218
void storeOldTimes() const
Store the old-time fields.
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
void storeOldTime() const
Store the old-time field.
void writeMinMax(Ostream &os) const
Helper function to write the min and max to an Ostream.
void operator*=(const FieldField< PatchField, scalar > &)
Definition: FieldField.C:379
void min(const dimensioned< Type > &)
GeometricField(const IOobject &, const Mesh &, const dimensionSet &, const word &patchFieldType=PatchField< Type >::calculatedType())
Constructor given IOobject, mesh, dimensions and patch field type.
void operator+=(const FieldField< PatchField, Type > &)
Definition: FieldField.C:377
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
const GeometricField< Type, PatchField, GeoMesh > & prevIter() const
Return previous iteration field.
MESH Mesh
Definition: GeoMesh.H:61
void operator/=(const FieldField< PatchField, scalar > &)
Definition: FieldField.C:380
const Field< Type > & field() const
tmp< FieldField< PatchField, cmptType > > component(const direction) const
Return a component field of the field.
Definition: FieldField.C:230
virtual ~GeometricField()
Destructor.
void replace(const direction, const FieldField< PatchField, cmptType > &)
Replace a component field of the field.
Definition: FieldField.C:248
label timeIndex() const
Return the time index of the field.
Internal & ref()
Return a reference to the dimensioned internal field.
static const GeometricField< Type, PatchField, GeoMesh > & null()
Return a null geometric field.
List< word > wordList
A List of words.
Definition: fileName.H:54
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:82
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
PatchField< Type > Patch
Type of the patch field of which the.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
void max(const dimensioned< Type > &)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
void correctBoundaryConditions()
Correct boundary field.
lduInterfaceFieldPtrsList scalarInterfaces() const
Return a list of pointers for each patch field with only those.
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
tmp< FieldField< PatchField, Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: FieldField.C:275
void storePrevIter() const
Store the field as the previous iteration value.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
void operator-=(const FieldField< PatchField, Type > &)
Definition: FieldField.C:378
A class for managing temporary objects.
Definition: PtrList.H:53
word patchFieldType(const PatchField &pf)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
const T * operator()(const label) const
Return element const pointer.
Definition: UPtrListI.H:128
Boundary boundaryInternalField() const
Return BoundaryField of the cell values neighbouring.
List of coupled interface fields to be used in coupling.
void relax()
Relax field (for steady-state solution).
tmp< FieldField< PatchField, Type > > clone() const
Clone.
Definition: FieldField.C:188
Namespace for OpenFOAM.