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-2023 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  void readIfPresent(const word& fieldDictEntry = "value");
119 
120  //- Implementation for 'New' with specified registerObject preference.
121  // For LEGACY_REGISTER, registration is determined by
122  // objectRegistry::is_cacheTemporaryObject().
123  template<class... Args>
124  static tmp<DimensionedField<Type, GeoMesh>> New_impl
125  (
127  const word& name,
128  const Mesh& mesh,
129  Args&&... args
130  );
131 
132 public:
133 
134  //- Runtime type information
135  TypeName("DimensionedField");
136 
137 
138  // Static Member Functions
139 
140  //- Return a NullObjectRef DimensionedField
141  inline static const DimensionedField<Type, GeoMesh>& null();
142 
143 
144  // Constructors
145 
146  //- Construct from components, copy initial field content
148  (
149  const IOobject& io,
150  const Mesh& mesh,
151  const dimensionSet& dims,
152  const Field<Type>& field
153  );
154 
155  //- Construct from components, transferring initial field content
157  (
158  const IOobject& io,
159  const Mesh& mesh,
160  const dimensionSet& dims,
162  );
163 
164  //- Construct from components, transferring initial field content
166  (
167  const IOobject& io,
168  const Mesh& mesh,
169  const dimensionSet& dims,
170  List<Type>&& field
171  );
172 
173  //- Construct from components, copy or transfer tmp content
175  (
176  const IOobject& io,
177  const Mesh& mesh,
178  const dimensionSet& dims,
179  const tmp<Field<Type>>& tfield
180  );
181 
182  //- Construct from components, setting initial size and dimensions,
183  //- but not initialising any field values.
184  // Used for temporary fields which are initialised after construction
186  (
187  const IOobject& io,
188  const Mesh& mesh,
189  const dimensionSet& dims,
190  const bool checkIOFlags = true
191  );
192 
193  //- Construct from components, setting dimensions and initial
194  //- uniform field value.
196  (
197  const IOobject& io,
198  const Mesh& mesh,
199  const Type& value,
200  const dimensionSet& dims,
201  const bool checkIOFlags = true
202  );
203 
204  //- Construct from components, setting dimensions and initial
205  //- uniform field value.
206  // The name of the dimensioned<Type> has no influence.
208  (
209  const IOobject& io,
210  const Mesh& mesh,
211  const dimensioned<Type>& dt,
212  const bool checkIOFlags = true
213  );
214 
215  //- Construct from Istream.
217  (
218  const IOobject& io,
219  const Mesh& mesh,
220  const word& fieldDictEntry = "value"
221  );
222 
223  //- Construct from dictionary
225  (
226  const IOobject& io,
227  const Mesh& mesh,
228  const dictionary& fieldDict,
229  const word& fieldDictEntry = "value"
230  );
231 
232  //- Copy construct
234 
235  //- Move construct
237 
238  //- Copy construct or reuse (move) as specified.
240 
241  //- Construct from tmp<DimensionedField> deleting argument
243  (
245  );
246 
247  //- Copy construct, resetting IO parameters
249  (
250  const IOobject& io,
252  );
253 
254  //- Move construct, resetting IO parameters
256  (
257  const IOobject& io,
259  );
260 
261  //- Copy or move construct, resetting IO parameters.
263  (
264  const IOobject& io,
266  bool reuse
267  );
268 
269  //- Construct from tmp<DimensionedField> deleting argument,
270  //- resetting IO parameters.
272  (
273  const IOobject& io,
275  );
276 
277  //- Copy construct with a new name
279  (
280  const word& newName,
282  );
283 
284  //- Move construct with a new name
286  (
287  const word& newName,
289  );
290 
291  //- Copy or move construct, resetting name.
293  (
294  const word& newName,
296  bool reuse
297  );
298 
299  //- Construct with a new name from tmp<DimensionedField>
301  (
302  const word& newName,
304  );
305 
306  //- Clone
308 
309 
310  // Factory Methods
311 
312  //- Return tmp field (NO_READ, NO_WRITE)
313  //- from name, mesh, dimensions, copy of internal field.
314  //- [Takes current timeName from the mesh registry].
315  // For LEGACY_REGISTER, registration is determined by
316  // objectRegistry::is_cacheTemporaryObject().
318  (
319  const word& name,
321  const Mesh& mesh,
322  const dimensionSet& dims,
323  const Field<Type>& iField
324  );
325 
326  //- Return tmp field (NO_READ, NO_WRITE)
327  //- from name, mesh, dimensions, copy of internal field.
328  //- [Takes current timeName from the mesh registry].
329  // Registration/persistence determined by
330  // objectRegistry::is_cacheTemporaryObject().
332  (
333  const word& name,
334  const Mesh& mesh,
335  const dimensionSet& dims,
336  const Field<Type>& iField
337  );
338 
339  //- Return tmp field (NO_READ, NO_WRITE)
340  //- from name, mesh, dimensions, move internal field contents.
341  //- [Takes current timeName from the mesh registry].
342  // For LEGACY_REGISTER, registration is determined by
343  // objectRegistry::is_cacheTemporaryObject().
345  (
346  const word& name,
348  const Mesh& mesh,
349  const dimensionSet& dims,
350  Field<Type>&& iField
351  );
352 
353  //- Return tmp field (NO_READ, NO_WRITE)
354  //- from name, mesh, dimensions, move internal field contents.
355  //- [Takes current timeName from the mesh registry].
356  // Registration/persistence determined by
357  // objectRegistry::is_cacheTemporaryObject().
359  (
360  const word& name,
361  const Mesh& mesh,
362  const dimensionSet& dims,
363  Field<Type>&& iField
364  );
365 
366  //- Return tmp field (NO_READ, NO_WRITE)
367  //- from name, mesh, dimensions.
368  //- [Takes current timeName from the mesh registry].
369  // For LEGACY_REGISTER, registration is determined by
370  // objectRegistry::is_cacheTemporaryObject().
372  (
373  const word& name,
375  const Mesh& mesh,
376  const dimensionSet& dims
377  );
378 
379  //- Return tmp field (NO_READ, NO_WRITE)
380  //- from name, mesh, dimensions.
381  //- [Takes current timeName from the mesh registry].
382  // Registration/persistence determined by
383  // objectRegistry::is_cacheTemporaryObject().
385  (
386  const word& name,
387  const Mesh& mesh,
388  const dimensionSet& dims
389  );
390 
391  //- Return tmp field (NO_READ, NO_WRITE)
392  //- from name, mesh, value, dimensions.
393  //- [Takes current timeName from the mesh registry].
394  // For LEGACY_REGISTER, registration is determined by
395  // objectRegistry::is_cacheTemporaryObject().
397  (
398  const word& name,
400  const Mesh& mesh,
401  const Type& value,
402  const dimensionSet& dims
403  );
404 
405  //- Return tmp field (NO_READ, NO_WRITE)
406  //- from name, mesh, value, dimensions.
407  //- [Takes current timeName from the mesh registry].
408  // Registration/persistence determined by
409  // objectRegistry::is_cacheTemporaryObject().
411  (
412  const word& name,
413  const Mesh& mesh,
414  const Type& value,
415  const dimensionSet& dims
416  );
417 
418  //- Return tmp field (NO_READ, NO_WRITE)
419  //- from name, mesh, dimensioned-type.
420  //- [Takes current timeName from the mesh registry].
421  // For LEGACY_REGISTER, registration is determined by
422  // objectRegistry::is_cacheTemporaryObject().
424  (
425  const word& name,
427  const Mesh& mesh,
428  const dimensioned<Type>& dt
429  );
430 
431  //- Return tmp field (NO_READ, NO_WRITE)
432  //- from name, mesh, dimensioned-type.
433  //- [Takes current timeName from the mesh registry].
434  // Registration/persistence determined by
435  // objectRegistry::is_cacheTemporaryObject().
437  (
438  const word& name,
439  const Mesh& mesh,
440  const dimensioned<Type>& dt
441  );
442 
443  //- Return renamed tmp field (NO_READ, NO_WRITE).
444  //- [Takes current timeName from the mesh registry].
445  // Registration/persistence determined by
446  // objectRegistry::is_cacheTemporaryObject().
448  (
449  const word& newName,
451  );
452 
453  //- Construct tmp field (NO_READ, NO_WRITE)
454  //- based on mesh/registry information from an existing field.
455  //- [Takes instance from the field].
456  // Registration/persistence determined by
457  // objectRegistry::is_cacheTemporaryObject().
458  template<class AnyType>
460  (
462  const word& name,
463  const dimensionSet& dims
464  );
465 
466  //- Construct tmp field (NO_READ, NO_WRITE)
467  //- based on mesh/registry information from an existing field
468  //- and initialise with value.
469  // Registration/persistence determined by
470  // objectRegistry::is_cacheTemporaryObject().
471  template<class AnyType>
473  (
475  const word& name,
476  const dimensioned<Type>& dt
477  );
478 
479 
480  //- Destructor
481  virtual ~DimensionedField();
482 
483 
484  // Member Functions
485 
486  //- Resize to the mesh size and read the field from the dictionary.
487  //- Internal implementation checks field vs mesh size.
488  void readField
489  (
490  const dictionary& fieldDict,
491  const word& fieldDictEntry = "value"
492  );
493 
494  //- Return mesh
495  inline const Mesh& mesh() const noexcept;
496 
497  //- Return dimensions
498  inline const dimensionSet& dimensions() const noexcept;
499 
500  //- Return non-const access to dimensions
501  inline dimensionSet& dimensions() noexcept;
502 
503  //- Return oriented type
504  inline orientedType oriented() const noexcept;
505 
506  //- Return non-const access to the oriented type
507  inline orientedType& oriented() noexcept;
508 
509  //- True if field is ORIENTED
510  inline bool is_oriented() const noexcept;
511 
512  //- Set the oriented flag: on/off
513  inline void setOriented(bool on = true) noexcept;
514 
515  //- Return const-reference to the field values
516  inline const Field<Type>& field() const noexcept;
517 
518  //- Return reference to the field values
519  inline Field<Type>& field() noexcept;
520 
521  //- Return a component field of the field
523  (
524  const direction d
525  ) const;
526 
527  //- Replace a component field of the field
528  void replace
529  (
530  const direction d,
531  const DimensionedField<cmptType, GeoMesh>& df
532  );
533 
534  //- Replace a component field of the field
535  void replace
536  (
537  const direction d,
538  const tmp<DimensionedField<cmptType, GeoMesh>>& tdf
539  );
540 
541  // Inherits clamp, clamp_min, clamp_max (without dimensions) from Field
542 
543  //- Return the field transpose (only defined for second rank tensors)
544  tmp<DimensionedField<Type, GeoMesh>> T() const;
545 
546  //- Calculate and return arithmetic average
547  dimensioned<Type> average() const;
548 
549  //- Calculate and return weighted average
551  (
552  const DimensionedField<scalar, GeoMesh>& weightField
553  ) const;
554 
555  //- Calculate and return weighted average
557  (
558  const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
559  ) const;
560 
561 
562  // Write
563 
564  //- Write dimensions, oriented flag (if valid) and the
565  //- field data as a dictionary entry with the specified name.
566  bool writeData(Ostream& os, const word& fieldDictEntry) const;
567 
568  //- The writeData function (required by regIOobject),
569  //- call writeData with dictionary entry name = "value"
570  bool writeData(Ostream& os) const;
571 
572 
573  // Member Operators
574 
575  void operator=(const DimensionedField<Type, GeoMesh>& df);
576  void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
577 
578  //- Assign dimensions and value.
579  void operator=(const dimensioned<Type>& dt);
580 
581  void operator+=(const DimensionedField<Type, GeoMesh>& df);
582  void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
583 
584  void operator-=(const DimensionedField<Type, GeoMesh>& df);
585  void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
586 
587  void operator*=(const DimensionedField<scalar, GeoMesh>& df);
588  void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
589 
590  void operator/=(const DimensionedField<scalar, GeoMesh>& df);
591  void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
592 
593  void operator+=(const dimensioned<Type>& dt);
594  void operator-=(const dimensioned<Type>& dt);
595 
596  void operator*=(const dimensioned<scalar>& dt);
597  void operator/=(const dimensioned<scalar>& dt);
598 
599 
600  // Ostream Operators
601 
602  friend Ostream& operator<< <Type, GeoMesh>
603  (
604  Ostream& os,
605  const DimensionedField<Type, GeoMesh>& df
606  );
607 
608  friend Ostream& operator<< <Type, GeoMesh>
609  (
610  Ostream& os,
611  const tmp<DimensionedField<Type, GeoMesh>>& tdf
612  );
613 };
614 
615 
616 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
617 
618 } // End namespace Foam
619 
620 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
621 
622 #include "DimensionedFieldI.H"
624 
625 #ifdef NoRepository
626  #include "DimensionedField.C"
627 #endif
628 
629 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
630 
631 #endif
632 
633 // ************************************************************************* //
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
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.
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 readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Resize to the mesh size and read the field from the dictionary. Internal implementation checks field ...
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
static const DimensionedField< Type, GeoMesh > & null()
Return a NullObjectRef DimensionedField.
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 setOriented(bool on=true) noexcept
Set the oriented flag: on/off.
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)
friend Ostream & operator(Ostream &os, const DimensionedField< Type, GeoMesh > &df)
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...
Definition: areaFieldsFwd.H:42
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:172
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.