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-2022 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 "dimensionedType.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of friend functions and operators
51 
52 template<class Type, class GeoMesh> class DimensionedField;
53 
54 template<class Type, class GeoMesh> Ostream& operator<<
55 (
56  Ostream&,
58 );
59 
60 template<class Type, class GeoMesh> Ostream& operator<<
61 (
62  Ostream&,
64 );
65 
66 
67 /*---------------------------------------------------------------------------*\
68  Class DimensionedField Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 template<class Type, class GeoMesh>
72 class DimensionedField
73 :
74  public regIOobject,
75  public Field<Type>
76 {
77 
78 public:
79 
80  // Public Typedefs
81 
82  //- Type of mesh on which this DimensionedField is instantiated
83  typedef typename GeoMesh::Mesh Mesh;
84 
85  //- Type of the field from which this DimensionedField is derived
86  typedef Field<Type> FieldType;
87 
88  //- Component type of the elements of the field
89  typedef typename Field<Type>::cmptType cmptType;
90 
91 
92 private:
93 
94  // Private Data
95 
96  //- Reference to mesh
97  const Mesh& mesh_;
98 
99  //- Dimension set for this field
100  dimensionSet dimensions_;
101 
102 
103  // Private Member Functions
104 
105  void readIfPresent(const word& fieldDictEntry = "value");
106 
107 
108 public:
109 
110  //- Runtime type information
111  TypeName("DimensionedField");
112 
113 
114  // Static Member Functions
115 
116  //- Return a null DimensionedField
117  inline static const DimensionedField<Type, GeoMesh>& null();
118 
119 
120  // Constructors
121 
122  //- Construct from components
124  (
125  const IOobject&,
126  const Mesh& mesh,
127  const dimensionSet&,
128  const Field<Type>&
129  );
130 
131  //- Construct from components
132  // Used for temporary fields which are initialised after construction
134  (
135  const IOobject&,
136  const Mesh& mesh,
137  const dimensionSet&,
138  const bool checkIOFlags = true
139  );
140 
141  //- Construct from components
143  (
144  const IOobject&,
145  const Mesh& mesh,
146  const dimensioned<Type>&,
147  const bool checkIOFlags = true
148  );
149 
150  //- Construct from Istream
152  (
153  const IOobject&,
154  const Mesh& mesh,
155  const word& fieldDictEntry="value"
156  );
157 
158  //- Construct from dictionary
160  (
161  const IOobject&,
162  const Mesh& mesh,
163  const dictionary& fieldDict,
164  const word& fieldDictEntry="value"
165  );
166 
167  //- Copy constructor
169  (
171  );
172 
173  //- Copy constructor or re-use as specified.
175  (
177  bool reuse
178  );
179 
180  //- Move constructor
182  (
184  );
185 
186  //- Copy constructor of tmp<DimensionedField> deleting argument
188  (
190  );
191 
192  //- Copy constructor resetting IO parameters
194  (
195  const IOobject&,
197  );
198 
199  //- Copy constructor resetting IO parameters and re-use as specified.
201  (
202  const IOobject&,
204  bool reuse
205  );
206 
207  //- Copy constructor resetting name
209  (
210  const word& newName,
212  );
213 
214  //- Copy constructor resetting name and re-use as specified.
216  (
217  const word& newName,
219  bool reuse
220  );
221 
222  //- Copy constructor resetting name
224  (
225  const word& newName,
227  );
228 
229  //- Clone
231 
232  //- Return a temporary field constructed from name, mesh,
233  // dimensionSet and field
235  (
236  const word& name,
237  const Mesh& mesh,
238  const dimensionSet&,
239  const Field<Type>&
240 
241  );
242 
243  //- Return a temporary field constructed from name, mesh
244  // and dimensionSet
246  (
247  const word& name,
248  const Mesh& mesh,
249  const dimensionSet&
250  );
251 
252  //- Return a temporary field constructed from name, mesh
253  // and dimensionType providing dimensions and value
255  (
256  const word& name,
257  const Mesh& mesh,
258  const dimensioned<Type>&
259  );
260 
261  //- Return a temporary field constructed from name and a field
263  (
264  const word& newName,
266  );
267 
268  //- Return renamed temporary field
270  (
271  const word& newName,
273  );
274 
275 
276  //- Destructor
277  virtual ~DimensionedField();
278 
279 
280  // Member Functions
281 
282  void readField
283  (
284  const dictionary& fieldDict,
285  const word& fieldDictEntry = "value"
286  );
287 
288  //- Return mesh
289  inline const Mesh& mesh() const;
290 
291  //- Return dimensions
292  inline const dimensionSet& dimensions() const;
293 
294  //- Return non-const access to dimensions
295  inline dimensionSet& dimensions();
296 
297  inline const Field<Type>& field() const;
298 
299  inline Field<Type>& field();
300 
301  //- Return a component field of the field
303  (
304  const direction
305  ) const;
306 
307  //- Replace a component field of the field
308  void replace
309  (
310  const direction,
312  );
313 
314  //- Replace a component field of the field
315  void replace
316  (
317  const direction,
319  );
320 
321  //- Return the field transpose (only defined for second rank tensors)
323 
324  //- Calculate and return arithmetic average
325  dimensioned<Type> average() const;
326 
327  //- Calculate and return weighted average
329  (
331  ) const;
332 
333  //- Calculate and return weighted average
335  (
337  ) const;
338 
339  //- Reset the field values to the given field
340  // Used for mesh to mesh mapping
342 
343 
344  // Write
345 
346  bool writeData(Ostream&, const word& fieldDictEntry) const;
347 
348  bool writeData(Ostream&) const;
349 
350 
351  // Member Operators
352 
356  void operator=(const dimensioned<Type>&);
357  void operator=(const zero&);
358 
361 
364 
367 
370 
371  void operator+=(const dimensioned<Type>&);
372  void operator-=(const dimensioned<Type>&);
373 
374  void operator*=(const dimensioned<scalar>&);
375  void operator/=(const dimensioned<scalar>&);
376 
377 
378  // Ostream Operators
379 
380  friend Ostream& operator<< <Type, GeoMesh>
381  (
382  Ostream&,
384  );
385 
386  friend Ostream& operator<< <Type, GeoMesh>
387  (
388  Ostream&,
390  );
391 };
392 
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 } // End namespace Foam
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 #include "DimensionedFieldI.H"
402 
403 #ifdef NoRepository
404  #include "DimensionedField.C"
405 #endif
406 
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
408 
409 #endif
410 
411 // ************************************************************************* //
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.
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.
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
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.
const Field< Type > & field() const
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.
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:82
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:97
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
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:160
Dimension set for the base types.
Definition: dimensionSet.H:122
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