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-2015 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  typedef typename GeoMesh::Mesh Mesh;
83  typedef typename Field<Type>::cmptType cmptType;
84 
85 
86 private:
87 
88  // Private data
89 
90  //- Reference to mesh
91  const Mesh& mesh_;
92 
93  //- Dimension set for this field
94  dimensionSet dimensions_;
95 
96 
97  // Private Member Functions
98 
99  void readIfPresent(const word& fieldDictEntry = "value");
100 
101 
102 public:
103 
104  //- Runtime type information
105  TypeName("DimensionedField");
106 
107 
108  // Static Member Functions
109 
110  //- Return a null DimensionedField
111  inline static const DimensionedField<Type, GeoMesh>& null();
112 
113 
114  // Constructors
115 
116  //- Construct from components
118  (
119  const IOobject&,
120  const Mesh& mesh,
121  const dimensionSet&,
122  const Field<Type>&
123  );
124 
125  //- Construct from components
126  // Used for temporary fields which are initialised after construction
128  (
129  const IOobject&,
130  const Mesh& mesh,
131  const dimensionSet&,
132  const bool checkIOFlags = true
133  );
134 
135  //- Construct from components
137  (
138  const IOobject&,
139  const Mesh& mesh,
140  const dimensioned<Type>&,
141  const bool checkIOFlags = true
142  );
143 
144  //- Construct from Istream
146  (
147  const IOobject&,
148  const Mesh& mesh,
149  const word& fieldDictEntry="value"
150  );
151 
152  //- Construct as copy
154  (
156  );
157 
158  //- Construct as copy or re-use as specified.
160  (
162  bool reUse
163  );
164 
165  //- Construct by transferring the DimensionedField
167  (
169  );
170 
171  //- Construct as copy of tmp<DimensionedField> deleting argument
172  #ifndef NoConstructFromTmp
174  (
176  );
177  #endif
178 
179  //- Construct as copy resetting IO parameters
181  (
182  const IOobject&,
184  );
185 
186  //- Construct as copy resetting IO parameters and re-use as specified.
188  (
189  const IOobject&,
191  bool reUse
192  );
193 
194  //- Construct as copy resetting name
196  (
197  const word& newName,
199  );
200 
201  //- Construct as copy resetting name and re-use as specified.
203  (
204  const word& newName,
206  bool reUse
207  );
208 
209  //- Construct by transferring the DimensionedField with a new name
211  (
212  const word& newName,
214  );
215 
216  //- Construct as copy resetting name
217  #ifndef NoConstructFromTmp
219  (
220  const word& newName,
222  );
223  #endif
224 
225  //- Clone
227 
228 
229  //- Destructor
230  virtual ~DimensionedField();
231 
232 
233  // Member Functions
234 
235  void readField
236  (
237  const dictionary& fieldDict,
238  const word& fieldDictEntry = "value"
239  );
240 
241  //- Return mesh
242  inline const Mesh& mesh() const;
243 
244  //- Return dimensions
245  inline const dimensionSet& dimensions() const;
246 
247  //- Return non-const access to dimensions
248  inline dimensionSet& dimensions();
249 
250  inline const Field<Type>& field() const;
251 
252  inline Field<Type>& field();
253 
254  //- Return a component field of the field
256  (
257  const direction
258  ) const;
259 
260  //- Replace a component field of the field
261  void replace
262  (
263  const direction,
265  );
266 
267  //- Replace a component field of the field
268  void replace
269  (
270  const direction,
272  );
273 
274  //- Return the field transpose (only defined for second rank tensors)
276 
277  //- Calculate and return arithmetic average
278  dimensioned<Type> average() const;
279 
280  //- Calculate and return weighted average
282  (
284  ) const;
285 
286  //- Calculate and return weighted average
288  (
290  ) const;
291 
292 
293  // Write
294 
295  bool writeData(Ostream&, const word& fieldDictEntry) const;
296 
297  bool writeData(Ostream&) const;
298 
299 
300  // Member Operators
301 
304  void operator=(const dimensioned<Type>&);
305 
308 
311 
314 
317 
318  void operator+=(const dimensioned<Type>&);
319  void operator-=(const dimensioned<Type>&);
320 
321  void operator*=(const dimensioned<scalar>&);
322  void operator/=(const dimensioned<scalar>&);
323 
324 
325  // Ostream Operators
326 
327  friend Ostream& operator<< <Type, GeoMesh>
328  (
329  Ostream&,
331  );
332 
333  friend Ostream& operator<< <Type, GeoMesh>
334  (
335  Ostream&,
337  );
338 };
339 
340 
341 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
342 
343 } // End namespace Foam
344 
345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 
347 #include "DimensionedFieldI.H"
349 
350 #ifdef NoRepository
351 # include "DimensionedField.C"
352 #endif
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 #endif
357 
358 // ************************************************************************* //
unsigned char direction
Definition: direction.H:43
virtual ~DimensionedField()
Destructor.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Field< Type > & field() const
void operator-=(const DimensionedField< Type, GeoMesh > &)
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
void operator+=(const DimensionedField< Type, GeoMesh > &)
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A class for handling words, derived from string.
Definition: word.H:59
bool writeData(Ostream &, const word &fieldDictEntry) const
const Mesh & mesh() const
Return mesh.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
DimensionedField(const IOobject &, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Construct from components.
Generic dimensioned Type class.
TypeName("DimensionedField")
Runtime type information.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
Dimension set for the base types.
Definition: dimensionSet.H:116
MESH Mesh
Definition: GeoMesh.H:61
void operator/=(const DimensionedField< scalar, GeoMesh > &)
const dimensionSet & dimensions() const
Return dimensions.
Pre-declare SubField and related Field type.
Definition: Field.H:57
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction) const
Return a component field of the field.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
void operator=(const DimensionedField< Type, GeoMesh > &)
void replace(const direction, const DimensionedField< cmptType, GeoMesh > &)
Replace a component field of the field.
Field< Type >::cmptType cmptType
void operator*=(const DimensionedField< scalar, GeoMesh > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
dimensioned< Type > average() const
Calculate and return arithmetic average.
A class for managing temporary objects.
Definition: PtrList.H:118
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &) const
Calculate and return weighted average.
static const DimensionedField< Type, GeoMesh > & null()
Return a null DimensionedField.
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")