Loading...
Searching...
No Matches
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-2024 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;
124
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,
179 const word& entryName,
180 const dictionary& dict,
181 const bool faceValues = true
182 );
183
184 //- Copy construct, setting patch
185 explicit CodedField
186 (
187 const CodedField<Type>& rhs,
188 const polyPatch& pp
189 );
190
191 //- Copy construct
192 explicit CodedField(const CodedField<Type>& rhs);
194 //- Return a clone
195 virtual tmp<PatchFunction1<Type>> clone() const
196 {
197 return PatchFunction1<Type>::Clone(*this);
198 }
200 //- Return a clone, setting the patch
201 virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
202 {
203 return PatchFunction1<Type>::Clone(*this, pp);
204 }
205
207 //- Destructor
208 virtual ~CodedField() = default;
209
210
211 // Member Functions
212
213 //- Is value uniform (i.e. independent of coordinate)
214 virtual inline bool uniform() const { return false; }
215
216
217 // Evaluation
218
219 //- Return CodedField value
220 virtual tmp<Field<Type>> value(const scalar x) const;
221
222 //- Integrate between two values
224 (
225 const scalar x1,
226 const scalar x2
227 ) const;
228
229
230 // Mapping
231
232 //- Map (and resize as needed) from self given a mapping object
233 virtual void autoMap(const FieldMapper& mapper);
234
235 //- Reverse map the given PatchFunction1 onto this PatchFunction1
236 virtual void rmap
237 (
238 const PatchFunction1<Type>& pf1,
239 const labelList& addr
240 );
241
242
243 // I-O
244
245 //- Write in dictionary format
246 virtual void writeData(Ostream& os) const;
247};
249
250// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251
252} // End namespace PatchFunction1Types
253} // End namespace Foam
254
255// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256
257#ifdef NoRepository
258 #include "CodedField.C"
259#endif
260
261// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262
263#endif
264
265// ************************************************************************* //
Abstract base class to hold the Field mapping addressing and weights.
Definition FieldMapper.H:44
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
PatchFunction1 with the code supplied by an on-the-fly compiled C++ expression.
Definition CodedField.H:124
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition CodedField.C:248
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate).
Definition CodedField.H:265
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition CodedField.C:276
virtual const dictionary & codeContext() const
Additional 'codeContext' dictionary to pass through.
Definition CodedField.C:52
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition CodedField.C:88
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition CodedField.C:262
CodedField(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from entry name and dictionary.
Definition CodedField.C:140
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition CodedField.C:291
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Return a clone, setting the patch.
Definition CodedField.H:248
virtual tmp< Field< Type > > value(const scalar x) const
Return CodedField value.
Definition CodedField.C:234
TypeName("coded")
Runtime type information.
virtual tmp< PatchFunction1< Type > > clone() const
Return a clone.
Definition CodedField.H:240
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
Definition CodedField.H:194
void operator=(const CodedField< Type > &)=delete
No copy assignment.
virtual ~CodedField()=default
Destructor.
virtual const dictionary & codeDict() const
Definition CodedField.C:80
virtual void clearRedirect() const
Clear redirected object(s).
Definition CodedField.C:44
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
Definition CodedField.H:200
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition CodedField.C:29
virtual string description() const
Description (type + name) for the output.
Definition CodedField.C:37
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
static tmp< PatchFunction1< Type > > Clone(const Derived &fun)
Clone a PatchFunction1.
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:65
codedBase(const codedBase &)=delete
No copy construct.
A table of dynamically loaded libraries.
Encapsulation of dynamic code dictionaries.
Tools for handling dynamic code compilation.
Definition dynamicCode.H:57
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68