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
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 field types and optionally
143  // the actual patch 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 field 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 field 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 field 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>
328  // and patch field type.
330  (
331  const IOobject&,
332  const Mesh&,
333  const dimensioned<Type>&,
334  const word& patchFieldType=PatchField<Type>::calculatedType()
335  );
336 
337  //- Constructor given IOobject, mesh, dimensioned<Type>
338  // and patch field types.
340  (
341  const IOobject&,
342  const Mesh&,
343  const dimensioned<Type>&,
344  const wordList& wantedPatchTypes,
345  const wordList& actualPatchTypes = wordList()
346  );
347 
348  //- Constructor from components
350  (
351  const IOobject&,
352  const Internal&,
353  const PtrList<PatchField<Type>>&
354  );
355 
356  //- Constructor from components
358  (
359  const IOobject&,
360  const Mesh&,
361  const dimensionSet&,
362  const Field<Type>&,
363  const PtrList<PatchField<Type>>&
364  );
365 
366  //- Construct and read given IOobject
368  (
369  const IOobject&,
370  const Mesh&
371  );
372 
373  //- Construct from dictionary
375  (
376  const IOobject&,
377  const Mesh&,
378  const dictionary&
379  );
380 
381  //- Copy constructor
383  (
385  );
386 
387  //- Move constructor
389  (
391  );
392 
393  //- Construct as copy of tmp<GeometricField> deleting argument
395  (
397  );
398 
399  //- Construct as copy resetting IO parameters
401  (
402  const IOobject&,
404  );
405 
406  //- Construct as copy of tmp<GeometricField> resetting IO parameters
408  (
409  const IOobject&,
411  );
412 
413  //- Construct as copy resetting name
415  (
416  const word& newName,
418  );
419 
420  //- Construct as copy resetting name
422  (
423  const word& newName,
425  );
426 
427  //- Construct as copy resetting IO parameters and patch field type
429  (
430  const IOobject&,
432  const word& patchFieldType
433  );
434 
435  //- Construct as copy resetting IO parameters and boundary types
437  (
438  const IOobject&,
440  const wordList& patchFieldTypes,
441  const wordList& actualPatchTypes = wordList()
442  );
443 
444  //- Construct as copy resetting IO parameters and boundary types
446  (
447  const IOobject&,
449  const wordList& patchFieldTypes,
450  const wordList& actualPatchTypes = wordList()
451  );
452 
453  //- Clone
455 
456  //- Return a temporary field constructed from name,
457  // internal field and list of patch fields
459  (
460  const word& name,
461  const Internal&,
462  const PtrList<PatchField<Type>>&
463  );
464 
465  //- Return a temporary field constructed from name, mesh, dimensionSet
466  // and patch field type.
468  (
469  const word& name,
470  const Mesh&,
471  const dimensionSet&,
472  const word& patchFieldType=PatchField<Type>::calculatedType()
473  );
474 
475  //- Return a temporary field constructed from mesh, dimensioned<Type>
476  // and patch field type.
478  (
479  const word& name,
480  const Mesh&,
481  const dimensioned<Type>&,
482  const word& patchFieldType=PatchField<Type>::calculatedType()
483  );
484 
485  //- Return a temporary field constructed from mesh, dimensioned<Type>
486  // and patch field types.
488  (
489  const word& name,
490  const Mesh&,
491  const dimensioned<Type>&,
492  const wordList& patchFieldTypes,
493  const wordList& actualPatchTypes = wordList()
494  );
495 
496  //- Rename temporary field and return
498  (
499  const word& newName,
501  );
502 
503  //- Rename temporary field, reset patch field type and return
505  (
506  const word& newName,
508  const word&
509  );
510 
511  //- Rename and reset patch fields types of temporary field and return
513  (
514  const word& newName,
516  const wordList& patchFieldTypes,
517  const wordList& actualPatchTypes = wordList()
518  );
519 
520 
521  //- Destructor
522  virtual ~GeometricField();
523 
524 
525  // Member Functions
526 
527  //- Return a reference to the dimensioned internal field
528  // Note: this increments the event counter and checks the
529  // old-time fields; avoid in loops.
530  Internal& ref();
531 
532  //- Return a const-reference to the dimensioned internal field
533  inline const Internal& internalField() const;
534 
535  //- Return a const-reference to the dimensioned internal field
536  // of a "vol" field. Useful in the formulation of source-terms
537  // for FV equations
538  inline const Internal& v() const;
539 
540  //- Return a reference to the internal field
541  // Note: this increments the event counter and checks the
542  // old-time fields; avoid in loops.
544 
545  //- Return a const-reference to the internal field
546  inline const typename Internal::FieldType& primitiveField() const;
547 
548  //- Return a reference to the boundary field
549  // Note: this increments the event counter and checks the
550  // old-time fields; avoid in loops.
552 
553  //- Return const-reference to the boundary field
554  inline const Boundary& boundaryField() const;
555 
556  //- Return the time index of the field
557  inline label timeIndex() const;
558 
559  //- Return the time index of the field
560  inline label& timeIndex();
561 
562  //- Store the old-time fields
563  void storeOldTimes() const;
564 
565  //- Store the old-time field
566  void storeOldTime() const;
567 
568  //- Return the number of old time fields stored
569  label nOldTimes() const;
570 
571  //- Return old time field
573 
574  //- Return non-const old time field
575  // (Not a good idea but it is used for sub-cycling)
577 
578  //- Store the field as the previous iteration value
579  void storePrevIter() const;
580 
581  //- Return previous iteration field
583 
584  //- Correct boundary field
586 
587  //- Does the field need a reference level for solution
588  bool needReference() const;
589 
590  //- Return a component of the field
592  (
593  const direction
594  ) const;
595 
596  //- WriteData member function required by regIOobject
597  bool writeData(Ostream&) const;
598 
599  //- Return transpose (only if it is a tensor field)
601 
602  //- Relax field (for steady-state solution).
603  // alpha = 1 : no relaxation
604  // alpha < 1 : relaxation
605  // alpha = 0 : do nothing
606  void relax(const scalar alpha);
607 
608  //- Relax field (for steady-state solution).
609  // alpha is read from controlDict
610  void relax();
611 
612  //- Select the final iteration parameters if `final' is true
613  // by returning the field name + "Final"
614  // otherwise the standard parameters by returning the field name
615  word select(bool final) const;
616 
617  //- Helper function to write the min and max to an Ostream
618  void writeMinMax(Ostream& os) const;
619 
620 
621  // Member function *this operators
622 
623  void negate();
624 
625  void replace
626  (
627  const direction,
629  );
630 
631  void replace
632  (
633  const direction,
634  const dimensioned<cmptType>&
635  );
636 
637  void max(const dimensioned<Type>&);
638 
639  void min(const dimensioned<Type>&);
640 
641  void maxMin
642  (
643  const dimensioned<Type>& minDt,
644  const dimensioned<Type>& maxDt
645  );
646 
647 
648  // Member Operators
649 
650  //- Return a const-reference to the dimensioned internal field
651  // Useful in the formulation of source-terms for FV equations
652  inline const Internal& operator()() const;
653 
657  void operator=(const dimensioned<Type>&);
658  void operator=(const zero&);
659 
661  void operator==(const dimensioned<Type>&);
662  void operator==(const zero&);
663 
666 
669 
672 
675 
676  void operator+=(const dimensioned<Type>&);
677  void operator-=(const dimensioned<Type>&);
678 
679  void operator*=(const dimensioned<scalar>&);
680  void operator/=(const dimensioned<scalar>&);
681 
682 
683  // Ostream operators
684 
685  friend Ostream& operator<< <Type, PatchField, GeoMesh>
686  (
687  Ostream&,
689  );
690 
691  friend Ostream& operator<< <Type, PatchField, GeoMesh>
692  (
693  Ostream&,
695  );
696 };
697 
698 
699 template<class Type, template<class> class PatchField, class GeoMesh>
700 Ostream& operator<<
701 (
702  Ostream&,
704  Boundary&
705 );
706 
707 
708 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
709 
710 } // End namespace Foam
711 
712 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
713 
714 #include "GeometricFieldI.H"
715 
716 #ifdef NoRepository
717  #include "GeometricField.C"
718 #endif
719 
720 #include "GeometricFieldFunctions.H"
721 
722 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
723 
724 #endif
725 
726 // ************************************************************************* //
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
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.
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
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.