PatchFunction1.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) 2018-2022 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::PatchFunction1
28 
29 Description
30  Top level data entry class for use in dictionaries. Provides a mechanism
31  to specify a variable as a certain type, e.g. constant or time varying, and
32  provide functions to return the (interpolated) value, and integral between
33  limits.
34 
35  Extends the Function1 class by adding autoMap and rMap functions
36 
37 SourceFiles
38  PatchFunction1.C
39  PatchFunction1New.C
40 
41 SeeAlso
42  Foam::Function1
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef Foam_PatchFunction1_H
47 #define Foam_PatchFunction1_H
48 
49 #include "patchFunction1Base.H"
50 #include "coordinateScaling.H"
51 #include "Field.H"
52 #include "HashPtrTable.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward Declarations
60 class Time;
61 template<class Type> class PatchFunction1;
62 
63 template<class Type>
64 Ostream& operator<<(Ostream&, const PatchFunction1<Type>&);
65 
66 /*---------------------------------------------------------------------------*\
67  Class PatchFunction1 Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template<class Type>
71 class PatchFunction1
72 :
73  public patchFunction1Base
74 {
75  // Private Member Functions
76 
77  //- Selector, with alternative entry etc
79  (
80  const polyPatch& pp,
81  const word& entryName,
82  const entry* eptr,
83  const dictionary& dict,
84  const bool faceValues,
85  const bool mandatory
86  );
87 
88 
89 protected:
90 
91  // Protected Data
92 
93  //- Optional local coordinate system and scaling
95 
96 
97  // Protected Member Functions
98 
99  //- No copy assignment
100  void operator=(const PatchFunction1<Type>&) = delete;
101 
102 
103 public:
104 
105  // Data Types
106 
107  //- The return type is a field of values
108  typedef Field<Type> returnType;
109 
110 
111  //- Runtime type information
112  TypeName("PatchFunction1")
113 
114  //- Declare runtime constructor selection table
116  (
117  autoPtr,
119  dictionary,
120  (
121  const polyPatch& pp,
122  const word& type,
123  const word& entryName,
124  const dictionary& dict,
125  const bool faceValues
126  ),
128  );
129 
130 
131  // Constructors
132 
133  //- Construct from polyPatch and entry name
135  (
136  const polyPatch& pp,
137  const word& entryName,
138  const bool faceValues = true
139  );
140 
141  //- Construct from polyPatch, dictionary and entry name
143  (
144  const polyPatch& pp,
145  const word& entryName,
146  const dictionary& dict,
147  const bool faceValues = true
148  );
149 
150  //- Copy construct
151  explicit PatchFunction1(const PatchFunction1<Type>& rhs);
152 
153  //- Copy construct setting patch
154  explicit PatchFunction1
155  (
156  const PatchFunction1<Type>& rhs,
157  const polyPatch& pp
158  );
159 
160  //- Return a clone
161  virtual tmp<PatchFunction1<Type>> clone() const = 0;
162 
163  //- Return a clone, setting patch
164  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const = 0;
165 
166 
167  // Selectors
168 
169  //- Selector
170  static autoPtr<PatchFunction1<Type>> New
171  (
172  const polyPatch& pp,
173  const word& entryName,
174  const dictionary& dict,
175  const bool faceValues = true,
176  const bool mandatory = true
177  );
178 
179  //- Compatibility selector
180  static autoPtr<PatchFunction1<Type>> NewCompat
181  (
182  const polyPatch& pp,
183  const word& entryName,
184  std::initializer_list<std::pair<const char*,int>> compat,
185  const dictionary& dict,
186  const bool faceValues = true,
187  const bool mandatory = true
188  );
189 
190  //- An optional selector
191  static autoPtr<PatchFunction1<Type>> NewIfPresent
192  (
193  const polyPatch& pp,
194  const word& entryName,
195  const dictionary& dict,
196  const bool faceValues = true
197  );
198 
199 
200  // Caching Selectors - accept wildcards in dictionary
201 
202  //- Selector with external storage.
203  //- This also allows wildcard matches in a dictionary
204  static refPtr<PatchFunction1<Type>> New
205  (
206  HashPtrTable<PatchFunction1<Type>>& cache,
207  const polyPatch& pp,
208  const word& entryName,
209  const dictionary& dict,
210  enum keyType::option matchOpt = keyType::LITERAL,
211  const bool faceValues = true,
212  const bool mandatory = true
213  );
214 
215 
216  //- Destructor
217  virtual ~PatchFunction1() = default;
218 
219 
220  // Member Functions
221 
222  //- Is value constant (i.e. independent of x)
223  virtual bool constant() const { return false; }
224 
225  //- Can function be evaluated?
226  virtual bool good() const { return true; }
227 
228  //- Is value uniform (i.e. independent of coordinate)
229  virtual bool uniform() const = 0;
230 
231 
232  // Evaluation
233 
234  //- Return value as a function of (scalar) independent variable
235  virtual tmp<Field<Type>> value(const scalar x) const;
236 
237  //- Integrate between two (scalar) values
238  virtual tmp<Field<Type>> integrate
239  (
240  const scalar x1,
241  const scalar x2
242  ) const;
243 
244  //- Helper: optionally convert coordinates to local coordinates
245  virtual tmp<pointField> localPosition
246  (
247  const pointField& globalPos
248  ) const;
249 
250  //- Apply optional transformation
251  virtual tmp<Field<Type>> transform(const Field<Type>& fld) const;
252 
253  //- Apply optional transformation
255  (
256  const tmp<Field<Type>>& tfld
257  ) const;
258 
260  // Mapping
261 
262  //- Map (and resize as needed) from self given a mapping object
263  virtual void autoMap(const FieldMapper& mapper);
264 
265  //- Reverse map the given PatchFunction1 onto this PatchFunction1
266  virtual void rmap
267  (
268  const PatchFunction1<Type>& rhs,
269  const labelList& addr
270  );
271 
272 
273  // I/O
274 
275  //- Ostream Operator
276  friend Ostream& operator<< <Type>
277  (
278  Ostream& os,
279  const PatchFunction1<Type>& rhs
280  );
281 
282  //- Write in dictionary format
283  virtual void writeData(Ostream& os) const;
284 };
285 
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 } // End namespace Foam
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 // Define PatchFunction1 run-time selection
294 #define makePatchFunction1(Type) \
295  \
296  defineNamedTemplateTypeNameAndDebug(PatchFunction1<Type>, 0); \
297  \
298  defineTemplateRunTimeSelectionTable \
299  ( \
300  PatchFunction1<Type>, \
301  dictionary \
302  );
303 
304 
305 // Define (templated) PatchFunction1, add to (templated) run-time selection
306 #define makePatchFunction1Type(SS, Type) \
307  \
308  defineNamedTemplateTypeNameAndDebug(PatchFunction1Types::SS<Type>, 0); \
309  \
310  PatchFunction1<Type>::adddictionaryConstructorToTable \
311  <PatchFunction1Types::SS<Type>> \
312  add##SS##Type##ConstructorToTable_;
313 
314 
315 // Define (non-templated) PatchFunction1, add to (templated) run-time selection
316 #define makeConcretePatchFunction1Type(SS, Type) \
317  \
318  defineTypeNameAndDebug(SS, 0); \
319  \
320  PatchFunction1<Type>::adddictionaryConstructorToTable \
321  <PatchFunction1Types::SS> \
322  add##SS##Type##ConstructorToTable_;
323 
324 
325 // Define scalar PatchFunction1 and add to (templated) run-time selection
326 #define makeScalarPatchFunction1(SS) \
327  \
328  makeConcretePatchFunction1Type(SS, scalar);
329 
330 
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 
333 #ifdef NoRepository
334  #include "PatchFunction1.C"
335  #include "PatchFunction1New.C"
336 #endif
337 
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 
340 #endif
341 
342 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
virtual bool constant() const
Is value constant (i.e. independent of x)
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
coordinateScaling< Type > coordSys_
Optional local coordinate system and scaling.
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers...
Definition: HashPtrTable.H:51
const polyPatch const word const word const dictionary & dict
virtual bool good() const
Can function be evaluated?
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
static autoPtr< PatchFunction1< Type > > NewCompat(const polyPatch &pp, const word &entryName, std::initializer_list< std::pair< const char *, int >> compat, const dictionary &dict, const bool faceValues=true, const bool mandatory=true)
Compatibility selector.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:43
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
void operator=(const PatchFunction1< Type > &)=delete
No copy assignment.
const polyPatch const word & type
virtual tmp< pointField > localPosition(const pointField &globalPos) const
Helper: optionally convert coordinates to local coordinates.
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
const polyPatch const word const word & entryName
virtual void writeData(Ostream &os) const
Write in dictionary format.
bool faceValues() const noexcept
Generate face or point values on patch?
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
OBJstream os(runTime.globalPath()/outputName)
virtual tmp< Field< Type > > value(const scalar x) const
Return value as a function of (scalar) independent variable.
Helper class to wrap coordinate system and component-wise scaling.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
virtual tmp< PatchFunction1< Type > > clone() const =0
Return a clone.
virtual tmp< Field< Type > > transform(const Field< Type > &fld) const
Apply optional transformation.
static autoPtr< PatchFunction1< Type > > NewIfPresent(const polyPatch &pp, const word &entryName, const dictionary &dict, const bool faceValues=true)
An optional selector.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
TypeName("PatchFunction1") declareRunTimeSelectionTable(autoPtr
Runtime type information.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
virtual void rmap(const PatchFunction1< Type > &rhs, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Namespace for OpenFOAM.
const polyPatch & pp
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
Field< Type > returnType
The return type is a field of values.