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-2019 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 type
133  Boundary
134  (
135  const BoundaryMesh&,
136  const Internal&,
137  const word&
138  );
139 
140  //- Construct from a BoundaryMesh,
141  // reference to the internal field
142  // and a wordList of patch types and optional the actual patch
143  // types (to override constraint patches)
144  Boundary
145  (
146  const BoundaryMesh&,
147  const Internal&,
148  const wordList& wantedPatchTypes,
149  const wordList& actualPatchTypes = wordList()
150  );
151 
152  //- Construct from a BoundaryMesh,
153  // reference to the internal field
154  // and a PtrList<PatchField<Type>>
155  Boundary
156  (
157  const BoundaryMesh&,
158  const Internal&,
159  const PtrList<PatchField<Type>>&
160  );
161 
162  //- Construct as copy setting the reference to the internal field
163  Boundary
164  (
165  const Internal&,
166  const Boundary&
167  );
168 
169  //- Copy constructor
170  // Dangerous because Field may be set to a field which gets deleted
171  // Need new type of BoundaryField, one which is part of a geometric
172  // field for which snGrad etc. may be called and a free standing
173  // BoundaryField for which such operations are unavailable.
174  Boundary
175  (
176  const Boundary&
177  );
178 
179  //- Move constructor
180  // Dangerous because Field may be set to a field which gets deleted
181  // Need new type of BoundaryField, one which is part of a geometric
182  // field for which snGrad etc. may be called and a free standing
183  // BoundaryField for which such operations are unavailable.
184  Boundary
185  (
186  Boundary&&
187  );
188 
189  //- Construct from dictionary
190  Boundary
191  (
192  const BoundaryMesh&,
193  const Internal&,
194  const dictionary&
195  );
196 
197 
198  // Member Functions
199 
200  //- Read the boundary field
201  void readField
202  (
203  const Internal& field,
204  const dictionary& dict
205  );
206 
207  //- Update the boundary condition coefficients
208  void updateCoeffs();
209 
210  //- Evaluate boundary conditions
211  void evaluate();
212 
213  //- Return a list of the patch types
214  wordList types() const;
215 
216  //- Return BoundaryField of the cell values neighbouring
217  // the boundary
219 
220  //- Return a list of pointers for each patch field with only those
221  // pointing to interfaces being set
223 
224  //- Return a list of pointers for each patch field with only those
225  // pointing to interfaces being set
227 
228  //- Write boundary field as dictionary entry
229  void writeEntry(const word& keyword, Ostream& os) const;
230 
231 
232  // Member Operators
233 
234  //- Assignment operator
235  void operator=(const Boundary&);
236 
237  //- Move assignment operator
238  void operator=(Boundary&&);
239 
240  //- Assignment to FieldField<PatchField, Type>
242 
243  //- Assignment to Type
244  void operator=(const Type&);
245 
246 
247  //- Forced assignment to
248  // BoundaryField<Type, PatchField, BoundaryMesh>
249  void operator==(const Boundary&);
250 
251  //- Forced assignment to FieldField<PatchField, Type>
253 
254  //- Forced assignment to Type
255  void operator==(const Type&);
256  };
257 
258 
259 private:
260 
261  // Private Data
262 
263  //- Current time index.
264  // Used to trigger the storing of the old-time value
265  mutable label timeIndex_;
266 
267  //- Pointer to old time field
268  mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
269 
270  //- Pointer to previous iteration (used for under-relaxation)
271  mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
272 
273  //- Boundary Type field containing boundary field values
274  Boundary boundaryField_;
275 
276 
277  // Private Member Functions
278 
279  //- Read the field from the dictionary
280  void readFields(const dictionary&);
281 
282  //- Read the field - create the field dictionary on-the-fly
283  void readFields();
284 
285 
286 public:
287 
288  //- Runtime type information
289  TypeName("GeometricField");
290 
291 
292  // Public Typedefs
294  typedef typename Field<Type>::cmptType cmptType;
295 
296  // Static Member Functions
297 
298  //- Return a null geometric field
299  inline static const GeometricField<Type, PatchField, GeoMesh>& null();
300 
301 
302  // Constructors
303 
304  //- Constructor given IOobject, mesh, dimensions and patch type.
305  // This allocates storage for the field but not values.
306  // Used only within this class to create TEMPORARY variables
308  (
309  const IOobject&,
310  const Mesh&,
311  const dimensionSet&,
312  const word& patchFieldType=PatchField<Type>::calculatedType()
313  );
314 
315  //- Constructor given IOobject, mesh, dimensions and patch types.
316  // This allocates storage for the field but not values.
317  // Used only within this class to create TEMPORARY variables
319  (
320  const IOobject&,
321  const Mesh&,
322  const dimensionSet&,
323  const wordList& wantedPatchTypes,
324  const wordList& actualPatchTypes = wordList()
325  );
326 
327  //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
329  (
330  const IOobject&,
331  const Mesh&,
332  const dimensioned<Type>&,
333  const word& patchFieldType=PatchField<Type>::calculatedType()
334  );
335 
336  //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
338  (
339  const IOobject&,
340  const Mesh&,
341  const dimensioned<Type>&,
342  const wordList& wantedPatchTypes,
343  const wordList& actualPatchTypes = wordList()
344  );
345 
346  //- Constructor from components
348  (
349  const IOobject&,
350  const Internal&,
351  const PtrList<PatchField<Type>>&
352  );
353 
354  //- Constructor from components
356  (
357  const IOobject&,
358  const Mesh&,
359  const dimensionSet&,
360  const Field<Type>&,
361  const PtrList<PatchField<Type>>&
362  );
363 
364  //- Construct and read given IOobject
366  (
367  const IOobject&,
368  const Mesh&
369  );
370 
371  //- Construct from dictionary
373  (
374  const IOobject&,
375  const Mesh&,
376  const dictionary&
377  );
378 
379  //- Copy constructor
381  (
383  );
384 
385  //- Move constructor
387  (
389  );
390 
391  //- Construct as copy of tmp<GeometricField> deleting argument
393  (
395  );
396 
397  //- Construct as copy resetting IO parameters
399  (
400  const IOobject&,
402  );
403 
404  //- Construct as copy of tmp<GeometricField> resetting IO parameters
406  (
407  const IOobject&,
409  );
410 
411  //- Construct as copy resetting name
413  (
414  const word& newName,
416  );
417 
418  //- Construct as copy resetting name
420  (
421  const word& newName,
423  );
424 
425  //- Construct as copy resetting IO parameters and patch type
427  (
428  const IOobject&,
430  const word& patchFieldType
431  );
432 
433  //- Construct as copy resetting IO parameters and boundary types
435  (
436  const IOobject&,
438  const wordList& patchFieldTypes,
439  const wordList& actualPatchTypes = wordList()
440  );
441 
442  //- Construct as copy resetting IO parameters and boundary types
444  (
445  const IOobject&,
447  const wordList& patchFieldTypes,
448  const wordList& actualPatchTypes = wordList()
449  );
450 
451  //- Clone
453 
454  //- Return a temporary field constructed from name, mesh, dimensionSet
455  // and patch type.
457  (
458  const word& name,
459  const Mesh&,
460  const dimensionSet&,
461  const word& patchFieldType=PatchField<Type>::calculatedType()
462  );
463 
464  //- Return a temporary field constructed from mesh, dimensioned<Type>
465  // and patch type.
467  (
468  const word& name,
469  const Mesh&,
470  const dimensioned<Type>&,
471  const word& patchFieldType=PatchField<Type>::calculatedType()
472  );
473 
474  //- Return a temporary field constructed from mesh, dimensioned<Type>
475  // and patch types.
477  (
478  const word& name,
479  const Mesh&,
480  const dimensioned<Type>&,
481  const wordList& patchFieldTypes,
482  const wordList& actualPatchTypes = wordList()
483  );
484 
485  //- Rename temporary field and return
487  (
488  const word& newName,
490  );
491 
492  //- Rename and reset patch fields types of temporary field and return
494  (
495  const word& newName,
497  const wordList& patchFieldTypes,
498  const wordList& actualPatchTypes = wordList()
499  );
500 
501 
502  //- Destructor
503  virtual ~GeometricField();
504 
505 
506  // Member Functions
507 
508  //- Return a reference to the dimensioned internal field
509  // Note: this increments the event counter and checks the
510  // old-time fields; avoid in loops.
511  Internal& ref();
512 
513  //- Return a const-reference to the dimensioned internal field
514  inline const Internal& internalField() const;
515 
516  //- Return a const-reference to the dimensioned internal field
517  // of a "vol" field. Useful in the formulation of source-terms
518  // for FV equations
519  inline const Internal& v() const;
520 
521  //- Return a reference to the internal field
522  // Note: this increments the event counter and checks the
523  // old-time fields; avoid in loops.
525 
526  //- Return a const-reference to the internal field
527  inline const typename Internal::FieldType& primitiveField() const;
528 
529  //- Return a reference to the boundary field
530  // Note: this increments the event counter and checks the
531  // old-time fields; avoid in loops.
533 
534  //- Return const-reference to the boundary field
535  inline const Boundary& boundaryField() const;
536 
537  //- Return the time index of the field
538  inline label timeIndex() const;
539 
540  //- Return the time index of the field
541  inline label& timeIndex();
542 
543  //- Store the old-time fields
544  void storeOldTimes() const;
545 
546  //- Store the old-time field
547  void storeOldTime() const;
548 
549  //- Return the number of old time fields stored
550  label nOldTimes() const;
551 
552  //- Return old time field
554 
555  //- Return non-const old time field
556  // (Not a good idea but it is used for sub-cycling)
558 
559  //- Store the field as the previous iteration value
560  void storePrevIter() const;
561 
562  //- Return previous iteration field
564 
565  //- Correct boundary field
567 
568  //- Does the field need a reference level for solution
569  bool needReference() const;
570 
571  //- Return a component of the field
573  (
574  const direction
575  ) const;
576 
577  //- WriteData member function required by regIOobject
578  bool writeData(Ostream&) const;
579 
580  //- Return transpose (only if it is a tensor field)
582 
583  //- Relax field (for steady-state solution).
584  // alpha = 1 : no relaxation
585  // alpha < 1 : relaxation
586  // alpha = 0 : do nothing
587  void relax(const scalar alpha);
588 
589  //- Relax field (for steady-state solution).
590  // alpha is read from controlDict
591  void relax();
592 
593  //- Select the final iteration parameters if `final' is true
594  // by returning the field name + "Final"
595  // otherwise the standard parameters by returning the field name
596  word select(bool final) const;
597 
598  //- Helper function to write the min and max to an Ostream
599  void writeMinMax(Ostream& os) const;
600 
601 
602  // Member function *this operators
603 
604  void negate();
605 
606  void replace
607  (
608  const direction,
610  );
611 
612  void replace
613  (
614  const direction,
615  const dimensioned<cmptType>&
616  );
617 
618  void max(const dimensioned<Type>&);
619  void min(const dimensioned<Type>&);
620 
621  void maxMin
622  (
623  const dimensioned<Type>& minDt,
624  const dimensioned<Type>& maxDt
625  );
626 
627  void max
628  (
630  const dimensioned<Type>&
631  );
632 
633  void min
634  (
636  const dimensioned<Type>&
637  );
638 
639  void scale
640  (
643  );
644 
645  void scale
646  (
648  const dimensioned<Type>&
649  );
650 
651 
652  // Member Operators
653 
654  //- Return a const-reference to the dimensioned internal field
655  // Useful in the formulation of source-terms for FV equations
656  inline const Internal& operator()() const;
657 
661  void operator=(const dimensioned<Type>&);
662  void operator=(const zero&);
663 
665  void operator==(const dimensioned<Type>&);
666  void operator==(const zero&);
667 
670 
673 
676 
679 
680  void operator+=(const dimensioned<Type>&);
681  void operator-=(const dimensioned<Type>&);
682 
683  void operator*=(const dimensioned<scalar>&);
684  void operator/=(const dimensioned<scalar>&);
685 
686 
687  // Ostream operators
688 
689  friend Ostream& operator<< <Type, PatchField, GeoMesh>
690  (
691  Ostream&,
693  );
694 
695  friend Ostream& operator<< <Type, PatchField, GeoMesh>
696  (
697  Ostream&,
699  );
700 };
701 
702 
703 template<class Type, template<class> class PatchField, class GeoMesh>
704 Ostream& operator<<
705 (
706  Ostream&,
708  Boundary&
709 );
710 
711 
712 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
713 
714 } // End namespace Foam
715 
716 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
717 
718 #include "GeometricFieldI.H"
719 
720 #ifdef NoRepository
721  #include "GeometricField.C"
722 #endif
723 
724 #include "GeometricFieldFunctions.H"
725 
726 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
727 
728 #endif
729 
730 // ************************************************************************* //
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:158
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
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 types.
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Mesh &, const dimensionSet &, const word &patchFieldType=PatchField< Type >::calculatedType())
Return a temporary field constructed from name, mesh, dimensionSet.
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 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.
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
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
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
void scale(const GeometricField< Type, PatchField, GeoMesh > &, const GeometricField< Type, PatchField, GeoMesh > &)
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.