sampledSurface.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::sampledSurface
29
30Group
31 grpUtilitiesFunctionObjects
32
33Description
34 An abstract class for surfaces with sampling.
35
36 The constructors for the derived classes should generally start in a
37 'expired' condition (ie, needsUpdate() == true) and rely on a
38 subsequent call to the update() method to complete the initialization.
39 Delaying the final construction as late as possible allows the
40 construction of surfaces that may depend on intermediate calculation
41 results (eg, iso-surfaces) and also avoids the unnecessary
42 reconstruction of surfaces between sampling intervals.
43
44 It is the responsibility of the caller to ensure that the surface
45 update() is called before the surface is used. The update() method
46 implementation should do nothing when the surface is already
47 up-to-date.
48
49 Any sampler is assumed to work for the standard volume field types.
50 Some may also support surface fields.
51
52 Dictionary entries:
53 \table
54 Property | Description | Required | Default
55 name | Alternative name | no |
56 enabled | Enable/disable the surface? | no | yes
57 interpolate | Interpolate to nodes instead of faces | no | false
58 invariant | Invariant with geometry change (use with caution!) | no | false
59 \endtable
60
61Note
62 The invariant switch is an advanced feature to declare that the surface
63 is unaffected by changes in the general mesh geometry. For example, if
64 sampling on a static patch while some other motion occurs elsewhere. If
65 used improperly, there is a significant possibility for problems
66 (caveat emptor).
67
68SourceFiles
69 sampledSurface.C
70 sampledSurfaceTemplates.C
71
72\*---------------------------------------------------------------------------*/
73
74#ifndef Foam_sampledSurface_H
75#define Foam_sampledSurface_H
76
77#include "polySurface.H"
78#include "typeInfo.H"
80#include "autoPtr.H"
81#include "polyMesh.H"
82#include "volFieldsFwd.H"
83#include "surfaceFieldsFwd.H"
84#include "surfaceMesh.H"
85#include "interpolation.H"
86
87// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88
89namespace Foam
90{
91
92/*---------------------------------------------------------------------------*\
93 Class sampledSurface Declaration
94\*---------------------------------------------------------------------------*/
95
96class sampledSurface
97:
98 public meshedSurf
99{
100 // Private Data
101
102 //- The name of the sample surface
103 word name_;
104
105 //- Reference to mesh
106 const polyMesh& mesh_;
107
108 //- Should surface sampling be enabled?
109 bool enabled_;
110
111 //- Geometry is invariant (never changes)
112 bool invariant_;
113
114 //- Is point vs cell data
115 bool isPointData_;
116
117 //- Total surface area (demand-driven)
118 mutable scalar area_;
119
121protected:
122
123 // Protected Member Functions
124
125 //- Loop for sampling volume elements to faces.
126 // The defaultValue is used for invalid (negative) elements
127 template<class Type>
129 (
130 const interpolation<Type>& sampler,
131 const labelUList& elements,
132 const faceList& fcs,
133 const pointField& pts,
134 const Type& defaultValue = Type(Zero)
135 );
136
137
138 //- Loop for interpolating volume elements to face points.
139 template<class Type>
141 (
142 const interpolation<Type>& interpolator,
143 const labelUList& elements,
144 const faceList& fcs,
145 const pointField& pts
146 );
147
148
149 //- Create cell values by averaging the point values
150 template<class Type>
153 const PointField<Type>& pfld
154 );
155
156
157 //- Additional cleanup when clearing the geometry
158 virtual void clearGeom() const;
159
160 //- Construct null
161 explicit sampledSurface(const word& name, std::nullptr_t);
162
163
164public:
165
166 //- Runtime type information
167 TypeName("sampledSurface");
168
169 //- Declare run-time constructor selection table
171 (
172 autoPtr,
174 word,
176 const word& name,
177 const polyMesh& mesh,
178 const dictionary& dict
179 ),
180 (name, mesh, dict)
181 );
182
183
184 //- PtrList read-construction helper
185 class iNew
186 {
187 //- Reference to the volume mesh
188 const polyMesh& mesh_;
189
190 public:
192 iNew(const polyMesh& mesh)
193 :
194 mesh_(mesh)
195 {}
196
198 {
199 word name(is);
200 dictionary dict(is);
201
202 return sampledSurface::New(name, mesh_, dict);
203 }
204 };
205
206
207 //- PtrList read-construction helper that captures dictionaries used
208 //- during creation.
210 {
211 //- Reference to the volume mesh
212 const polyMesh& mesh_;
213
214 //- Captured (recorded) dictionaries
215 DynamicList<dictionary>& capture_;
217 public:
218
220 :
221 mesh_(mesh),
222 capture_(capture)
223 {}
224
226 {
227 word name(is);
228 capture_.append(dictionary(is));
229
230 return sampledSurface::New(name, mesh_, capture_.last());
231 }
232 };
234
235 // Constructors
236
237 //- Construct from name, mesh
239 (
240 const word& name,
241 const polyMesh& mesh,
242 const bool interpolateToPoints = false
243 );
244
245 //- Construct from dictionary
247 (
248 const word& name,
250 const dictionary& dict
251 );
252
253 //- Clone
255 {
257 return nullptr;
258 }
259
260
261 // Selectors
262
263 //- Return a reference to the selected surface
265 (
266 const word& name,
267 const polyMesh& mesh,
268 const dictionary& dict
269 );
270
271
272 //- Destructor - calls clearGeom()
273 virtual ~sampledSurface();
274
275
276 // Member Functions
277
278 // Access
279
280 //- Access to the underlying mesh
281 const polyMesh& mesh() const noexcept
282 {
283 return mesh_;
284 }
285
286 //- Name of surface
287 const word& name() const noexcept
288 {
289 return name_;
290 }
291
292 //- Surface is enabled
293 bool enabled() const noexcept
294 {
295 return enabled_;
296 }
297
298 //- Surface is invariant with geometry change (caution)
299 bool invariant() const noexcept
300 {
301 return invariant_;
302 }
303
304 //- Using interpolation to surface points
306 {
307 return isPointData_;
308 }
309
310 //- Change point/cell representation, may trigger an expire().
311 // \return old value
312 virtual bool isPointData(const bool on);
313
314 //- Does the surface need an update?
315 virtual bool needsUpdate() const = 0;
316
317 //- Mark the surface as needing an update.
318 // May also free up unneeded data.
319 // Return false if surface was already marked as expired.
320 virtual bool expire() = 0;
321
322 //- Update the surface as required.
323 // Do nothing (and return false) if no update was required
324 virtual bool update() = 0;
325
326 //- Points of surface
327 virtual const pointField& points() const = 0;
328
329 //- Faces of surface
330 virtual const faceList& faces() const = 0;
331
332 //- Face area vectors
333 virtual const vectorField& Sf() const = 0;
334
335 //- Face area magnitudes
336 virtual const scalarField& magSf() const = 0;
337
338 //- Face centres
339 virtual const vectorField& Cf() const = 0;
340
341 //- The total surface area
342 scalar area() const;
343
344 //- If element ids/order of the original surface are available
345 virtual bool hasFaceIds() const
346 {
347 return false;
349
350
351 // General registry storage (optional)
352
353 //- Get surface from registry if available.
354 // \param obr The objectRegistry to use
355 // \param lookupName Optional lookup name, use surface name if empty
356 // \return surface or nullptr
358 (
359 const objectRegistry& obr,
360 word lookupName = ""
361 ) const;
362
363 //- Copy surface into registry.
364 // \param obr The objectRegistry to use
365 // \param lookupName Optional lookup name, use surface name if empty
366 // \return surface or nullptr it surface should not be stored
368 (
370 word lookupName = ""
371 ) const;
372
373 //- Remove surface from registry.
374 // \param obr The objectRegistry to use
375 // \param lookupName Optional lookup name, use surface name if empty
376 // \return True if surface existed and was removed
378 (
379 objectRegistry& obr,
380 word lookupName = ""
381 ) const;
382
383 //- Copy/store sampled field onto registered surface (if it exists)
384 template<class Type, class GeoMeshType>
386 (
387 const objectRegistry& obr,
388 const word& fieldName,
389 const dimensionSet& dims,
390 const Field<Type>& values,
391 word lookupName = ""
392 ) const;
393
394 //- Move/store sampled field onto registered surface (if it exists)
395 template<class Type, class GeoMeshType>
397 (
398 const objectRegistry& obr,
399 const word& fieldName,
400 const dimensionSet& dims,
401 Field<Type>&& values,
402 word lookupName = ""
403 ) const;
404
405
406 // Sample (faces)
407
408 //- Sample volume field onto surface faces
410 (
411 const interpolation<scalar>& sampler
412 ) const = 0;
413
414 //- Sample volume field onto surface faces
416 (
417 const interpolation<vector>& sampler
418 ) const = 0;
419
420 //- Sample volume field onto surface faces
422 (
423 const interpolation<sphericalTensor>& sampler
424 ) const = 0;
425
426 //- Sample volume field onto surface faces
428 (
429 const interpolation<symmTensor>& sampler
430 ) const = 0;
431
432 //- Sample volume field onto surface faces
434 (
435 const interpolation<tensor>& sampler
436 ) const = 0;
437
438
439 //- Can it sample surface-fields?
440 virtual bool withSurfaceFields() const;
441
442
443 //- Sample surface field onto surface
446 const surfaceScalarField& sField
447 ) const;
448
449 //- Sample surface field onto surface
452 const surfaceVectorField& sField
453 ) const;
454
455 //- Sample surface field onto surface
458 const surfaceSphericalTensorField& sField
459 ) const;
460
461 //- Sample surface field onto surface
463 (
464 const surfaceSymmTensorField& sField
465 ) const;
466
467 //- Sample surface field onto surface
469 (
470 const surfaceTensorField& sField
471 ) const;
472
473
474 // Interpolate (points)
475
476 //- Interpolate volume field onto surface points
478 (
479 const interpolation<scalar>& interpolator
480 ) const = 0;
481
482 //- Interpolate volume field onto surface points
484 (
485 const interpolation<vector>& interpolator
486 ) const = 0;
487
488 //- Interpolate volume field onto surface points
490 (
491 const interpolation<sphericalTensor>& interpolator
492 ) const = 0;
493
494 //- Interpolate volume field onto surface points
496 (
497 const interpolation<symmTensor>& interpolator
498 ) const = 0;
499
500 //- Interpolate volume field onto surface points
502 (
503 const interpolation<tensor>& interpolator
504 ) const = 0;
505
506
507 // Edit
508
509 //- Rename
510 virtual void rename(const word& newName)
511 {
512 name_ = newName;
514
515
516 // Write
517
518 //- Print information
519 virtual void print(Ostream& os, int level=0) const;
520
521
522 // Housekeeping
523
524 //- Same as isPointData()
525 bool interpolate() const noexcept { return isPointData_; }
526};
527
528
529// Global Operators
530
531//- Ostream operator
532Ostream& operator<<(Ostream& os, const sampledSurface& s);
533
534// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
535
536} // End namespace Foam
537
538// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
539
540#ifdef NoRepository
542#endif
543
544// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
545
546#endif
547
548// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
Minimal example by using system/controlDict.functions:
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
T & last()
Return the last element of the list.
Definition: UListI.H:216
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:109
Abstract base class for volume field interpolation.
Definition: interpolation.H:60
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:50
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:71
autoPtr< sampledSurface > operator()(Istream &is) const
iNewCapture(const polyMesh &mesh, DynamicList< dictionary > &capture)
PtrList read-construction helper.
iNew(const polyMesh &mesh)
autoPtr< sampledSurface > operator()(Istream &is) const
An abstract class for surfaces with sampling.
virtual const scalarField & magSf() const =0
Face area magnitudes.
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
virtual bool needsUpdate() const =0
Does the surface need an update?
bool enabled() const noexcept
Surface is enabled.
static tmp< Field< Type > > sampleOnPoints(const interpolation< Type > &interpolator, const labelUList &elements, const faceList &fcs, const pointField &pts)
Loop for interpolating volume elements to face points.
polySurface * getRegistrySurface(const objectRegistry &obr, word lookupName="") const
Get surface from registry if available.
virtual const vectorField & Sf() const =0
Face area vectors.
static tmp< Field< Type > > sampleOnFaces(const interpolation< Type > &sampler, const labelUList &elements, const faceList &fcs, const pointField &pts, const Type &defaultValue=Type(Zero))
Loop for sampling volume elements to faces.
virtual const vectorField & Cf() const =0
Face centres.
virtual tmp< symmTensorField > interpolate(const interpolation< symmTensor > &interpolator) const =0
Interpolate volume field onto surface points.
bool isPointData() const noexcept
Using interpolation to surface points.
virtual const faceList & faces() const =0
Faces of surface.
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const =0
Sample volume field onto surface faces.
virtual tmp< tensorField > sample(const interpolation< tensor > &sampler) const =0
Sample volume field onto surface faces.
virtual tmp< scalarField > interpolate(const interpolation< scalar > &interpolator) const =0
Interpolate volume field onto surface points.
virtual tmp< sphericalTensorField > interpolate(const interpolation< sphericalTensor > &interpolator) const =0
Interpolate volume field onto surface points.
virtual void print(Ostream &os, int level=0) const
Print information.
static tmp< VolumeField< Type > > pointAverage(const PointField< Type > &pfld)
Create cell values by averaging the point values.
bool storeRegistryField(const objectRegistry &obr, const word &fieldName, const dimensionSet &dims, const Field< Type > &values, word lookupName="") const
Copy/store sampled field onto registered surface (if it exists)
virtual tmp< symmTensorField > sample(const interpolation< symmTensor > &sampler) const =0
Sample volume field onto surface faces.
virtual bool update()=0
Update the surface as required.
polySurface * storeRegistrySurface(objectRegistry &obr, word lookupName="") const
Copy surface into registry.
virtual bool hasFaceIds() const
If element ids/order of the original surface are available.
const word & name() const noexcept
Name of surface.
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
virtual tmp< tensorField > interpolate(const interpolation< tensor > &interpolator) const =0
Interpolate volume field onto surface points.
static autoPtr< sampledSurface > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected surface.
bool removeRegistrySurface(objectRegistry &obr, word lookupName="") const
Remove surface from registry.
autoPtr< sampledSurface > clone() const
Clone.
virtual ~sampledSurface()
Destructor - calls clearGeom()
virtual bool withSurfaceFields() const
Can it sample surface-fields?
virtual void rename(const word &newName)
Rename.
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
virtual tmp< vectorField > interpolate(const interpolation< vector > &interpolator) const =0
Interpolate volume field onto surface points.
virtual tmp< sphericalTensorField > sample(const interpolation< sphericalTensor > &sampler) const =0
Sample volume field onto surface faces.
scalar area() const
The total surface area.
bool invariant() const noexcept
Surface is invariant with geometry change (caution)
virtual bool expire()=0
Mark the surface as needing an update.
TypeName("sampledSurface")
Runtime type information.
virtual const pointField & points() const =0
Points of surface.
virtual tmp< vectorField > sample(const interpolation< vector > &sampler) const =0
Sample volume field onto surface faces.
bool interpolate() const noexcept
Same as isPointData()
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
OBJstream os(runTime.globalPath()/outputName)
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;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
const direction noexcept
Definition: Scalar.H:223
Macros to ease declaration of run-time selection tables.
#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:73