GeometricField.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2015-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::GeometricField
29
30Description
31 Generic GeometricField class.
32
33SourceFiles
34 GeometricFieldI.H
35 GeometricField.C
36 GeometricFieldFunctions.H
37 GeometricFieldFunctions.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_GeometricField_H
42#define Foam_GeometricField_H
43
44#include "regIOobject.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51
52// Forward Declarations
53class dictionary;
54
55template<class Type, template<class> class PatchField, class GeoMesh>
56class GeometricField;
57
58template<class Type, template<class> class PatchField, class GeoMesh>
59Ostream& operator<<
60(
61 Ostream&,
63);
64
65template<class Type, template<class> class PatchField, class GeoMesh>
66Ostream& operator<<
67(
68 Ostream&,
70);
71
72
73/*---------------------------------------------------------------------------*\
74 Class GeometricField Declaration
75\*---------------------------------------------------------------------------*/
76
77template<class Type, template<class> class PatchField, class GeoMesh>
79:
80 public DimensionedField<Type, GeoMesh>
81{
82public:
83
84 // Public Typedefs
85
86 //- The mesh type for the GeometricField
87 typedef typename GeoMesh::Mesh Mesh;
88
89 //- The boundary mesh type for the boundary fields
90 typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
91
92 //- The internal field type from which this GeometricField is derived
94
95 //- Type of boundary fields
97
98 //- The patch field type for the GeometricBoundaryField
99 typedef PatchField<Type> Patch;
100
101 //- The field component type
102 typedef typename Field<Type>::cmptType cmptType;
103
104
105private:
106
107 // Private Data
108
109 //- Current time index.
110 // Used to trigger the storing of the old-time value
111 mutable label timeIndex_;
112
113 //- Pointer to old time field
115
116 //- Pointer to previous iteration (used for under-relaxation)
117 mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
118
119 //- Boundary field containing boundary field values
120 Boundary boundaryField_;
121
122
123 // Private Member Functions
124
125 //- Read from file if it is present
126 bool readIfPresent();
127
128 //- Read old time field from file if it is present
129 bool readOldTimeIfPresent();
130
131 //- Read the field from the dictionary
132 void readFields(const dictionary& dict);
133
134 //- Read the field - create the field dictionary on-the-fly
135 void readFields();
136
137
138public:
139
140 //- Runtime type information
141 TypeName("GeometricField");
142
143
144 // Static Member Functions
145
146 //- Return a null geometric field
147 inline static const GeometricField<Type, PatchField, GeoMesh>& null();
148
149
150 // Constructors
151
152 //- Construct given IOobject, mesh, dimensions and patch type.
153 // This allocates storage for the field but does not set values.
154 // Used only within this class to create TEMPORARY variables
156 (
157 const IOobject& io,
158 const Mesh& mesh,
159 const dimensionSet& ds,
160 const word& patchFieldType = PatchField<Type>::calculatedType()
161 );
162
163 //- Construct given IOobject, mesh, dimensions and patch types.
164 // This allocates storage for the field but does not set values.
165 // Used only within this class to create TEMPORARY variables
167 (
168 const IOobject& io,
169 const Mesh& mesh,
170 const dimensionSet& ds,
171 const wordList& wantedPatchTypes,
172 const wordList& actualPatchTypes = wordList()
173 );
174
175 //- Construct given IOobject, mesh, dimensioned<Type> and patch type.
176 // This assigns both dimensions and values.
177 // The name of the dimensioned<Type> has no influence.
179 (
180 const IOobject& io,
181 const Mesh& mesh,
182 const dimensioned<Type>& dt,
183 const word& patchFieldType = PatchField<Type>::calculatedType()
184 );
185
186 //- Construct given IOobject, mesh, dimensioned<Type> and patch types.
187 // This assigns both dimensions and values.
188 // The name of the dimensioned<Type> has no influence.
190 (
191 const IOobject& io,
192 const Mesh& mesh,
193 const dimensioned<Type>& dt,
194 const wordList& wantedPatchTypes,
195 const wordList& actualPatchTypes = wordList()
196 );
197
198 //- Copy construct from internal field and a patch list to clone
200 (
201 const IOobject& io,
202 const Internal& diField,
203 const PtrList<PatchField<Type>>& ptfl
204 );
205
206 //- Move construct from internal field and a patch list to clone
208 (
209 const IOobject& io,
210 Internal&& diField,
211 const PtrList<PatchField<Type>>& ptfl
212 );
213
214 //- Move construct from internal field and a patch list to clone
216 (
217 const IOobject& io,
218 const tmp<Internal>& tfield,
219 const PtrList<PatchField<Type>>& ptfl
220 );
221
222 //- Copy construct from internal field and a patch list to clone
224 (
225 const Internal& diField,
226 const PtrList<PatchField<Type>>& ptfl
227 );
228
229 //- Move construct from internal field and a patch list to clone
231 (
232 Internal&& diField,
233 const PtrList<PatchField<Type>>& ptfl
234 );
235
236 //- Copy construct from internal field, with specified patch type
238 (
239 const IOobject& io,
240 const Mesh& mesh,
241 const dimensionSet& ds,
242 const Field<Type>& iField,
243 const word& patchFieldType = PatchField<Type>::calculatedType()
244 );
245
246 //- Move construct from internal field, with specified patch type
248 (
249 const IOobject& io,
250 const Mesh& mesh,
251 const dimensionSet& ds,
252 Field<Type>&& iField,
253 const word& patchFieldType = PatchField<Type>::calculatedType()
254 );
255
256 //- Copy construct from components
258 (
259 const IOobject& io,
260 const Mesh& mesh,
261 const dimensionSet& ds,
262 const Field<Type>& iField,
263 const PtrList<PatchField<Type>>& ptfl
264 );
265
266 //- Move construct from internal field and a patch list to clone
268 (
269 const IOobject& io,
270 const Mesh& mesh,
271 const dimensionSet& ds,
272 Field<Type>&& iField,
273 const PtrList<PatchField<Type>>& ptfl
274 );
275
276 //- Copy construct from components
278 (
279 const IOobject& io,
280 const Mesh& mesh,
281 const dimensionSet& ds,
282 const tmp<Field<Type>>& tiField,
283 const PtrList<PatchField<Type>>& ptfl
284 );
285
286 //- Construct and read given IOobject
288 (
289 const IOobject& io,
290 const Mesh& mesh,
291 const bool readOldTime = true
292 );
293
294 //- Construct from dictionary
296 (
297 const IOobject& io,
298 const Mesh& mesh,
299 const dictionary& dict
300 );
301
302 //- Copy construct
304 (
306 );
307
308 //- Construct from tmp<GeometricField> deleting argument
310 (
312 );
313
314 //- Construct as copy resetting IO parameters
316 (
317 const IOobject& io,
319 );
320
321 //- Construct from tmp<GeometricField> resetting IO parameters
323 (
324 const IOobject& io,
326 );
327
328 //- Copy construct with a new name
330 (
331 const word& newName,
333 );
334
335 //- Construct with a new name from tmp<GeometricField>
337 (
338 const word& newName,
340 );
341
342 //- Construct as copy resetting IO parameters and patch type
344 (
345 const IOobject& io,
347 const word& patchFieldType
348 );
349
350 //- Construct as copy resetting IO parameters and boundary type
351 //- for selected patchIDs
353 (
354 const IOobject& io,
356 const labelList& patchIDs,
357 const word& patchFieldType
358 );
359
360 //- Construct as copy resetting IO parameters and boundary types
362 (
363 const IOobject& io,
365 const wordList& patchFieldTypes,
366 const wordList& actualPatchTypes = wordList()
367 );
368
369 //- Construct as copy resetting IO parameters and boundary types
371 (
372 const IOobject& io,
374 const wordList& patchFieldTypes,
375 const wordList& actualPatchTypes = wordList()
376 );
377
378 //- Clone
380
381
382 // Static Constructors
383
384 //- Return tmp field from name, mesh, dimensions and patch type.
385 // The field is NO_READ, NO_WRITE, unregistered and uses the
386 // current timeName from the mesh registry
388 (
389 const word& name,
390 const Mesh& mesh,
391 const dimensionSet& ds,
392 const word& patchFieldType = PatchField<Type>::calculatedType()
393 );
394
395 //- Return tmp field from name, mesh, dimensions,
396 //- copy of internal field, with specified patch type.
397 // The field is NO_READ, NO_WRITE, unregistered and uses the
398 // current timeName from the mesh registry
400 (
401 const word& name,
402 const Mesh& mesh,
403 const dimensionSet& ds,
404 const Field<Type>& iField,
405 const word& patchFieldType = PatchField<Type>::calculatedType()
406 );
407
408 //- Return tmp field from name, mesh, dimensions,
409 //- moved internal field contents, with specified patch type.
410 // The field is NO_READ, NO_WRITE, unregistered and uses the
411 // current timeName from the mesh registry
413 (
414 const word& name,
415 const Mesh& mesh,
416 const dimensionSet& ds,
417 Field<Type>&& iField,
418 const word& patchFieldType = PatchField<Type>::calculatedType()
419 );
420
421 //- Return tmp field from name, mesh, dimensioned<Type>
422 //- and patch type.
423 // The field is NO_READ, NO_WRITE, unregistered and uses the
424 // current timeName from the mesh registry
426 (
427 const word& name,
428 const Mesh& mesh,
429 const dimensioned<Type>& dt,
430 const word& patchFieldType = PatchField<Type>::calculatedType()
431 );
432
433 //- Return tmp field from name, mesh, dimensioned<Type>
434 //- and patch types.
435 // The field is NO_READ, NO_WRITE, unregistered and uses the
436 // current timeName from the mesh registry
438 (
439 const word& name,
440 const Mesh& mesh,
441 const dimensioned<Type>& dt,
442 const wordList& patchFieldTypes,
443 const wordList& actualPatchTypes = wordList()
444 );
445
446 //- Return renamed tmp field
447 // The field is NO_READ, NO_WRITE, unregistered and uses the
448 // current timeName from the mesh registry
450 (
451 const word& newName,
453 );
454
455 //- Rename tmp field and reset patch field types and return
456 // The field is NO_READ, NO_WRITE, unregistered and uses the
457 // current timeName from the mesh registry
459 (
460 const word& newName,
462 const wordList& patchFieldTypes,
463 const wordList& actualPatchTypes = wordList()
464 );
465
466
467 //- Destructor
468 virtual ~GeometricField();
469
470
471 // Member Functions
472
473 //- Return a reference to the dimensioned internal field
474 // \param updateAccessTime update event counter and check
475 // old-time fields
476 //
477 // \note Should avoid using updateAccessTime = true within loops.
478 Internal& ref(const bool updateAccessTime = true);
479
480 //- Return a const-reference to the dimensioned internal field
481 inline const Internal& internalField() const;
482
483 //- Return a const-reference to the dimensioned internal field
484 //- of a "vol" field.
485 // Useful in the formulation of source-terms for FV equations
486 //
487 // \note definition in finiteVolume/fields/volFields/volFieldsI.H
488 inline const Internal& v() const;
489
490 //- Return a reference to the internal field
491 // \param updateAccessTime update event counter and check
492 // old-time fields
493 //
494 // \note Should avoid using updateAccessTime = true within loops.
496 (
497 const bool updateAccessTime = true
498 );
499
500 //- Return a const-reference to the internal field
501 inline const typename Internal::FieldType& primitiveField() const;
502
503 //- Return a reference to the boundary field
504 // \param updateAccessTime update event counter and check
505 // old-time fields
506 //
507 // \note Should avoid using updateAccessTime = true within loops.
508 Boundary& boundaryFieldRef(const bool updateAccessTime = true);
509
510 //- Return const-reference to the boundary field
511 inline const Boundary& boundaryField() const;
512
513 //- Return the time index of the field
514 inline label timeIndex() const;
515
516 //- Return the time index of the field
517 inline label& timeIndex();
518
519 //- Store the old-time fields
520 void storeOldTimes() const;
521
522 //- Store the old-time field
523 void storeOldTime() const;
524
525 //- Return the number of old time fields stored
526 label nOldTimes() const;
527
528 //- Return old time field
530
531 //- Return non-const old time field
532 // (Not a good idea but it is used for sub-cycling)
534
535 //- Store the field as the previous iteration value
536 void storePrevIter() const;
537
538 //- Return previous iteration field
540
541 //- Correct boundary field
543
544 //- Does the field need a reference level for solution
545 bool needReference() const;
546
547 //- Return a component of the field
549 (
550 const direction
551 ) const;
552
553 //- WriteData member function required by regIOobject
554 bool writeData(Ostream&) const;
555
556 //- Return transpose (only if it is a tensor field)
558
559 //- Relax field (for steady-state solution).
560 // alpha = 1 : no relaxation
561 // alpha < 1 : relaxation
562 // alpha = 0 : do nothing
563 void relax(const scalar alpha);
564
565 //- Relax field (for steady-state solution).
566 // alpha is read from controlDict
567 void relax();
568
569 //- Select the final iteration parameters if `final' is true
570 // by returning the field name + "Final"
571 // otherwise the standard parameters by returning the field name
572 word select(bool final) const;
573
574 //- Helper function to write the min and max to an Ostream
575 void writeMinMax(Ostream& os) const;
576
577
578 // Member Function *this Operators
579
580 //- Negate the field inplace. See notes in Field
581 void negate();
582
583 //- Normalise the field inplace. See notes in Field
584 void normalise();
585
586 //- Replace specified field component with content from another field
587 void replace
588 (
589 const direction d,
591 );
592
593 //- Replace specified field component with specified value
594 void replace
595 (
596 const direction d,
597 const dimensioned<cmptType>& ds
598 );
599
600 //- Use the minimum of the field and specified value
601 // This sets the \em ceiling on the field values
602 void min(const dimensioned<Type>& dt);
603
604 //- Use the maximum of the field and specified value
605 // This sets the \em floor on the field values
606 void max(const dimensioned<Type>& dt);
607
608 //- Clip the field to be bounded within the specified range
609 void clip(const dimensioned<MinMax<Type>>& range);
610
611 //- Clip the field to be bounded within the specified range
612 void clip
613 (
614 const dimensioned<Type>& minVal,
615 const dimensioned<Type>& maxVal
616 );
617
618 //- Deprecated(2019-01) identical to clip()
619 // \deprecated(2019-01) identical to clip()
620 FOAM_DEPRECATED_FOR(2019-01, "clip() method")
621 void maxMin
622 (
623 const dimensioned<Type>& minVal,
624 const dimensioned<Type>& maxVal
625 );
626
627
628 // Member Operators
629
630 //- Return a const-reference to the dimensioned internal field
631 // Useful in the formulation of source-terms for FV equations
632 inline const Internal& operator()() const;
633
634 void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
635 void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
636 void operator=(const dimensioned<Type>&);
637
638 void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
639 void operator==(const dimensioned<Type>&);
640
641 void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
642 void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
643
644 void operator-=(const GeometricField<Type, PatchField, GeoMesh>&);
645 void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
646
647 void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&);
648 void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&);
649
650 void operator/=(const GeometricField<scalar, PatchField, GeoMesh>&);
651 void operator/=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&);
652
653 void operator+=(const dimensioned<Type>&);
654 void operator-=(const dimensioned<Type>&);
655
656 void operator*=(const dimensioned<scalar>&);
657 void operator/=(const dimensioned<scalar>&);
658
659
660 // Ostream operators
662 friend Ostream& operator<< <Type, PatchField, GeoMesh>
663 (
664 Ostream&,
665 const GeometricField<Type, PatchField, GeoMesh>&
666 );
668 friend Ostream& operator<< <Type, PatchField, GeoMesh>
669 (
670 Ostream&,
671 const tmp<GeometricField<Type, PatchField, GeoMesh>>&
672 );
673};
674
675
676template<class Type, template<class> class PatchField, class GeoMesh>
678(
679 Ostream&,
680 const typename GeometricField<Type, PatchField, GeoMesh>::
681 Boundary&
682);
683
684
685// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
686
687} // End namespace Foam
688
689// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
690
691#include "GeometricFieldI.H"
692
693#ifdef NoRepository
694 #include "GeometricField.C"
695#endif
696
698
699// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
700
701#endif
702
703// ************************************************************************* //
scalar range
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const
Return mesh.
Generic templated field type.
Definition: Field.H:82
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:49
MESH Mesh
Definition: GeoMesh.H:62
MESH::BoundaryMesh BoundaryMesh
Definition: GeoMesh.H:63
Generic GeometricBoundaryField class.
Generic GeometricField class.
void storeOldTime() const
Store the old-time field.
friend Ostream & operator(Ostream &, const GeometricField< Type, PatchField, GeoMesh > &)
DimensionedField< Type, GeoMesh > Internal
The internal field type from which this GeometricField is derived.
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 maxMin(const dimensioned< Type > &minVal, const dimensioned< Type > &maxVal)
Deprecated(2019-01) identical to clip()
void relax()
Relax field (for steady-state solution).
const GeometricField< Type, PatchField, GeoMesh > & oldTime() const
Return old time field.
TypeName("GeometricField")
Runtime type information.
label timeIndex() const
Return the time index of the field.
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Return transpose (only if it is a tensor field)
GeoMesh::Mesh Mesh
The mesh type for the GeometricField.
void replace(const direction d, const GeometricField< cmptType, PatchField, GeoMesh > &gcf)
Replace specified field component with content from another field.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const word &patchFieldType=PatchField< Type >::calculatedType())
Return tmp field from name, mesh, dimensions and patch type.
void max(const dimensioned< Type > &dt)
Use the maximum of the field and specified value.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of boundary fields.
GeoMesh::BoundaryMesh BoundaryMesh
The boundary mesh type for the boundary fields.
void clip(const dimensioned< MinMax< Type > > &range)
Clip the field to be bounded within the specified range.
const Internal & v() const
Definition: volFieldsI.H:33
PatchField< Type > Patch
The patch field type for the GeometricBoundaryField.
Field< Type >::cmptType cmptType
The field component type.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
const GeometricField< Type, PatchField, GeoMesh > & prevIter() const
Return previous iteration field.
bool needReference() const
Does the field need a reference level for solution.
virtual ~GeometricField()
Destructor.
void negate()
Negate the field inplace. See notes in Field.
void storePrevIter() const
Store the field as the previous iteration value.
void min(const dimensioned< Type > &dt)
Use the minimum of the field and specified value.
label nOldTimes() const
Return the number of old time fields stored.
word select(bool final) const
Select the final iteration parameters if `final' is true.
void storeOldTimes() const
Store the old-time fields.
static const GeometricField< Type, PatchField, GeoMesh > & null()
Return a null geometric field.
void correctBoundaryConditions()
Correct boundary field.
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
void normalise()
Normalise the field inplace. See notes in Field.
tmp< GeometricField< Type, PatchField, GeoMesh > > clone() const
Clone.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: MinMax.H:128
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:109
Generic dimensioned Type class.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaT ref()
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:63
uint8_t direction
Definition: direction.H:56
volScalarField & alpha
dictionary dict
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73
conserve primitiveFieldRef()+