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-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::GeometricField
29 
30 Description
31  Generic GeometricField class.
32 
33 SourceFiles
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 "GeometricBoundaryField.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward Declarations
52 
53 template<class Type, template<class> class PatchField, class GeoMesh>
54 class GeometricField;
55 
56 template<class Type, template<class> class PatchField, class GeoMesh>
57 Ostream& operator<<
58 (
59  Ostream&,
60  const GeometricField<Type, PatchField, GeoMesh>&
61 );
62 
63 template<class Type, template<class> class PatchField, class GeoMesh>
64 Ostream& operator<<
65 (
66  Ostream&,
67  const tmp<GeometricField<Type, PatchField, GeoMesh>>&
68 );
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class GeometricField Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<class Type, template<class> class PatchField, class GeoMesh>
76 class GeometricField
77 :
78  public DimensionedField<Type, GeoMesh>
79 {
80 public:
81 
82  // Public Typedefs
83 
84  //- The template instance used for this GeometricField type
86 
87  //- The mesh type for the GeometricField
88  typedef typename GeoMesh::Mesh Mesh;
89 
90  //- The boundary mesh type for the boundary fields
91  typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
92 
93  //- The internal field type from which this GeometricField is derived
95 
96  //- Type of boundary fields
98 
99  //- The patch field type for the GeometricBoundaryField
100  typedef PatchField<Type> Patch;
101 
102  //- Component type of the field elements
103  typedef typename Field<Type>::cmptType cmptType;
104 
105 
106 private:
108  // Private Data
109 
110  //- Current time index.
111  // Used to trigger the storing of the old-time value
112  mutable label timeIndex_;
113 
114  //- Pointer to old time field
115  mutable std::unique_ptr<this_type> field0Ptr_;
116 
117  //- Pointer to previous iteration (used for under-relaxation)
118  mutable std::unique_ptr<this_type> fieldPrevIterPtr_;
119 
120  //- Boundary field containing boundary field values
121  Boundary boundaryField_;
122 
123 
124  // Private Member Functions
125 
126  //- Read from file if it is present
127  bool readIfPresent();
128 
129  //- Read old time field from file if it is present
130  bool readOldTimeIfPresent();
131 
132  //- Read the field from the dictionary
133  void readFields(const dictionary& dict);
134 
135  //- Read the field - create the field dictionary on-the-fly
136  void readFields();
137 
138  //- Implementation for 'New' with specified registerObject preference.
139  // For LEGACY_REGISTER, registration is determined by
140  // objectRegistry::is_cacheTemporaryObject().
141  template<class... Args>
143  (
145  const word& name,
146  const Mesh& mesh,
147  Args&&... args
148  );
149 
150 public:
151 
152  //- Runtime type information
153  TypeName("GeometricField");
154 
155 
156  // Static Member Functions
157 
158  //- Return a null GeometricField (reference to a nullObject).
159  static const this_type& null() noexcept
160  {
161  return NullObjectRef<this_type>();
162  }
163 
164 
165  // Constructors
166 
167  //- Construct given IOobject, mesh, dimensions and patch type.
168  // This allocates storage for the field but does not set values.
169  // Used only within this class to create TEMPORARY variables
171  (
172  const IOobject& io,
173  const Mesh& mesh,
174  const dimensionSet& dims,
175  const word& patchFieldType = PatchField<Type>::calculatedType()
176  );
177 
178  //- Construct given IOobject, mesh, dimensions and patch types.
179  // This allocates storage for the field but does not set values.
180  // Used only within this class to create TEMPORARY variables
182  (
183  const IOobject& io,
184  const Mesh& mesh,
185  const dimensionSet& dims,
186  const wordList& wantedPatchTypes,
187  const wordList& actualPatchTypes = wordList()
188  );
189 
190  //- Construct given IOobject, mesh, dimensions, initial field value
191  //- and given patch type.
192  // This assigns both dimensions and values.
194  (
195  const IOobject& io,
196  const Mesh& mesh,
197  const Type& value,
198  const dimensionSet& dims,
199  const word& patchFieldType = PatchField<Type>::calculatedType()
200  );
201 
202  //- Construct given IOobject, mesh, dimensions, initial field value
203  //- and given patch types.
204  // This assigns both dimensions and values.
206  (
207  const IOobject& io,
208  const Mesh& mesh,
209  const Type& value,
210  const dimensionSet& dims,
211  const wordList& wantedPatchTypes,
212  const wordList& actualPatchTypes = wordList()
213  );
214 
215  //- Construct given IOobject, mesh, dimensioned<Type> and patch type.
216  // This assigns both dimensions and values.
217  // The name of the dimensioned<Type> has no influence.
219  (
220  const IOobject& io,
221  const Mesh& mesh,
222  const dimensioned<Type>& dt,
223  const word& patchFieldType = PatchField<Type>::calculatedType()
224  );
225 
226  //- Construct given IOobject, mesh, dimensioned<Type> and patch types.
227  // This assigns both dimensions and values.
228  // The name of the dimensioned<Type> has no influence.
230  (
231  const IOobject& io,
232  const Mesh& mesh,
233  const dimensioned<Type>& dt,
234  const wordList& wantedPatchTypes,
235  const wordList& actualPatchTypes = wordList()
236  );
237 
238  //- Copy construct from internal field and a patch list to clone
240  (
241  const IOobject& io,
242  const Internal& diField,
243  const PtrList<PatchField<Type>>& ptfl
244  );
245 
246  //- Move construct from internal field and a patch list to clone
248  (
249  const IOobject& io,
250  Internal&& diField,
251  const PtrList<PatchField<Type>>& ptfl
252  );
253 
254  //- Construct from internal field (tmp) and a patch list to clone
256  (
257  const IOobject& io,
258  const tmp<Internal>& tfield,
259  const PtrList<PatchField<Type>>& ptfl
260  );
261 
262  //- Copy construct from internal field and a patch list to clone
264  (
265  const Internal& diField,
266  const PtrList<PatchField<Type>>& ptfl
267  );
268 
269  //- Move construct from internal field and a patch list to clone
271  (
272  Internal&& diField,
273  const PtrList<PatchField<Type>>& ptfl
274  );
275 
276  //- Copy construct from primitive field, with specified patch type
278  (
279  const IOobject& io,
280  const Mesh& mesh,
281  const dimensionSet& dims,
282  const Field<Type>& iField,
283  const word& patchFieldType = PatchField<Type>::calculatedType()
284  );
285 
286  //- Move construct from primitive field, with specified patch type
288  (
289  const IOobject& io,
290  const Mesh& mesh,
291  const dimensionSet& dims,
292  Field<Type>&& iField,
293  const word& patchFieldType = PatchField<Type>::calculatedType()
294  );
295 
296  //- Construct from primitive field (tmp), with specified patch type
298  (
299  const IOobject& io,
300  const Mesh& mesh,
301  const dimensionSet& dims,
302  const tmp<Field<Type>>& tfield,
303  const word& patchFieldType = PatchField<Type>::calculatedType()
304  );
305 
306  //- Copy construct from primitive field and a patch list to clone
308  (
309  const IOobject& io,
310  const Mesh& mesh,
311  const dimensionSet& dims,
312  const Field<Type>& iField,
313  const PtrList<PatchField<Type>>& ptfl
314  );
315 
316  //- Move construct from primitive field and a patch list to clone
318  (
319  const IOobject& io,
320  const Mesh& mesh,
321  const dimensionSet& dims,
322  Field<Type>&& iField,
323  const PtrList<PatchField<Type>>& ptfl
324  );
325 
326  //- Copy construct from components
328  (
329  const IOobject& io,
330  const Mesh& mesh,
331  const dimensionSet& dims,
332  const tmp<Field<Type>>& tfield,
333  const PtrList<PatchField<Type>>& ptfl
334  );
335 
336  //- Read construct using given IOobject. Always reads!
338  (
339  const IOobject& io,
340  const Mesh& mesh,
341  const bool readOldTime = true
342  );
343 
344  //- Construct from dictionary
346  (
347  const IOobject& io,
348  const Mesh& mesh,
349  const dictionary& dict
350  );
351 
352  //- Copy construct
354  (
356  );
357 
358  //- Construct from tmp<GeometricField> deleting argument
360  (
362  );
363 
364  //- Construct as copy resetting IO parameters
366  (
367  const IOobject& io,
369  );
370 
371  //- Construct from tmp<GeometricField> resetting IO parameters
373  (
374  const IOobject& io,
376  );
377 
378  //- Copy construct with a new name
380  (
381  const word& newName,
383  );
384 
385  //- Construct with a new name from tmp<GeometricField>
387  (
388  const word& newName,
390  );
391 
392  //- Construct as copy resetting IO parameters and patch type
394  (
395  const IOobject& io,
397  const word& patchFieldType
398  );
399 
400  //- Construct as copy resetting IO parameters and boundary type
401  //- for selected patchIDs
403  (
404  const IOobject& io,
406  const labelList& patchIDs,
407  const word& patchFieldType
408  );
409 
410  //- Construct as copy resetting IO parameters and boundary types
412  (
413  const IOobject& io,
415  const wordList& patchFieldTypes,
416  const wordList& actualPatchTypes = wordList()
417  );
418 
419  //- Construct as copy resetting IO parameters and boundary types
421  (
422  const IOobject& io,
424  const wordList& patchFieldTypes,
425  const wordList& actualPatchTypes = wordList()
426  );
427 
428  //- Clone
430 
431 
432  // Factory Methods
433 
434  //- Return tmp field (NO_READ, NO_WRITE)
435  //- from name, mesh, dimensions and patch type.
436  //- [Takes current timeName from the mesh registry].
437  // For LEGACY_REGISTER, registration is determined by
438  // objectRegistry::is_cacheTemporaryObject().
440  (
441  const word& name,
443  const Mesh& mesh,
444  const dimensionSet& dims,
445  const word& patchFieldType = PatchField<Type>::calculatedType()
446  );
447 
448  //- Return tmp field (NO_READ, NO_WRITE)
449  //- from name, mesh, dimensions and patch type.
450  //- [Takes current timeName from the mesh registry].
451  // Registration/persistence determined by
452  // objectRegistry::is_cacheTemporaryObject().
454  (
455  const word& name,
456  const Mesh& mesh,
457  const dimensionSet& dims,
458  const word& patchFieldType = PatchField<Type>::calculatedType()
459  );
460 
461  //- Return tmp field (NO_READ, NO_WRITE)
462  //- from name, mesh, dimensions, copy of internal field and patch type.
463  //- [Takes current timeName from the mesh registry].
464  // For LEGACY_REGISTER, registration is determined by
465  // objectRegistry::is_cacheTemporaryObject().
467  (
468  const word& name,
470  const Mesh& mesh,
471  const dimensionSet& dims,
472  const Field<Type>& iField,
473  const word& patchFieldType = PatchField<Type>::calculatedType()
474  );
475 
476  //- Return tmp field (NO_READ, NO_WRITE)
477  //- from name, mesh, dimensions, copy of internal field and patch type.
478  //- [Takes current timeName from the mesh registry].
479  // Registration/persistence determined by
480  // objectRegistry::is_cacheTemporaryObject().
482  (
483  const word& name,
484  const Mesh& mesh,
485  const dimensionSet& dims,
486  const Field<Type>& iField,
487  const word& patchFieldType = PatchField<Type>::calculatedType()
488  );
489 
490  //- Return tmp field (NO_READ, NO_WRITE)
491  //- from name, mesh, dimensions, moved internal field contents
492  //- and patch type.
493  //- [Takes current timeName from the mesh registry].
494  // For LEGACY_REGISTER, registration is determined by
495  // objectRegistry::is_cacheTemporaryObject().
497  (
498  const word& name,
500  const Mesh& mesh,
501  const dimensionSet& dims,
502  Field<Type>&& iField,
503  const word& patchFieldType = PatchField<Type>::calculatedType()
504  );
505 
506  //- Return tmp field (NO_READ, NO_WRITE)
507  //- from name, mesh, dimensions, moved internal field contents
508  //- and patch type.
509  //- [Takes current timeName from the mesh registry].
510  // Registration/persistence determined by
511  // objectRegistry::is_cacheTemporaryObject().
513  (
514  const word& name,
515  const Mesh& mesh,
516  const dimensionSet& dims,
517  Field<Type>&& iField,
518  const word& patchFieldType = PatchField<Type>::calculatedType()
519  );
520 
521  //- Return tmp field (NO_READ, NO_WRITE)
522  //- from name, mesh, dimensions, tmp of primitive field
523  //- and patch type.
524  //- [Takes current timeName from the mesh registry].
525  // For LEGACY_REGISTER, registration is determined by
526  // objectRegistry::is_cacheTemporaryObject().
528  (
529  const word& name,
531  const Mesh& mesh,
532  const dimensionSet& dims,
533  const tmp<Field<Type>>& tfield,
534  const word& patchFieldType = PatchField<Type>::calculatedType()
535  );
536 
537  //- Return tmp field (NO_READ, NO_WRITE)
538  //- from name, mesh, dimensions, tmp of primitive field
539  //- and patch type.
540  //- [Takes current timeName from the mesh registry].
541  // Registration/persistence determined by
542  // objectRegistry::is_cacheTemporaryObject().
544  (
545  const word& name,
546  const Mesh& mesh,
547  const dimensionSet& dims,
548  const tmp<Field<Type>>& tfield,
549  const word& patchFieldType = PatchField<Type>::calculatedType()
550  );
551 
552  //- Return tmp field (NO_READ, NO_WRITE)
553  //- from name, mesh, dimensions, copy of internal field contents
554  //- and patch list to clone.
555  //- [Takes current timeName from the mesh registry].
556  // For LEGACY_REGISTER, registration is determined by
557  // objectRegistry::is_cacheTemporaryObject().
559  (
560  const word& name,
562  const Mesh& mesh,
563  const dimensionSet& dims,
564  const Field<Type>& iField,
565  const PtrList<PatchField<Type>>& pflds
566  );
567 
568  //- Return tmp field (NO_READ, NO_WRITE)
569  //- from name, mesh, dimensions, copy of internal field contents
570  //- and patch list to clone.
571  //- [Takes current timeName from the mesh registry].
572  // Registration/persistence determined by
573  // objectRegistry::is_cacheTemporaryObject().
575  (
576  const word& name,
577  const Mesh& mesh,
578  const dimensionSet& dims,
579  const Field<Type>& iField,
580  const PtrList<PatchField<Type>>& pflds
581  );
582 
583  //- Return tmp field (NO_READ, NO_WRITE)
584  //- from name, mesh, dimensions, moved internal field contents
585  //- and patch list to clone.
586  //- [Takes current timeName from the mesh registry].
587  // For LEGACY_REGISTER, registration is determined by
588  // objectRegistry::is_cacheTemporaryObject().
590  (
591  const word& name,
593  const Mesh& mesh,
594  const dimensionSet& dims,
595  Field<Type>&& iField,
596  const PtrList<PatchField<Type>>& pflds
597  );
598 
599  //- Return tmp field (NO_READ, NO_WRITE)
600  //- from name, mesh, dimensions, moved internal field contents
601  //- and patch list to clone.
602  //- [Takes current timeName from the mesh registry].
603  // Registration/persistence determined by
604  // objectRegistry::is_cacheTemporaryObject().
606  (
607  const word& name,
608  const Mesh& mesh,
609  const dimensionSet& dims,
610  Field<Type>&& iField,
611  const PtrList<PatchField<Type>>& pflds
612  );
613 
614  //- Return tmp field (NO_READ, NO_WRITE)
615  //- from name, mesh, field value, dimensions and patch type.
616  //- [Takes current timeName from the mesh registry].
617  // For LEGACY_REGISTER, registration is determined by
618  // objectRegistry::is_cacheTemporaryObject().
620  (
621  const word& name,
623  const Mesh& mesh,
624  const Type& value,
625  const dimensionSet& dims,
626  const word& patchFieldType = PatchField<Type>::calculatedType()
627  );
628 
629  //- Return tmp field (NO_READ, NO_WRITE)
630  //- from name, mesh, field value, dimensions and patch type.
631  //- [Takes current timeName from the mesh registry].
632  // Registration/persistence determined by
633  // objectRegistry::is_cacheTemporaryObject().
635  (
636  const word& name,
637  const Mesh& mesh,
638  const Type& value,
639  const dimensionSet& dims,
640  const word& patchFieldType = PatchField<Type>::calculatedType()
641  );
642 
643  //- Return tmp field (NO_READ, NO_WRITE)
644  //- from name, mesh, field value, dimensions and patch field types.
645  //- [Takes current timeName from the mesh registry].
646  // For LEGACY_REGISTER, registration is determined by
647  // objectRegistry::is_cacheTemporaryObject().
649  (
650  const word& name,
652  const Mesh& mesh,
653  const Type& value,
654  const dimensionSet& dims,
655  const wordList& patchFieldTypes,
656  const wordList& actualPatchTypes = wordList()
657  );
658 
659  //- Return tmp field (NO_READ, NO_WRITE)
660  //- from name, mesh, field value, dimensions and patch field types.
661  //- [Takes current timeName from the mesh registry].
662  // Registration/persistence determined by
663  // objectRegistry::is_cacheTemporaryObject().
665  (
666  const word& name,
667  const Mesh& mesh,
668  const Type& value,
669  const dimensionSet& dims,
670  const wordList& patchFieldTypes,
671  const wordList& actualPatchTypes = wordList()
672  );
673 
674  //- Return tmp field (NO_READ, NO_WRITE)
675  //- from name, mesh, dimensioned-type and patch type.
676  //- [Takes current timeName from the mesh registry].
677  // For LEGACY_REGISTER, registration is determined by
678  // objectRegistry::is_cacheTemporaryObject().
680  (
681  const word& name,
683  const Mesh& mesh,
684  const dimensioned<Type>& dt,
685  const word& patchFieldType = PatchField<Type>::calculatedType()
686  );
687 
688  //- Return tmp field (NO_READ, NO_WRITE)
689  //- from name, mesh, dimensioned-type and patch type.
690  //- [Takes current timeName from the mesh registry].
691  // Registration/persistence determined by
692  // objectRegistry::is_cacheTemporaryObject().
694  (
695  const word& name,
696  const Mesh& mesh,
697  const dimensioned<Type>& dt,
698  const word& patchFieldType = PatchField<Type>::calculatedType()
699  );
700 
701  //- Return tmp field (NO_READ, NO_WRITE)
702  //- from name, mesh, dimensioned-type and patch field types.
703  //- [Takes current timeName from the mesh registry].
704  // For LEGACY_REGISTER, registration is determined by
705  // objectRegistry::is_cacheTemporaryObject().
707  (
708  const word& name,
710  const Mesh& mesh,
711  const dimensioned<Type>& dt,
712  const wordList& patchFieldTypes,
713  const wordList& actualPatchTypes = wordList()
714  );
715 
716  //- Return tmp field (NO_READ, NO_WRITE)
717  //- from name, mesh, dimensioned-type and patch field types.
718  //- [Takes current timeName from the mesh registry].
719  // Registration/persistence determined by
720  // objectRegistry::is_cacheTemporaryObject().
722  (
723  const word& name,
724  const Mesh& mesh,
725  const dimensioned<Type>& dt,
726  const wordList& patchFieldTypes,
727  const wordList& actualPatchTypes = wordList()
728  );
729 
730  //- Return renamed tmp field (NO_READ, NO_WRITE)
731  //- retaining its instance/local.
732  // For LEGACY_REGISTER, registration is determined by
733  // objectRegistry::is_cacheTemporaryObject().
735  (
736  const word& newName,
739  );
740 
741  //- Return renamed tmp field (NO_READ, NO_WRITE)
742  //- retaining its instance/local.
743  // Registration/persistence determined by
744  // objectRegistry::is_cacheTemporaryObject().
746  (
747  const word& newName,
749  );
750 
751  //- Return renamed tmp field (NO_READ, NO_WRITE)
752  //- with reset patch field type, retaining its instance/local.
753  // For LEGACY_REGISTER, registration is determined by
754  // objectRegistry::is_cacheTemporaryObject().
756  (
757  const word& newName,
760  const word& patchFieldType
761  );
762 
763  //- Return renamed tmp field (NO_READ, NO_WRITE)
764  //- with reset patch field type, retaining its instance/local.
765  // Registration/persistence determined by
766  // objectRegistry::is_cacheTemporaryObject().
768  (
769  const word& newName,
771  const word& patchFieldType
772  );
773 
774  //- Return renamed tmp field (NO_READ, NO_WRITE)
775  //- with reset patch field types, retaining its instance/local.
776  // For LEGACY_REGISTER, registration is determined by
777  // objectRegistry::is_cacheTemporaryObject().
779  (
780  const word& newName,
783  const wordList& patchFieldTypes,
784  const wordList& actualPatchTypes = wordList()
785  );
786 
787  //- Return renamed tmp field (NO_READ, NO_WRITE)
788  //- with reset patch field types, retaining its instance/local.
789  // Registration/persistence determined by
790  // objectRegistry::is_cacheTemporaryObject().
792  (
793  const word& newName,
795  const wordList& patchFieldTypes,
796  const wordList& actualPatchTypes = wordList()
797  );
798 
799  //- Construct tmp field (NO_READ, NO_WRITE)
800  //- based on mesh/registry information from an existing field.
801  //- [Takes instance from the field].
802  // Registration/persistence determined by
803  // objectRegistry::is_cacheTemporaryObject().
804  template<class AnyType>
806  (
808  const word& name,
809  const dimensionSet& dims,
810  const word& patchFieldType = PatchField<Type>::calculatedType()
811  );
812 
813  //- Construct tmp field (NO_READ, NO_WRITE)
814  //- based on mesh/registry information from an existing field.
815  //- and initialise with value.
816  //- [Takes instance from the field].
817  // Registration/persistence determined by
818  // objectRegistry::is_cacheTemporaryObject().
819  template<class AnyType>
821  (
823  const word& name,
824  const dimensioned<Type>& dt,
825  const word& patchFieldType = PatchField<Type>::calculatedType()
826  );
827 
828 
829  //- Destructor
830  virtual ~GeometricField();
831 
832 
833  // Member Functions
834 
835  //- Return non-const reference to this field
836  this_type& constCast() const noexcept
837  {
838  return const_cast<this_type&>(*this);
839  }
840 
841  //- Return a const-reference to the dimensioned internal field.
842  inline const Internal& internalField() const noexcept;
843 
844  //- Return a reference to the dimensioned internal field.
845  // \param updateAccessTime update event counter and check
846  // old-time fields
847  //
848  // \note Should avoid using updateAccessTime = true within loops.
849  Internal& internalFieldRef(const bool updateAccessTime = true);
850 
851  //- Same as internalFieldRef()
852  Internal& ref(const bool updateAccessTime = true)
853  {
854  return this->internalFieldRef(updateAccessTime);
855  }
856 
857  //- Return a const-reference to the dimensioned internal field
858  //- of a "vol" field.
859  // Useful in the formulation of source-terms for FV equations
860  //
861  // \note definition in finiteVolume/fields/volFields/volFieldsI.H
862  inline const Internal& v() const;
863 
864  //- Return a const-reference to the internal field values.
865  inline const typename Internal::FieldType& primitiveField()
866  const noexcept;
867 
868  //- Return a reference to the internal field values.
869  // \param updateAccessTime update event counter and check
870  // old-time fields
871  //
872  // \note Should avoid using updateAccessTime = true within loops.
874  (
875  const bool updateAccessTime = true
876  );
877 
878  //- Return const-reference to the boundary field
879  inline const Boundary& boundaryField() const noexcept;
880 
881  //- Return a reference to the boundary field
882  // \param updateAccessTime update event counter and check
883  // old-time fields
884  //
885  // \note Should avoid using updateAccessTime = true within loops.
886  Boundary& boundaryFieldRef(const bool updateAccessTime = true);
887 
888  //- The time index of the field
889  label timeIndex() const noexcept { return timeIndex_; }
890 
891  //- Write-access to the time index of the field
892  label& timeIndex() noexcept { return timeIndex_; }
893 
894  //- The number of old time fields stored
895  label nOldTimes() const noexcept;
896 
897  //- Store the old-time fields
898  void storeOldTimes() const;
899 
900  //- Store the old-time field
901  void storeOldTime() const;
902 
903  //- Return old time field
904  const GeometricField<Type, PatchField, GeoMesh>& oldTime() const;
905 
906  //- Return non-const old time field
907  // (Not a good idea but it is used for sub-cycling)
908  GeometricField<Type, PatchField, GeoMesh>& oldTime();
909 
910  //- Store the field as the previous iteration value
911  void storePrevIter() const;
912 
913  //- Return previous iteration field
914  const GeometricField<Type, PatchField, GeoMesh>& prevIter() const;
915 
916  //- Remove old-time and prev-iter fields
917  void clearOldTimes();
918 
919  //- Correct boundary field
921 
922  //- Correct boundary conditions after a purely local operation.
923  // Is dummy for processor boundary conditions etc
925 
926  //- Does the field need a reference level for solution
927  bool needReference() const;
928 
929  //- Return a component of the field
930  tmp<GeometricField<cmptType, PatchField, GeoMesh>> component
931  (
932  const direction
933  ) const;
934 
935  //- Return transpose (only if it is a tensor field)
936  tmp<GeometricField<Type, PatchField, GeoMesh>> T() const;
937 
938  //- Relax field (for steady-state solution).
939  // alpha = 1 : no relaxation
940  // alpha < 1 : relaxation
941  // alpha = 0 : do nothing
942  void relax(const scalar alpha);
943 
944  //- Relax field (for steady-state solution).
945  // alpha is read from controlDict
946  void relax();
947 
948  //- Select the final iteration parameters if \c final is true
949  //- by returning the field name + "Final"
950  //- otherwise the standard parameters by returning the field name
951  word select(bool final) const;
952 
953  //- Helper function to write the min and max to an Ostream.
954  // Uses the specified communicator for reductions
955  void writeMinMax(Ostream& os, label comm = UPstream::worldComm) const;
956 
957 
958  // Member Function *this Operators
959 
960  //- Negate the field inplace. See notes in Field
961  void negate();
962 
963  //- Normalise the field inplace. See notes in Field
964  void normalise();
965 
966  //- Replace specified field component with content from another field
967  void replace
968  (
969  const direction d,
970  const GeometricField<cmptType, PatchField, GeoMesh>& gcf
971  );
972 
973  //- Replace specified field component with specified value
974  void replace
975  (
976  const direction d,
977  const dimensioned<cmptType>& ds
978  );
979 
980  //- Impose lower (floor) clamp on the field values (in-place)
981  void clamp_min(const Type& lower);
982 
983  //- Impose lower (floor) clamp on the field values (in-place)
984  // No dimension checking
985  void clamp_min(const dimensioned<Type>& lower);
986 
987  //- Impose lower (floor) clamp on the field values (in-place)
988  // No dimension checking
989  void clamp_min(const GeometricField<Type, PatchField, GeoMesh>& lower);
990 
991  //- Impose upper (ceiling) clamp on the field values (in-place)
992  void clamp_max(const Type& upper);
993 
994  //- Impose upper (ceiling) clamp on the field values (in-place)
995  // No dimension checking
996  void clamp_max(const dimensioned<Type>& upper);
997 
998  //- Impose upper (ceiling) clamp on the field values (in-place)
999  // No dimension checking
1000  void clamp_max(const GeometricField<Type, PatchField, GeoMesh>& upper);
1001 
1002  //- Clamp field values (in-place) to the specified range.
1003  // Does not check if range is valid or not. No dimension checking.
1004  void clamp_range(const dimensioned<MinMax<Type>>& range);
1005 
1006  //- Clamp field values (in-place) to the specified range.
1007  // Does not check if range is valid or not.
1008  void clamp_range(const Type& lower, const Type& upper);
1009 
1010  //- Clamp field values (in-place) to the specified range.
1011  // Does not check if range is valid or not.
1012  void clamp_range(const MinMax<Type>& range);
1013 
1014  //- Clamp field values (in-place) to the specified range.
1015  // Does not check if range is valid or not. No dimension checking.
1016  void clamp_range
1017  (
1018  const dimensioned<Type>& lower,
1019  const dimensioned<Type>& upper
1020  );
1021 
1022 
1023  // Member Operators
1024 
1025  //- Same as internalField().
1026  // Useful in the formulation of source-terms for FV equations
1027  const Internal& operator()() const { return *this; }
1028 
1031  void operator=(const dimensioned<Type>&);
1032 
1034  void operator==(const dimensioned<Type>&);
1035 
1038 
1041 
1044 
1047 
1048  void operator+=(const dimensioned<Type>&);
1049  void operator-=(const dimensioned<Type>&);
1050 
1051  void operator*=(const dimensioned<scalar>&);
1052  void operator/=(const dimensioned<scalar>&);
1053 
1054  // Prevent automatic comparison rewriting (c++20)
1055  bool operator!=
1056  (
1058  ) = delete;
1059  bool operator!=
1060  (
1062  ) = delete;
1063  bool operator!=(const dimensioned<Type>&) = delete;
1064 
1065 
1066  // Write
1067 
1068  //- The writeData function (required by regIOobject)
1069  bool writeData(Ostream& os) const;
1070 
1071 
1072  // Ostream Operators
1073 
1074  //- Calls GeometricField::writeData()
1075  friend Ostream& operator<< <Type, PatchField, GeoMesh>
1076  (
1077  Ostream&,
1079  );
1080 
1081  //- Calls GeometricField::writeData()
1082  friend Ostream& operator<< <Type, PatchField, GeoMesh>
1083  (
1084  Ostream&,
1086  );
1087 
1088 
1089  // Housekeeping
1090 
1091  //- Clamp field values (in-place) to the specified range.
1092  // \deprecated(2023-01) prefer clamp_range() naming
1093  FOAM_DEPRECATED_FOR(2023-01, "clamp_range() method")
1094  void clip(const dimensioned<MinMax<Type>>& range)
1095  {
1096  this->clamp_range(range);
1097  }
1099  //- Clamp field values (in-place) to the specified range.
1100  // \deprecated(2023-01) prefer clamp_range() naming
1101  FOAM_DEPRECATED_FOR(2023-01, "clamp_range() method")
1102  void clip(const dimensioned<Type>& lo, const dimensioned<Type>& hi)
1103  {
1104  this->clamp_range(lo.value(), hi.value());
1105  }
1106 
1107  //- Use minimum of the field and specified value. ie, clamp_max().
1108  // This sets the \em ceiling on the field values
1109  // \deprecated(2023-01) prefer clamp_max()
1110  FOAM_DEPRECATED_STRICT(2023-01, "clamp_max() method")
1111  void min(const dimensioned<Type>& upper) { this->clamp_max(upper); }
1112 
1113  //- Use maximum of the field and specified value. ie, clamp_min().
1114  // This sets the \em floor on the field values
1115  // \deprecated(2023-01) prefer clamp_min()
1116  FOAM_DEPRECATED_STRICT(2023-01, "clamp_min() method")
1117  void max(const dimensioned<Type>& lower) { this->clamp_min(lower); }
1118 
1119  //- Deprecated(2019-01) identical to clamp_range()
1120  // \deprecated(2019-01) identical to clamp_range()
1121  FOAM_DEPRECATED_FOR(2019-01, "clamp_range() method")
1122  void maxMin(const dimensioned<Type>& lo, const dimensioned<Type>& hi)
1123  {
1124  return this->clamp_range(lo.value(), hi.value());
1125  }
1126 };
1127 
1128 
1129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1130 
1131 } // End namespace Foam
1132 
1133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1134 
1135 #include "GeometricFieldI.H"
1136 #include "GeometricFieldFunctions.H"
1137 
1138 #ifdef NoRepository
1139  #include "GeometricField.C"
1140 #endif
1141 
1142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1143 
1144 #endif
1145 
1146 // ************************************************************************* //
void clamp_min(const Type &lower)
Impose lower (floor) clamp on the field values (in-place)
const labelList patchIDs(pbm.indices(polyPatchNames, true))
void clamp_range(const dimensioned< MinMax< Type >> &range)
Clamp field values (in-place) to the specified range.
dictionary dict
const GeometricField< Type, PatchField, GeoMesh > & oldTime() const
Return old time field.
uint8_t direction
Definition: direction.H:46
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
GeoMesh::BoundaryMesh BoundaryMesh
The boundary mesh type for the boundary fields.
void operator=(const GeometricField< Type, PatchField, GeoMesh > &)
void maxMin(const dimensioned< Type > &lo, const dimensioned< Type > &hi)
Deprecated(2019-01) identical to clamp_range()
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
void clearOldTimes()
Remove old-time and prev-iter fields.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Field< Type >::cmptType cmptType
Component type of the field elements.
MESH::BoundaryMesh BoundaryMesh
Definition: GeoMesh.H:62
const Internal & internalField() const noexcept
Return a const-reference to the dimensioned internal field.
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:172
A min/max value pair with additional methods. In addition to conveniently storing values...
Definition: HashSet.H:72
GeometricField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=PatchField< Type >::calculatedType())
Construct given IOobject, mesh, dimensions and patch type.
void operator/=(const GeometricField< scalar, PatchField, GeoMesh > &)
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
label nOldTimes() const noexcept
The number of old time fields stored.
void writeMinMax(Ostream &os, label comm=UPstream::worldComm) const
Helper function to write the min and max to an Ostream.
GeoMesh::Mesh Mesh
The mesh type for the GeometricField.
void clip(const dimensioned< MinMax< Type >> &range)
Clamp field values (in-place) to the specified range.
TypeName("GeometricField")
Runtime type information.
Generic GeometricField class.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of boundary fields.
Generic dimensioned Type class.
DimensionedField< Type, GeoMesh > Internal
The internal field type from which this GeometricField is derived.
Field< Type > FieldType
Type of the field from which this DimensionedField is derived.
bool writeData(Ostream &os) const
The writeData function (required by regIOobject)
word select(bool final) const
Select the final iteration parameters if final is true by returning the field name + "Final" otherwis...
scalar range
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
const word calculatedType
A calculated patch field type.
bool needReference() const
Does the field need a reference level for solution.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
const Internal & v() const
Return a const-reference to the dimensioned internal field of a "vol" field.
Definition: volFieldsI.H:26
void storeOldTimes() const
Store the old-time fields.
Generic templated field type.
Definition: Field.H:63
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool operator!=(const GeometricField< Type, PatchField, GeoMesh > &)=delete
void storeOldTime() const
Store the old-time field.
void operator*=(const GeometricField< scalar, PatchField, GeoMesh > &)
void operator+=(const GeometricField< Type, PatchField, GeoMesh > &)
void min(const dimensioned< Type > &upper)
Use minimum of the field and specified value. ie, clamp_max().
GeoMesh::Mesh Mesh
The mesh type for the DimensionedField.
#define FOAM_DEPRECATED_STRICT(since, replacement)
Definition: stdFoam.H:53
void negate()
Negate the field inplace. See notes in Field.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=PatchField< Type >::calculatedType())
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions and patch type. [Takes current timeN...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:255
Internal & internalFieldRef(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Return transpose (only if it is a tensor field)
void operator-=(const GeometricField< Type, PatchField, GeoMesh > &)
this_type & constCast() const noexcept
Return non-const reference to this field.
void normalise()
Normalise the field inplace. See notes in Field.
const GeometricField< Type, PatchField, GeoMesh > & prevIter() const
Return previous iteration field.
OBJstream os(runTime.globalPath()/outputName)
MESH Mesh
Definition: GeoMesh.H:61
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
label timeIndex() const noexcept
The time index of the field.
virtual ~GeometricField()
Destructor.
Generic GeometricBoundaryField class.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void clamp_max(const Type &upper)
Impose upper (ceiling) clamp on the field values (in-place)
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
List< word > wordList
List of word.
Definition: fileName.H:59
void operator==(const tmp< GeometricField< Type, PatchField, GeoMesh >> &)
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
tmp< GeometricField< Type, PatchField, GeoMesh > > clone() const
Clone.
static const this_type & null() noexcept
Return a null GeometricField (reference to a nullObject).
PatchField< Type > Patch
The patch field type for the GeometricBoundaryField.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
void max(const dimensioned< Type > &lower)
Use maximum of the field and specified value. ie, clamp_min().
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const noexcept
Return const reference to mesh.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
friend Ostream & operator(Ostream &, const GeometricField< Type, PatchField, GeoMesh > &)
Calls GeometricField::writeData()
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
void correctBoundaryConditions()
Correct boundary field.
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef()
void storePrevIter() const
Store the field as the previous iteration value.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
GeometricField< Type, PatchField, GeoMesh > this_type
The template instance used for this GeometricField type.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
void relax()
Relax field (for steady-state solution).
void correctLocalBoundaryConditions()
Correct boundary conditions after a purely local operation.
Namespace for OpenFOAM.
void replace(const direction d, const GeometricField< cmptType, PatchField, GeoMesh > &gcf)
Replace specified field component with content from another field.