Loading...
Searching...
No Matches
codedFunctionObject.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2019-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::functionObjects::codedFunctionObject
29
30Group
31 grpUtilitiesFunctionObjects
32
33Description
34 Provides a general interface to enable dynamic code compilation.
35
36Usage
37 Minimal example by using \c system/controlDict.functions:
38 \verbatim
39 difference
40 {
41 // Mandatory entries
42 type coded;
43 libs (utilityFunctionObjects);
44
45 // Name of on-the-fly generated functionObject
46 name <word>; // writeMagU;
47 codeWrite
48 #{
49 // Lookup U
50 const volVectorField& U = mesh().lookupObject<volVectorField>("U");
51
52 // Write
53 mag(U)().write();
54 #};
55 ...
56
57 // Inherited entries
58 ...
59 }
60 \endverbatim
61
62 where the entries mean:
63 \table
64 Property | Description | Type | Reqd | Deflt
65 type | Type name: coded | word | yes | -
66 libs | Library name: utilityFunctionObjects | word | yes | -
67 name | Name of the function object | word | yes | -
68 codeInclude | include files | word | no | -
69 codeOptions | compiler line: added to EXE_INC (Make/options) | word | no | -
70 codeLibs | linker line: added to LIB_LIBS (Make/options) | word | no | -
71 codeData | c++; local member data (default constructed) | word | no | -
72 localCode | c++; local static functions | word | no | -
73 codeRead | c++; upon functionObject::read() | word | no | -
74 codeExecute | c++; upon functionObject::execute() | word | no | -
75 codeWrite | c++; upon functionObject::write() | word | no | -
76 codeEnd | c++; upon functionObject::end() | word | no | -
77 codeContext | additional dictionary context for the code | word | no | -
78 \endtable
79
80 The inherited entries are elaborated in:
81 - \link timeFunctionObject.H \endlink
82 - \link codedBase.H \endlink
83Note
84 The code context dictionary can be supplied separately as the
85 \c codeContext entry.
86
87SourceFiles
88 codedFunctionObject.C
89
90\*---------------------------------------------------------------------------*/
91
92#ifndef Foam_functionObjects_codedFunctionObject_H
93#define Foam_functionObjects_codedFunctionObject_H
94
95#include "timeFunctionObject.H"
96#include "codedBase.H"
97
98// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99
100namespace Foam
101{
102namespace functionObjects
103{
104
105/*---------------------------------------------------------------------------*\
106 Class codedFunctionObject Declaration
107\*---------------------------------------------------------------------------*/
108
110:
111 public functionObjects::timeFunctionObject,
112 public codedBase
113{
114protected:
115
116 // Protected Data
117
118 //- Input dictionary
120
121 word name_;
122
123 string codeData_;
124 string codeRead_;
125 string codeExecute_;
126 string codeWrite_;
127 string codeEnd_;
128
129 //- Underlying functionObject
130 mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
131
132
133 // Protected Member Functions
134
135 //- Mutable access to the loaded dynamic libraries
136 virtual dlLibraryTable& libs() const;
137
138 //- Description (type + name) for the output
139 virtual string description() const;
140
141 //- Clear redirected object(s)
142 virtual void clearRedirect() const;
143
144 //- Additional 'codeContext' dictionary to pass through
145 virtual const dictionary& codeContext() const;
146
147 //- The code dictionary
148 virtual const dictionary& codeDict() const;
149
150 //- Adapt the context for the current object
151 virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
152
153
154 //- No copy construct
156
157 //- No copy assignment
158 void operator=(const codedFunctionObject&) = delete;
159
160
161public:
162
163 // Static Data Members
164
165 //- Name of the C code template to be used
166 static constexpr const char* const codeTemplateC
167 = "functionObjectTemplate.C";
168
169 //- Name of the H code template to be used
170 static constexpr const char* const codeTemplateH
171 = "functionObjectTemplate.H";
172
173
174 //- Runtime type information
175 TypeName("coded");
176
177
178 // Constructors
179
180 //- Construct from name, Time and dictionary
182 (
183 const word& name,
184 const Time& runTime,
185 const dictionary& dict
186 );
187
189 //- Destructor
190 virtual ~codedFunctionObject() = default;
191
192
193 // Member Functions
194
195 //- Dynamically compiled functionObject
197
198 //- Called at each ++ or += of the time-loop.
199 // postProcess overrides the usual executeControl behaviour and
200 // forces execution (used in post-processing mode)
201 virtual bool execute();
203 //- Called at each ++ or += of the time-loop.
204 // postProcess overrides the usual writeControl behaviour and
205 // forces writing always (used in post-processing mode)
206 virtual bool write();
208 //- Called when Time::run() determines that the time-loop exits.
209 // By default it simply calls execute().
210 virtual bool end();
211
212 //- Read and set the function object if its data have changed
213 virtual bool read(const dictionary&);
214};
215
216
217// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218
219} // End namespace functionObjects
220} // End namespace Foam
221
222// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223
224#endif
225
226// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
codedBase(const codedBase &)=delete
No copy construct.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A table of dynamically loaded libraries.
Encapsulation of dynamic code dictionaries.
Tools for handling dynamic code compilation.
Definition dynamicCode.H:57
const word & name() const noexcept
Return the name of this functionObject.
functionObject(const word &name, const bool withNamePrefix=defaultUseNamePrefix)
Construct from components.
Provides a general interface to enable dynamic code compilation.
virtual const dictionary & codeContext() const
Additional 'codeContext' dictionary to pass through.
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
autoPtr< functionObject > redirectFunctionObjectPtr_
Underlying functionObject.
functionObject & redirectFunctionObject() const
Dynamically compiled functionObject.
TypeName("coded")
Runtime type information.
void operator=(const codedFunctionObject &)=delete
No copy assignment.
virtual ~codedFunctionObject()=default
Destructor.
codedFunctionObject(const codedFunctionObject &)=delete
No copy construct.
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
virtual const dictionary & codeDict() const
The code dictionary.
virtual void clearRedirect() const
Clear redirected object(s).
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
virtual bool execute()
Called at each ++ or += of the time-loop.
virtual bool write()
Called at each ++ or += of the time-loop.
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
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.
virtual string description() const
Description (type + name) for the output.
Virtual base class for function objects with a reference to Time.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68