UFunctionalDimensionedField.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  Field<Type>& field,
38  const dictionary& dict
39 )
40 :
41  SlicedDimensionedField<Type, GeoMesh>
42  (
43  IOobject
44  (
45  name + '_' + funcName,
46  mesh.time().name(),
47  mesh.db(),
48  IOobject::NO_READ,
49  IOobject::NO_WRITE,
50  false
51  ),
52  mesh,
53  dimensions,
54  field
55  ),
56  field_(field),
57  funcName_(funcName),
58  funcPtr_
59  (
60  dict.isDict(funcName)
62  (
63  dict.subDict(funcName),
64  *this
65  )
67  (
68  nullptr
69  )
70  )
71 {
72  if (funcPtr_.valid())
73  {
74  if (mesh.time().completeCase())
75  {
76  funcPtr_->evaluate();
77  }
78  }
79  else
80  {
81  field_ = Field<Type>(funcName_, dimensions, dict, mesh.size());
82  }
83 }
84 
85 
86 template<class Type, class GeoMesh>
88 (
89  const word& name,
90  const word& funcName,
91  const GeoMesh& mesh,
92  const dimensionSet& dimensions,
93  Field<Type>& field,
94  const dictionary& dict,
95  const Type& defaultValue
96 )
97 :
98  SlicedDimensionedField<Type, GeoMesh>
99  (
100  IOobject
101  (
102  name + '_' + funcName,
103  mesh.time().name(),
104  mesh.db(),
105  IOobject::NO_READ,
106  IOobject::NO_WRITE,
107  false
108  ),
109  mesh,
110  dimensions,
111  field
112  ),
113  field_(field),
114  funcName_(funcName),
115  funcPtr_
116  (
117  dict.isDict(funcName)
119  (
120  dict.subDict(funcName),
121  *this
122  )
124  (
125  nullptr
126  )
127  )
128 {
129  if (funcPtr_.valid())
130  {
131  if (mesh.time().completeCase())
132  {
133  funcPtr_->evaluate();
134  }
135  }
136  else if (dict.found(funcName))
137  {
138  field_ = Field<Type>(funcName_, dimensions, dict, mesh.size());
140  }
141  else
142  {
143  field_ = Field<Type>(mesh.size(), defaultValue);
145  }
146 }
147 
148 
149 template<class Type, class GeoMesh>
151 (
153  const GeoMesh& mesh,
154  Field<Type>& field
155 )
156 :
157  SlicedDimensionedField<Type, GeoMesh>
158  (
159  udff,
160  mesh,
161  udff.dimensions(),
162  field
163  ),
164  field_(field),
165  funcName_(udff.funcName_),
166  funcPtr_
167  (
168  udff.funcPtr_.valid()
169  ? udff.funcPtr_->clone(*this)
171  (
172  nullptr
173  )
174  )
175 {}
176 
177 
178 template<class Type, class GeoMesh>
180 (
182  Field<Type>& field
183 )
184 :
185  SlicedDimensionedField<Type, GeoMesh>
186  (
187  udff,
188  udff.mesh(),
189  udff.dimensions(),
190  field
191  ),
192  field_(field),
193  funcName_(udff.funcName_),
194  funcPtr_
195  (
196  udff.funcPtr_.valid()
197  ? udff.funcPtr_->clone(*this)
199  (
200  nullptr
201  )
202  )
203 {}
204 
205 
206 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
207 
208 template<class Type, class GeoMesh>
210 {
212  if (evaluate && funcPtr_.valid())
213  {
214  funcPtr_->reset();
215  }
216 }
217 
218 
219 template<class Type, class GeoMesh>
221 {
223 
224  if (funcPtr_.valid())
225  {
226  funcPtr_->reset();
227  }
228 }
229 
230 
231 template<class Type, class GeoMesh>
233 {
234  if (funcPtr_.valid())
235  {
236  return funcPtr_->update();
237  }
238  else
239  {
240  return false;
241  }
242 }
243 
244 
245 template<class Type, class GeoMesh>
247 {
248  if (funcPtr_.valid())
249  {
250  funcPtr_->write(os);
251  }
252 }
253 
254 
255 template<class Type, class GeoMesh>
257 (
258  Ostream& os,
260 )
261 {
262  if (udff.funcPtr_.valid())
263  {
264  writeEntry(os, udff.funcName_, *udff.funcPtr_);
265  }
266  else
267  {
268  writeEntry(os, udff.funcName_, udff.field_);
269  }
270 }
271 
272 
273 // ************************************************************************* //
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.
const GeoMesh & mesh() const
Return mesh.
Pre-declare SubField and related Field type.
Definition: Field.H:83
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
Specialisation of DimensionedField which holds a slice of a given complete field in such a form that ...
void reset(const Field< Type > &iField)
Reset internalField pointer.
bool completeCase() const
Return true if this is a complete serial or parallel case.
Definition: Time.H:269
Combined class containing a field reference, a dimensionedField wrapper providing the corresponding m...
UFunctionalDimensionedField(const word &name, const word &funcName, const GeoMesh &, const dimensionSet &dimensions, Field< Type > &, const dictionary &)
Construct from name, mesh, dimensions, field and dictionary.
virtual bool write(const bool write=true) const
Write using setting from DB.
void map(const bool evaluate)
Map and optionally evaluate.
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
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:468
Dimension set for the base types.
Definition: dimensionSet.H:125
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
label size() const
Return fvMesh size.
Definition: fvMesh.H:468
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)
dictionary dict