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-2021 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 DimensionedField_H
42 #define 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,
62 );
63 
64 template<class Type, class GeoMesh>
65 Ostream& operator<<
66 (
67  Ostream& os,
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 elements of the field
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
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 the initial size and assigning
169  //- the dimensions, 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 the initial size and assigning
180  //- both dimensions and values.
181  // The internal name for the dimensioned<Type> has no influence.
183  (
184  const IOobject& io,
185  const Mesh& mesh,
186  const dimensioned<Type>& dt,
187  const bool checkIOFlags = true
188  );
189 
190  //- Construct from Istream.
192  (
193  const IOobject& io,
194  const Mesh& mesh,
195  const word& fieldDictEntry = "value"
196  );
197 
198  //- Construct from dictionary
200  (
201  const IOobject& io,
202  const Mesh& mesh,
203  const dictionary& fieldDict,
204  const word& fieldDictEntry = "value"
205  );
206 
207  //- Copy construct
209 
210  //- Move construct
212 
213  //- Copy construct or reuse (move) as specified.
215 
216  //- Construct from tmp<DimensionedField> deleting argument
218  (
220  );
221 
222  //- Copy construct, resetting IO parameters
224  (
225  const IOobject& io,
227  );
228 
229  //- Move construct, resetting IO parameters
231  (
232  const IOobject& io,
234  );
235 
236  //- Copy or move construct, resetting IO parameters.
238  (
239  const IOobject& io,
241  bool reuse
242  );
243 
244  //- Construct from tmp<DimensionedField> deleting argument,
245  //- resetting IO parameters.
247  (
248  const IOobject& io,
250  );
251 
252  //- Copy construct with a new name
254  (
255  const word& newName,
257  );
258 
259  //- Move construct with a new name
261  (
262  const word& newName,
264  );
265 
266  //- Copy or move construct, resetting name.
268  (
269  const word& newName,
271  bool reuse
272  );
273 
274  //- Construct with a new name from tmp<DimensionedField>
276  (
277  const word& newName,
279  );
280 
281  //- Clone
283 
284 
285  //- Destructor
286  virtual ~DimensionedField() = default;
287 
288 
289  // Member Functions
290 
291  void readField
292  (
293  const dictionary& fieldDict,
294  const word& fieldDictEntry = "value"
295  );
296 
297  //- Return mesh
298  inline const Mesh& mesh() const;
299 
300  //- Return dimensions
301  inline const dimensionSet& dimensions() const;
302 
303  //- Return non-const access to dimensions
304  inline dimensionSet& dimensions();
305 
306  //- Return oriented type
307  inline const orientedType& oriented() const noexcept;
308 
309  //- Return non-const access to the oriented type
310  inline orientedType& oriented() noexcept;
311 
312  //- Set the oriented flag
313  inline void setOriented(const bool oriented = true) noexcept;
314 
315  //- Return field
316  inline const Field<Type>& field() const;
317 
318  //- Return field
319  inline Field<Type>& field();
320 
321  //- Return a component field of the field
323  (
324  const direction d
325  ) const;
326 
327  //- Replace a component field of the field
328  void replace
329  (
330  const direction d,
331  const DimensionedField<cmptType, GeoMesh>& df
332  );
333 
334  //- Replace a component field of the field
335  void replace
336  (
337  const direction d,
338  const tmp<DimensionedField<cmptType, GeoMesh>>& tdf
339  );
340 
341  //- Return the field transpose (only defined for second rank tensors)
342  tmp<DimensionedField<Type, GeoMesh>> T() const;
343 
344  //- Calculate and return arithmetic average
345  dimensioned<Type> average() const;
346 
347  //- Calculate and return weighted average
349  (
350  const DimensionedField<scalar, GeoMesh>& weightField
351  ) const;
352 
353  //- Calculate and return weighted average
355  (
356  const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
357  ) const;
358 
359 
360  // Write
361 
362  bool writeData(Ostream& os, const word& fieldDictEntry) const;
363 
364  bool writeData(Ostream& os) const;
365 
366 
367  // Member Operators
368 
369  void operator=(const DimensionedField<Type, GeoMesh>& df);
370  void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
371 
372  //- Assign dimensions and value.
373  void operator=(const dimensioned<Type>& dt);
374 
375  void operator+=(const DimensionedField<Type, GeoMesh>& df);
376  void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
377 
378  void operator-=(const DimensionedField<Type, GeoMesh>& df);
379  void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
380 
381  void operator*=(const DimensionedField<scalar, GeoMesh>& df);
382  void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
383 
384  void operator/=(const DimensionedField<scalar, GeoMesh>& df);
385  void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
386 
387  void operator+=(const dimensioned<Type>& dt);
388  void operator-=(const dimensioned<Type>& dt);
389 
390  void operator*=(const dimensioned<scalar>& dt);
391  void operator/=(const dimensioned<scalar>& dt);
392 
393 
394  // Ostream Operators
395 
396  friend Ostream& operator<< <Type, GeoMesh>
397  (
398  Ostream& os,
399  const DimensionedField<Type, GeoMesh>& df
400  );
401 
402  friend Ostream& operator<< <Type, GeoMesh>
403  (
404  Ostream& os,
405  const tmp<DimensionedField<Type, GeoMesh>>& tdf
406  );
407 };
408 
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 } // End namespace Foam
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 #include "DimensionedFieldI.H"
418 
419 #ifdef NoRepository
420  #include "DimensionedField.C"
421 #endif
422 
423 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
424 
425 #endif
426 
427 // ************************************************************************* //
regIOobject.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::DimensionedField::FieldType
Field< Type > FieldType
Type of the field from which this DimensionedField is derived.
Definition: DimensionedField.H:89
Foam::DimensionedField::readField
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Definition: DimensionedFieldIO.C:36
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::DimensionedField::~DimensionedField
virtual ~DimensionedField()=default
Destructor.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DimensionedField::field
const Field< Type > & field() const
Return field.
Definition: DimensionedFieldI.H:90
Foam::DimensionedField::DimensionedField
DimensionedField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &field)
Construct from components.
Definition: DimensionedField.C:71
Foam::DimensionedField::replace
void replace(const direction d, const DimensionedField< cmptType, GeoMesh > &df)
Replace a component field of the field.
DimensionedFieldFunctions.H
DimensionedField.C
Foam::DimensionedField::average
dimensioned< Type > average() const
Calculate and return arithmetic average.
Definition: DimensionedField.C:447
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
Foam::DimensionedField::operator
friend Ostream & operator(Ostream &os, const DimensionedField< Type, GeoMesh > &df)
Foam::DimensionedField::clone
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
Definition: DimensionedField.C:353
orientedType.H
Foam::Field::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
Foam::DimensionedField::Mesh
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
Definition: DimensionedField.H:86
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::DimensionedField::mesh
const Mesh & mesh() const
Return mesh.
Definition: DimensionedFieldI.H:41
Foam::DimensionedField::cmptType
Field< Type >::cmptType cmptType
Component type of the elements of the field.
Definition: DimensionedField.H:92
Foam::DimensionedField::setOriented
void setOriented(const bool oriented=true) noexcept
Set the oriented flag.
Definition: DimensionedFieldI.H:80
Foam::DimensionedField::TypeName
TypeName("DimensionedField")
Runtime type information.
Field.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:42
Foam::GeoMesh
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:48
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::DimensionedField::oriented
const orientedType & oriented() const noexcept
Return oriented type.
Definition: DimensionedFieldI.H:64
Foam::DimensionedField::dimensions
const dimensionSet & dimensions() const
Return dimensions.
Definition: DimensionedFieldI.H:49
Foam::DimensionedField::T
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: DimensionedField.C:426
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::DimensionedField::weightedAverage
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
Definition: DimensionedField.C:461
Foam::List< Type >
Foam::DimensionedField::writeData
bool writeData(Ostream &os, const word &fieldDictEntry) const
Definition: DimensionedFieldIO.C:118
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::DimensionedField::component
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction d) const
Return a component field of the field.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeoMesh::Mesh
MESH Mesh
Definition: GeoMesh.H:62
Foam::orientedType
Class to determine the 'oriented' status of surface fields.
Definition: orientedType.H:56
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
dimensionedType.H