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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::PatchFunction1Types::CodedField
28 
29 Description
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 
42 Usage
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 
73 Note
74  The code context dictionary is simply the dictionary used to specify
75  the PatchFunction1 coefficients.
76 
77 See also
78  Foam::dynamicCode
79  Foam::codedFixedValue
80  Foam::functionEntries::codeStream
81 
82 SourceFiles
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 
95 namespace Foam
96 {
97 namespace PatchFunction1Types
98 {
99 
100 /*---------------------------------------------------------------------------*\
101  Class CodedField Declaration
102 \*---------------------------------------------------------------------------*/
103 
104 template<class Type>
105 class 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 
126 protected:
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 
155 public:
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
175  CodedField
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
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
229  virtual tmp<Field<Type>> integrate
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 // ************************************************************************* //
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::PatchFunction1Types::CodedField::libs
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: CodedField.C:36
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:53
PatchFunction1.H
Foam::PatchFunction1Types::CodedField::rmap
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: CodedField.C:283
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:66
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:49
Foam::PatchFunction1Types::CodedField::autoMap
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: CodedField.C:269
Foam::PatchFunction1Types::CodedField::CodedField
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:147
Foam::PatchFunction1Types::CodedField::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: CodedField.H:239
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:118
CodedField.C
Foam::PatchFunction1Types::CodedField::clone
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: CodedField.H:223
Foam::PatchFunction1Types::CodedField::value
virtual tmp< Field< Type > > value(const scalar x) const
Return CodedField value.
Definition: CodedField.C:241
Foam::PatchFunction1Types::CodedField::clone
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: CodedField.H:214
Foam::PatchFunction1Types::CodedField::codeTemplateC
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
Definition: CodedField.H:180
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::PatchFunction1Types::CodedField::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: CodedField.C:95
Foam::PatchFunction1Types::CodedField::codeContext
virtual const dictionary & codeContext() const
Additional 'codeContext' dictionary to pass through.
Definition: CodedField.C:59
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:60
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PatchFunction1Types::CodedField::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: CodedField.C:255
Foam::PatchFunction1Types::CodedField::codeTemplateH
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
Definition: CodedField.H:184
Foam::PatchFunction1Types::CodedField::~CodedField
virtual ~CodedField()=default
Destructor.
Foam::PatchFunction1Types::CodedField::codeDict
virtual const dictionary & codeDict() const
Definition: CodedField.C:87
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::PatchFunction1::pp
const polyPatch & pp
Definition: PatchFunction1.H:116
Foam::PatchFunction1Types::CodedField::clearRedirect
virtual void clearRedirect() const
Clear redirected object(s)
Definition: CodedField.C:51
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:119
Foam::List< label >
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:121
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::PatchFunction1Types::CodedField::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: CodedField.C:298
codedBase.H
Foam::PatchFunction1Types::CodedField::TypeName
TypeName("coded")
Runtime type information.
Foam::PatchFunction1::dictionary
dictionary
Definition: PatchFunction1.H:114
Foam::PatchFunction1Types::CodedField::operator=
void operator=(const CodedField< Type > &)=delete
No copy assignment.
Foam::PatchFunction1Types::CodedField::description
virtual string description() const
Description (type + name) for the output.
Definition: CodedField.C:44
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::PatchFunction1Types::CodedField
PatchFunction1 with the code supplied by an on-the-fly compiled C++ expression.
Definition: CodedField.H:124