Coded_DimensionedFieldFunction.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 #include "DimensionedField.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  {"evaluate", "update", "codeInclude"}
35 );
36 
37 template<class Type>
39 (
40  {word::null, word::null, word::null}
41 );
42 
43 template<class Type>
45 (
46  "codedDimensionedFieldFunctionOptions"
47 );
48 
49 template<class Type>
51 {
52  "codedDimensionedFieldFunctionTemplate.C"
53 };
54 
55 template<class Type>
57 {
58  "codedDimensionedFieldFunctionTemplate.H"
59 };
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 template<class DimensionedFieldType>
66 Coded
67 (
68  const dictionary& dict,
69  DimensionedFieldType& field
70 )
71 :
72  DimensionedFieldFunction<DimensionedFieldType>(dict, field),
73  codedBase
74  (
75  dict.lookupOrDefault<word>
76  (
77  "name",
78  (
79  field.mesh().db().name() == polyMesh::defaultRegion
80  ? word::null
81  : word(field.mesh().db().name() + '_')
82  )
83  + field.name()
84  + (
85  field.mesh().name() == field.mesh().db().name()
86  ? word::null
87  : word('_' + field.mesh().name())
88  )
89  ),
90  dict,
91  codeKeys,
92  codeDictVars,
93  codeOptions,
94  compileFiles,
95  copyFiles
96  )
97 {
98  // Set variable substitutions
99  varSubstitutions().set
100  (
101  {
102  {"DimensionedFieldType", DimensionedFieldType::typeName},
103  {
104  "DimensionedFieldTypeName",
106  },
107  {"verbose", Foam::name(bool(debug))}
108  }
109  );
110 
111  this->updateLibrary(dict);
112 }
113 
114 
115 template<class DimensionedFieldType>
117 Coded
118 (
119  const Coded& dff,
120  DimensionedFieldType& field
121 )
122 :
123  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
124  codedBase(dff)
125 {}
126 
127 
128 template<class DimensionedFieldType>
131 (
132  DimensionedFieldType& field
133 ) const
134 {
136  (
137  new Coded<DimensionedFieldType>(*this, field)
138  );
139 }
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
144 template<class DimensionedFieldType>
146 evaluate()
147 {
148  if (!redirectFunctionPtr_.valid())
149  {
150  dictionary redirectDict;
151  redirectDict.set("type", codeName());
152 
153  redirectFunctionPtr_ =
155  (
156  redirectDict,
157  this->field_
158  );
159  }
160 
161  redirectFunctionPtr_->evaluate();
162 }
163 
164 
165 template<class DimensionedFieldType>
167 update()
168 {
169  if (!redirectFunctionPtr_.valid())
170  {
171  dictionary redirectDict;
172  redirectDict.set("type", codeName());
173 
174  redirectFunctionPtr_ =
176  (
177  redirectDict,
178  this->field_
179  );
180  }
181 
182  return redirectFunctionPtr_->update();
183 }
184 
185 
186 template<class DimensionedFieldType>
188 (
189  Ostream& os
190 ) const
191 {
192  codedBase::write(os);
193 }
194 
195 
196 // ************************************************************************* //
Base class for run-time selectable internal and patch field initialisation evaluation and update with...
virtual autoPtr< DimensionedFieldFunction< DimensionedFieldType > > clone() const
Construct and return a clone for the specified field.
static autoPtr< DimensionedFieldFunction< DimensionedFieldType > > New(const dictionary &dict, DimensionedFieldType &field)
Select null constructed.
Coded internal and patch field initialisation, evaluation and update with dimension checking.
virtual void evaluate()
Evaluate the function and set the field.
virtual void write(Ostream &os) const
Write data to dictionary stream.
Coded(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
virtual bool update()
Update the field if the function has changed and return true.
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
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
static word codedName(const word &name)
Create a coded name from the given name.
Definition: codedBase.C:202
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:230
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
HashTable< string > & varSubstitutions()
Definition: dynamicCode.H:252
void write(Ostream &os) const
Write the code for restart.
Definition: dynamicCode.C:744
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
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)
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict