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  // and dimensionSet
235  (
236  const word& name,
237  const Mesh& mesh,
238  const dimensionSet&
239  );
240 
241  //- Return a temporary field constructed from name, mesh
242  // and dimensionType providing dimensions and value
244  (
245  const word& name,
246  const Mesh& mesh,
247  const dimensioned<Type>&
248  );
249 
250  //- Return a temporary field constructed from name and a field
252  (
253  const word& newName,
255  );
256 
257  //- Return renamed temporary field
259  (
260  const word& newName,
262  );
263 
264 
265  //- Destructor
266  virtual ~DimensionedField();
267 
268 
269  // Member Functions
270 
271  void readField
272  (
273  const dictionary& fieldDict,
274  const word& fieldDictEntry = "value"
275  );
276 
277  //- Return mesh
278  inline const Mesh& mesh() const;
279 
280  //- Return dimensions
281  inline const dimensionSet& dimensions() const;
282 
283  //- Return non-const access to dimensions
284  inline dimensionSet& dimensions();
285 
286  inline const Field<Type>& field() const;
287 
288  inline Field<Type>& field();
289 
290  //- Return a component field of the field
292  (
293  const direction
294  ) const;
295 
296  //- Replace a component field of the field
297  void replace
298  (
299  const direction,
301  );
302 
303  //- Replace a component field of the field
304  void replace
305  (
306  const direction,
308  );
309 
310  //- Return the field transpose (only defined for second rank tensors)
312 
313  //- Calculate and return arithmetic average
314  dimensioned<Type> average() const;
315 
316  //- Calculate and return weighted average
318  (
320  ) const;
321 
322  //- Calculate and return weighted average
324  (
326  ) const;
327 
328  //- Reset the field values to the given field
329  // Used for mesh to mesh mapping
331 
332 
333  // Write
334 
335  bool writeData(Ostream&, const word& fieldDictEntry) const;
336 
337  bool writeData(Ostream&) const;
338 
339 
340  // Member Operators
341 
345  void operator=(const dimensioned<Type>&);
346  void operator=(const zero&);
347 
350 
353 
356 
359 
360  void operator+=(const dimensioned<Type>&);
361  void operator-=(const dimensioned<Type>&);
362 
363  void operator*=(const dimensioned<scalar>&);
364  void operator/=(const dimensioned<scalar>&);
365 
366 
367  // Ostream Operators
368 
369  friend Ostream& operator<< <Type, GeoMesh>
370  (
371  Ostream&,
373  );
374 
375  friend Ostream& operator<< <Type, GeoMesh>
376  (
377  Ostream&,
379  );
380 };
381 
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 } // End namespace Foam
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #include "DimensionedFieldI.H"
391 
392 #ifdef NoRepository
393  #include "DimensionedField.C"
394 #endif
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #endif
399 
400 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:315
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &)
Return a temporary field constructed from name, mesh.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
uint8_t direction
Definition: direction.H:45
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:97
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &) const
Calculate and return weighted average.
Generic dimensioned Type class.
Field< Type >::cmptType cmptType
Component type of the elements of the field.
Field< Type > FieldType
Type of the field from which this DimensionedField is derived.
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
void operator*=(const DimensionedField< scalar, GeoMesh > &)
const dimensionSet & dimensions() const
Return dimensions.
void operator-=(const DimensionedField< Type, GeoMesh > &)
Dimension set for the base types.
Definition: dimensionSet.H:121
void operator=(const DimensionedField< Type, GeoMesh > &)
static const DimensionedField< Type, GeoMesh > & null()
Return a null DimensionedField.
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
void operator+=(const DimensionedField< Type, GeoMesh > &)
TypeName("DimensionedField")
Runtime type information.
virtual ~DimensionedField()
Destructor.
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
bool writeData(Ostream &, const word &fieldDictEntry) const
const Mesh & mesh() const
Return mesh.
DimensionedField(const IOobject &, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Construct from components.
void replace(const direction, const DimensionedField< cmptType, GeoMesh > &)
Replace a component field of the field.
MESH Mesh
Definition: GeoMesh.H:61
const Field< Type > & field() const
dimensioned< Type > average() const
Calculate and return arithmetic average.
void operator/=(const DimensionedField< scalar, GeoMesh > &)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction) const
Return a component field of the field.
A class for managing temporary objects.
Definition: PtrList.H:53
void reset(const DimensionedField< Type, GeoMesh > &)
Reset the field values to the given field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
Namespace for OpenFOAM.