FunctionalDimensionedField.C
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 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type, class GeoMesh>
32 (
33  const word& name,
34  const word& funcName,
35  const GeoMesh& mesh,
36  const dimensionSet& dimensions,
37  const dictionary& dict
38 )
39 :
40  DimensionedField<Type, GeoMesh>
41  (
42  IOobject
43  (
44  name + '_' + funcName,
45  mesh.time().name(),
46  mesh.db(),
47  IOobject::NO_READ,
48  IOobject::NO_WRITE,
49  false
50  ),
51  mesh,
52  dimensions,
53  false
54  ),
55  funcName_(funcName),
56  funcPtr_
57  (
58  dict.isDict(funcName)
60  (
61  dict.subDict(funcName),
62  *this
63  )
65  (
66  nullptr
67  )
68  )
69 {
70  if (funcPtr_.valid())
71  {
72  if (mesh.time().completeCase())
73  {
74  funcPtr_->evaluate();
75  }
76  }
77  else
78  {
79  this->primitiveFieldRef() =
80  Field<Type>(funcName_, dimensions, dict, mesh.size());
81  }
82 }
83 
84 
85 template<class Type, class GeoMesh>
87 (
88  const word& name,
89  const word& funcName,
90  const GeoMesh& mesh,
91  const dimensionSet& dimensions,
92  const dictionary& dict,
93  const Type& defaultValue
94 )
95 :
96  DimensionedField<Type, GeoMesh>
97  (
98  IOobject
99  (
100  name + '_' + funcName,
101  mesh.time().name(),
102  mesh.db(),
103  IOobject::NO_READ,
104  IOobject::NO_WRITE,
105  false
106  ),
107  mesh,
108  dimensions,
109  defaultValue
110  ),
111  funcName_(funcName),
112  funcPtr_
113  (
114  dict.isDict(funcName)
116  (
117  dict.subDict(funcName),
118  *this
119  )
121  (
122  nullptr
123  )
124  )
125 {
126  if (funcPtr_.valid())
127  {
128  if (mesh.time().completeCase())
129  {
130  funcPtr_->evaluate();
131  }
132  }
133  else if (dict.found(funcName))
134  {
135  this->primitiveFieldRef() =
136  Field<Type>(funcName_, dimensions, dict, mesh.size());
137  }
138  else
139  {
140  this->primitiveFieldRef() =
141  Field<Type>(mesh.size(), defaultValue);
142  }
143 }
144 
145 
146 template<class Type, class GeoMesh>
148 (
150  const GeoMesh& mesh
151 )
152 :
153  DimensionedField<Type, GeoMesh>
154  (
155  udff,
156  mesh,
157  udff.dimensions(),
158  false
159  ),
160  funcName_(udff.funcName_),
161  funcPtr_
162  (
163  udff.funcPtr_.valid()
164  ? udff.funcPtr_->clone(*this)
166  (
167  nullptr
168  )
169  )
170 {}
171 
172 
173 template<class Type, class GeoMesh>
175 (
177  const GeoMesh& mesh,
178  const fieldMapper& mapper
179 )
180 :
181  DimensionedField<Type, GeoMesh>
182  (
183  udff,
184  mesh,
185  udff.dimensions(),
186  false
187  ),
188  funcName_(udff.funcName_),
189  funcPtr_
190  (
191  udff.funcPtr_.valid()
192  ? udff.funcPtr_->clone(*this)
194  (
195  nullptr
196  )
197  )
198 {
199  if (!funcPtr_.valid())
200  {
201  mapper(*this, udff);
202  }
203 }
204 
205 
206 template<class Type, class GeoMesh>
208 (
210 )
211 :
212  DimensionedField<Type, GeoMesh>(udff),
213  funcName_(udff.funcName_),
214  funcPtr_
215  (
216  udff.funcPtr_.valid()
217  ? udff.funcPtr_->clone(*this)
219  (
220  nullptr
221  )
222  )
223 {}
224 
225 
226 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
227 
228 template<class Type, class GeoMesh>
230 (
232  const fieldMapper& mapper
233 )
234 {
235  if (!mapper.direct() && funcPtr_.valid())
236  {
237  this->setSize(this->mesh().size());
238  funcPtr_->reset();
239  }
240  else
241  {
242  mapper(*this, df);
243  }
244 }
245 
246 
247 template<class Type, class GeoMesh>
249 {
250  this->setSize(this->mesh().size());
251 
252  if (funcPtr_.valid())
253  {
254  funcPtr_->reset();
255  }
256 }
257 
258 
259 template<class Type, class GeoMesh>
261 {
262  if (funcPtr_.valid())
263  {
264  return funcPtr_->update();
265  }
266  else
267  {
268  return false;
269  }
270 }
271 
272 
273 template<class Type, class GeoMesh>
275 {
276  if (funcPtr_.valid())
277  {
278  funcPtr_->write(os);
279  }
280 }
281 
282 
283 template<class Type, class GeoMesh>
285 (
286  Ostream& os,
288 )
289 {
290  if (udff.funcPtr_.valid())
291  {
292  writeEntry(os, udff.funcName_, *udff.funcPtr_);
293  }
294  else
295  {
296  writeEntry(os, udff.funcName_, udff.primitiveField());
297  }
298 }
299 
300 
301 // ************************************************************************* //
Base class for run-time selectable internal and patch field initialisation evaluation and update with...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
PrimitiveField< Type > & primitiveFieldRef()
Return a reference to the internal field.
const GeoMesh & mesh() const
Return mesh.
const PrimitiveField< Type > & primitiveField() const
Return a const-reference to the primitive field.
Pre-declare SubField and related Field type.
Definition: Field.H:83
DimensionedField with a corresponding run-time selected function to evaluate and update the field.
virtual bool write(const bool write=true) const
Write using setting from DB.
FunctionalDimensionedField(const word &name, const word &funcName, const GeoMesh &, const dimensionSet &dimensions, const dictionary &)
Construct from name, mesh, dimensions, field and dictionary.
void map(const DimensionedField< Type, GeoMesh > &df, const fieldMapper &mapper)
Map if mapping direct or evaluate if function defined.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
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
Dimension set for the base types.
Definition: dimensionSet.H:125
Abstract base class for field mapping.
Definition: fieldMapper.H:48
virtual bool direct() const
Is the mapper direct?
Definition: fieldMapper.H:132
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
bool valid(const PtrList< ModelType > &l)
const dimensionSet time
T clone(const T &t)
Definition: List.H:55
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
points setSize(newPointi)
dictionary dict