codedFunctionObject.H
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 Class
25  Foam::codedFunctionObject
26 
27 Description
28  Provides a general interface to enable dynamic code compilation.
29 
30  The entries are:
31  \plaintable
32  codeInclude | include files
33  codeOptions | include paths; inserted into EXE_INC in Make/options
34  codeLibs | link line; inserted into LIB_LIBS in Make/options
35  codeData | c++; local member data (null constructed);
36  localCode | c++; local static functions;
37  codeRead | c++; upon functionObject::read();
38  codeFields | c++; upon functionObject::fields();
39  codeExecute | c++; upon functionObject::execute();
40  codeWrite | c++; upon functionObject::write()
41  codeEnd | c++; upon functionObject::end();
42  \endplaintable
43 
44  Example of function object specification:
45  \verbatim
46  writeMagU
47  {
48  libs ("libutilityFunctionObjects.so");
49 
50  type coded;
51 
52  codeWrite
53  #{
54  // Lookup U
55  const volVectorField& U = mesh().lookupObject<volVectorField>("U");
56  // Write
57  mag(U)().write();
58  #};
59  }
60  \endverbatim
61 
62 See also
63  Foam::functionObject
64  Foam::codedBase
65 
66 SourceFiles
67  codedFunctionObject.C
68 
69 \*---------------------------------------------------------------------------*/
70 
71 #ifndef codedFunctionObject_functionObject_H
72 #define codedFunctionObject_functionObject_H
73 
74 #include "functionObject.H"
75 #include "codedBase.H"
76 
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 
79 namespace Foam
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class codedFunctionObject Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class codedFunctionObject
87 :
88  public functionObject,
89  public codedBase
90 {
91  // Private Data
92 
93  //- Keywords associated with source code
94  static const wordList codeKeys;
95 
96  //- Name of the dictionary variables in the source code
97  static const wordList codeDictVars;
98 
99  // Name of the code options template file
100  static const word codeOptions;
101 
102  // Names of the source files to compile
103  static const wordList compileFiles;
104 
105  // Names of the source files to copy (header files)
106  static const wordList copyFiles;
107 
108  //- The dynamically generated functionObject pointer
109  mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
110 
111 
112  // Private Member Functions
113 
114  //- Compile, link and load the compiled functionObject
115  void updateLibrary(const dictionary& dict);
116 
117  //- Return the compiled functionObject
118  functionObject& redirectFunctionObject() const;
119 
120 
121 public:
122 
123  //- Runtime type information
124  TypeName("coded");
125 
126 
127  // Constructors
128 
129  //- Construct from Time and dictionary
131  (
132  const word& name,
133  const Time& time,
134  const dictionary& dict
135  );
136 
137  //- Disallow default bitwise copy construction
138  codedFunctionObject(const codedFunctionObject&) = delete;
139 
140 
141  //- Destructor
142  virtual ~codedFunctionObject();
143 
144 
145  // Member Functions
146 
147  //- Return the list of fields required
148  virtual wordList fields() const;
149 
150  //- Called at each ++ or += of the time-loop.
151  // foamPostProcess overrides the usual executeControl behaviour and
152  // forces execution (used in post-processing mode)
153  virtual bool execute();
154 
155  //- Called at each ++ or += of the time-loop.
156  // foamPostProcess overrides the usual writeControl behaviour and
157  // forces writing always (used in post-processing mode)
158  virtual bool write();
159 
160  //- Called when Time::run() determines that the time-loop exits.
161  // By default it simply calls execute().
162  virtual bool end();
163 
164  //- Read and set the function object if its data have changed
165  virtual bool read(const dictionary&);
166 
167 
168  // Member Operators
169 
170  //- Disallow default bitwise assignment
171  void operator=(const codedFunctionObject&) = delete;
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 } // End namespace Foam
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #endif
182 
183 // ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
Provides a general interface to enable dynamic code compilation.
virtual ~codedFunctionObject()
Destructor.
virtual wordList fields() const
Return the list of fields required.
TypeName("coded")
Runtime type information.
void operator=(const codedFunctionObject &)=delete
Disallow default bitwise assignment.
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
functionObject(const word &name, const Time &runTime)
Construct from components.
const word & name() const
Return the name of this functionObject.
A class for handling words, derived from string.
Definition: word.H:63
const dimensionSet time
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
dictionary dict