codedFunctionObject.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) 2011-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 
26 #include "codedFunctionObject.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "Time.H"
30 #include "stringOps.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
38 
40  (
44  );
45 }
46 
47 
48 const Foam::wordList Foam::codedFunctionObject::codeKeys
49 {
50  "codeData",
51  "codeEnd",
52  "codeExecute",
53  "codeInclude",
54  "codeRead",
55  "codeFields",
56  "codeWrite",
57  "localCode"
58 };
59 
60 const Foam::wordList Foam::codedFunctionObject::codeDictVars
61 {
62  word::null,
63  word::null,
64  word::null,
65  word::null,
66  "dict",
67  word::null,
68  word::null,
69  word::null,
70 };
71 
72 const Foam::word Foam::codedFunctionObject::codeOptions
73 (
74  "codedFunctionObjectOptions"
75 );
76 
77 const Foam::wordList Foam::codedFunctionObject::compileFiles
78 {
79  "codedFunctionObjectTemplate.C"
80 };
81 
82 const Foam::wordList Foam::codedFunctionObject::copyFiles
83 {
84  "codedFunctionObjectTemplate.H"
85 };
86 
87 
88 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
89 
90 void Foam::codedFunctionObject::updateLibrary(const dictionary& dict)
91 {
92  redirectFunctionObjectPtr_.clear();
93 
95 
96  dictionary constructDict(dict);
97  constructDict.set("type", codeName());
98 
99  redirectFunctionObjectPtr_ = functionObject::New
100  (
101  codeName(),
102  time_,
103  constructDict
104  );
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109 
111 (
112  const word& name,
113  const Time& time,
114  const dictionary& dict
115 )
116 :
118  codedBase
119  (
120  name,
121  dict,
122  codeKeys,
123  codeDictVars,
124  codeOptions,
125  compileFiles,
126  copyFiles
127  )
128 {
129  // Set verbose if debugging
130  varSubstitutions().set("verbose", Foam::name(bool(debug)));
131 
132  updateLibrary(dict);
133 }
134 
135 
136 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
137 
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
144 Foam::functionObject& Foam::codedFunctionObject::redirectFunctionObject() const
145 {
146  if (!redirectFunctionObjectPtr_.valid())
147  {
149  << "redirectFunctionObject not allocated" << exit(FatalError);
150  }
151 
152  return redirectFunctionObjectPtr_();
153 }
154 
155 
157 {
158  return redirectFunctionObject().fields();
159 }
160 
161 
163 {
164  return redirectFunctionObject().execute();
165 }
166 
167 
169 {
170  return redirectFunctionObject().write();
171 }
172 
173 
175 {
176  return redirectFunctionObject().end();
177 }
178 
179 
181 {
183  {
185  updateLibrary(dict);
186  return true;
187  }
188  else
189  {
190  return false;
191  }
192 }
193 
194 
195 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:230
Provides a general interface to enable dynamic code compilation.
virtual ~codedFunctionObject()
Destructor.
virtual wordList fields() const
Return the list of fields required.
codedFunctionObject(const word &name, const Time &time, const dictionary &dict)
Construct from Time and dictionary.
virtual bool execute()
Called at each ++ or += of the time-loop.
virtual bool write()
Called at each ++ or += of the time-loop.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & codeName() const
Return the code-name.
Definition: dynamicCode.H:226
HashTable< string > & varSubstitutions()
Definition: dynamicCode.H:252
void read(const dictionary &contextDict, const dictionary &codeDict)
Definition: dynamicCode.C:386
Abstract base-class for Time/database functionObjects.
const Time & time_
Reference to time.
static autoPtr< functionObject > New(const word &name, const Time &, const dictionary &)
Select from dictionary, based on its "type" entry.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const dimensionSet time
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict