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-2024 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 "regIOobject.H"
42 #include "Field.H"
43 #include "OldTimeField.H"
44 #include "dimensionedType.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of friend functions and operators
52 
53 template<class Type, class GeoMesh> class DimensionedField;
54 
55 template<class Type, class GeoMesh> Ostream& operator<<
56 (
57  Ostream&,
59 );
60 
61 template<class Type, class GeoMesh> Ostream& operator<<
62 (
63  Ostream&,
65 );
66 
67 
68 /*---------------------------------------------------------------------------*\
69  Class DimensionedField Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 template<class Type, class GeoMesh>
73 class DimensionedField
74 :
75  public regIOobject,
76  public Field<Type>,
77  public OldTimeField<DimensionedField<Type, GeoMesh>>
78 {
79 
80 public:
81 
82  // Public Typedefs
83 
84  //- Type of mesh on which this DimensionedField is instantiated
85  typedef typename GeoMesh::Mesh Mesh;
86 
87  //- Type of the field from which this DimensionedField is derived
88  typedef Field<Type> FieldType;
89 
90  //- Type of the field from which this DimensionedField is derived
91  typedef Field<Type> Base;
92 
93  //- Component type of the elements of the field
94  typedef typename Field<Type>::cmptType cmptType;
95 
96 
97 private:
98 
99  // Private Data
100 
101  //- Reference to mesh
102  const Mesh& mesh_;
103 
104  //- Dimension set for this field
105  dimensionSet dimensions_;
106 
107 
108  // Private Member Functions
109 
110  //- Read from file if it is present
111  bool readIfPresent(const word& fieldDictEntry = "value");
112 
113 
114 public:
115 
116  //- Runtime type information
117  TypeName("DimensionedField");
118 
119 
120  // Static Member Functions
121 
122  //- Return a null DimensionedField
123  inline static const DimensionedField<Type, GeoMesh>& null();
124 
125 
126  // Constructors
127 
128  //- Construct from components
130  (
131  const IOobject&,
132  const Mesh& mesh,
133  const dimensionSet&,
134  const Field<Type>&
135  );
136 
137  //- Construct from components
138  // Used for temporary fields which are initialised after construction
140  (
141  const IOobject&,
142  const Mesh& mesh,
143  const dimensionSet&,
144  const bool checkIOFlags = true
145  );
146 
147  //- Construct from components
149  (
150  const IOobject&,
151  const Mesh& mesh,
152  const dimensioned<Type>&,
153  const bool checkIOFlags = true
154  );
155 
156  //- Construct from Istream
158  (
159  const IOobject&,
160  const Mesh& mesh,
161  const word& fieldDictEntry="value"
162  );
163 
164  //- Construct from dictionary
166  (
167  const IOobject&,
168  const Mesh& mesh,
169  const dictionary& fieldDict,
170  const word& fieldDictEntry="value"
171  );
172 
173  //- Copy constructor
175  (
177  );
178 
179  //- Copy constructor or reuse as specified.
181  (
183  bool reuse
184  );
185 
186  //- Move constructor
188  (
190  );
191 
192  //- Copy constructor of tmp<DimensionedField> deleting argument
194  (
196  );
197 
198  //- Copy constructor resetting IO parameters
200  (
201  const IOobject&,
203  const bool checkIOFlags = true
204  );
205 
206  //- Copy constructor resetting IO parameters and reuse as specified.
208  (
209  const IOobject&,
211  bool reuse,
212  const bool checkIOFlags = true
213  );
214 
215  //- Copy constructor from tmp resetting IO parameters
217  (
218  const IOobject&,
220  const bool checkIOFlags = true
221  );
222 
223  //- Copy constructor resetting name
225  (
226  const word& newName,
228  );
229 
230  //- Copy constructor resetting name and reuse as specified.
232  (
233  const word& newName,
235  bool reuse
236  );
237 
238  //- Copy constructor from tmp resetting name
240  (
241  const word& newName,
243  );
244 
245  //- Clone
247 
248  //- Return a temporary field constructed from name, mesh,
249  // dimensionSet and field
251  (
252  const word& name,
253  const Mesh& mesh,
254  const dimensionSet&,
255  const Field<Type>&
256  );
257 
258  //- Return a temporary field constructed from name, mesh
259  // and dimensionSet
261  (
262  const word& name,
263  const Mesh& mesh,
264  const dimensionSet&
265  );
266 
267  //- Return a temporary field constructed from name, mesh
268  // and dimensionType providing dimensions and value
270  (
271  const word& name,
272  const Mesh& mesh,
273  const dimensioned<Type>&
274  );
275 
276  //- Return a temporary field constructed from name and a field
278  (
279  const word& newName,
281  );
282 
283  //- Return renamed temporary field
285  (
286  const word& newName,
288  );
289 
290 
291  //- Destructor
292  virtual ~DimensionedField();
293 
294 
295  // Member Functions
296 
297  void readField
298  (
299  const dictionary& fieldDict,
300  const word& fieldDictEntry = "value"
301  );
302 
303  //- Return mesh
304  inline const Mesh& mesh() const;
305 
306  //- Return dimensions
307  inline const dimensionSet& dimensions() const;
308 
309  //- Return non-const access to dimensions
310  inline dimensionSet& dimensions();
311 
312  //- Return a reference to the internal field
314 
315  //- Return a const-reference to the primitive field
316  inline const Field<Type>& primitiveField() const;
317 
318  //- Use old-time methods from the base class
320 
321  //- Return a component field of the field
323  (
324  const direction
325  ) const;
326 
327  //- Replace a component field of the field
328  void replace
329  (
330  const direction,
332  );
333 
334  //- Replace a component field of the field
335  void replace
336  (
337  const direction,
339  );
340 
341  //- Return the field transpose (only defined for second rank tensors)
343 
344  //- Calculate and return arithmetic average
345  dimensioned<Type> average() const;
346 
347  //- Calculate and return weighted average
349  (
351  ) const;
352 
353  //- Calculate and return weighted average
355  (
357  ) const;
358 
359  //- Reset the field values to the given field
360  // Used for mesh to mesh mapping
362 
363 
364  // Write
365 
366  bool writeData(Ostream&, const word& fieldDictEntry) const;
367 
368  bool writeData(Ostream&) const;
369 
370 
371  // Member Operators
372 
376  void operator=(const dimensioned<Type>&);
377  void operator=(const zero&);
378 
380  void operator==(const dimensioned<Type>&);
381  void operator==(const zero&);
382 
385 
388 
391 
394 
395  void operator+=(const dimensioned<Type>&);
396  void operator-=(const dimensioned<Type>&);
397 
398  void operator*=(const dimensioned<scalar>&);
399  void operator/=(const dimensioned<scalar>&);
400 
401 
402  // Ostream Operators
403 
404  friend Ostream& operator<< <Type, GeoMesh>
405  (
406  Ostream&,
408  );
409 
410  friend Ostream& operator<< <Type, GeoMesh>
411  (
412  Ostream&,
414  );
415 };
416 
417 
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 
420 } // End namespace Foam
421 
422 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
423 
424 #include "DimensionedFieldI.H"
426 
427 #ifdef NoRepository
428  #include "DimensionedField.C"
429 #endif
430 
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
432 
433 #endif
434 
435 // ************************************************************************* //
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")
TypeName("DimensionedField")
Runtime type information.
Field< Type > & primitiveFieldRef()
Return a reference to the internal field.
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
void replace(const direction, const DimensionedField< cmptType, GeoMesh > &)
Replace a component field of the field.
void operator*=(const DimensionedField< scalar, GeoMesh > &)
const dimensionSet & dimensions() const
Return dimensions.
Field< Type > Base
Type of the field from which this DimensionedField is derived.
void operator+=(const DimensionedField< Type, GeoMesh > &)
void operator=(const DimensionedField< Type, GeoMesh > &)
Field< Type > FieldType
Type of the field from which this DimensionedField is derived.
void operator/=(const DimensionedField< scalar, GeoMesh > &)
bool writeData(Ostream &, const word &fieldDictEntry) const
USING_OLD_TIME_FIELD(DimensionedField)
Use old-time methods from the base class.
const Field< Type > & primitiveField() const
Return a const-reference to the primitive field.
const Mesh & mesh() const
Return mesh.
void operator-=(const DimensionedField< Type, GeoMesh > &)
Field< Type >::cmptType cmptType
Component type of the elements of the field.
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction) const
Return a component field of the field.
void reset(const DimensionedField< Type, GeoMesh > &)
Reset the field values to the given field.
dimensioned< Type > average() const
Calculate and return arithmetic average.
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Return a temporary field constructed from name, mesh,.
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &) const
Calculate and return weighted average.
void operator==(const tmp< DimensionedField< Type, GeoMesh >> &)
virtual ~DimensionedField()
Destructor.
DimensionedField(const IOobject &, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Construct from components.
Pre-declare SubField and related Field type.
Definition: Field.H:83
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:98
MESH Mesh
Definition: GeoMesh.H:61
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:310
Class to add into field types to provide old-time storage and retrieval.
Definition: OldTimeField.H:93
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
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