DimensionedField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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 "DimensionedFieldFwd.H"
42 #include "regIOobject.H"
43 #include "Field.H"
44 #include "OldTimeField.H"
45 #include "dimensionedType.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 template<class Type, class GeoMesh, template<class> class PrimitiveField>
55 class DimensionedField;
56 
57 template<class Type, class GeoMesh, template<class> class PrimitiveField>
58 Ostream& operator<<
59 (
60  Ostream&,
62 );
63 
64 template<class Type, class GeoMesh, template<class> class PrimitiveField>
65 Ostream& operator<<
66 (
67  Ostream&,
69 );
70 
71 
72 /*---------------------------------------------------------------------------*\
73  Class DimensionedField Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class Type, class GeoMesh, template<class> class PrimitiveField>
77 class DimensionedField
78 :
79  public regIOobject,
80  public PrimitiveField<Type>,
81  public OldTimeField<DimensionedField<Type, GeoMesh, PrimitiveField>>
82 {
83 
84 public:
85 
86  // Public Typedefs
87 
88  //- Value type
89  typedef Type Type_;
90 
91  //- Geometric mesh type
92  typedef GeoMesh GeoMesh_;
93 
94  //- Base mesh type from which GeoMesh is constructed
95  typedef typename GeoMesh::Mesh Mesh;
96 
97  //- Type of the field from which this DimensionedField is derived
98  typedef PrimitiveField<Type> FieldType;
99 
100  //- Type of the field from which this DimensionedField is derived
101  typedef PrimitiveField<Type> Base;
102 
103  //- Component type of the elements of the field
104  typedef typename PrimitiveField<Type>::cmptType cmptType;
105 
106 
107 private:
108 
109  // Private Data
110 
111  //- Reference to mesh
112  const GeoMesh& mesh_;
113 
114  //- Dimension set for this field
115  dimensionSet dimensions_;
116 
117 
118  // Private Member Functions
119 
120  //- Read from file if it is present
121  bool readIfPresent(const word& fieldDictEntry = "value");
122 
123 
124 public:
125 
126  //- Runtime type information
127  TypeName("DimensionedField");
128 
129 
130  //- Declare friendship with other dimensioned fields
131  template<class Type2, class GeoMesh2, template<class> class PrimitiveField2>
132  friend class DimensionedField;
133 
134 
135  // Static Member Functions
136 
137  //- Return a null DimensionedField
138  inline static const
140 
141 
142  // Constructors
143 
144  //- Construct from components
146  (
147  const IOobject&,
148  const GeoMesh& mesh,
149  const dimensionSet&,
150  const PrimitiveField<Type>&
151  );
152 
153  //- Construct from components
155  (
156  const IOobject&,
157  const GeoMesh& mesh,
158  const dimensionSet&,
159  const tmp<PrimitiveField<Type>>&
160  );
161 
162  //- Construct from components
163  // Used for temporary fields which are initialised after construction
165  (
166  const IOobject&,
167  const GeoMesh& mesh,
168  const dimensionSet&,
169  const bool checkIOFlags
170  );
171 
172  //- Construct from components
174  (
175  const IOobject&,
176  const GeoMesh& mesh,
177  const dimensioned<Type>&,
178  const bool checkIOFlags = true
179  );
180 
181  //- Construct from dictionary
183  (
184  const IOobject&,
185  const GeoMesh& mesh,
186  const dictionary& fieldDict,
187  const dimensionSet& dims = dimensions::invalid,
188  const word& fieldDictEntry="value"
189  );
190 
191  //- Construct from dictionary constructed from IOobject
193  (
194  const IOobject&,
195  const GeoMesh& mesh,
196  const dimensionSet& dims = dimensions::invalid,
197  const word& fieldDictEntry="value"
198  );
199 
200  //- Copy constructor
202  (
204  );
205 
206  //- Move constructor
208  (
210  );
211 
212  //- Copy constructor
213  template<template<class> class PrimitiveField2>
214  explicit DimensionedField
215  (
217  );
218 
219  //- Copy constructor or reuse as specified.
220  template<template<class> class PrimitiveField2>
222  (
224  const bool reuse
225  );
226 
227  //- Copy constructor of tmp<DimensionedField> deleting argument
229  (
231  );
232 
233  //- Copy constructor resetting IO parameters
234  template<template<class> class PrimitiveField2>
236  (
237  const IOobject&,
239  const bool checkIOFlags = true
240  );
241 
242  //- Copy constructor resetting IO parameters and reuse as specified.
243  template<template<class> class PrimitiveField2>
245  (
246  const IOobject&,
248  const bool reuse,
249  const bool checkIOFlags = true
250  );
251 
252  //- Copy constructor from tmp resetting IO parameters
254  (
255  const IOobject&,
257  const bool checkIOFlags = true
258  );
259 
260  //- Copy constructor resetting name
261  template<template<class> class PrimitiveField2>
263  (
264  const word& newName,
266  );
267 
268  //- Copy constructor resetting name and reuse as specified.
269  template<template<class> class PrimitiveField2>
271  (
272  const word& newName,
274  const bool reuse
275  );
276 
277  //- Copy constructor from tmp resetting name
279  (
280  const word& newName,
282  );
283 
284  //- Clone
286 
287  //- Return a temporary field constructed from name, mesh,
288  // dimensionSet and field
290  (
291  const word& name,
292  const GeoMesh& mesh,
293  const dimensionSet&,
294  const PrimitiveField<Type>&
295  );
296 
297  //- Return a temporary field constructed from name, mesh,
298  // dimensionSet and tmp field
300  (
301  const word& name,
302  const GeoMesh& mesh,
303  const dimensionSet&,
304  const tmp<PrimitiveField<Type>>&
305  );
306 
307  //- Return a temporary field constructed from name, mesh
308  // and dimensionSet
310  (
311  const word& name,
312  const GeoMesh& mesh,
313  const dimensionSet&
314  );
315 
316  //- Return a temporary field constructed from name, mesh
317  // and dimensionType providing dimensions and value
319  (
320  const word& name,
321  const GeoMesh& mesh,
322  const dimensioned<Type>&
323  );
324 
325  //- Return a temporary field constructed from name and a field
326  template<template<class> class PrimitiveField2>
328  (
329  const word& newName,
331  );
332 
333  //- Return renamed temporary field
335  (
336  const word& newName,
338  );
339 
340 
341  //- Destructor
342  virtual ~DimensionedField();
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 GeoMesh& 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 a reference to the internal field
363  PrimitiveField<Type>& primitiveFieldRef();
364 
365  //- Return a const-reference to the primitive field
366  inline const PrimitiveField<Type>& primitiveField() const;
367 
368  //- Transfer the list pointer from the given PrimitiveField
369  inline virtual void transfer(PrimitiveField<Type>&);
370 
371  //- Use old-time methods from the base class
373 
374  //- Return a component field of the field
376  (
377  const direction
378  ) const;
379 
380  //- Replace a component field of the field
381  template<template<class> class PrimitiveField2>
382  void replace
383  (
384  const direction,
386  );
387 
388  //- Replace a component field of the field
389  template<template<class> class PrimitiveField2>
390  void replace
391  (
392  const direction,
394  );
395 
396  //- Return the field transpose (only defined for second rank tensors)
398 
399  //- Calculate and return arithmetic average
400  dimensioned<Type> average() const;
401 
402  //- Calculate and return weighted average
403  template<template<class> class PrimitiveField2>
405  (
407  ) const;
408 
409  //- Calculate and return weighted average
410  template<template<class> class PrimitiveField2>
412  (
414  ) const;
415 
416  //- Reset the field values to the given field
417  // Used for mesh to mesh mapping
418  template<template<class> class PrimitiveField2>
420 
421  //- Reset the field values to the given tmp-field
422  // Used for mesh to mesh mapping
424 
425  //- Reset the field values to the given tmp-field
426  // Used for mesh to mesh mapping
427  template<template<class> class PrimitiveField2>
428  void reset
429  (
431  );
432 
433  //- Set the field to the maximum of its value and a given value
434  void max(const dimensioned<Type>&);
435 
436  //- Set the field to the minimum of its value and a given value
437  void min(const dimensioned<Type>&);
438 
439  //- Clip the field to between two values
440  void maxMin
441  (
442  const dimensioned<Type>& minDt,
443  const dimensioned<Type>& maxDt
444  );
445 
446 
447  // Write
448 
449  bool writeData(Ostream&, const word& fieldDictEntry) const;
450 
451  bool writeData(Ostream&) const;
452 
453 
454  // Member Operators
455 
458  void operator=
459  (
461  );
462  template<template<class> class PrimitiveField2>
463  void operator=
464  (
466  );
467  template<template<class> class PrimitiveField2>
468  void operator=
469  (
471  );
472  void operator=(const dimensioned<Type>&);
473  void operator=(const zero&);
474 
475  template<template<class> class PrimitiveField2>
476  void operator==
477  (
479  );
480  template<template<class> class PrimitiveField2>
481  void operator==
482  (
484  );
485  void operator==(const dimensioned<Type>&);
486  void operator==(const zero&);
487 
488  template<template<class> class PrimitiveField2>
489  void operator+=
490  (
492  );
493  template<template<class> class PrimitiveField2>
494  void operator+=
495  (
497  );
498  void operator+=(const dimensioned<Type>&);
499 
500  template<template<class> class PrimitiveField2>
501  void operator-=
502  (
504  );
505  template<template<class> class PrimitiveField2>
506  void operator-=
507  (
509  );
510  void operator-=(const dimensioned<Type>&);
511 
512  template<template<class> class PrimitiveField2>
513  void operator*=
514  (
516  );
517  template<template<class> class PrimitiveField2>
518  void operator*=
519  (
521  );
522  void operator*=(const dimensioned<scalar>&);
523 
524  template<template<class> class PrimitiveField2>
525  void operator/=
526  (
528  );
529  template<template<class> class PrimitiveField2>
530  void operator/=
531  (
533  );
534  void operator/=(const dimensioned<scalar>&);
535 
536 
537  // Ostream Operators
538 
539  friend Ostream& operator<< <Type, GeoMesh, PrimitiveField>
540  (
541  Ostream&,
543  );
544 
545  friend Ostream& operator<< <Type, GeoMesh, PrimitiveField>
546  (
547  Ostream&,
549  );
550 };
551 
552 
553 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
554 
555 } // End namespace Foam
556 
557 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
558 
559 #include "DimensionedFieldI.H"
561 
562 #ifdef NoRepository
563  #include "DimensionedField.C"
564 #endif
565 
566 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
567 
568 #endif
569 
570 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
void max(const dimensioned< Type > &)
Set the field to the maximum of its value and a given value.
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const GeoMesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
PrimitiveField< Type >::cmptType cmptType
Component type of the elements of the field.
TypeName("DimensionedField")
Runtime type information.
void operator-=(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
friend class DimensionedField
Declare friendship with other dimensioned fields.
void maxMin(const dimensioned< Type > &minDt, const dimensioned< Type > &maxDt)
Clip the field to between two values.
void replace(const direction, const DimensionedField< cmptType, GeoMesh, PrimitiveField2 > &)
Replace a component field of the field.
GeoMesh::Mesh Mesh
Base mesh type from which GeoMesh is constructed.
void operator=(const DimensionedField< Type, GeoMesh, PrimitiveField > &)
void operator+=(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
const dimensionSet & dimensions() const
Return dimensions.
tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > clone() const
Clone.
void operator/=(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &)
PrimitiveField< Type > & primitiveFieldRef()
Return a reference to the internal field.
GeoMesh GeoMesh_
Geometric mesh type.
PrimitiveField< Type > Base
Type of the field from which this DimensionedField is derived.
PrimitiveField< Type > FieldType
Type of the field from which this DimensionedField is derived.
void min(const dimensioned< Type > &)
Set the field to the minimum of its value and a given value.
bool writeData(Ostream &, const word &fieldDictEntry) const
USING_OLD_TIME_FIELD(DimensionedField)
Use old-time methods from the base class.
void reset(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
Reset the field values to the given field.
dimensioned< Type > average() const
Calculate and return arithmetic average.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &) const
Calculate and return weighted average.
const GeoMesh & mesh() const
Return mesh.
void operator==(const DimensionedField< Type, GeoMesh, PrimitiveField2 > &)
virtual void transfer(PrimitiveField< Type > &)
Transfer the list pointer from the given PrimitiveField.
const PrimitiveField< Type > & primitiveField() const
Return a const-reference to the primitive field.
void operator*=(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &)
tmp< DimensionedField< cmptType, GeoMesh, Field > > component(const direction) const
Return a component field of the field.
tmp< DimensionedField< Type, GeoMesh, Field > > T() const
Return the field transpose (only defined for second rank tensors)
virtual ~DimensionedField()
Destructor.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:307
Class to add into field types to provide old-time storage and retrieval.
Definition: OldTimeField.H:115
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Generic dimensioned Type class.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
const dimensionSet invalid
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:45