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  ),
54  funcName_(funcName),
55  funcPtr_
56  (
57  dict.isDict(funcName)
59  (
60  dict.subDict(funcName),
61  *this
62  )
64  (
65  nullptr
66  )
67  )
68 {
69  if (funcPtr_.valid())
70  {
71  if (mesh.time().completeCase())
72  {
73  funcPtr_->evaluate();
74  }
75  }
76  else
77  {
78  this->primitiveFieldRef() =
79  Field<Type>(funcName_, dimensions, dict, mesh.size());
80  }
81 }
82 
83 
84 template<class Type, class GeoMesh>
86 (
87  const word& name,
88  const word& funcName,
89  const GeoMesh& mesh,
90  const dimensionSet& dimensions,
91  const dictionary& dict,
92  const Type& defaultValue
93 )
94 :
95  DimensionedField<Type, GeoMesh>
96  (
97  IOobject
98  (
99  name + '_' + funcName,
100  mesh.time().name(),
101  mesh.db(),
102  IOobject::NO_READ,
103  IOobject::NO_WRITE,
104  false
105  ),
106  mesh,
107  dimensions,
108  defaultValue
109  ),
110  funcName_(funcName),
111  funcPtr_
112  (
113  dict.isDict(funcName)
115  (
116  dict.subDict(funcName),
117  *this
118  )
120  (
121  nullptr
122  )
123  )
124 {
125  if (funcPtr_.valid())
126  {
127  if (mesh.time().completeCase())
128  {
129  funcPtr_->evaluate();
130  }
131  }
132  else if (dict.found(funcName))
133  {
134  this->primitiveFieldRef() =
135  Field<Type>(funcName_, dimensions, dict, mesh.size());
136  }
137  else
138  {
139  this->primitiveFieldRef() =
140  Field<Type>(mesh.size(), defaultValue);
141  }
142 }
143 
144 
145 template<class Type, class GeoMesh>
147 (
149  const GeoMesh& mesh
150 )
151 :
152  DimensionedField<Type, GeoMesh>
153  (
154  udff,
155  mesh,
156  udff.dimensions()
157  ),
158  funcName_(udff.funcName_),
159  funcPtr_
160  (
161  udff.funcPtr_.valid()
162  ? udff.funcPtr_->clone(*this)
164  (
165  nullptr
166  )
167  )
168 {}
169 
170 
171 template<class Type, class GeoMesh>
173 (
175 )
176 :
177  DimensionedField<Type, GeoMesh>(udff),
178  funcName_(udff.funcName_),
179  funcPtr_
180  (
181  udff.funcPtr_.valid()
182  ? udff.funcPtr_->clone(*this)
184  (
185  nullptr
186  )
187  )
188 {}
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
193 template<class Type, class GeoMesh>
195 {
196  this->setSize(this->mesh().size());
197 
198  if (evaluate && funcPtr_.valid())
199  {
200  funcPtr_->reset();
201  }
202 }
203 
204 
205 template<class Type, class GeoMesh>
207 {
208  this->setSize(this->mesh().size());
209 
210  if (funcPtr_.valid())
211  {
212  funcPtr_->reset();
213  }
214 }
215 
216 
217 template<class Type, class GeoMesh>
219 {
220  if (funcPtr_.valid())
221  {
222  return funcPtr_->update();
223  }
224  else
225  {
226  return false;
227  }
228 }
229 
230 
231 template<class Type, class GeoMesh>
233 {
234  if (funcPtr_.valid())
235  {
236  funcPtr_->write(os);
237  }
238 }
239 
240 
241 template<class Type, class GeoMesh>
243 (
244  Ostream& os,
246 )
247 {
248  if (udff.funcPtr_.valid())
249  {
250  writeEntry(os, udff.funcName_, *udff.funcPtr_);
251  }
252  else
253  {
254  writeEntry(os, udff.funcName_, udff.primitiveField());
255  }
256 }
257 
258 
259 // ************************************************************************* //
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.
void map(const bool evaluate)
Map and optionally evaluate.
FunctionalDimensionedField(const word &name, const word &funcName, const GeoMesh &, const dimensionSet &dimensions, const dictionary &)
Construct from name, mesh, dimensions, field and dictionary.
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
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
void evaluate(GeometricField< Type, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, GeoMesh > &x)
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