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
36 The entries are:
37 \plaintable
38 codeInclude | include files
39 codeOptions | compiler line: added to EXE_INC (Make/options)
40 codeLibs | linker line: added to LIB_LIBS (Make/options)
41 codeData | c++; local member data (default constructed)
42 localCode | c++; local static functions
43 codeRead | c++; upon functionObject::read()
44 codeExecute | c++; upon functionObject::execute()
45 codeWrite | c++; upon functionObject::write()
46 codeEnd | c++; upon functionObject::end()
47 codeContext | additional dictionary context for the code
48 \endplaintable
49
50Usage
51 Example of function object specification:
52 \verbatim
53 difference
54 {
55 type coded;
56 libs (utilityFunctionObjects);
57
58 // Name of on-the-fly generated functionObject
59 name writeMagU;
60 codeWrite
61 #{
62 // Lookup U
63 const volVectorField& U = mesh().lookupObject<volVectorField>("U");
64
65 // Write
66 mag(U)().write();
67 #};
68 }
69 \endverbatim
70
71Note
72 The code context dictionary can be supplied separately as the
73 \c codeContext entry.
74
75See also
76 Foam::functionObject
77 Foam::codedBase
78
79SourceFiles
80 codedFunctionObject.C
81
82\*---------------------------------------------------------------------------*/
83
84#ifndef functionObjects_codedFunctionObject_H
85#define functionObjects_codedFunctionObject_H
86
87#include "timeFunctionObject.H"
88#include "codedBase.H"
89
90// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91
92namespace Foam
93{
94namespace functionObjects
95{
96
97/*---------------------------------------------------------------------------*\
98 Class codedFunctionObject Declaration
99\*---------------------------------------------------------------------------*/
100
101class codedFunctionObject
102:
103 public functionObjects::timeFunctionObject,
104 public codedBase
105{
106protected:
107
108 // Protected Data
109
110 //- Input dictionary
111 dictionary dict_;
112
113 word name_;
114
115 string codeData_;
116 string codeRead_;
117 string codeExecute_;
118 string codeWrite_;
119 string codeEnd_;
120
121 //- Underlying functionObject
122 mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
123
124
125 // Protected Member Functions
126
127 //- Mutable access to the loaded dynamic libraries
128 virtual dlLibraryTable& libs() const;
129
130 //- Description (type + name) for the output
131 virtual string description() const;
132
133 //- Clear redirected object(s)
134 virtual void clearRedirect() const;
135
136 //- Additional 'codeContext' dictionary to pass through
137 virtual const dictionary& codeContext() const;
138
139 //- The code dictionary
140 virtual const dictionary& codeDict() const;
141
142 //- Adapt the context for the current object
143 virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
144
145
146 //- No copy construct
148
149 //- No copy assignment
150 void operator=(const codedFunctionObject&) = delete;
151
153public:
155 // Static Data Members
157 //- Name of the C code template to be used
158 static constexpr const char* const codeTemplateC
159 = "functionObjectTemplate.C";
160
161 //- Name of the H code template to be used
162 static constexpr const char* const codeTemplateH
163 = "functionObjectTemplate.H";
164
165
166 //- Runtime type information
167 TypeName("coded");
168
169
170 // Constructors
171
172 //- Construct from Time and dictionary
174 (
175 const word& name,
176 const Time& runTime,
177 const dictionary& dict
178 );
179
180
181 //- Destructor
182 virtual ~codedFunctionObject() = default;
183
184
185 // Member Functions
187 //- Dynamically compiled functionObject
190 //- Called at each ++ or += of the time-loop.
191 // postProcess overrides the usual executeControl behaviour and
192 // forces execution (used in post-processing mode)
193 virtual bool execute();
194
195 //- Called at each ++ or += of the time-loop.
196 // postProcess overrides the usual writeControl behaviour and
197 // forces writing always (used in post-processing mode)
198 virtual bool write();
199
200 //- Called when Time::run() determines that the time-loop exits.
201 // By default it simply calls execute().
202 virtual bool end();
203
204 //- Read and set the function object if its data have changed
205 virtual bool read(const dictionary&);
207
208
209// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210
211} // End namespace functionObjects
212} // End namespace Foam
213
214// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215
216#endif
217
218// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:67
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A table of dynamically loaded libraries.
Encapsulation of dynamic code dictionaries.
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:60
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
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:68
engineTime & runTime
Namespace for OpenFOAM.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73