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-2024 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 mesh type for the GeometricField
85  typedef typename GeoMesh::Mesh Mesh;
86 
87  //- The boundary mesh type for the boundary fields
88  typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
89 
90  //- The internal field type from which this GeometricField is derived
92 
93  //- Type of boundary fields
95 
96  //- The patch field type for the GeometricBoundaryField
97  typedef PatchField<Type> Patch;
98 
99  //- Component type of the field elements
100  typedef typename Field<Type>::cmptType cmptType;
101 
103 private:
104 
105  // Private Typedefs
106 
107  //- The GeometricField type
109 
110 
111  // Private Data
112 
113  //- Current time index.
114  // Used to trigger the storing of the old-time value
115  mutable label timeIndex_;
116 
117  //- Pointer to old time field
118  mutable std::unique_ptr<this_type> field0Ptr_;
119 
120  //- Pointer to previous iteration (used for under-relaxation)
121  mutable std::unique_ptr<this_type> fieldPrevIterPtr_;
122 
123  //- Boundary field containing boundary field values
124  Boundary boundaryField_;
125 
126 
127  // Private Member Functions
128 
129  //- Read from file if it is present
130  bool readIfPresent();
131 
132  //- Read old time field from file if it is present
133  bool readOldTimeIfPresent();
134 
135  //- Read the field from the dictionary
136  void readFields(const dictionary& dict);
137 
138  //- Read the field - create the field dictionary on-the-fly
139  void readFields();
140 
141  //- Implementation for 'New' with specified registerObject preference.
142  // For LEGACY_REGISTER, registration is determined by
143  // objectRegistry::is_cacheTemporaryObject().
144  template<class... Args>
146  (
148  const word& name,
149  const Mesh& mesh,
150  Args&&... args
151  );
152 
153 public:
154 
155  //- Runtime type information
156  TypeName("GeometricField");
157 
158 
159  // Static Member Functions
160 
161  //- Return a null GeometricField (reference to a nullObject).
163  {
164  return NullObjectRef<GeometricField<Type, PatchField, GeoMesh>>();
165  }
166 
167 
168  // Constructors
169 
170  //- Construct given IOobject, mesh, dimensions and patch type.
171  // This allocates storage for the field but does not set values.
172  // Used only within this class to create TEMPORARY variables
174  (
175  const IOobject& io,
176  const Mesh& mesh,
177  const dimensionSet& dims,
178  const word& patchFieldType = PatchField<Type>::calculatedType()
179  );
180 
181  //- Construct given IOobject, mesh, dimensions and patch types.
182  // This allocates storage for the field but does not set values.
183  // Used only within this class to create TEMPORARY variables
185  (
186  const IOobject& io,
187  const Mesh& mesh,
188  const dimensionSet& dims,
189  const wordList& wantedPatchTypes,
190  const wordList& actualPatchTypes = wordList()
191  );
192 
193  //- Construct given IOobject, mesh, dimensions, initial field value
194  //- and given patch type.
195  // This assigns both dimensions and values.
197  (
198  const IOobject& io,
199  const Mesh& mesh,
200  const Type& value,
201  const dimensionSet& dims,
202  const word& patchFieldType = PatchField<Type>::calculatedType()
203  );
204 
205  //- Construct given IOobject, mesh, dimensions, initial field value
206  //- and given patch types.
207  // This assigns both dimensions and values.
209  (
210  const IOobject& io,
211  const Mesh& mesh,
212  const Type& value,
213  const dimensionSet& dims,
214  const wordList& wantedPatchTypes,
215  const wordList& actualPatchTypes = wordList()
216  );
217 
218  //- Construct given IOobject, mesh, dimensioned<Type> and patch type.
219  // This assigns both dimensions and values.
220  // The name of the dimensioned<Type> has no influence.
222  (
223  const IOobject& io,
224  const Mesh& mesh,
225  const dimensioned<Type>& dt,
226  const word& patchFieldType = PatchField<Type>::calculatedType()
227  );
228 
229  //- Construct given IOobject, mesh, dimensioned<Type> and patch types.
230  // This assigns both dimensions and values.
231  // The name of the dimensioned<Type> has no influence.
233  (
234  const IOobject& io,
235  const Mesh& mesh,
236  const dimensioned<Type>& dt,
237  const wordList& wantedPatchTypes,
238  const wordList& actualPatchTypes = wordList()
239  );
240 
241  //- Copy construct from internal field and a patch list to clone
243  (
244  const IOobject& io,
245  const Internal& diField,
246  const PtrList<PatchField<Type>>& ptfl
247  );
248 
249  //- Move construct from internal field and a patch list to clone
251  (
252  const IOobject& io,
253  Internal&& diField,
254  const PtrList<PatchField<Type>>& ptfl
255  );
256 
257  //- Move construct from internal field and a patch list to clone
259  (
260  const IOobject& io,
261  const tmp<Internal>& tfield,
262  const PtrList<PatchField<Type>>& ptfl
263  );
264 
265  //- Copy construct from internal field and a patch list to clone
267  (
268  const Internal& diField,
269  const PtrList<PatchField<Type>>& ptfl
270  );
271 
272  //- Move construct from internal field and a patch list to clone
274  (
275  Internal&& diField,
276  const PtrList<PatchField<Type>>& ptfl
277  );
278 
279  //- Copy construct from internal field, with specified patch type
281  (
282  const IOobject& io,
283  const Mesh& mesh,
284  const dimensionSet& dims,
285  const Field<Type>& iField,
286  const word& patchFieldType = PatchField<Type>::calculatedType()
287  );
288 
289  //- Move construct from internal field, with specified patch type
291  (
292  const IOobject& io,
293  const Mesh& mesh,
294  const dimensionSet& dims,
295  Field<Type>&& iField,
296  const word& patchFieldType = PatchField<Type>::calculatedType()
297  );
298 
299  //- Copy construct from components
301  (
302  const IOobject& io,
303  const Mesh& mesh,
304  const dimensionSet& dims,
305  const Field<Type>& iField,
306  const PtrList<PatchField<Type>>& ptfl
307  );
308 
309  //- Move construct from internal field and a patch list to clone
311  (
312  const IOobject& io,
313  const Mesh& mesh,
314  const dimensionSet& dims,
315  Field<Type>&& iField,
316  const PtrList<PatchField<Type>>& ptfl
317  );
318 
319  //- Copy construct from components
321  (
322  const IOobject& io,
323  const Mesh& mesh,
324  const dimensionSet& dims,
325  const tmp<Field<Type>>& tiField,
326  const PtrList<PatchField<Type>>& ptfl
327  );
328 
329  //- Read construct using given IOobject. Always reads!
331  (
332  const IOobject& io,
333  const Mesh& mesh,
334  const bool readOldTime = true
335  );
336 
337  //- Construct from dictionary
339  (
340  const IOobject& io,
341  const Mesh& mesh,
342  const dictionary& dict
343  );
344 
345  //- Copy construct
347  (
349  );
350 
351  //- Construct from tmp<GeometricField> deleting argument
353  (
355  );
356 
357  //- Construct as copy resetting IO parameters
359  (
360  const IOobject& io,
362  );
363 
364  //- Construct from tmp<GeometricField> resetting IO parameters
366  (
367  const IOobject& io,
369  );
370 
371  //- Copy construct with a new name
373  (
374  const word& newName,
376  );
377 
378  //- Construct with a new name from tmp<GeometricField>
380  (
381  const word& newName,
383  );
384 
385  //- Construct as copy resetting IO parameters and patch type
387  (
388  const IOobject& io,
390  const word& patchFieldType
391  );
392 
393  //- Construct as copy resetting IO parameters and boundary type
394  //- for selected patchIDs
396  (
397  const IOobject& io,
399  const labelList& patchIDs,
400  const word& patchFieldType
401  );
402 
403  //- Construct as copy resetting IO parameters and boundary types
405  (
406  const IOobject& io,
408  const wordList& patchFieldTypes,
409  const wordList& actualPatchTypes = wordList()
410  );
411 
412  //- Construct as copy resetting IO parameters and boundary types
414  (
415  const IOobject& io,
417  const wordList& patchFieldTypes,
418  const wordList& actualPatchTypes = wordList()
419  );
420 
421  //- Clone
423 
424 
425  // Factory Methods
426 
427  //- Return tmp field (NO_READ, NO_WRITE)
428  //- from name, mesh, dimensions and patch type.
429  //- [Takes current timeName from the mesh registry].
430  // For LEGACY_REGISTER, registration is determined by
431  // objectRegistry::is_cacheTemporaryObject().
433  (
434  const word& name,
436  const Mesh& mesh,
437  const dimensionSet& dims,
438  const word& patchFieldType = PatchField<Type>::calculatedType()
439  );
440 
441  //- Return tmp field (NO_READ, NO_WRITE)
442  //- from name, mesh, dimensions and patch type.
443  //- [Takes current timeName from the mesh registry].
444  // Registration/persistence determined by
445  // objectRegistry::is_cacheTemporaryObject().
447  (
448  const word& name,
449  const Mesh& mesh,
450  const dimensionSet& dims,
451  const word& patchFieldType = PatchField<Type>::calculatedType()
452  );
453 
454  //- Return tmp field (NO_READ, NO_WRITE)
455  //- from name, mesh, dimensions, copy of internal field and patch type.
456  //- [Takes current timeName from the mesh registry].
457  // For LEGACY_REGISTER, registration is determined by
458  // objectRegistry::is_cacheTemporaryObject().
460  (
461  const word& name,
463  const Mesh& mesh,
464  const dimensionSet& dims,
465  const Field<Type>& iField,
466  const word& patchFieldType = PatchField<Type>::calculatedType()
467  );
468 
469  //- Return tmp field (NO_READ, NO_WRITE)
470  //- from name, mesh, dimensions, copy of internal field and patch type.
471  //- [Takes current timeName from the mesh registry].
472  // Registration/persistence determined by
473  // objectRegistry::is_cacheTemporaryObject().
475  (
476  const word& name,
477  const Mesh& mesh,
478  const dimensionSet& dims,
479  const Field<Type>& iField,
480  const word& patchFieldType = PatchField<Type>::calculatedType()
481  );
482 
483  //- Return tmp field (NO_READ, NO_WRITE)
484  //- from name, mesh, dimensions, moved internal field contents
485  //- and patch type.
486  //- [Takes current timeName from the mesh registry].
487  // For LEGACY_REGISTER, registration is determined by
488  // objectRegistry::is_cacheTemporaryObject().
490  (
491  const word& name,
493  const Mesh& mesh,
494  const dimensionSet& dims,
495  Field<Type>&& iField,
496  const word& patchFieldType = PatchField<Type>::calculatedType()
497  );
498 
499  //- Return tmp field (NO_READ, NO_WRITE)
500  //- from name, mesh, dimensions, moved internal field contents
501  //- and patch type.
502  //- [Takes current timeName from the mesh registry].
503  // Registration/persistence determined by
504  // objectRegistry::is_cacheTemporaryObject().
506  (
507  const word& name,
508  const Mesh& mesh,
509  const dimensionSet& dims,
510  Field<Type>&& iField,
511  const word& patchFieldType = PatchField<Type>::calculatedType()
512  );
513 
514  //- Return tmp field (NO_READ, NO_WRITE)
515  //- from name, mesh, dimensions, copy of internal field contents
516  //- and patch list to clone.
517  //- [Takes current timeName from the mesh registry].
518  // For LEGACY_REGISTER, registration is determined by
519  // objectRegistry::is_cacheTemporaryObject().
521  (
522  const word& name,
524  const Mesh& mesh,
525  const dimensionSet& dims,
526  const Field<Type>& iField,
527  const PtrList<PatchField<Type>>& pflds
528  );
529 
530  //- Return tmp field (NO_READ, NO_WRITE)
531  //- from name, mesh, dimensions, copy of internal field contents
532  //- and patch list to clone.
533  //- [Takes current timeName from the mesh registry].
534  // Registration/persistence determined by
535  // objectRegistry::is_cacheTemporaryObject().
537  (
538  const word& name,
539  const Mesh& mesh,
540  const dimensionSet& dims,
541  const Field<Type>& iField,
542  const PtrList<PatchField<Type>>& pflds
543  );
544 
545  //- Return tmp field (NO_READ, NO_WRITE)
546  //- from name, mesh, dimensions, moved internal field contents
547  //- and patch list to clone.
548  //- [Takes current timeName from the mesh registry].
549  // For LEGACY_REGISTER, registration is determined by
550  // objectRegistry::is_cacheTemporaryObject().
552  (
553  const word& name,
555  const Mesh& mesh,
556  const dimensionSet& dims,
557  Field<Type>&& iField,
558  const PtrList<PatchField<Type>>& pflds
559  );
560 
561  //- Return tmp field (NO_READ, NO_WRITE)
562  //- from name, mesh, dimensions, moved internal field contents
563  //- and patch list to clone.
564  //- [Takes current timeName from the mesh registry].
565  // Registration/persistence determined by
566  // objectRegistry::is_cacheTemporaryObject().
568  (
569  const word& name,
570  const Mesh& mesh,
571  const dimensionSet& dims,
572  Field<Type>&& iField,
573  const PtrList<PatchField<Type>>& pflds
574  );
575 
576  //- Return tmp field (NO_READ, NO_WRITE)
577  //- from name, mesh, field value, dimensions and patch type.
578  //- [Takes current timeName from the mesh registry].
579  // For LEGACY_REGISTER, registration is determined by
580  // objectRegistry::is_cacheTemporaryObject().
582  (
583  const word& name,
585  const Mesh& mesh,
586  const Type& value,
587  const dimensionSet& dims,
588  const word& patchFieldType = PatchField<Type>::calculatedType()
589  );
590 
591  //- Return tmp field (NO_READ, NO_WRITE)
592  //- from name, mesh, field value, dimensions and patch type.
593  //- [Takes current timeName from the mesh registry].
594  // Registration/persistence determined by
595  // objectRegistry::is_cacheTemporaryObject().
597  (
598  const word& name,
599  const Mesh& mesh,
600  const Type& value,
601  const dimensionSet& dims,
602  const word& patchFieldType = PatchField<Type>::calculatedType()
603  );
604 
605  //- Return tmp field (NO_READ, NO_WRITE)
606  //- from name, mesh, field value, dimensions and patch field types.
607  //- [Takes current timeName from the mesh registry].
608  // For LEGACY_REGISTER, registration is determined by
609  // objectRegistry::is_cacheTemporaryObject().
611  (
612  const word& name,
614  const Mesh& mesh,
615  const Type& value,
616  const dimensionSet& dims,
617  const wordList& patchFieldTypes,
618  const wordList& actualPatchTypes = wordList()
619  );
620 
621  //- Return tmp field (NO_READ, NO_WRITE)
622  //- from name, mesh, field value, dimensions and patch field types.
623  //- [Takes current timeName from the mesh registry].
624  // Registration/persistence determined by
625  // objectRegistry::is_cacheTemporaryObject().
627  (
628  const word& name,
629  const Mesh& mesh,
630  const Type& value,
631  const dimensionSet& dims,
632  const wordList& patchFieldTypes,
633  const wordList& actualPatchTypes = wordList()
634  );
635 
636  //- Return tmp field (NO_READ, NO_WRITE)
637  //- from name, mesh, dimensioned-type and patch type.
638  //- [Takes current timeName from the mesh registry].
639  // For LEGACY_REGISTER, registration is determined by
640  // objectRegistry::is_cacheTemporaryObject().
642  (
643  const word& name,
645  const Mesh& mesh,
646  const dimensioned<Type>& dt,
647  const word& patchFieldType = PatchField<Type>::calculatedType()
648  );
649 
650  //- Return tmp field (NO_READ, NO_WRITE)
651  //- from name, mesh, dimensioned-type and patch type.
652  //- [Takes current timeName from the mesh registry].
653  // Registration/persistence determined by
654  // objectRegistry::is_cacheTemporaryObject().
656  (
657  const word& name,
658  const Mesh& mesh,
659  const dimensioned<Type>& dt,
660  const word& patchFieldType = PatchField<Type>::calculatedType()
661  );
662 
663  //- Return tmp field (NO_READ, NO_WRITE)
664  //- from name, mesh, dimensioned-type and patch field types.
665  //- [Takes current timeName from the mesh registry].
666  // For LEGACY_REGISTER, registration is determined by
667  // objectRegistry::is_cacheTemporaryObject().
669  (
670  const word& name,
672  const Mesh& mesh,
673  const dimensioned<Type>& dt,
674  const wordList& patchFieldTypes,
675  const wordList& actualPatchTypes = wordList()
676  );
677 
678  //- Return tmp field (NO_READ, NO_WRITE)
679  //- from name, mesh, dimensioned-type and patch field types.
680  //- [Takes current timeName from the mesh registry].
681  // Registration/persistence determined by
682  // objectRegistry::is_cacheTemporaryObject().
684  (
685  const word& name,
686  const Mesh& mesh,
687  const dimensioned<Type>& dt,
688  const wordList& patchFieldTypes,
689  const wordList& actualPatchTypes = wordList()
690  );
691 
692  //- Return renamed tmp field (NO_READ, NO_WRITE)
693  //- retaining its instance/local.
694  // For LEGACY_REGISTER, registration is determined by
695  // objectRegistry::is_cacheTemporaryObject().
697  (
698  const word& newName,
701  );
702 
703  //- Return renamed tmp field (NO_READ, NO_WRITE)
704  //- retaining its instance/local.
705  // Registration/persistence determined by
706  // objectRegistry::is_cacheTemporaryObject().
708  (
709  const word& newName,
711  );
712 
713  //- Return renamed tmp field (NO_READ, NO_WRITE)
714  //- with reset patch field type, retaining its instance/local.
715  // For LEGACY_REGISTER, registration is determined by
716  // objectRegistry::is_cacheTemporaryObject().
718  (
719  const word& newName,
722  const word& patchFieldType
723  );
724 
725  //- Return renamed tmp field (NO_READ, NO_WRITE)
726  //- with reset patch field type, retaining its instance/local.
727  // Registration/persistence determined by
728  // objectRegistry::is_cacheTemporaryObject().
730  (
731  const word& newName,
733  const word& patchFieldType
734  );
735 
736  //- Return renamed tmp field (NO_READ, NO_WRITE)
737  //- with reset patch field types, retaining its instance/local.
738  // For LEGACY_REGISTER, registration is determined by
739  // objectRegistry::is_cacheTemporaryObject().
741  (
742  const word& newName,
745  const wordList& patchFieldTypes,
746  const wordList& actualPatchTypes = wordList()
747  );
748 
749  //- Return renamed tmp field (NO_READ, NO_WRITE)
750  //- with reset patch field types, retaining its instance/local.
751  // Registration/persistence determined by
752  // objectRegistry::is_cacheTemporaryObject().
754  (
755  const word& newName,
757  const wordList& patchFieldTypes,
758  const wordList& actualPatchTypes = wordList()
759  );
760 
761  //- Construct tmp field (NO_READ, NO_WRITE)
762  //- based on mesh/registry information from an existing field.
763  //- [Takes instance from the field].
764  // Registration/persistence determined by
765  // objectRegistry::is_cacheTemporaryObject().
766  template<class AnyType>
768  (
770  const word& name,
771  const dimensionSet& dims,
772  const word& patchFieldType = PatchField<Type>::calculatedType()
773  );
774 
775  //- Construct tmp field (NO_READ, NO_WRITE)
776  //- based on mesh/registry information from an existing field.
777  //- and initialise with value.
778  //- [Takes instance from the field].
779  // Registration/persistence determined by
780  // objectRegistry::is_cacheTemporaryObject().
781  template<class AnyType>
783  (
785  const word& name,
786  const dimensioned<Type>& dt,
787  const word& patchFieldType = PatchField<Type>::calculatedType()
788  );
789 
790 
791  //- Destructor
792  virtual ~GeometricField();
793 
794 
795  // Member Functions
796 
797  //- Return a const-reference to the dimensioned internal field.
798  inline const Internal& internalField() const noexcept;
799 
800  //- Return a reference to the dimensioned internal field.
801  // \param updateAccessTime update event counter and check
802  // old-time fields
803  //
804  // \note Should avoid using updateAccessTime = true within loops.
805  Internal& internalFieldRef(const bool updateAccessTime = true);
806 
807  //- Same as internalFieldRef()
808  Internal& ref(const bool updateAccessTime = true)
809  {
810  return this->internalFieldRef(updateAccessTime);
811  }
812 
813  //- Return a const-reference to the dimensioned internal field
814  //- of a "vol" field.
815  // Useful in the formulation of source-terms for FV equations
816  //
817  // \note definition in finiteVolume/fields/volFields/volFieldsI.H
818  inline const Internal& v() const;
819 
820  //- Return a const-reference to the internal field values.
821  inline const typename Internal::FieldType& primitiveField()
822  const noexcept;
823 
824  //- Return a reference to the internal field values.
825  // \param updateAccessTime update event counter and check
826  // old-time fields
827  //
828  // \note Should avoid using updateAccessTime = true within loops.
830  (
831  const bool updateAccessTime = true
832  );
833 
834  //- Return const-reference to the boundary field
835  inline const Boundary& boundaryField() const noexcept;
836 
837  //- Return a reference to the boundary field
838  // \param updateAccessTime update event counter and check
839  // old-time fields
840  //
841  // \note Should avoid using updateAccessTime = true within loops.
842  Boundary& boundaryFieldRef(const bool updateAccessTime = true);
843 
844  //- Return the time index of the field
845  inline label timeIndex() const noexcept;
846 
847  //- Write-access to the time index of the field
848  inline label& timeIndex() noexcept;
849 
850  //- The number of old time fields stored
851  label nOldTimes() const noexcept;
852 
853  //- Store the old-time fields
854  void storeOldTimes() const;
855 
856  //- Store the old-time field
857  void storeOldTime() const;
858 
859  //- Return old time field
860  const GeometricField<Type, PatchField, GeoMesh>& oldTime() const;
861 
862  //- Return non-const old time field
863  // (Not a good idea but it is used for sub-cycling)
864  GeometricField<Type, PatchField, GeoMesh>& oldTime();
865 
866  //- Store the field as the previous iteration value
867  void storePrevIter() const;
868 
869  //- Return previous iteration field
870  const GeometricField<Type, PatchField, GeoMesh>& prevIter() const;
871 
872  //- Remove old-time and prev-iter fields
873  void clearOldTimes();
874 
875  //- Correct boundary field
877 
878  //- Correct boundary conditions after a purely local operation.
879  // Is dummy for processor boundary conditions etc
881 
882  //- Does the field need a reference level for solution
883  bool needReference() const;
884 
885  //- Return a component of the field
887  (
888  const direction
889  ) const;
890 
891  //- Return transpose (only if it is a tensor field)
892  tmp<GeometricField<Type, PatchField, GeoMesh>> T() const;
893 
894  //- Relax field (for steady-state solution).
895  // alpha = 1 : no relaxation
896  // alpha < 1 : relaxation
897  // alpha = 0 : do nothing
898  void relax(const scalar alpha);
899 
900  //- Relax field (for steady-state solution).
901  // alpha is read from controlDict
902  void relax();
903 
904  //- Select the final iteration parameters if \c final is true
905  //- by returning the field name + "Final"
906  //- otherwise the standard parameters by returning the field name
907  word select(bool final) const;
908 
909  //- Helper function to write the min and max to an Ostream
910  void writeMinMax(Ostream& os) const;
911 
912 
913  // Member Function *this Operators
914 
915  //- Negate the field inplace. See notes in Field
916  void negate();
917 
918  //- Normalise the field inplace. See notes in Field
919  void normalise();
920 
921  //- Replace specified field component with content from another field
922  void replace
923  (
924  const direction d,
925  const GeometricField<cmptType, PatchField, GeoMesh>& gcf
926  );
927 
928  //- Replace specified field component with specified value
929  void replace
930  (
931  const direction d,
932  const dimensioned<cmptType>& ds
933  );
934 
935  //- Impose lower (floor) clamp on the field values (in-place)
936  void clamp_min(const Type& lower);
937 
938  //- Impose upper (ceiling) clamp on the field values (in-place)
939  void clamp_max(const Type& upper);
940 
941  //- Impose lower (floor) clamp on the field values (in-place)
942  // No dimension checking
943  void clamp_min(const dimensioned<Type>& lower);
944 
945  //- Impose upper (ceiling) clamp on the field values (in-place)
946  // No dimension checking
947  void clamp_max(const dimensioned<Type>& upper);
948 
949  //- Clamp field values (in-place) to the specified range.
950  // Does not check if range is valid or not. No dimension checking.
951  void clamp_range(const dimensioned<MinMax<Type>>& range);
952 
953  //- Clamp field values (in-place) to the specified range.
954  // Does not check if range is valid or not.
955  void clamp_range(const Type& lower, const Type& upper);
956 
957  //- Clamp field values (in-place) to the specified range.
958  // Does not check if range is valid or not.
959  void clamp_range(const MinMax<Type>& range);
960 
961  //- Clamp field values (in-place) to the specified range.
962  // Does not check if range is valid or not. No dimension checking.
963  void clamp_range
964  (
965  const dimensioned<Type>& lower,
966  const dimensioned<Type>& upper
967  );
968 
969 
970  // Member Operators
971 
972  //- Same as internalField().
973  // Useful in the formulation of source-terms for FV equations
974  const Internal& operator()() const { return *this; }
975 
976  void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
977  void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
978  void operator=(const dimensioned<Type>&);
979 
980  void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
981  void operator==(const dimensioned<Type>&);
982 
983  void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
984  void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
985 
986  void operator-=(const GeometricField<Type, PatchField, GeoMesh>&);
987  void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
988 
989  void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&);
990  void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&);
991 
994 
995  void operator+=(const dimensioned<Type>&);
996  void operator-=(const dimensioned<Type>&);
997 
998  void operator*=(const dimensioned<scalar>&);
999  void operator/=(const dimensioned<scalar>&);
1000 
1001  // Prevent automatic comparison rewriting (c++20)
1002  bool operator!=
1003  (
1005  ) = delete;
1006  bool operator!=
1007  (
1009  ) = delete;
1010  bool operator!=(const dimensioned<Type>&) = delete;
1011 
1012 
1013  // Write
1014 
1015  //- The writeData function (required by regIOobject)
1016  bool writeData(Ostream& os) const;
1017 
1018 
1019  // Ostream Operators
1020 
1021  //- Calls GeometricField::writeData()
1022  friend Ostream& operator<< <Type, PatchField, GeoMesh>
1023  (
1024  Ostream&,
1026  );
1027 
1028  //- Calls GeometricField::writeData()
1029  friend Ostream& operator<< <Type, PatchField, GeoMesh>
1030  (
1031  Ostream&,
1033  );
1034 
1035 
1036  // Housekeeping
1037 
1038  //- Clamp field values (in-place) to the specified range.
1039  // \deprecated(2023-01) prefer clamp_range() naming
1040  void clip(const dimensioned<MinMax<Type>>& range)
1041  {
1042  this->clamp_range(range);
1043  }
1044 
1045  //- Clamp field values (in-place) to the specified range.
1046  // \deprecated(2023-01) prefer clamp_range() naming
1047  void clip(const dimensioned<Type>& lo, const dimensioned<Type>& hi)
1048  {
1049  this->clamp_range(lo.value(), hi.value());
1050  }
1051 
1052  //- Use minimum of the field and specified value. ie, clamp_max().
1053  // This sets the \em ceiling on the field values
1054  // \deprecated(2023-01) prefer clamp_max()
1055  void min(const dimensioned<Type>& upper) { this->clamp_max(upper); }
1056 
1057  //- Use maximum of the field and specified value. ie, clamp_min().
1058  // This sets the \em floor on the field values
1059  // \deprecated(2023-01) prefer clamp_min()
1060  void max(const dimensioned<Type>& lower) { this->clamp_min(lower); }
1061 
1062  //- Deprecated(2019-01) identical to clamp_range()
1063  // \deprecated(2019-01) identical to clamp_range()
1064  FOAM_DEPRECATED_FOR(2019-01, "clamp_range() method")
1065  void maxMin(const dimensioned<Type>& lo, const dimensioned<Type>& hi)
1066  {
1067  return this->clamp_range(lo.value(), hi.value());
1068  }
1069 };
1070 
1071 
1072 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1073 
1074 } // End namespace Foam
1075 
1076 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1077 
1078 #include "GeometricFieldI.H"
1079 
1080 #ifdef NoRepository
1081  #include "GeometricField.C"
1082 #endif
1083 
1084 #include "GeometricFieldFunctions.H"
1085 
1086 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1087 
1088 #endif
1089 
1090 // ************************************************************************* //
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.
const Type & value() const noexcept
Return const reference to value.
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:59
const Internal & internalField() const noexcept
Return a const-reference to the dimensioned internal field.
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:123
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.
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.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
Definition: stringOps.C:1187
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:62
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 > &)
static const GeometricField< Type, PatchField, GeoMesh > & null() noexcept
Return a null GeometricField (reference to a nullObject).
void writeMinMax(Ostream &os) const
Helper function to write the min and max to an Ostream.
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.
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...
const Mesh & mesh() const noexcept
Return mesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
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 > &)
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:58
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.
label timeIndex() const noexcept
Return the time index of the field.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
Definition: stringOps.C:1171
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:55
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...
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.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:42
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
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.