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-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::sampledSurface
29 
30 Group
31  grpUtilitiesFunctionObjects
32 
33 Description
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 
61 Note
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 
68 SourceFiles
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"
79 #include "runTimeSelectionTables.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 
89 namespace Foam
90 {
91 
92 /*---------------------------------------------------------------------------*\
93  Class sampledSurface Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 class 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_;
117  //- Total surface area (demand-driven)
118  mutable scalar area_;
119 
120 
121 protected:
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>
152  (
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 
164 public:
165 
166  //- Runtime type information
167  TypeName("sampledSurface");
168 
169  //- Declare run-time constructor selection table
171  (
172  autoPtr,
174  word,
175  (
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:
191 
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.
209  class iNewCapture
210  {
211  //- Reference to the volume mesh
212  const polyMesh& mesh_;
213 
214  //- Captured (recorded) dictionaries
215  DynamicList<dictionary>& capture_;
216 
217  public:
218 
219  iNewCapture(const polyMesh& mesh, DynamicList<dictionary>& capture)
220  :
221  mesh_(mesh),
222  capture_(capture)
223  {}
224 
225  autoPtr<sampledSurface> operator()(Istream& is) const
226  {
227  word name(is);
228  dictionary& dict = capture_.emplace_back(is);
229 
230  return sampledSurface::New(name, mesh_, dict);
231  }
232  };
233 
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,
249  const polyMesh& mesh,
250  const dictionary& dict
251  );
252 
253  //- Clone
255  {
257  return nullptr;
258  }
259 
260 
261  // Selectors
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
305  bool isPointData() const noexcept
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;
348  }
349 
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  (
369  objectRegistry& obr,
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;
383  //- Copy/store sampled field onto registered surface (if it exists)
384  template<class Type, class GeoMeshType>
385  bool storeRegistryField
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>
396  bool storeRegistryField
397  (
398  const objectRegistry& obr,
399  const word& fieldName,
400  const dimensionSet& dims,
402  word lookupName = ""
403  ) const;
404 
405 
406  // Sample (faces)
407 
408  //- Sample volume field onto surface faces
409  virtual tmp<scalarField> sample
410  (
411  const interpolation<scalar>& sampler
412  ) const = 0;
413 
414  //- Sample volume field onto surface faces
415  virtual tmp<vectorField> sample
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
433  virtual tmp<tensorField> sample
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
444  virtual tmp<scalarField> sample
445  (
446  const surfaceScalarField& sField
447  ) const;
448 
449  //- Sample surface field onto surface
450  virtual tmp<vectorField> sample
451  (
452  const surfaceVectorField& sField
453  ) const;
454 
455  //- Sample surface field onto surface
457  (
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
468  virtual tmp<tensorField> sample
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;
513  }
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
532 Ostream& operator<<(Ostream& os, const sampledSurface& s);
533 
534 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
535 
536 } // End namespace Foam
537 
538 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
539 
540 #ifdef NoRepository
541  #include "sampledSurfaceTemplates.C"
542 #endif
543 
544 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
545 
546 #endif
547 
548 // ************************************************************************* //
A surface mesh consisting of general polygon faces and capable of holding fields. ...
Definition: polySurface.H:62
dictionary dict
bool interpolate() const noexcept
Same as isPointData()
virtual ~sampledSurface()
Destructor - calls clearGeom()
virtual const scalarField & magSf() const =0
Face area magnitudes.
TypeName("sampledSurface")
Runtime type information.
virtual bool expire()=0
Mark the surface as needing an update.
static tmp< VolumeField< Type > > pointAverage(const PointField< Type > &pfld)
Create cell values by averaging the point values.
Forwards and collection of common volume field types.
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
An abstract class for surfaces with sampling.
autoPtr< sampledSurface > clone() const
Clone.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual const vectorField & Sf() const =0
Face area vectors.
autoPtr< sampledSurface > operator()(Istream &is) const
static autoPtr< sampledSurface > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected surface.
bool enabled() const noexcept
Surface is enabled.
iNewCapture(const polyMesh &mesh, DynamicList< dictionary > &capture)
const word & name() const noexcept
Name of surface.
virtual const faceList & faces() const =0
Faces of surface.
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.
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 bool withSurfaceFields() const
Can it sample surface-fields?
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
virtual bool needsUpdate() const =0
Does the surface need an update?
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
A class for handling words, derived from Foam::string.
Definition: word.H:63
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
bool invariant() const noexcept
Surface is invariant with geometry change (caution)
scalar area() const
The total surface area.
virtual bool update()=0
Update the surface as required.
sampledSurface(const word &name, std::nullptr_t)
Construct null.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
polySurface * getRegistrySurface(const objectRegistry &obr, word lookupName="") const
Get surface from registry if available.
iNew(const polyMesh &mesh)
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const =0
Sample volume field onto surface faces.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual const vectorField & Cf() const =0
Face centres.
autoPtr< sampledSurface > operator()(Istream &is) const
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 const pointField & points() const =0
Points of surface.
virtual void print(Ostream &os, int level=0) const
Print information.
Abstract base class for volume field interpolation.
virtual void rename(const word &newName)
Rename.
bool removeRegistrySurface(objectRegistry &obr, word lookupName="") const
Remove surface from registry.
virtual bool hasFaceIds() const
If element ids/order of the original surface are available.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Macros to ease declaration of run-time selection tables.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
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))
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
polySurface * storeRegistrySurface(objectRegistry &obr, word lookupName="") const
Copy surface into registry.
PtrList read-construction helper.
Namespace for OpenFOAM.
bool isPointData() const noexcept
Using interpolation to surface points.
const pointField & pts
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127