DimensionedField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::DimensionedField
26 
27 Description
28  Field with dimensions and associated with geometry type GeoMesh which is
29  used to size the field and a reference to it is maintained.
30 
31 SourceFiles
32  DimensionedFieldI.H
33  DimensionedField.C
34  DimensionedFieldIO.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef DimensionedField_H
39 #define DimensionedField_H
40 
41 #include "DimensionedFieldFwd.H"
42 #include "regIOobject.H"
43 #include "Field.H"
44 #include "OldTimeField.H"
45 #include "dimensionedType.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 template<class Type, class GeoMesh, template<class> class PrimitiveField>
55 class DimensionedField;
56 
57 template<class Type, class GeoMesh, template<class> class PrimitiveField>
58 Ostream& operator<<
59 (
60  Ostream&,
62 );
63 
64 template<class Type, class GeoMesh, template<class> class PrimitiveField>
65 Ostream& operator<<
66 (
67  Ostream&,
69 );
70 
71 
72 /*---------------------------------------------------------------------------*\
73  Class DimensionedField Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class Type, class GeoMesh, template<class> class PrimitiveField>
77 class DimensionedField
78 :
79  public regIOobject,
80  public PrimitiveField<Type>,
81  public OldTimeField<DimensionedField<Type, GeoMesh, PrimitiveField>>
82 {
83 
84 public:
85 
86  // Public Typedefs
87 
88  //- Type of mesh on which this DimensionedField is instantiated
89  typedef typename GeoMesh::Mesh Mesh;
90 
91  //- Type of the field from which this DimensionedField is derived
92  typedef PrimitiveField<Type> FieldType;
93 
94  //- Type of the field from which this DimensionedField is derived
95  typedef PrimitiveField<Type> Base;
96 
97  //- Component type of the elements of the field
98  typedef typename PrimitiveField<Type>::cmptType cmptType;
99 
100 
101 private:
102 
103  // Private Data
104 
105  //- Reference to mesh
106  const Mesh& mesh_;
107 
108  //- Dimension set for this field
109  dimensionSet dimensions_;
110 
111 
112  // Private Member Functions
113 
114  //- Read from file if it is present
115  bool readIfPresent(const word& fieldDictEntry = "value");
116 
117 
118 public:
119 
120  //- Runtime type information
121  TypeName("DimensionedField");
122 
123 
124  //- Declare friendship with other dimensioned fields
125  template<class Type2, class GeoMesh2, template<class> class PrimitiveField2>
126  friend class DimensionedField;
127 
128 
129  // Static Member Functions
130 
131  //- Return a null DimensionedField
132  inline static const
134 
135 
136  // Constructors
137 
138  //- Construct from components
140  (
141  const IOobject&,
142  const Mesh& mesh,
143  const dimensionSet&,
144  const PrimitiveField<Type>&
145  );
146 
147  //- Construct from components
148  // Used for temporary fields which are initialised after construction
150  (
151  const IOobject&,
152  const Mesh& mesh,
153  const dimensionSet&,
154  const bool checkIOFlags = true
155  );
156 
157  //- Construct from components
159  (
160  const IOobject&,
161  const Mesh& mesh,
162  const dimensioned<Type>&,
163  const bool checkIOFlags = true
164  );
165 
166  //- Construct from Istream
168  (
169  const IOobject&,
170  const Mesh& mesh,
171  const word& fieldDictEntry="value"
172  );
173 
174  //- Construct from dictionary
176  (
177  const IOobject&,
178  const Mesh& mesh,
179  const dictionary& fieldDict,
180  const word& fieldDictEntry="value"
181  );
182 
183  //- Copy constructor
185  (
187  );
188 
189  //- Move constructor
191  (
193  );
194 
195  //- Copy constructor
196  template<template<class> class PrimitiveField2>
197  explicit DimensionedField
198  (
200  );
201 
202  //- Copy constructor or reuse as specified.
203  template<template<class> class PrimitiveField2>
205  (
207  const bool reuse
208  );
209 
210  //- Copy constructor of tmp<DimensionedField> deleting argument
212  (
214  );
215 
216  //- Copy constructor resetting IO parameters
217  template<template<class> class PrimitiveField2>
219  (
220  const IOobject&,
222  const bool checkIOFlags = true
223  );
224 
225  //- Copy constructor resetting IO parameters and reuse as specified.
226  template<template<class> class PrimitiveField2>
228  (
229  const IOobject&,
231  const bool reuse,
232  const bool checkIOFlags = true
233  );
234 
235  //- Copy constructor from tmp resetting IO parameters
237  (
238  const IOobject&,
240  const bool checkIOFlags = true
241  );
242 
243  //- Copy constructor resetting name
244  template<template<class> class PrimitiveField2>
246  (
247  const word& newName,
249  );
250 
251  //- Copy constructor resetting name and reuse as specified.
252  template<template<class> class PrimitiveField2>
254  (
255  const word& newName,
257  const bool reuse
258  );
259 
260  //- Copy constructor from tmp resetting name
262  (
263  const word& newName,
265  );
266 
267  //- Clone
269 
270  //- Return a temporary field constructed from name, mesh,
271  // dimensionSet and field
273  (
274  const word& name,
275  const Mesh& mesh,
276  const dimensionSet&,
277  const PrimitiveField<Type>&
278  );
279 
280  //- Return a temporary field constructed from name, mesh
281  // and dimensionSet
283  (
284  const word& name,
285  const Mesh& mesh,
286  const dimensionSet&
287  );
288 
289  //- Return a temporary field constructed from name, mesh
290  // and dimensionType providing dimensions and value
292  (
293  const word& name,
294  const Mesh& mesh,
295  const dimensioned<Type>&
296  );
297 
298  //- Return a temporary field constructed from name and a field
299  template<template<class> class PrimitiveField2>
301  (
302  const word& newName,
304  );
305 
306  //- Return renamed temporary field
308  (
309  const word& newName,
311  );
312 
313 
314  //- Destructor
315  virtual ~DimensionedField();
316 
317 
318  // Member Functions
319 
320  void readField
321  (
322  const dictionary& fieldDict,
323  const word& fieldDictEntry = "value"
324  );
325 
326  //- Return mesh
327  inline const Mesh& mesh() const;
328 
329  //- Return dimensions
330  inline const dimensionSet& dimensions() const;
331 
332  //- Return non-const access to dimensions
333  inline dimensionSet& dimensions();
334 
335  //- Return a reference to the internal field
336  PrimitiveField<Type>& primitiveFieldRef();
337 
338  //- Return a const-reference to the primitive field
339  inline const PrimitiveField<Type>& primitiveField() const;
340 
341  //- Use old-time methods from the base class
343 
344  //- Return a component field of the field
346  (
347  const direction
348  ) const;
349 
350  //- Replace a component field of the field
351  template<template<class> class PrimitiveField2>
352  void replace
353  (
354  const direction,
356  );
357 
358  //- Replace a component field of the field
359  template<template<class> class PrimitiveField2>
360  void replace
361  (
362  const direction,
364  );
365 
366  //- Return the field transpose (only defined for second rank tensors)
368 
369  //- Calculate and return arithmetic average
370  dimensioned<Type> average() const;
371 
372  //- Calculate and return weighted average
373  template<template<class> class PrimitiveField2>
375  (
377  ) const;
378 
379  //- Calculate and return weighted average
380  template<template<class> class PrimitiveField2>
382  (
384  ) const;
385 
386  //- Reset the field values to the given field
387  // Used for mesh to mesh mapping
388  template<template<class> class PrimitiveField2>
390 
391  //- Reset the field values to the given tmp-field
392  // Used for mesh to mesh mapping
394 
395  //- Reset the field values to the given tmp-field
396  // Used for mesh to mesh mapping
397  template<template<class> class PrimitiveField2>
398  void reset
399  (
401  );
402 
403 
404  // Write
405 
406  bool writeData(Ostream&, const word& fieldDictEntry) const;
407 
408  bool writeData(Ostream&) const;
409 
410 
411  // Member Operators
412 
415  void operator=
416  (
418  );
419  template<template<class> class PrimitiveField2>
420  void operator=
421  (
423  );
424  template<template<class> class PrimitiveField2>
425  void operator=
426  (
428  );
429  void operator=(const dimensioned<Type>&);
430  void operator=(const zero&);
431 
432  template<template<class> class PrimitiveField2>
433  void operator==
434  (
436  );
437  template<template<class> class PrimitiveField2>
438  void operator==
439  (
441  );
442  void operator==(const dimensioned<Type>&);
443  void operator==(const zero&);
444 
445  template<template<class> class PrimitiveField2>
446  void operator+=
447  (
449  );
450  template<template<class> class PrimitiveField2>
451  void operator+=
452  (
454  );
455  void operator+=(const dimensioned<Type>&);
456 
457  template<template<class> class PrimitiveField2>
458  void operator-=
459  (
461  );
462  template<template<class> class PrimitiveField2>
463  void operator-=
464  (
466  );
467  void operator-=(const dimensioned<Type>&);
468 
469  template<template<class> class PrimitiveField2>
470  void operator*=
471  (
473  );
474  template<template<class> class PrimitiveField2>
475  void operator*=
476  (
478  );
479  void operator*=(const dimensioned<scalar>&);
480 
481  template<template<class> class PrimitiveField2>
482  void operator/=
483  (
485  );
486  template<template<class> class PrimitiveField2>
487  void operator/=
488  (
490  );
491  void operator/=(const dimensioned<scalar>&);
492 
493 
494  // Ostream Operators
495 
496  friend Ostream& operator<< <Type, GeoMesh, PrimitiveField>
497  (
498  Ostream&,
500  );
501 
502  friend Ostream& operator<< <Type, GeoMesh, PrimitiveField>
503  (
504  Ostream&,
506  );
507 };
508 
509 
510 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
511 
512 } // End namespace Foam
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 
516 #include "DimensionedFieldI.H"
518 
519 #ifdef NoRepository
520  #include "DimensionedField.C"
521 #endif
522 
523 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
524 
525 #endif
526 
527 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
PrimitiveField< Type >::cmptType cmptType
Component type of the elements of the field.
TypeName("DimensionedField")
Runtime type information.
void operator-=(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
friend class DimensionedField
Declare friendship with other dimensioned fields.
void replace(const direction, const DimensionedField< cmptType, GeoMesh, PrimitiveField2 > &)
Replace a component field of the field.
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
void operator=(const DimensionedField< Type, GeoMesh, PrimitiveField > &)
void operator+=(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
const dimensionSet & dimensions() const
Return dimensions.
tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > clone() const
Clone.
void operator/=(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &)
PrimitiveField< Type > & primitiveFieldRef()
Return a reference to the internal field.
PrimitiveField< Type > Base
Type of the field from which this DimensionedField is derived.
PrimitiveField< Type > FieldType
Type of the field from which this DimensionedField is derived.
bool writeData(Ostream &, const word &fieldDictEntry) const
USING_OLD_TIME_FIELD(DimensionedField)
Use old-time methods from the base class.
const Mesh & mesh() const
Return mesh.
void reset(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
Reset the field values to the given field.
dimensioned< Type > average() const
Calculate and return arithmetic average.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &) const
Calculate and return weighted average.
void operator==(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
const PrimitiveField< Type > & primitiveField() const
Return a const-reference to the primitive field.
void operator*=(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &)
tmp< DimensionedField< cmptType, GeoMesh, Field > > component(const direction) const
Return a component field of the field.
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Mesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
tmp< DimensionedField< Type, GeoMesh, Field > > T() const
Return the field transpose (only defined for second rank tensors)
virtual ~DimensionedField()
Destructor.
MESH Mesh
Mesh type.
Definition: GeoMesh.H:62
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:307
Class to add into field types to provide old-time storage and retrieval.
Definition: OldTimeField.H:113
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Generic dimensioned Type class.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:45