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 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 Usage
34  Example:
35  \verbatim
36  <patchName>
37  {
38  type uniformFixedValue;
39  uniformValue
40  {
41  type coded;
42  // Explictly supply name of generated PatchFunction1. Only needed
43  // if entryname ('uniformValue') would clash with existing
44  // runtime selection tables.
45  name myExpression;
46 
47  code
48  #{
49  const polyPatch& pp = this->patch();
50  Pout<< "** Patch size:" << pp.size() << endl;
51  return tmp<vectorField>::New(pp.size(), vector(1, 0, 0))
52  #};
53  }
54 
55  //codeInclude
56  //#{
57  // #include "fvCFD.H"
58  //#};
59 
60  //codeOptions
61  //#{
62  // -I$(LIB_SRC)/finiteVolume/lnInclude
63  //#};
64  }
65  \endverbatim
66 
67 See also
68  Foam::dynamicCode
69  Foam::codedFixedValue
70  Foam::functionEntries::codeStream
71 
72 SourceFiles
73  CodedField.C
74 
75 \*---------------------------------------------------------------------------*/
76 
77 #ifndef PatchFunction1Types_CodedField_H
78 #define PatchFunction1Types_CodedField_H
79 
80 #include "PatchFunction1.H"
81 #include "codedBase.H"
82 
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85 namespace Foam
86 {
87 namespace PatchFunction1Types
88 {
89 
90 /*---------------------------------------------------------------------------*\
91  Class CodedField Declaration
92 \*---------------------------------------------------------------------------*/
93 
94 template<class Type>
95 class CodedField
96 :
97  public PatchFunction1<Type>,
98  protected codedBase
99 {
100  // Private Data
101 
102  //- Dictionary contents for the function
103  const dictionary dict_;
104 
105  const word name_;
106 
107  mutable autoPtr<PatchFunction1<Type>> redirectFunctionPtr_;
108 
109 
110  // Private Member Functions
111 
112  //- Get reference to the underlying Function1
113  const PatchFunction1<Type>& redirectFunction() const;
114 
115 
116 protected:
117 
118  // Protected Member Functions
119 
120  //- Mutable access to the loaded dynamic libraries
121  virtual dlLibraryTable& libs() const;
122 
123  //- Adapt the context for the current object
124  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
125 
126  // Return a description (type + name) for the output
127  virtual string description() const;
128 
129  // Clear the ptr to the redirected object
130  virtual void clearRedirect() const;
131 
132  // Get the (sub)dictionary to initialize the codeContext
133  virtual const dictionary& codeDict(const dictionary& fullDict) const;
134 
135  // Get the dictionary to initialize the codeContext
136  virtual const dictionary& codeDict() const;
137 
138 public:
139 
140  // Static Data Members
141 
142  //- Name of the C code template to be used
143  static constexpr const char* const codeTemplateC
144  = "codedPatchFunction1Template.C";
145 
146  //- Name of the H code template to be used
147  static constexpr const char* const codeTemplateH
148  = "codedPatchFunction1Template.H";
149 
150 
151  //- Runtime type information
152  TypeName("coded");
153 
154 
155  // Generated Methods
156 
157  //- No copy assignment
158  void operator=(const CodedField<Type>&) = delete;
159 
160 
161  // Constructors
162 
163  //- Construct from entry name and dictionary
164  CodedField
165  (
166  const polyPatch& pp,
167  const word& redirectType,
168  const word& entryName,
169  const dictionary& dict,
170  const bool faceValues = true
171  );
172 
173  //- Copy construct
174  explicit CodedField(const CodedField<Type>& rhs);
175 
176  //- Copy construct, setting patch
177  explicit CodedField
178  (
179  const CodedField<Type>& rhs,
180  const polyPatch& pp
181  );
182 
183  //- Construct and return a clone
184  virtual tmp<PatchFunction1<Type>> clone() const
185  {
187  (
188  new CodedField<Type>(*this)
189  );
190  }
191 
192  //- Construct and return a clone setting patch
193  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
194  {
196  (
197  new CodedField<Type>(*this, pp)
198  );
199  }
200 
201 
202  //- Destructor
203  virtual ~CodedField() = default;
204 
205 
206  // Member Functions
207 
208  // Evaluation
209 
210  //- Return CodedField value
211  virtual tmp<Field<Type>> value(const scalar x) const;
212 
213  //- Is value constant (i.e. independent of x)
214  virtual inline bool constant() const
215  {
216  return false;
217  }
218 
219  //- Is value uniform (i.e. independent of coordinate)
220  virtual inline bool uniform() const
221  {
222  return false;
223  }
224 
225  //- Integrate between two values
226  virtual tmp<Field<Type>> integrate
227  (
228  const scalar x1,
229  const scalar x2
230  ) const;
231 
232 
233  // Mapping
234 
235  //- Map (and resize as needed) from self given a mapping object
236  virtual void autoMap(const FieldMapper& mapper);
237 
238  //- Reverse map the given PatchFunction1 onto this PatchFunction1
239  virtual void rmap
240  (
241  const PatchFunction1<Type>& pf1,
242  const labelList& addr
243  );
244 
245 
246  // I-O
247 
248  //- Write in dictionary format
249  virtual void writeData(Ostream& os) const;
250 };
251 
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 } // End namespace PatchFunction1Types
256 } // End namespace Foam
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 #ifdef NoRepository
261  #include "CodedField.C"
262 #endif
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 #endif
267 
268 // ************************************************************************* //
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:62
Foam::PatchFunction1Types::CodedField::constant
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: CodedField.H:213
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:34
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:255
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:67
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:241
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:136
Foam::PatchFunction1Types::CodedField::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: CodedField.H:219
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:117
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:192
Foam::PatchFunction1Types::CodedField::value
virtual tmp< Field< Type > > value(const scalar x) const
Return CodedField value.
Definition: CodedField.C:213
Foam::PatchFunction1Types::CodedField::clone
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: CodedField.H:183
Foam::PatchFunction1Types::CodedField::codeTemplateC
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
Definition: CodedField.H:143
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:42
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:59
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:227
Foam::PatchFunction1Types::CodedField::codeTemplateH
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
Definition: CodedField.H:147
Foam::PatchFunction1Types::CodedField::~CodedField
virtual ~CodedField()=default
Destructor.
Foam::PatchFunction1Types::CodedField::codeDict
virtual const dictionary & codeDict() const
Definition: CodedField.C:110
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:115
Foam::PatchFunction1Types::CodedField::clearRedirect
virtual void clearRedirect() const
Definition: CodedField.C:125
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:118
Foam::List< label >
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:120
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::PatchFunction1Types::CodedField::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: CodedField.C:270
codedBase.H
Foam::PatchFunction1Types::CodedField::TypeName
TypeName("coded")
Runtime type information.
Foam::PatchFunction1Types::CodedField::operator=
void operator=(const CodedField< Type > &)=delete
No copy assignment.
Foam::PatchFunction1Types::CodedField::description
virtual string description() const
Definition: CodedField.C:118
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:94