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 | Copyright (C) 2011-2016 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  //- Construct as copy
169  (
171  );
172 
173  //- Construct as copy or re-use as specified.
175  (
177  bool reuse
178  );
179 
180  //- Construct by transferring the DimensionedField
182  (
184  );
185 
186  //- Construct as copy of tmp<DimensionedField> deleting argument
187  #ifndef NoConstructFromTmp
189  (
191  );
192  #endif
193 
194  //- Construct as copy resetting IO parameters
196  (
197  const IOobject&,
199  );
200 
201  //- Construct as copy resetting IO parameters and re-use as specified.
203  (
204  const IOobject&,
206  bool reuse
207  );
208 
209  //- Construct as copy resetting name
211  (
212  const word& newName,
214  );
215 
216  //- Construct as copy resetting name and re-use as specified.
218  (
219  const word& newName,
221  bool reuse
222  );
223 
224  //- Construct by transferring the DimensionedField with a new name
226  (
227  const word& newName,
229  );
230 
231  //- Construct as copy resetting name
232  #ifndef NoConstructFromTmp
234  (
235  const word& newName,
237  );
238  #endif
239 
240  //- Clone
242 
243 
244  //- Destructor
245  virtual ~DimensionedField();
246 
247 
248  // Member Functions
249 
250  void readField
251  (
252  const dictionary& fieldDict,
253  const word& fieldDictEntry = "value"
254  );
255 
256  //- Return mesh
257  inline const Mesh& mesh() const;
258 
259  //- Return dimensions
260  inline const dimensionSet& dimensions() const;
261 
262  //- Return non-const access to dimensions
263  inline dimensionSet& dimensions();
264 
265  inline const Field<Type>& field() const;
266 
267  inline Field<Type>& field();
268 
269  //- Return a component field of the field
271  (
272  const direction
273  ) const;
274 
275  //- Replace a component field of the field
276  void replace
277  (
278  const direction,
280  );
281 
282  //- Replace a component field of the field
283  void replace
284  (
285  const direction,
287  );
288 
289  //- Return the field transpose (only defined for second rank tensors)
291 
292  //- Calculate and return arithmetic average
293  dimensioned<Type> average() const;
294 
295  //- Calculate and return weighted average
297  (
299  ) const;
300 
301  //- Calculate and return weighted average
303  (
305  ) const;
306 
307 
308  // Write
309 
310  bool writeData(Ostream&, const word& fieldDictEntry) const;
311 
312  bool writeData(Ostream&) const;
313 
314 
315  // Member Operators
316 
319  void operator=(const dimensioned<Type>&);
320 
323 
326 
329 
332 
333  void operator+=(const dimensioned<Type>&);
334  void operator-=(const dimensioned<Type>&);
335 
336  void operator*=(const dimensioned<scalar>&);
337  void operator/=(const dimensioned<scalar>&);
338 
339 
340  // Ostream Operators
341 
342  friend Ostream& operator<< <Type, GeoMesh>
343  (
344  Ostream&,
346  );
347 
348  friend Ostream& operator<< <Type, GeoMesh>
349  (
350  Ostream&,
352  );
353 };
354 
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 } // End namespace Foam
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 #include "DimensionedFieldI.H"
364 
365 #ifdef NoRepository
366  #include "DimensionedField.C"
367 #endif
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #endif
372 
373 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
uint8_t direction
Definition: direction.H:45
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
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:120
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:57
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:53
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:65
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
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.