CodedField.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) 2020-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::PatchFunction1Types::CodedField
28
29Description
30 PatchFunction1 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 CodedField.C
84
85\*---------------------------------------------------------------------------*/
86
87#ifndef PatchFunction1Types_CodedField_H
88#define PatchFunction1Types_CodedField_H
89
90#include "PatchFunction1.H"
91#include "codedBase.H"
92
93// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94
95namespace Foam
96{
97namespace PatchFunction1Types
98{
99
100/*---------------------------------------------------------------------------*\
101 Class CodedField Declaration
102\*---------------------------------------------------------------------------*/
103
104template<class Type>
105class CodedField
106:
107 public PatchFunction1<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<PatchFunction1<Type>> redirectFunctionPtr_;
118
119
120 // Private Member Functions
121
122 //- Get reference to the underlying Function1
123 const PatchFunction1<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 //- No copy assignment
153 void operator=(const CodedField<Type>&) = delete;
154
155public:
156
157 // Static Data Members
158
159 //- Name of the C code template to be used
160 static constexpr const char* const codeTemplateC
161 = "codedPatchFunction1Template.C";
162
163 //- Name of the H code template to be used
164 static constexpr const char* const codeTemplateH
165 = "codedPatchFunction1Template.H";
166
167
168 //- Runtime type information
169 TypeName("coded");
170
171
172 // Constructors
173
174 //- Construct from entry name and dictionary
176 (
177 const polyPatch& pp,
178 const word& redirectType,
180 const dictionary& dict,
181 const bool faceValues = true
182 );
184 //- Copy construct
185 explicit CodedField(const CodedField<Type>& rhs);
186
187 //- Copy construct, setting patch
188 explicit CodedField
189 (
190 const CodedField<Type>& rhs,
191 const polyPatch& pp
192 );
193
194 //- Construct and return a clone
195 virtual tmp<PatchFunction1<Type>> clone() const
196 {
198 (
199 new CodedField<Type>(*this)
200 );
201 }
202
203 //- Construct and return a clone setting patch
204 virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
205 {
207 (
208 new CodedField<Type>(*this, pp)
209 );
210 }
211
212
213 //- Destructor
214 virtual ~CodedField() = default;
215
216
217 // Member Functions
218
219 //- Is value uniform (i.e. independent of coordinate)
220 virtual inline bool uniform() const { return false; }
221
222
223 // Evaluation
224
225 //- Return CodedField value
226 virtual tmp<Field<Type>> value(const scalar x) const;
227
228 //- Integrate between two values
230 (
231 const scalar x1,
232 const scalar x2
233 ) const;
234
235
236 // Mapping
237
238 //- Map (and resize as needed) from self given a mapping object
239 virtual void autoMap(const FieldMapper& mapper);
240
241 //- Reverse map the given PatchFunction1 onto this PatchFunction1
242 virtual void rmap
243 (
244 const PatchFunction1<Type>& pf1,
245 const labelList& addr
246 );
247
248
249 // I-O
250
251 //- Write in dictionary format
252 virtual void writeData(Ostream& os) const;
253};
254
255
256// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257
258} // End namespace PatchFunction1Types
259} // End namespace Foam
260
261// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262
263#ifdef NoRepository
264 #include "CodedField.C"
265#endif
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269#endif
270
271// ************************************************************************* //
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:50
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
PatchFunction1 with the code supplied by an on-the-fly compiled C++ expression.
Definition: CodedField.H:128
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: CodedField.C:255
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: CodedField.H:239
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: CodedField.C:283
virtual const dictionary & codeContext() const
Additional 'codeContext' dictionary to pass through.
Definition: CodedField.C:59
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedField.C:95
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: CodedField.C:269
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: CodedField.C:298
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: CodedField.H:223
virtual tmp< Field< Type > > value(const scalar x) const
Return CodedField value.
Definition: CodedField.C:241
TypeName("coded")
Runtime type information.
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: CodedField.H:214
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
Definition: CodedField.H:180
void operator=(const CodedField< Type > &)=delete
No copy assignment.
virtual ~CodedField()=default
Destructor.
virtual const dictionary & codeDict() const
Definition: CodedField.C:87
virtual void clearRedirect() const
Clear redirected object(s)
Definition: CodedField.C:51
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
Definition: CodedField.H:184
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: CodedField.C:36
virtual string description() const
Description (type + name) for the output.
Definition: CodedField.C:44
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const polyPatch const word const word & entryName
const polyPatch const word const word const dictionary & dict
const polyPatch & pp
const polyPatch const word const word const dictionary const bool faceValues
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
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
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