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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::DimensionedField
29
30Description
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
34SourceFiles
35 DimensionedFieldI.H
36 DimensionedField.C
37 DimensionedFieldIO.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_DimensionedField_H
42#define Foam_DimensionedField_H
43
44#include "regIOobject.H"
45#include "Field.H"
46#include "dimensionedType.H"
47#include "orientedType.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55template<class Type, class GeoMesh> class DimensionedField;
56
57template<class Type, class GeoMesh>
58Ostream& operator<<
59(
60 Ostream& os,
62);
63
64template<class Type, class GeoMesh>
65Ostream& operator<<
66(
67 Ostream& os,
69);
70
71
72/*---------------------------------------------------------------------------*\
73 Class DimensionedField Declaration
74\*---------------------------------------------------------------------------*/
75
76template<class Type, class GeoMesh>
78:
79 public regIOobject,
80 public Field<Type>
81{
82public:
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
96private:
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
118public:
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, copy initial field content
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,
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 // Static Constructors
286
287 //- Return tmp field from name, mesh, dimensions,
288 //- copy of internal field.
289 // The field is NO_READ, NO_WRITE, unregistered and uses the
290 // current timeName from the mesh registry
292 (
293 const word& name,
294 const Mesh& mesh,
295 const dimensionSet& ds,
296 const Field<Type>& iField
297 );
298
299 //- Return tmp field from name, mesh, dimensions,
300 //- moved internal field contents.
301 // The field is NO_READ, NO_WRITE, unregistered and uses the
302 // current timeName from the mesh registry
304 (
305 const word& name,
306 const Mesh& mesh,
307 const dimensionSet& ds,
308 Field<Type>&& iField
309 );
310
311 //- Return tmp field from name, mesh, dimensions.
312 // The field is NO_READ, NO_WRITE, unregistered and uses the
313 // current timeName from the mesh registry
315 (
316 const word& name,
317 const Mesh& mesh,
318 const dimensionSet& ds
319 );
320
321 //- Return tmp field from name, mesh, dimensioned<Type>.
322 // The field is NO_READ, NO_WRITE, unregistered and uses the
323 // current timeName from the mesh registry
325 (
326 const word& name,
327 const Mesh& mesh,
328 const dimensioned<Type>& dt
329 );
330
331 //- Return renamed tmp field
332 // The field is NO_READ, NO_WRITE, unregistered and uses the
333 // current timeName from the mesh registry
335 (
336 const word& newName,
338 );
339
340
341 //- Destructor
342 virtual ~DimensionedField() = default;
343
344
345 // Member Functions
346
347 void readField
348 (
349 const dictionary& fieldDict,
350 const word& fieldDictEntry = "value"
351 );
352
353 //- Return mesh
354 inline const Mesh& mesh() const;
355
356 //- Return dimensions
357 inline const dimensionSet& dimensions() const;
358
359 //- Return non-const access to dimensions
360 inline dimensionSet& dimensions();
361
362 //- Return oriented type
363 inline const orientedType& oriented() const noexcept;
364
365 //- Return non-const access to the oriented type
367
368 //- Set the oriented flag
369 inline void setOriented(const bool oriented = true) noexcept;
370
371 //- Return field
372 inline const Field<Type>& field() const;
373
374 //- Return field
375 inline Field<Type>& field();
376
377 //- Return a component field of the field
379 (
380 const direction d
381 ) const;
382
383 //- Replace a component field of the field
384 void replace
385 (
386 const direction d,
388 );
389
390 //- Replace a component field of the field
391 void replace
392 (
393 const direction d,
395 );
396
397 //- Return the field transpose (only defined for second rank tensors)
398 tmp<DimensionedField<Type, GeoMesh>> T() const;
399
400 //- Calculate and return arithmetic average
401 dimensioned<Type> average() const;
402
403 //- Calculate and return weighted average
405 (
406 const DimensionedField<scalar, GeoMesh>& weightField
407 ) const;
408
409 //- Calculate and return weighted average
411 (
412 const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
413 ) const;
414
415
416 // Write
417
418 bool writeData(Ostream& os, const word& fieldDictEntry) const;
419
420 bool writeData(Ostream& os) const;
421
422
423 // Member Operators
424
425 void operator=(const DimensionedField<Type, GeoMesh>& df);
426 void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
427
428 //- Assign dimensions and value.
429 void operator=(const dimensioned<Type>& dt);
430
431 void operator+=(const DimensionedField<Type, GeoMesh>& df);
432 void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
433
434 void operator-=(const DimensionedField<Type, GeoMesh>& df);
435 void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
436
437 void operator*=(const DimensionedField<scalar, GeoMesh>& df);
438 void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
439
440 void operator/=(const DimensionedField<scalar, GeoMesh>& df);
441 void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
442
443 void operator+=(const dimensioned<Type>& dt);
444 void operator-=(const dimensioned<Type>& dt);
445
446 void operator*=(const dimensioned<scalar>& dt);
447 void operator/=(const dimensioned<scalar>& dt);
448
449
450 // Ostream Operators
452 friend Ostream& operator<< <Type, GeoMesh>
453 (
454 Ostream& os,
455 const DimensionedField<Type, GeoMesh>& df
456 );
458 friend Ostream& operator<< <Type, GeoMesh>
459 (
460 Ostream& os,
461 const tmp<DimensionedField<Type, GeoMesh>>& tdf
462 );
463};
464
465
466// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
467
468} // End namespace Foam
469
470// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471
472#include "DimensionedFieldI.H"
474
475#ifdef NoRepository
476 #include "DimensionedField.C"
477#endif
478
479// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
480
481#endif
482
483// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
TypeName("DimensionedField")
Runtime type information.
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
const dimensionSet & dimensions() const
Return dimensions.
static const DimensionedField< Type, GeoMesh > & null()
Return a NullObjectRef DimensionedField.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
Field< Type > FieldType
Type of the field from which this DimensionedField is derived.
tmp< DimensionedField< cmptType, GeoMesh > > component(const direction d) const
Return a component field of the field.
void replace(const direction d, const DimensionedField< cmptType, GeoMesh > &df)
Replace a component field of the field.
bool writeData(Ostream &os, const word &fieldDictEntry) const
dimensioned< Type > average() const
Calculate and return arithmetic average.
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const Field< Type > &iField)
virtual ~DimensionedField()=default
Destructor.
const Mesh & mesh() const
Return mesh.
Field< Type >::cmptType cmptType
Component type of the elements of the field.
void setOriented(const bool oriented=true) noexcept
Set the oriented flag.
friend Ostream & operator(Ostream &os, const DimensionedField< Type, GeoMesh > &df)
const Field< Type > & field() const
Return field.
const orientedType & oriented() const noexcept
Return oriented type.
Generic templated field type.
Definition: Field.H:82
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:49
MESH Mesh
Definition: GeoMesh.H:62
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:109
Generic dimensioned Type class.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
Class to determine the 'oriented' status of surface fields.
Definition: orientedType.H:57
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:56
const direction noexcept
Definition: Scalar.H:223
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73