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 -------------------------------------------------------------------------------
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 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 
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,
61  const DimensionedField<Type, GeoMesh>& df
62 );
63 
64 template<class Type, class GeoMesh>
65 Ostream& operator<<
66 (
67  Ostream& os,
68  const tmp<DimensionedField<Type, GeoMesh>>& tdf
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 field elements
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, 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,
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  // Factory Methods
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  //- Construct tmp field based on mesh/registry information from
341  //- an existing field.
342  // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance
343  // from the field
344  template<class AnyType>
346  (
348  const word& name,
349  const dimensionSet& dims
350  );
351 
352  //- Construct tmp field based on mesh/registry information from
353  //- an existing field and initialise with value.
354  // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance
355  // from the field
356  template<class AnyType>
358  (
360  const word& name,
361  const dimensioned<Type>& dt
362  );
363 
364 
365  //- Destructor
366  virtual ~DimensionedField() = default;
367 
368 
369  // Member Functions
370 
371  void readField
372  (
373  const dictionary& fieldDict,
374  const word& fieldDictEntry = "value"
375  );
376 
377  //- Return mesh
378  inline const Mesh& mesh() const noexcept;
379 
380  //- Return dimensions
381  inline const dimensionSet& dimensions() const noexcept;
382 
383  //- Return non-const access to dimensions
384  inline dimensionSet& dimensions() noexcept;
385 
386  //- Return oriented type
387  inline orientedType oriented() const noexcept;
388 
389  //- Return non-const access to the oriented type
390  inline orientedType& oriented() noexcept;
391 
392  //- True if field is ORIENTED
393  inline bool is_oriented() const noexcept;
394 
395  //- Set the oriented flag: on/off
396  inline void setOriented(bool on = true) noexcept;
397 
398  //- Return const-reference to the field values
399  inline const Field<Type>& field() const noexcept;
400 
401  //- Return reference to the field values
402  inline Field<Type>& field() noexcept;
403 
404  //- Return a component field of the field
406  (
407  const direction d
408  ) const;
409 
410  //- Replace a component field of the field
411  void replace
412  (
413  const direction d,
414  const DimensionedField<cmptType, GeoMesh>& df
415  );
416 
417  //- Replace a component field of the field
418  void replace
419  (
420  const direction d,
421  const tmp<DimensionedField<cmptType, GeoMesh>>& tdf
422  );
423 
424  //- Return the field transpose (only defined for second rank tensors)
425  tmp<DimensionedField<Type, GeoMesh>> T() const;
426 
427  //- Calculate and return arithmetic average
428  dimensioned<Type> average() const;
429 
430  //- Calculate and return weighted average
432  (
433  const DimensionedField<scalar, GeoMesh>& weightField
434  ) const;
435 
436  //- Calculate and return weighted average
438  (
439  const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
440  ) const;
441 
442 
443  // Write
444 
445  bool writeData(Ostream& os, const word& fieldDictEntry) const;
446 
447  bool writeData(Ostream& os) const;
448 
449 
450  // Member Operators
451 
452  void operator=(const DimensionedField<Type, GeoMesh>& df);
453  void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
454 
455  //- Assign dimensions and value.
456  void operator=(const dimensioned<Type>& dt);
457 
458  void operator+=(const DimensionedField<Type, GeoMesh>& df);
459  void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
460 
461  void operator-=(const DimensionedField<Type, GeoMesh>& df);
462  void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
463 
464  void operator*=(const DimensionedField<scalar, GeoMesh>& df);
465  void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
466 
467  void operator/=(const DimensionedField<scalar, GeoMesh>& df);
468  void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
469 
470  void operator+=(const dimensioned<Type>& dt);
471  void operator-=(const dimensioned<Type>& dt);
472 
473  void operator*=(const dimensioned<scalar>& dt);
474  void operator/=(const dimensioned<scalar>& dt);
475 
476 
477  // Ostream Operators
478 
479  friend Ostream& operator<< <Type, GeoMesh>
480  (
481  Ostream& os,
482  const DimensionedField<Type, GeoMesh>& df
483  );
484 
485  friend Ostream& operator<< <Type, GeoMesh>
486  (
487  Ostream& os,
488  const tmp<DimensionedField<Type, GeoMesh>>& tdf
489  );
490 };
491 
492 
493 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
494 
495 } // End namespace Foam
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 #include "DimensionedFieldI.H"
501 
502 #ifdef NoRepository
503  #include "DimensionedField.C"
504 #endif
505 
506 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
507 
508 #endif
509 
510 // ************************************************************************* //
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
dimensioned< Type > average() const
Calculate and return arithmetic average.
uint8_t direction
Definition: direction.H:46
void replace(const direction d, const DimensionedField< cmptType, GeoMesh > &df)
Replace a component field of the field.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
DimensionedField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &field)
Construct from components, copy initial field content.
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:123
bool is_oriented() const noexcept
True if field is ORIENTED.
orientedType oriented() const noexcept
Return oriented type.
Class to determine the &#39;oriented&#39; status of surface fields.
Definition: orientedType.H:52
Generic dimensioned Type class.
Field< Type >::cmptType cmptType
Component type of the field elements.
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 readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
virtual ~DimensionedField()=default
Destructor.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
static const DimensionedField< Type, GeoMesh > & null()
Return a NullObjectRef DimensionedField.
Generic templated field type.
Definition: Field.H:61
bool writeData(Ostream &os, const word &fieldDictEntry) const
A class for handling words, derived from Foam::string.
Definition: word.H:63
void setOriented(bool on=true) noexcept
Set the oriented flag: on/off.
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
TypeName("DimensionedField")
Runtime type information.
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const Field< Type > &iField)
Return tmp field from name, mesh, dimensions, copy of internal field.
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
const Mesh & mesh() const noexcept
Return mesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
MESH Mesh
Definition: GeoMesh.H:58
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const Field< Type > & field() const noexcept
Return const-reference to the field values.
friend Ostream & operator(Ostream &os, const DimensionedField< Type, GeoMesh > &df)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:42
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.