DimensionedFieldFunction.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) 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::DimensionedFieldFunction
26 
27 Description
28  Base class for run-time selectable internal and patch field initialisation
29  evaluation and update with dimension checking.
30 
31 SourceFiles
32  DimensionedFieldFunction.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef DimensionedFieldFunction_H
37 #define DimensionedFieldFunction_H
38 
39 #include "DimensionedFieldFwd.H"
40 #include "runTimeSelectionTables.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class DimensionedFieldFunction Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class DimensionedFieldType>
53 {
54 
55 protected:
56 
57  //- Reference to the field the function applies to
58  DimensionedFieldType& field_;
59 
60 
61 public:
62 
63  //- Runtime type information
64  TypeName("DimensionedFieldFunction");
65 
66 
67  // Declare runtime constructor selection tables
68 
70  (
71  autoPtr,
73  dictionary,
74  (
75  const dictionary& dict,
76  DimensionedFieldType& field
77  ),
78  (dict, field)
79  );
80 
81 
82  // Constructors
83 
84  //- Construct with dictionary to initialise given field
86  (
87  const dictionary& dict,
88  DimensionedFieldType& field
89  );
90 
91  //- Construct a copy for the given field
93  (
94  const DimensionedFieldFunction& dff,
95  DimensionedFieldType& field
96  );
97 
98  //- Disallow default bitwise copy construction
100  (
102  ) = delete;
103 
104  //- Construct and return a clone for the specified field
106  clone(DimensionedFieldType& field) const = 0;
107 
108  //- Construct and return a clone for the specified field
110  clone() const
111  {
114  (
115  nullptr
116  );
117  }
118 
119 
120  // Selectors
121 
122  //- Select null constructed
124  (
125  const dictionary& dict,
126  DimensionedFieldType& field
127  );
128 
129 
130  //- Destructor
131  virtual ~DimensionedFieldFunction()
132  {}
133 
134 
135  // Member Functions
136 
137  //- Evaluate the function and set the field
138  virtual void evaluate() = 0;
139 
140  //- Update the field if the function has changed and return true
141  // otherwise return false
142  virtual bool update()
143  {
144  return false;
145  }
146 
147  //- Reset the field size
148  virtual void reset()
149  {
150  field_.setSize(field_.mesh().size());
151  evaluate();
152  }
153 
154  //- Write data to dictionary stream
155  virtual void write(Ostream& os) const = 0;
156 
157 
158  // Member Operators
159 
160  //- Disallow default bitwise assignment
161  void operator=
162  (
164  ) = delete;
165 };
166 
167 
168 template<class DimensionedFieldType>
169 void writeEntry
170 (
171  Ostream& os,
172  const word& key,
174 );
175 
176 
177 namespace DimensionedFieldFunctions
178 {
179  //- Dummy function to call on a variable to avoid "unused variable" warnings
180  template<class T> void ignore(const T&){}
181 }
182 
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 } // End namespace Foam
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #define defineDimensionedFieldFunction(DimensionedFieldType) \
191  \
192  typedef DimensionedFieldFunction<DimensionedFieldType> \
193  DimensionedFieldType##DimensionedFieldFunction; \
194  defineNamedTemplateTypeNameAndDebug \
195  ( \
196  DimensionedFieldType##DimensionedFieldFunction, \
197  0 \
198  ); \
199  defineTemplateRunTimeSelectionTable \
200  ( \
201  DimensionedFieldType##DimensionedFieldFunction, \
202  dictionary \
203  );
204 
205 
206 #define addDimensionedFieldFunction(SS, DimensionedFieldType) \
207  \
208  typedef DimensionedFieldFunction<DimensionedFieldType> \
209  DimensionedFieldType##DimensionedFieldFunction; \
210  typedef SS<DimensionedFieldType> \
211  DimensionedFieldType##SS##DimensionedFieldFunction; \
212  defineNamedTemplateTypeNameAndDebug \
213  ( \
214  DimensionedFieldType##SS##DimensionedFieldFunction, \
215  0 \
216  ); \
217  addToRunTimeSelectionTable \
218  ( \
219  DimensionedFieldType##DimensionedFieldFunction, \
220  DimensionedFieldType##SS##DimensionedFieldFunction, \
221  dictionary \
222  )
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #ifdef NoRepository
229 #endif
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #endif
234 
235 // ************************************************************************* //
Base class for run-time selectable internal and patch field initialisation evaluation and update with...
virtual bool update()
Update the field if the function has changed and return true.
TypeName("DimensionedFieldFunction")
Runtime type information.
declareRunTimeSelectionTable(autoPtr, DimensionedFieldFunction, dictionary,(const dictionary &dict, DimensionedFieldType &field),(dict, field))
virtual ~DimensionedFieldFunction()
Destructor.
DimensionedFieldFunction(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
virtual void reset()
Reset the field size.
virtual autoPtr< DimensionedFieldFunction< DimensionedFieldType > > clone() const
Construct and return a clone for the specified field.
DimensionedFieldType & field_
Reference to the field the function applies to.
static autoPtr< DimensionedFieldFunction< DimensionedFieldType > > New(const dictionary &dict, DimensionedFieldType &field)
Select null constructed.
virtual void evaluate()=0
Evaluate the function and set the field.
virtual void write(Ostream &os) const =0
Write data to dictionary stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
void ignore(const T &)
Dummy function to call on a variable to avoid "unused variable" warnings.
Namespace for OpenFOAM.
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
labelList f(nPoints)
Macros to ease declaration of run-time selection tables.
dictionary dict