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  //- Type of mesh on which this DimensionedField is instantiated
87  typedef typename GeoMesh::Mesh Mesh;
88 
89  //- Type of the field from which this DimensionedField is derived
90  typedef Field<Type> FieldType;
91 
92  //- Component type of the field elements
93  typedef typename Field<Type>::cmptType cmptType;
94 
95 
96 private:
97 
98  // Private Data
99 
100  //- Reference to mesh
101  const Mesh& mesh_;
102 
103  //- Dimension set for this field
104  dimensionSet dimensions_;
105 
106  //- Oriented flag
107  orientedType oriented_;
108 
109 
110  // Private Member Functions
111 
112  //- Assert that non-zero field size == mesh size
113  void checkFieldSize() const;
114 
115  void readIfPresent(const word& fieldDictEntry = "value");
116 
117 
118 public:
119 
120  //- Runtime type information
121  TypeName("DimensionedField");
122 
123 
124  // Static Member Functions
125 
126  //- Return a NullObjectRef DimensionedField
127  inline static const DimensionedField<Type, GeoMesh>& null();
128 
129 
130  // Constructors
131 
132  //- Construct from components, copy initial field content
134  (
135  const IOobject& io,
136  const Mesh& mesh,
137  const dimensionSet& dims,
138  const Field<Type>& field
139  );
140 
141  //- Construct from components, transferring initial field content
143  (
144  const IOobject& io,
145  const Mesh& mesh,
146  const dimensionSet& dims,
148  );
149 
150  //- Construct from components, transferring initial field content
152  (
153  const IOobject& io,
154  const Mesh& mesh,
155  const dimensionSet& dims,
156  List<Type>&& field
157  );
158 
159  //- Construct from components, copy or transfer tmp content
161  (
162  const IOobject& io,
163  const Mesh& mesh,
164  const dimensionSet& dims,
165  const tmp<Field<Type>>& tfield
166  );
167 
168  //- Construct from components, setting initial size and dimensions,
169  //- but not initialising any field values.
170  // Used for temporary fields which are initialised after construction
172  (
173  const IOobject& io,
174  const Mesh& mesh,
175  const dimensionSet& dims,
176  const bool checkIOFlags = true
177  );
178 
179  //- Construct from components, setting dimensions and initial
180  //- uniform field value.
182  (
183  const IOobject& io,
184  const Mesh& mesh,
185  const Type& value,
186  const dimensionSet& dims,
187  const bool checkIOFlags = true
188  );
189 
190  //- Construct from components, setting dimensions and initial
191  //- uniform field value.
192  // The name of the dimensioned<Type> has no influence.
194  (
195  const IOobject& io,
196  const Mesh& mesh,
197  const dimensioned<Type>& dt,
198  const bool checkIOFlags = true
199  );
200 
201  //- Construct from Istream.
203  (
204  const IOobject& io,
205  const Mesh& mesh,
206  const word& fieldDictEntry = "value"
207  );
208 
209  //- Construct from dictionary
211  (
212  const IOobject& io,
213  const Mesh& mesh,
214  const dictionary& fieldDict,
215  const word& fieldDictEntry = "value"
216  );
217 
218  //- Copy construct
220 
221  //- Move construct
223 
224  //- Copy construct or reuse (move) as specified.
226 
227  //- Construct from tmp<DimensionedField> deleting argument
229  (
231  );
232 
233  //- Copy construct, resetting IO parameters
235  (
236  const IOobject& io,
238  );
239 
240  //- Move construct, resetting IO parameters
242  (
243  const IOobject& io,
245  );
246 
247  //- Copy or move construct, resetting IO parameters.
249  (
250  const IOobject& io,
252  bool reuse
253  );
254 
255  //- Construct from tmp<DimensionedField> deleting argument,
256  //- resetting IO parameters.
258  (
259  const IOobject& io,
261  );
262 
263  //- Copy construct with a new name
265  (
266  const word& newName,
268  );
269 
270  //- Move construct with a new name
272  (
273  const word& newName,
275  );
276 
277  //- Copy or move construct, resetting name.
279  (
280  const word& newName,
282  bool reuse
283  );
284 
285  //- Construct with a new name from tmp<DimensionedField>
287  (
288  const word& newName,
290  );
291 
292  //- Clone
294 
295 
296  // Factory Methods
297 
298  //- Return tmp field from name, mesh, dimensions,
299  //- copy of internal field.
300  // The field is NO_READ, NO_WRITE, unregistered and uses the
301  // current timeName from the mesh registry
303  (
304  const word& name,
305  const Mesh& mesh,
306  const dimensionSet& dims,
307  const Field<Type>& iField
308  );
309 
310  //- Return tmp field from name, mesh, dimensions,
311  //- moved internal field contents.
312  // The field is NO_READ, NO_WRITE, unregistered and uses the
313  // current timeName from the mesh registry
315  (
316  const word& name,
317  const Mesh& mesh,
318  const dimensionSet& dims,
319  Field<Type>&& iField
320  );
321 
322  //- Return tmp field from name, mesh, dimensions.
323  // The field is NO_READ, NO_WRITE, unregistered and uses the
324  // current timeName from the mesh registry
326  (
327  const word& name,
328  const Mesh& mesh,
329  const dimensionSet& dims
330  );
331 
332  //- Return uniform value tmp field from name, mesh, dimensions, value.
333  // The field is NO_READ, NO_WRITE, unregistered and uses the
334  // current timeName from the mesh registry
336  (
337  const word& name,
338  const Mesh& mesh,
339  const Type& value,
340  const dimensionSet& dims
341  );
342 
343  //- Return tmp field from name, mesh, dimensioned<Type>.
344  // The field is NO_READ, NO_WRITE, unregistered and uses the
345  // current timeName from the mesh registry
347  (
348  const word& name,
349  const Mesh& mesh,
350  const dimensioned<Type>& dt
351  );
352 
353  //- Return renamed tmp field
354  // The field is NO_READ, NO_WRITE, unregistered and uses the
355  // current timeName from the mesh registry
357  (
358  const word& newName,
360  );
361 
362  //- Construct tmp field based on mesh/registry information from
363  //- an existing field.
364  // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance
365  // from the field
366  template<class AnyType>
368  (
370  const word& name,
371  const dimensionSet& dims
372  );
373 
374  //- Construct tmp field based on mesh/registry information from
375  //- an existing field and initialise with value.
376  // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance
377  // from the field
378  template<class AnyType>
380  (
382  const word& name,
383  const dimensioned<Type>& dt
384  );
385 
386 
387  //- Destructor
388  virtual ~DimensionedField() = default;
389 
390 
391  // Member Functions
392 
393  void readField
394  (
395  const dictionary& fieldDict,
396  const word& fieldDictEntry = "value"
397  );
398 
399  //- Return mesh
400  inline const Mesh& mesh() const noexcept;
401 
402  //- Return dimensions
403  inline const dimensionSet& dimensions() const noexcept;
404 
405  //- Return non-const access to dimensions
406  inline dimensionSet& dimensions() noexcept;
407 
408  //- Return oriented type
409  inline orientedType oriented() const noexcept;
410 
411  //- Return non-const access to the oriented type
412  inline orientedType& oriented() noexcept;
413 
414  //- True if field is ORIENTED
415  inline bool is_oriented() const noexcept;
416 
417  //- Set the oriented flag: on/off
418  inline void setOriented(bool on = true) noexcept;
419 
420  //- Return const-reference to the field values
421  inline const Field<Type>& field() const noexcept;
422 
423  //- Return reference to the field values
424  inline Field<Type>& field() noexcept;
425 
426  //- Return a component field of the field
428  (
429  const direction d
430  ) const;
431 
432  //- Replace a component field of the field
433  void replace
434  (
435  const direction d,
436  const DimensionedField<cmptType, GeoMesh>& df
437  );
438 
439  //- Replace a component field of the field
440  void replace
441  (
442  const direction d,
443  const tmp<DimensionedField<cmptType, GeoMesh>>& tdf
444  );
445 
446  // Inherits clamp, clamp_min, clamp_max (without dimensions) from Field
447 
448  //- Return the field transpose (only defined for second rank tensors)
449  tmp<DimensionedField<Type, GeoMesh>> T() const;
450 
451  //- Calculate and return arithmetic average
452  dimensioned<Type> average() const;
453 
454  //- Calculate and return weighted average
456  (
457  const DimensionedField<scalar, GeoMesh>& weightField
458  ) const;
459 
460  //- Calculate and return weighted average
462  (
463  const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
464  ) const;
465 
466 
467  // Write
468 
469  bool writeData(Ostream& os, const word& fieldDictEntry) const;
470 
471  bool writeData(Ostream& os) const;
472 
473 
474  // Member Operators
475 
476  void operator=(const DimensionedField<Type, GeoMesh>& df);
477  void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
478 
479  //- Assign dimensions and value.
480  void operator=(const dimensioned<Type>& dt);
481 
482  void operator+=(const DimensionedField<Type, GeoMesh>& df);
483  void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
484 
485  void operator-=(const DimensionedField<Type, GeoMesh>& df);
486  void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
487 
488  void operator*=(const DimensionedField<scalar, GeoMesh>& df);
489  void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
490 
491  void operator/=(const DimensionedField<scalar, GeoMesh>& df);
492  void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
493 
494  void operator+=(const dimensioned<Type>& dt);
495  void operator-=(const dimensioned<Type>& dt);
496 
497  void operator*=(const dimensioned<scalar>& dt);
498  void operator/=(const dimensioned<scalar>& dt);
499 
500 
501  // Ostream Operators
502 
503  friend Ostream& operator<< <Type, GeoMesh>
504  (
505  Ostream& os,
506  const DimensionedField<Type, GeoMesh>& df
507  );
508 
509  friend Ostream& operator<< <Type, GeoMesh>
510  (
511  Ostream& os,
512  const tmp<DimensionedField<Type, GeoMesh>>& tdf
513  );
514 };
515 
516 
517 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
518 
519 } // End namespace Foam
520 
521 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
522 
523 #include "DimensionedFieldI.H"
525 
526 #ifdef NoRepository
527  #include "DimensionedField.C"
528 #endif
529 
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
531 
532 #endif
533 
534 // ************************************************************************* //
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
dimensioned< Type > average() const
Calculate and return arithmetic average.
uint8_t direction
Definition: direction.H:48
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:120
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:162
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")
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
virtual ~DimensionedField()=default
Destructor.
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
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.
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
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:55
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.
friend Ostream & operator(Ostream &os, const DimensionedField< Type, GeoMesh > &df)
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.
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
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:171
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &iField)
Return tmp field from name, mesh, dimensions, copy of internal field.
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.