Loading...
Searching...
No Matches
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-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::PatchFunction1
28
29Description
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
37SourceFiles
38 PatchFunction1.C
39 PatchFunction1New.C
40
41SeeAlso
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
56namespace Foam
57{
58
59// Forward Declarations
60class Time;
61template<class Type> class PatchFunction1;
62
63template<class Type>
65
66/*---------------------------------------------------------------------------*\
67 Class PatchFunction1 Declaration
68\*---------------------------------------------------------------------------*/
69
70template<class Type>
72:
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
89protected:
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;
102
103public:
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 (
120 (
121 const polyPatch& pp,
122 const word& type,
123 const word& entryName,
124 const dictionary& dict,
125 const bool faceValues
126 ),
128 );
131 // Constructors
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
144 const polyPatch& pp,
145 const word& entryName,
146 const dictionary& dict,
147 const bool faceValues = true
148 );
149
150 //- Copy construct setting patch
151 explicit PatchFunction1
152 (
153 const PatchFunction1<Type>& rhs,
154 const polyPatch& pp
155 );
156
157 //- Copy construct
158 explicit PatchFunction1(const PatchFunction1<Type>& rhs);
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 // Factory Methods
168
169 //- Clone a PatchFunction1
170 template<class Derived>
171 static tmp<PatchFunction1<Type>>
172 Clone(const Derived& fun)
174 return tmp<PatchFunction1<Type>>(new Derived(fun));
175 }
176
177 //- Clone a PatchFunction1 with a patch
178 template<class Derived>
180 Clone(const Derived& fun, const polyPatch& pp)
181 {
182 return tmp<PatchFunction1<Type>>(new Derived(fun, pp));
184
185
186 //- Selector
188 (
189 const polyPatch& pp,
190 const word& entryName,
191 const dictionary& dict,
192 const bool faceValues = true,
193 const bool mandatory = true
194 );
195
196 //- Compatibility selector
198 (
199 const polyPatch& pp,
200 const word& entryName,
201 std::initializer_list<std::pair<const char*,int>> compat,
202 const dictionary& dict,
203 const bool faceValues = true,
204 const bool mandatory = true
205 );
206
207 //- An optional selector
209 (
210 const polyPatch& pp,
211 const word& entryName,
212 const dictionary& dict,
213 const bool faceValues = true
214 );
215
216
217 // Caching Selectors - accept wildcards in dictionary
218
219 //- Selector with external storage.
220 //- This also allows wildcard matches in a dictionary
222 (
224 const polyPatch& pp,
225 const word& entryName,
226 const dictionary& dict,
227 enum keyType::option matchOpt = keyType::LITERAL,
228 const bool faceValues = true,
229 const bool mandatory = true
230 );
231
232
233 //- Destructor
234 virtual ~PatchFunction1() = default;
235
236
237 // Member Functions
238
239 //- Is value constant (i.e. independent of x)
240 virtual bool constant() const { return false; }
241
242 //- Can function be evaluated?
243 virtual bool good() const { return true; }
244
245 //- Is value uniform (i.e. independent of coordinate)
246 virtual bool uniform() const = 0;
247
248
249 // Evaluation
250
251 //- Return value as a function of (scalar) independent variable
252 virtual tmp<Field<Type>> value(const scalar x) const;
253
254 //- Integrate between two (scalar) values
255 virtual tmp<Field<Type>> integrate
256 (
257 const scalar x1,
258 const scalar x2
259 ) const;
260
261 //- Helper: optionally convert coordinates to local coordinates
262 virtual tmp<pointField> localPosition
263 (
264 const pointField& globalPos
265 ) const;
266
267 //- Apply optional transformation
268 virtual tmp<Field<Type>> transform(const Field<Type>& fld) const;
269
270 //- Apply optional transformation
272 (
273 const tmp<Field<Type>>& tfld
274 ) const;
276
277 // Mapping
278
279 //- Map (and resize as needed) from self given a mapping object
280 virtual void autoMap(const FieldMapper& mapper);
281
282 //- Reverse map the given PatchFunction1 onto this PatchFunction1
283 virtual void rmap
284 (
286 const labelList& addr
287 );
288
289
290 // I/O
291
292 //- Ostream Operator
293 friend Ostream& operator<< <Type>
294 (
295 Ostream& os,
297 );
298
299 //- Write in dictionary format
300 virtual void writeData(Ostream& os) const;
301};
302
303
304// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305
306} // End namespace Foam
307
308// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309
310// Define PatchFunction1 run-time selection
311#define makePatchFunction1(Type) \
312 \
313 defineNamedTemplateTypeNameAndDebug(PatchFunction1<Type>, 0); \
314 \
315 defineTemplateRunTimeSelectionTable \
316 ( \
317 PatchFunction1<Type>, \
318 dictionary \
319 );
320
321
322// Define (templated) PatchFunction1, add to (templated) run-time selection
323#define makePatchFunction1Type(SS, Type) \
324 \
325 defineNamedTemplateTypeNameAndDebug(PatchFunction1Types::SS<Type>, 0); \
326 \
327 PatchFunction1<Type>::adddictionaryConstructorToTable \
328 <PatchFunction1Types::SS<Type>> \
329 add##SS##Type##ConstructorToTable_;
330
331
332// Define (non-templated) PatchFunction1, add to (templated) run-time selection
333#define makeConcretePatchFunction1Type(SS, Type) \
334 \
335 defineTypeNameAndDebug(SS, 0); \
336 \
337 PatchFunction1<Type>::adddictionaryConstructorToTable \
338 <PatchFunction1Types::SS> \
339 add##SS##Type##ConstructorToTable_;
340
341
342// Define scalar PatchFunction1 and add to (templated) run-time selection
343#define makeScalarPatchFunction1(SS) \
344 \
345 makeConcretePatchFunction1Type(SS, scalar);
346
347
348// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349
350#ifdef NoRepository
351 #include "PatchFunction1.C"
352 #include "PatchFunction1New.C"
353#endif
354
355// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356
357#endif
358
359// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Abstract base class to hold the Field mapping addressing and weights.
Definition FieldMapper.H:44
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
const polyPatch const word const word & entryName
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate).
virtual void rmap(const PatchFunction1< Type > &rhs, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
virtual ~PatchFunction1()=default
Destructor.
const polyPatch const word & type
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Field< Type > returnType
The return type is a field of values.
virtual void writeData(Ostream &os) const
Write in dictionary format.
coordinateScaling< Type > coordSys_
Optional local coordinate system and scaling.
virtual bool constant() const
Is value constant (i.e. independent of x).
virtual tmp< Field< Type > > value(const scalar x) const
Return value as a function of (scalar) independent variable.
const polyPatch const word const word const dictionary & dict
virtual tmp< pointField > localPosition(const pointField &globalPos) const
Helper: optionally convert coordinates to local coordinates.
static tmp< PatchFunction1< Type > > Clone(const Derived &fun)
Clone a PatchFunction1.
void operator=(const PatchFunction1< Type > &)=delete
No copy assignment.
virtual bool good() const
Can function be evaluated?
virtual tmp< Field< Type > > transform(const Field< Type > &fld) const
Apply optional transformation.
const polyPatch & pp
static tmp< PatchFunction1< Type > > Clone(const Derived &fun, const polyPatch &pp)
Clone a PatchFunction1 with a patch.
TypeName("PatchFunction1") declareRunTimeSelectionTable(autoPtr
Runtime type information.
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.
virtual tmp< PatchFunction1< Type > > clone() const =0
Return a clone.
static autoPtr< PatchFunction1< Type > > NewIfPresent(const polyPatch &pp, const word &entryName, const dictionary &dict, const bool faceValues=true)
An optional selector.
const polyPatch const word const word const dictionary const bool faceValues
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Helper class to wrap coordinate system and component-wise scaling.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
option
Enumeration for the data type and search/match modes (bitmask).
Definition keyType.H:80
@ LITERAL
String literal.
Definition keyType.H:82
patchFunction1Base(const polyPatch &pp, const word &entryName, const bool faceValues=true)
Construct from polyPatch and entry name.
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
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.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
vectorField pointField
pointField is a vectorField.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68