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 | Copyright (C) 2015 OpenCFD Ltd.
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
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 from dictionary
154  (
155  const IOobject&,
156  const Mesh& mesh,
157  const dictionary& fieldDict,
158  const word& fieldDictEntry="value"
159  );
160 
161  //- Construct as copy
163  (
165  );
166 
167  //- Construct as copy or re-use as specified.
169  (
171  bool reUse
172  );
173 
174  //- Construct by transferring the DimensionedField
176  (
178  );
179 
180  //- Construct as copy of tmp<DimensionedField> deleting argument
181  #ifndef NoConstructFromTmp
183  (
185  );
186  #endif
187 
188  //- Construct as copy resetting IO parameters
190  (
191  const IOobject&,
193  );
194 
195  //- Construct as copy resetting IO parameters and re-use as specified.
197  (
198  const IOobject&,
200  bool reUse
201  );
202 
203  //- Construct as copy resetting name
205  (
206  const word& newName,
208  );
209 
210  //- Construct as copy resetting name and re-use as specified.
212  (
213  const word& newName,
215  bool reUse
216  );
217 
218  //- Construct by transferring the DimensionedField with a new name
220  (
221  const word& newName,
223  );
224 
225  //- Construct as copy resetting name
226  #ifndef NoConstructFromTmp
228  (
229  const word& newName,
231  );
232  #endif
233 
234  //- Clone
236 
237 
238  //- Destructor
239  virtual ~DimensionedField();
240 
241 
242  // Member Functions
243 
244  void readField
245  (
246  const dictionary& fieldDict,
247  const word& fieldDictEntry = "value"
248  );
249 
250  //- Return mesh
251  inline const Mesh& mesh() const;
252 
253  //- Return dimensions
254  inline const dimensionSet& dimensions() const;
255 
256  //- Return non-const access to dimensions
257  inline dimensionSet& dimensions();
258 
259  inline const Field<Type>& field() const;
260 
261  inline Field<Type>& field();
262 
263  //- Return a component field of the field
265  (
266  const direction
267  ) const;
268 
269  //- Replace a component field of the field
270  void replace
271  (
272  const direction,
274  );
275 
276  //- Replace a component field of the field
277  void replace
278  (
279  const direction,
281  );
282 
283  //- Return the field transpose (only defined for second rank tensors)
285 
286  //- Calculate and return arithmetic average
287  dimensioned<Type> average() const;
288 
289  //- Calculate and return weighted average
291  (
293  ) const;
294 
295  //- Calculate and return weighted average
297  (
299  ) const;
300 
301 
302  // Write
303 
304  bool writeData(Ostream&, const word& fieldDictEntry) const;
305 
306  bool writeData(Ostream&) const;
307 
308 
309  // Member Operators
310 
313  void operator=(const dimensioned<Type>&);
314 
317 
320 
323 
326 
327  void operator+=(const dimensioned<Type>&);
328  void operator-=(const dimensioned<Type>&);
329 
330  void operator*=(const dimensioned<scalar>&);
331  void operator/=(const dimensioned<scalar>&);
332 
333 
334  // Ostream Operators
335 
336  friend Ostream& operator<< <Type, GeoMesh>
337  (
338  Ostream&,
340  );
341 
342  friend Ostream& operator<< <Type, GeoMesh>
343  (
344  Ostream&,
346  );
347 };
348 
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 } // End namespace Foam
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 #include "DimensionedFieldI.H"
358 
359 #ifdef NoRepository
360 # include "DimensionedField.C"
361 #endif
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 #endif
366 
367 // ************************************************************************* //
regIOobject.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::DimensionedField::readField
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Definition: DimensionedFieldIO.C:34
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::DimensionedField::field
const Field< Type > & field() const
Definition: DimensionedFieldI.H:61
DimensionedFieldFunctions.H
DimensionedField.C
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::DimensionedField::dimensions_
dimensionSet dimensions_
Dimension set for this field.
Definition: DimensionedField.H:93
Foam::DimensionedField::readIfPresent
void readIfPresent(const word &fieldDictEntry="value")
Definition: DimensionedFieldIO.C:48
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::DimensionedField::operator-=
void operator-=(const DimensionedField< Type, GeoMesh > &)
Foam::DimensionedField::operator/=
void operator/=(const DimensionedField< scalar, GeoMesh > &)
Foam::DimensionedField::DimensionedField
DimensionedField(const IOobject &, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Construct from components.
Foam::DimensionedField::operator*=
void operator*=(const DimensionedField< scalar, GeoMesh > &)
Foam::DimensionedField::Mesh
GeoMesh::Mesh Mesh
Definition: DimensionedField.H:81
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::DimensionedField::mesh
const Mesh & mesh() const
Return mesh.
Definition: DimensionedFieldI.H:38
Foam::DimensionedField::cmptType
Field< Type >::cmptType cmptType
Definition: DimensionedField.H:82
Foam::DimensionedField::operator+=
void operator+=(const DimensionedField< Type, GeoMesh > &)
Foam::DimensionedField::TypeName
TypeName("DimensionedField")
Runtime type information.
Foam::DimensionedField::T
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: DimensionedField.C:354
Field.H
Foam::DimensionedField::mesh_
const Mesh & mesh_
Reference to mesh.
Definition: DimensionedField.H:90
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::dimensioned< Type >
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DimensionedField::replace
void replace(const direction, const DimensionedField< cmptType, GeoMesh > &)
Replace a component field of the field.
Foam::DimensionedField::dimensions
const dimensionSet & dimensions() const
Return dimensions.
Definition: DimensionedFieldI.H:46
Foam::DimensionedField::writeData
bool writeData(Ostream &, const word &fieldDictEntry) const
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
Foam::DimensionedField::~DimensionedField
virtual ~DimensionedField()
Destructor.
Definition: DimensionedField.C:286
Foam::DimensionedField::operator=
void operator=(const DimensionedField< Type, GeoMesh > &)
Foam::DimensionedField::component
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction) const
Return a component field of the field.
Foam::DimensionedField::clone
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
Definition: DimensionedField.C:274
DimensionedFieldI.H
Foam::DimensionedField::weightedAverage
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &) const
Calculate and return weighted average.
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::GeoMesh::Mesh
MESH Mesh
Definition: GeoMesh.H:61
Foam::DimensionedField::average
dimensioned< Type > average() const
Calculate and return arithmetic average.
Definition: DimensionedField.C:378
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51
dimensionedType.H