DimensionedField.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-2016 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::DimensionedField
29 
30 Description
31  Field with dimensions and associated with geometry type GeoMesh which is
32  used to size the field and a reference to it is maintained.
33 
34 SourceFiles
35  DimensionedFieldI.H
36  DimensionedField.C
37  DimensionedFieldIO.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_DimensionedField_H
42 #define Foam_DimensionedField_H
43 
44 #include "regIOobject.H"
45 #include "Field.H"
46 #include "dimensionedType.H"
47 #include "orientedType.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 template<class Type, class GeoMesh> class DimensionedField;
56 
57 template<class Type, class GeoMesh>
58 Ostream& operator<<
59 (
60  Ostream& os,
61  const DimensionedField<Type, GeoMesh>& df
62 );
63 
64 template<class Type, class GeoMesh>
65 Ostream& operator<<
66 (
67  Ostream& os,
68  const tmp<DimensionedField<Type, GeoMesh>>& tdf
69 );
70 
71 
72 /*---------------------------------------------------------------------------*\
73  Class DimensionedField Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class Type, class GeoMesh>
77 class DimensionedField
78 :
79  public regIOobject,
80  public Field<Type>
81 {
82 public:
83 
84  // Public Typedefs
85 
86  //- The mesh type for the DimensionedField
87  typedef typename GeoMesh::Mesh Mesh;
88 
89  //- The DimensionedField is usually synonymous with an internal field
91 
92  //- Type of the field from which this DimensionedField is derived
93  typedef Field<Type> FieldType;
94 
95  //- Component type of the field elements
96  typedef typename Field<Type>::cmptType cmptType;
97 
98 
99 private:
100 
101  // Private Data
102 
103  //- Reference to mesh
104  const Mesh& mesh_;
105 
106  //- Dimension set for this field
107  dimensionSet dimensions_;
108 
109  //- Oriented flag
110  orientedType oriented_;
111 
112 
113  // Private Member Functions
114 
115  //- Assert that non-zero field size == mesh size
116  void checkFieldSize() const;
117 
118  //- Read from file if it is present. Checks the readOption flag
119  void readIfPresent(const word& fieldDictEntry = "value");
120 
121  //- Read the field - create the field dictionary on-the-fly
122  void readField(const word& fieldDictEntry = "value");
123 
124  //- Implementation for 'New' with specified registerObject preference.
125  // For LEGACY_REGISTER, registration is determined by
126  // objectRegistry::is_cacheTemporaryObject().
127  template<class... Args>
128  static tmp<DimensionedField<Type, GeoMesh>> New_impl
129  (
131  const word& name,
132  const Mesh& mesh,
133  Args&&... args
134  );
135 
136 public:
137 
138  //- Runtime type information
139  TypeName("DimensionedField");
140 
141 
142  // Static Member Functions
143 
144  //- Return a null DimensionedField (reference to a nullObject).
146  {
147  return NullObjectRef<DimensionedField<Type, GeoMesh>>();
148  }
149 
150 
151  // Constructors
152 
153  //- Construct from components, copy initial field content
155  (
156  const IOobject& io,
157  const Mesh& mesh,
158  const dimensionSet& dims,
159  const Field<Type>& field
160  );
161 
162  //- Construct from components, transferring initial field content
164  (
165  const IOobject& io,
166  const Mesh& mesh,
167  const dimensionSet& dims,
169  );
170 
171  //- Construct from components, transferring initial field content
173  (
174  const IOobject& io,
175  const Mesh& mesh,
176  const dimensionSet& dims,
177  List<Type>&& field
178  );
179 
180  //- Construct from components, copy or transfer tmp content
182  (
183  const IOobject& io,
184  const Mesh& mesh,
185  const dimensionSet& dims,
186  const tmp<Field<Type>>& tfield
187  );
188 
189  //- Construct from components, setting initial size and dimensions,
190  //- but not initialising any field values.
191  // Used for temporary fields which are initialised after construction
193  (
194  const IOobject& io,
195  const Mesh& mesh,
196  const dimensionSet& dims,
197  const bool checkIOFlags = true
198  );
199 
200  //- Construct from components, setting dimensions and initial
201  //- uniform field value.
203  (
204  const IOobject& io,
205  const Mesh& mesh,
206  const Type& value,
207  const dimensionSet& dims,
208  const bool checkIOFlags = true
209  );
210 
211  //- Construct from components, setting dimensions and initial
212  //- uniform field value.
213  // The name of the dimensioned<Type> has no influence.
215  (
216  const IOobject& io,
217  const Mesh& mesh,
218  const dimensioned<Type>& dt,
219  const bool checkIOFlags = true
220  );
221 
222  //- Construct from Istream.
224  (
225  const IOobject& io,
226  const Mesh& mesh,
227  const word& fieldDictEntry = "value"
228  );
229 
230  //- Construct from dictionary
232  (
233  const IOobject& io,
234  const Mesh& mesh,
235  const dictionary& fieldDict,
236  const word& fieldDictEntry = "value"
237  );
238 
239  //- Copy construct
241 
242  //- Move construct
244 
245  //- Copy construct or reuse (move) as specified.
247 
248  //- Construct from tmp<DimensionedField> deleting argument
250  (
252  );
253 
254  //- Copy construct, resetting IO parameters
256  (
257  const IOobject& io,
259  );
260 
261  //- Move construct, resetting IO parameters
263  (
264  const IOobject& io,
266  );
267 
268  //- Copy or move construct, resetting IO parameters.
270  (
271  const IOobject& io,
273  bool reuse
274  );
275 
276  //- Construct from tmp<DimensionedField> deleting argument,
277  //- resetting IO parameters.
279  (
280  const IOobject& io,
282  );
283 
284  //- Copy construct with a new name
286  (
287  const word& newName,
289  );
290 
291  //- Move construct with a new name
293  (
294  const word& newName,
296  );
297 
298  //- Copy or move construct, resetting name.
300  (
301  const word& newName,
303  bool reuse
304  );
305 
306  //- Construct with a new name from tmp<DimensionedField>
308  (
309  const word& newName,
311  );
312 
313  //- Clone
315 
316 
317  // Factory Methods
318 
319  //- Return tmp field (NO_READ, NO_WRITE)
320  //- from name, mesh, dimensions, copy of internal field.
321  //- [Takes current timeName from the mesh registry].
322  // For LEGACY_REGISTER, registration is determined by
323  // objectRegistry::is_cacheTemporaryObject().
325  (
326  const word& name,
328  const Mesh& mesh,
329  const dimensionSet& dims,
330  const Field<Type>& iField
331  );
332 
333  //- Return tmp field (NO_READ, NO_WRITE)
334  //- from name, mesh, dimensions, copy of internal field.
335  //- [Takes current timeName from the mesh registry].
336  // Registration/persistence determined by
337  // objectRegistry::is_cacheTemporaryObject().
339  (
340  const word& name,
341  const Mesh& mesh,
342  const dimensionSet& dims,
343  const Field<Type>& iField
344  );
345 
346  //- Return tmp field (NO_READ, NO_WRITE)
347  //- from name, mesh, dimensions, move internal field contents.
348  //- [Takes current timeName from the mesh registry].
349  // For LEGACY_REGISTER, registration is determined by
350  // objectRegistry::is_cacheTemporaryObject().
352  (
353  const word& name,
355  const Mesh& mesh,
356  const dimensionSet& dims,
357  Field<Type>&& iField
358  );
359 
360  //- Return tmp field (NO_READ, NO_WRITE)
361  //- from name, mesh, dimensions, move internal field contents.
362  //- [Takes current timeName from the mesh registry].
363  // Registration/persistence determined by
364  // objectRegistry::is_cacheTemporaryObject().
366  (
367  const word& name,
368  const Mesh& mesh,
369  const dimensionSet& dims,
370  Field<Type>&& iField
371  );
372 
373  //- Return tmp field (NO_READ, NO_WRITE)
374  //- from name, mesh, dimensions.
375  //- [Takes current timeName from the mesh registry].
376  // For LEGACY_REGISTER, registration is determined by
377  // objectRegistry::is_cacheTemporaryObject().
379  (
380  const word& name,
382  const Mesh& mesh,
383  const dimensionSet& dims
384  );
385 
386  //- Return tmp field (NO_READ, NO_WRITE)
387  //- from name, mesh, dimensions.
388  //- [Takes current timeName from the mesh registry].
389  // Registration/persistence determined by
390  // objectRegistry::is_cacheTemporaryObject().
392  (
393  const word& name,
394  const Mesh& mesh,
395  const dimensionSet& dims
396  );
397 
398  //- Return tmp field (NO_READ, NO_WRITE)
399  //- from name, mesh, value, dimensions.
400  //- [Takes current timeName from the mesh registry].
401  // For LEGACY_REGISTER, registration is determined by
402  // objectRegistry::is_cacheTemporaryObject().
404  (
405  const word& name,
407  const Mesh& mesh,
408  const Type& value,
409  const dimensionSet& dims
410  );
411 
412  //- Return tmp field (NO_READ, NO_WRITE)
413  //- from name, mesh, value, dimensions.
414  //- [Takes current timeName from the mesh registry].
415  // Registration/persistence determined by
416  // objectRegistry::is_cacheTemporaryObject().
418  (
419  const word& name,
420  const Mesh& mesh,
421  const Type& value,
422  const dimensionSet& dims
423  );
424 
425  //- Return tmp field (NO_READ, NO_WRITE)
426  //- from name, mesh, dimensioned-type.
427  //- [Takes current timeName from the mesh registry].
428  // For LEGACY_REGISTER, registration is determined by
429  // objectRegistry::is_cacheTemporaryObject().
431  (
432  const word& name,
434  const Mesh& mesh,
435  const dimensioned<Type>& dt
436  );
437 
438  //- Return tmp field (NO_READ, NO_WRITE)
439  //- from name, mesh, dimensioned-type.
440  //- [Takes current timeName from the mesh registry].
441  // Registration/persistence determined by
442  // objectRegistry::is_cacheTemporaryObject().
444  (
445  const word& name,
446  const Mesh& mesh,
447  const dimensioned<Type>& dt
448  );
449 
450  //- Return renamed tmp field (NO_READ, NO_WRITE)
451  //- retaining its instance/local.
452  // For LEGACY_REGISTER, registration is determined by
453  // objectRegistry::is_cacheTemporaryObject().
455  (
456  const word& newName,
459  );
460 
461  //- Return renamed tmp field (NO_READ, NO_WRITE)
462  //- retaining its instance/local.
463  // Registration/persistence determined by
464  // objectRegistry::is_cacheTemporaryObject().
466  (
467  const word& newName,
469  );
470 
471  //- Construct tmp field (NO_READ, NO_WRITE)
472  //- based on mesh/registry information from an existing field.
473  //- [Takes instance from the field].
474  // Registration/persistence determined by
475  // objectRegistry::is_cacheTemporaryObject().
476  template<class AnyType>
478  (
480  const word& name,
481  const dimensionSet& dims
482  );
483 
484  //- Construct tmp field (NO_READ, NO_WRITE)
485  //- based on mesh/registry information from an existing field
486  //- and initialise with value.
487  // Registration/persistence determined by
488  // objectRegistry::is_cacheTemporaryObject().
489  template<class AnyType>
491  (
493  const word& name,
494  const dimensioned<Type>& dt
495  );
496 
497 
498  //- Destructor
499  virtual ~DimensionedField();
500 
501 
502  // Member Functions
503 
504  //- Resize to the mesh size and read the field from the dictionary.
505  //- Internal implementation checks field vs mesh size.
506  void readField
507  (
508  const dictionary& fieldDict,
509  const word& fieldDictEntry = "value"
510  );
511 
512  //- Return mesh
513  inline const Mesh& mesh() const noexcept;
514 
515  //- Return dimensions
516  inline const dimensionSet& dimensions() const noexcept;
517 
518  //- Return non-const access to dimensions
519  inline dimensionSet& dimensions() noexcept;
520 
521  //- Return oriented type
522  inline orientedType oriented() const noexcept;
523 
524  //- Return non-const access to the oriented type
525  inline orientedType& oriented() noexcept;
526 
527  //- True if field is ORIENTED
528  inline bool is_oriented() const noexcept;
529 
530  //- Set the oriented flag: on/off
531  inline void setOriented(bool on = true) noexcept;
532 
533  //- Return const-reference to the field values
534  inline const Field<Type>& field() const noexcept;
535 
536  //- Return reference to the field values
537  inline Field<Type>& field() noexcept;
538 
539  //- Return a component field of the field
541  (
542  const direction d
543  ) const;
544 
545  //- Replace a component field of the field
546  void replace
547  (
548  const direction d,
549  const DimensionedField<cmptType, GeoMesh>& df
550  );
551 
552  //- Replace a component field of the field
553  void replace
554  (
555  const direction d,
556  const tmp<DimensionedField<cmptType, GeoMesh>>& tdf
557  );
558 
559  // Inherits clamp, clamp_min, clamp_max (without dimensions) from Field
560 
561  //- Return the field transpose (only defined for second rank tensors)
562  tmp<DimensionedField<Type, GeoMesh>> T() const;
563 
564  //- Calculate and return arithmetic average
565  dimensioned<Type> average() const;
566 
567  //- Calculate and return weighted average
569  (
570  const DimensionedField<scalar, GeoMesh>& weightField
571  ) const;
572 
573  //- Calculate and return weighted average
575  (
576  const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
577  ) const;
578 
579 
580  // Write
581 
582  //- Write dimensions, oriented flag (if valid) and the
583  //- field data as a dictionary entry with the specified name.
584  bool writeData(Ostream& os, const word& fieldDictEntry) const;
585 
586  //- The writeData function (required by regIOobject),
587  //- calls writeData with dictionary entry name = "value"
588  bool writeData(Ostream& os) const { return writeData(os, "value"); }
589 
590 
591  // Member Operators
592 
595 
596  //- Assign dimensions and value.
597  void operator=(const dimensioned<Type>& dt);
598 
601 
604 
607 
610 
611  void operator+=(const dimensioned<Type>& dt);
612  void operator-=(const dimensioned<Type>& dt);
613 
614  void operator*=(const dimensioned<scalar>& dt);
615  void operator/=(const dimensioned<scalar>& dt);
616 
617 
618  // Ostream Operators
619 
620  //- Calls DimensionedField::writeData()
621  friend Ostream& operator<< <Type, GeoMesh>
622  (
623  Ostream& os,
625  );
626 
627  //- Calls DimensionedField::writeData()
628  friend Ostream& operator<< <Type, GeoMesh>
629  (
630  Ostream& os,
632  );
633 };
634 
635 
636 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
637 
638 } // End namespace Foam
639 
640 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641 
642 #include "DimensionedFieldI.H"
644 
645 #ifdef NoRepository
646  #include "DimensionedField.C"
647 #endif
648 
649 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
650 
651 #endif
652 
653 // ************************************************************************* //
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
dimensioned< Type > average() const
Calculate and return arithmetic average.
uint8_t direction
Definition: direction.H:46
void replace(const direction d, const DimensionedField< cmptType, GeoMesh > &df)
Replace a component field of the field.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static const DimensionedField< Type, GeoMesh > & null() noexcept
Return a null DimensionedField (reference to a nullObject).
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
DimensionedField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &field)
Construct from components, copy initial field content.
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:123
bool is_oriented() const noexcept
True if field is ORIENTED.
orientedType oriented() const noexcept
Return oriented type.
void operator-=(const DimensionedField< Type, GeoMesh > &df)
Class to determine the &#39;oriented&#39; status of surface fields.
Definition: orientedType.H:52
Generic dimensioned Type class.
Field< Type >::cmptType cmptType
Component type of the field elements.
Field< Type > FieldType
Type of the field from which this DimensionedField is derived.
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction d) const
Return a component field of the field.
void operator/=(const DimensionedField< scalar, GeoMesh > &df)
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
Generic templated field type.
Definition: Field.H:62
bool writeData(Ostream &os, const word &fieldDictEntry) const
Write dimensions, oriented flag (if valid) and the field data as a dictionary entry with the specifie...
A class for handling words, derived from Foam::string.
Definition: word.H:63
void operator*=(const DimensionedField< scalar, GeoMesh > &df)
void operator=(const DimensionedField< Type, GeoMesh > &df)
void setOriented(bool on=true) noexcept
Set the oriented flag: on/off.
void operator+=(const DimensionedField< Type, GeoMesh > &df)
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
TypeName("DimensionedField")
Runtime type information.
virtual ~DimensionedField()
Destructor.
GeoMesh::Mesh Mesh
The mesh type for the DimensionedField.
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
OBJstream os(runTime.globalPath()/outputName)
MESH Mesh
Definition: GeoMesh.H:58
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))
const Field< Type > & field() const noexcept
Return const-reference to the field values.
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &iField)
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions, copy of internal field...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
DimensionedField< Type, GeoMesh > Internal
The DimensionedField is usually synonymous with an internal field.
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
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.