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 = true
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 Istream
183  (
184  const IOobject&,
185  const GeoMesh& mesh,
186  const word& fieldDictEntry="value"
187  );
188 
189  //- Construct from dictionary
191  (
192  const IOobject&,
193  const GeoMesh& mesh,
194  const dictionary& fieldDict,
195  const word& fieldDictEntry="value"
196  );
197 
198  //- Copy constructor
200  (
202  );
203 
204  //- Move constructor
206  (
208  );
209 
210  //- Copy constructor
211  template<template<class> class PrimitiveField2>
212  explicit DimensionedField
213  (
215  );
216 
217  //- Copy constructor or reuse as specified.
218  template<template<class> class PrimitiveField2>
220  (
222  const bool reuse
223  );
224 
225  //- Copy constructor of tmp<DimensionedField> deleting argument
227  (
229  );
230 
231  //- Copy constructor resetting IO parameters
232  template<template<class> class PrimitiveField2>
234  (
235  const IOobject&,
237  const bool checkIOFlags = true
238  );
239 
240  //- Copy constructor resetting IO parameters and reuse as specified.
241  template<template<class> class PrimitiveField2>
243  (
244  const IOobject&,
246  const bool reuse,
247  const bool checkIOFlags = true
248  );
249 
250  //- Copy constructor from tmp resetting IO parameters
252  (
253  const IOobject&,
255  const bool checkIOFlags = true
256  );
257 
258  //- Copy constructor resetting name
259  template<template<class> class PrimitiveField2>
261  (
262  const word& newName,
264  );
265 
266  //- Copy constructor resetting name and reuse as specified.
267  template<template<class> class PrimitiveField2>
269  (
270  const word& newName,
272  const bool reuse
273  );
274 
275  //- Copy constructor from tmp resetting name
277  (
278  const word& newName,
280  );
281 
282  //- Clone
284 
285  //- Return a temporary field constructed from name, mesh,
286  // dimensionSet and field
288  (
289  const word& name,
290  const GeoMesh& mesh,
291  const dimensionSet&,
292  const PrimitiveField<Type>&
293  );
294 
295  //- Return a temporary field constructed from name, mesh,
296  // dimensionSet and tmp field
298  (
299  const word& name,
300  const GeoMesh& mesh,
301  const dimensionSet&,
302  const tmp<PrimitiveField<Type>>&
303  );
304 
305  //- Return a temporary field constructed from name, mesh
306  // and dimensionSet
308  (
309  const word& name,
310  const GeoMesh& mesh,
311  const dimensionSet&
312  );
313 
314  //- Return a temporary field constructed from name, mesh
315  // and dimensionType providing dimensions and value
317  (
318  const word& name,
319  const GeoMesh& mesh,
320  const dimensioned<Type>&
321  );
322 
323  //- Return a temporary field constructed from name and a field
324  template<template<class> class PrimitiveField2>
326  (
327  const word& newName,
329  );
330 
331  //- Return renamed temporary field
333  (
334  const word& newName,
336  );
337 
338 
339  //- Destructor
340  virtual ~DimensionedField();
341 
342 
343  // Member Functions
344 
345  void readField
346  (
347  const dictionary& fieldDict,
348  const word& fieldDictEntry = "value"
349  );
350 
351  //- Return mesh
352  inline const GeoMesh& mesh() const;
353 
354  //- Return dimensions
355  inline const dimensionSet& dimensions() const;
356 
357  //- Return non-const access to dimensions
358  inline dimensionSet& dimensions();
359 
360  //- Return a reference to the internal field
361  PrimitiveField<Type>& primitiveFieldRef();
362 
363  //- Return a const-reference to the primitive field
364  inline const PrimitiveField<Type>& primitiveField() const;
365 
366  //- Transfer the list pointer from the given PrimitiveField
367  inline virtual void transfer(PrimitiveField<Type>&);
368 
369  //- Use old-time methods from the base class
371 
372  //- Return a component field of the field
374  (
375  const direction
376  ) const;
377 
378  //- Replace a component field of the field
379  template<template<class> class PrimitiveField2>
380  void replace
381  (
382  const direction,
384  );
385 
386  //- Replace a component field of the field
387  template<template<class> class PrimitiveField2>
388  void replace
389  (
390  const direction,
392  );
393 
394  //- Return the field transpose (only defined for second rank tensors)
396 
397  //- Calculate and return arithmetic average
398  dimensioned<Type> average() const;
399 
400  //- Calculate and return weighted average
401  template<template<class> class PrimitiveField2>
403  (
405  ) const;
406 
407  //- Calculate and return weighted average
408  template<template<class> class PrimitiveField2>
410  (
412  ) const;
413 
414  //- Reset the field values to the given field
415  // Used for mesh to mesh mapping
416  template<template<class> class PrimitiveField2>
418 
419  //- Reset the field values to the given tmp-field
420  // Used for mesh to mesh mapping
422 
423  //- Reset the field values to the given tmp-field
424  // Used for mesh to mesh mapping
425  template<template<class> class PrimitiveField2>
426  void reset
427  (
429  );
430 
431  //- Set the field to the maximum of its value and a given value
432  void max(const dimensioned<Type>&);
433 
434  //- Set the field to the minimum of its value and a given value
435  void min(const dimensioned<Type>&);
436 
437  //- Clip the field to between two values
438  void maxMin
439  (
440  const dimensioned<Type>& minDt,
441  const dimensioned<Type>& maxDt
442  );
443 
444 
445  // Write
446 
447  bool writeData(Ostream&, const word& fieldDictEntry) const;
448 
449  bool writeData(Ostream&) const;
450 
451 
452  // Member Operators
453 
456  void operator=
457  (
459  );
460  template<template<class> class PrimitiveField2>
461  void operator=
462  (
464  );
465  template<template<class> class PrimitiveField2>
466  void operator=
467  (
469  );
470  void operator=(const dimensioned<Type>&);
471  void operator=(const zero&);
472 
473  template<template<class> class PrimitiveField2>
474  void operator==
475  (
477  );
478  template<template<class> class PrimitiveField2>
479  void operator==
480  (
482  );
483  void operator==(const dimensioned<Type>&);
484  void operator==(const zero&);
485 
486  template<template<class> class PrimitiveField2>
487  void operator+=
488  (
490  );
491  template<template<class> class PrimitiveField2>
492  void operator+=
493  (
495  );
496  void operator+=(const dimensioned<Type>&);
497 
498  template<template<class> class PrimitiveField2>
499  void operator-=
500  (
502  );
503  template<template<class> class PrimitiveField2>
504  void operator-=
505  (
507  );
508  void operator-=(const dimensioned<Type>&);
509 
510  template<template<class> class PrimitiveField2>
511  void operator*=
512  (
514  );
515  template<template<class> class PrimitiveField2>
516  void operator*=
517  (
519  );
520  void operator*=(const dimensioned<scalar>&);
521 
522  template<template<class> class PrimitiveField2>
523  void operator/=
524  (
526  );
527  template<template<class> class PrimitiveField2>
528  void operator/=
529  (
531  );
532  void operator/=(const dimensioned<scalar>&);
533 
534 
535  // Ostream Operators
536 
537  friend Ostream& operator<< <Type, GeoMesh, PrimitiveField>
538  (
539  Ostream&,
541  );
542 
543  friend Ostream& operator<< <Type, GeoMesh, PrimitiveField>
544  (
545  Ostream&,
547  );
548 };
549 
550 
551 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
552 
553 } // End namespace Foam
554 
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
556 
557 #include "DimensionedFieldI.H"
559 
560 #ifdef NoRepository
561  #include "DimensionedField.C"
562 #endif
563 
564 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
565 
566 #endif
567 
568 // ************************************************************************* //
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
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:45