CodedFunction1.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) 2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::Function1Types::CodedFunction1
28
29Description
30 Function1 with the code supplied by an on-the-fly compiled C++
31 expression.
32
33 The code entries:
34 \plaintable
35 codeInclude | include files
36 codeOptions | compiler line: added to EXE_INC (Make/options)
37 codeLibs | linker line: added to LIB_LIBS (Make/options)
38 localCode | c++; local static functions
39 code | c++; return the patch values at (scalar x)
40 \endplaintable
41
42Usage
43 Example:
44 \verbatim
45 <patchName>
46 {
47 type uniformFixedValue;
48 uniformValue
49 {
50 type coded;
51 name myExpression; // Name of generated PatchFunction1
52
53 code
54 #{
55 const polyPatch& pp = this->patch();
56 Pout<< "** Patch size:" << pp.size() << endl;
57 return tmp<vectorField>::New(pp.size(), vector(1, 0, 0))
58 #};
59
60 //codeInclude
61 //#{
62 // #include "volFields.H"
63 //#};
64
65 //codeOptions
66 //#{
67 // -I$(LIB_SRC)/finiteVolume/lnInclude
68 //#};
69 }
70 }
71 \endverbatim
72
73Note
74 The code context dictionary is simply the dictionary used to specify
75 the PatchFunction1 coefficients.
76
77See also
78 Foam::dynamicCode
79 Foam::codedFixedValue
80 Foam::functionEntries::codeStream
81
82SourceFiles
83 CodedFunction1.C
84
85\*---------------------------------------------------------------------------*/
86
87#ifndef Function1Types_CodedFunction1_H
88#define Function1Types_CodedFunction1_H
89
90#include "Function1.H"
91#include "codedBase.H"
92
93// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94
95namespace Foam
96{
97namespace Function1Types
98{
99
100/*---------------------------------------------------------------------------*\
101 Class CodedFunction1 Declaration
102\*---------------------------------------------------------------------------*/
103
104template<class Type>
105class CodedFunction1
106:
107 public Function1<Type>,
108 protected codedBase
109{
110 // Private Data
111
112 //- Dictionary contents for the function
113 const dictionary dict_;
114
115 const word redirectName_;
116
117 mutable autoPtr<Function1<Type>> redirectFunctionPtr_;
118
119
120 // Private Member Functions
121
122 //- Get reference to the underlying Function1
123 const Function1<Type>& redirectFunction() const;
125
126protected:
127
128 // Protected Member Functions
129
130 //- Mutable access to the loaded dynamic libraries
131 virtual dlLibraryTable& libs() const;
132
133 //- Description (type + name) for the output
134 virtual string description() const;
135
136 //- Clear redirected object(s)
137 virtual void clearRedirect() const;
138
139 //- Additional 'codeContext' dictionary to pass through
140 virtual const dictionary& codeContext() const;
141
142 // Get the code (sub)dictionary
143 virtual const dictionary& codeDict(const dictionary& dict) const;
144
145 // Get the code dictionary
146 virtual const dictionary& codeDict() const;
147
148 //- Adapt the context for the current object
149 virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
150
151
152 // Generated Methods
153
154 //- No copy assignment
155 void operator=(const CodedFunction1<Type>&) = delete;
156
157public:
158
159 // Static Data Members
160
161 //- Name of the C code template to be used
162 static constexpr const char* const codeTemplateC
163 = "codedFunction1Template.C";
164
165 //- Name of the H code template to be used
166 static constexpr const char* const codeTemplateH
167 = "codedFunction1Template.H";
168
169
170 //- Runtime type information
171 TypeName("coded");
172
173
174 // Constructors
175
176 //- Construct from entry name, dictionary and optional registry
178 (
179 const word& entryName,
180 const dictionary& dict,
181 const objectRegistry* obrPtr = nullptr
182 );
183
184 //- Copy construct
186
187 //- Construct and return a clone
188 virtual tmp<Function1<Type>> clone() const
189 {
191 }
192
193
194 //- Destructor
195 virtual ~CodedFunction1() = default;
196
197
198 // Member Functions
199
200 //- Return value at current time
201 virtual inline Type value(const scalar x) const;
202
203 // Integrate etc are not implemented!
204
205 //- Write in dictionary format
206 virtual void writeData(Ostream& os) const;
208
209
210// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211
212} // End namespace Function1Types
213} // End namespace Foam
215// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216
217#ifdef NoRepository
218 #include "CodedFunction1.C"
219#endif
220
221// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222
223#endif
224
225// ************************************************************************* //
Function1 with the code supplied by an on-the-fly compiled C++ expression.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
virtual const dictionary & codeContext() const
Additional 'codeContext' dictionary to pass through.
void operator=(const CodedFunction1< Type > &)=delete
No copy assignment.
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
virtual void writeData(Ostream &os) const
Write in dictionary format.
TypeName("coded")
Runtime type information.
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
virtual const dictionary & codeDict() const
virtual Type value(const scalar x) const
Return value at current time.
virtual ~CodedFunction1()=default
Destructor.
virtual void clearRedirect() const
Clear redirected object(s)
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
virtual string description() const
Description (type + name) for the output.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
const word const dictionary & dict
Definition: Function1.H:134
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
const word & entryName
Definition: Function1.H:133
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
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
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73