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-2019 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 | Sample 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 is
63  unaffected by changes in the general mesh geometry. For example, if sampling
64  on a static patch while some other motion occurs elsewhere. If used improperly,
65  there is a significant possibility for problems (caveat emptor).
66 
67 SourceFiles
68  sampledSurface.C
69  sampledSurfaceTemplates.C
70 
71 \*---------------------------------------------------------------------------*/
72 
73 #ifndef sampledSurface_H
74 #define sampledSurface_H
75 
76 #include "polySurface.H"
77 #include "surfMesh.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 public:
101 
102  // Public Static Data
103 
104  //- Class names for surface field types
105  static const wordList surfaceFieldTypes;
106 
107 
108 private:
109 
110  // Private Data
111 
112  //- The name of the sample surface
113  word name_;
114 
115  //- Reference to mesh
116  const polyMesh& mesh_;
117 
118  //- Should surface sampling be enabled?
119  bool enabled_;
120 
121  //- Geometry is invariant (never changes)
122  bool invariant_;
123 
124  //- Interpolate information to the nodes?
125  bool interpolate_;
126 
127  //- Total surface area (demand-driven)
128  mutable scalar area_;
129 
130 
131 protected:
132 
133  // Protected Member Functions
134 
135  //- General loop for sampling elements to faces
136  template<class Type>
138  (
139  const interpolation<Type>& sampler,
140  const labelUList& elements,
141  const faceList& fcs,
142  const pointField& pts
143  );
144 
145 
146  //- Create cell values by averaging the point values
147  template<class Type>
149  (
151  );
152 
153 
154  //- Additional cleanup when clearing the geometry
155  virtual void clearGeom() const;
156 
157  //- Construct null
158  explicit sampledSurface(const word& name, std::nullptr_t);
159 
160 
161 public:
162 
163  //- Runtime type information
164  TypeName("sampledSurface");
165 
166  //- Declare run-time constructor selection table
168  (
169  autoPtr,
171  word,
172  (
173  const word& name,
174  const polyMesh& mesh,
175  const dictionary& dict
176  ),
177  (name, mesh, dict)
178  );
179 
180 
181  //- PtrList read-construction helper
182  class iNew
183  {
184  //- Reference to the volume mesh
185  const polyMesh& mesh_;
186 
187  public:
188 
189  iNew(const polyMesh& mesh)
190  :
191  mesh_(mesh)
192  {}
193 
195  {
196  word name(is);
197  dictionary dict(is);
198 
199  return sampledSurface::New(name, mesh_, dict);
200  }
201  };
202 
203 
204  //- PtrList read-construction helper that captures dictionaries used
205  //- during creation.
207  {
208  //- Reference to the volume mesh
209  const polyMesh& mesh_;
210 
211  //- Captured (recorded) dictionaries
212  DynamicList<dictionary>& capture_;
213 
214  public:
215 
217  :
218  mesh_(mesh),
219  capture_(capture)
220  {}
221 
223  {
224  word name(is);
225  capture_.append(dictionary(is));
226 
227  return sampledSurface::New(name, mesh_, capture_.last());
228  }
229  };
230 
231 
232  // Constructors
233 
234  //- Construct from name, mesh
236  (
237  const word& name,
238  const polyMesh& mesh,
239  const bool interpolate = false
240  );
241 
242  //- Construct from dictionary
244  (
245  const word& name,
246  const polyMesh& mesh,
247  const dictionary& dict
248  );
249 
250  //- Clone
252  {
254  return nullptr;
255  }
256 
257 
258  // Selectors
259 
260  //- Return a reference to the selected surface
262  (
263  const word& name,
264  const polyMesh& mesh,
265  const dictionary& dict
266  );
267 
268 
269  //- Destructor - calls clearGeom()
270  virtual ~sampledSurface();
271 
272 
273  // Member Functions
274 
275  // Access
276 
277  //- Access to the underlying mesh
278  const polyMesh& mesh() const
279  {
280  return mesh_;
281  }
282 
283  //- Name of surface
284  const word& name() const
285  {
286  return name_;
287  }
288 
289  //- Surface is enabled
290  bool enabled() const
291  {
292  return enabled_;
293  }
294 
295  //- Surface is invariant with geometry change (caution)
296  bool invariant() const
297  {
298  return invariant_;
299  }
300 
301  //- Interpolation to nodes requested for surface
302  bool interpolate() const
303  {
304  return interpolate_;
305  }
306 
307  //- Does the surface need an update?
308  virtual bool needsUpdate() const = 0;
309 
310  //- Mark the surface as needing an update.
311  // May also free up unneeded data.
312  // Return false if surface was already marked as expired.
313  virtual bool expire() = 0;
314 
315  //- Update the surface as required.
316  // Do nothing (and return false) if no update was required
317  virtual bool update() = 0;
318 
319  //- Points of surface
320  virtual const pointField& points() const = 0;
321 
322  //- Faces of surface
323  virtual const faceList& faces() const = 0;
324 
325  //- Face area vectors
326  virtual const vectorField& Sf() const = 0;
327 
328  //- Face area magnitudes
329  virtual const scalarField& magSf() const = 0;
330 
331  //- Face centres
332  virtual const vectorField& Cf() const = 0;
333 
334  //- The total surface area
335  scalar area() const;
336 
337  //- If element ids/order of the original surface are available
338  virtual bool hasFaceIds() const
339  {
340  return false;
341  }
342 
343 
344  // General registry storage (optional)
345 
346  //- Get surface from registry if available.
347  // \param obr The objectRegistry to use
348  // \param lookupName Optional lookup name, use surface name if empty
349  // \return surface or nullptr
351  (
352  const objectRegistry& obr,
353  word lookupName = ""
354  ) const;
355 
356  //- Copy surface into registry.
357  // \param obr The objectRegistry to use
358  // \param lookupName Optional lookup name, use surface name if empty
359  // \return surface or nullptr it surface should not be stored
361  (
363  word lookupName = ""
364  ) const;
365 
366  //- Remove surface from registry.
367  // \param obr The objectRegistry to use
368  // \param lookupName Optional lookup name, use surface name if empty
369  // \return True if surface existed and was removed
371  (
372  objectRegistry& obr,
373  word lookupName = ""
374  ) const;
375 
376  //- Copy/store sampled field onto registered surface (if it exists)
377  template<class Type, class GeoMeshType>
378  bool storeRegistryField
379  (
380  const objectRegistry& obr,
381  const word& fieldName,
382  const dimensionSet& dims,
383  const Field<Type>& values,
384  word lookupName = ""
385  ) const;
386 
387  //- Move/store sampled field onto registered surface (if it exists)
388  template<class Type, class GeoMeshType>
389  bool storeRegistryField
390  (
391  const objectRegistry& obr,
392  const word& fieldName,
393  const dimensionSet& dims,
395  word lookupName = ""
396  ) const;
397 
398 
399  // Specialized surfMesh storage (optional)
400 
401  //- Get surface from registry if available.
402  // \param lookupName Optional lookup name, use surface name if empty
403  // \return surface or nullptr
404  surfMesh* getSurfMesh(word lookupName = "") const;
405 
406  //- Copy surface into registry.
407  // \param lookupName Optional lookup name, use surface name if empty
408  // \return surface or nullptr it surface should not be stored
409  surfMesh* storeSurfMesh(word lookupName = "") const;
410 
411  //- Remove surface from registry.
412  // \param lookupName Optional lookup name, use surface name if empty
413  // \return True if surface existed and was removed
414  bool removeSurfMesh(word lookupName = "") const;
415 
416  //- Copy/store sampled Face field onto surfMesh (if it exists)
417  template<class Type, class GeoMeshType>
418  bool storeSurfMeshField
419  (
420  const word& fieldName,
421  const dimensionSet& dims,
422  const Field<Type>& values,
423  word lookupName = ""
424  ) const;
425 
426  //- Move/store sampled Face field onto surfMesh (if it exists)
427  template<class Type, class GeoMeshType>
428  bool storeSurfMeshField
429  (
430  const word& fieldName,
431  const dimensionSet& dims,
433  word lookupName = ""
434  ) const;
435 
436 
437  // Sample (faces)
438 
439  //- Sample volume field onto surface faces
440  virtual tmp<scalarField> sample
441  (
442  const interpolation<scalar>& sampler
443  ) const = 0;
444 
445  //- Sample volume field onto surface faces
446  virtual tmp<vectorField> sample
447  (
448  const interpolation<vector>& sampler
449  ) const = 0;
450 
451  //- Sample volume field onto surface faces
453  (
454  const interpolation<sphericalTensor>& sampler
455  ) const = 0;
456 
457  //- Sample volume field onto surface faces
459  (
460  const interpolation<symmTensor>& sampler
461  ) const = 0;
462 
463  //- Sample volume field onto surface faces
464  virtual tmp<tensorField> sample
465  (
466  const interpolation<tensor>& sampler
467  ) const = 0;
468 
469 
470  //- Can it sample surface-fields?
471  virtual bool withSurfaceFields() const;
472 
473 
474  //- Sample surface field onto surface
475  virtual tmp<scalarField> sample
476  (
477  const surfaceScalarField& sField
478  ) const;
479 
480  //- Sample surface field onto surface
481  virtual tmp<vectorField> sample
482  (
483  const surfaceVectorField& sField
484  ) const;
485 
486  //- Sample surface field onto surface
488  (
489  const surfaceSphericalTensorField& sField
490  ) const;
491 
492  //- Sample surface field onto surface
494  (
495  const surfaceSymmTensorField& sField
496  ) const;
497 
498  //- Sample surface field onto surface
499  virtual tmp<tensorField> sample
500  (
501  const surfaceTensorField& sField
502  ) const;
503 
504 
505  // Interpolate (points)
506 
507  //- Interpolate volume field onto surface points
509  (
510  const interpolation<scalar>& interpolator
511  ) const = 0;
512 
513  //- Interpolate volume field onto surface points
515  (
516  const interpolation<vector>& interpolator
517  ) const = 0;
518 
519  //- Interpolate volume field onto surface points
521  (
522  const interpolation<sphericalTensor>& interpolator
523  ) const = 0;
524 
525  //- Interpolate volume field onto surface points
527  (
528  const interpolation<symmTensor>& interpolator
529  ) const = 0;
530 
531  //- Interpolate volume field onto surface points
533  (
534  const interpolation<tensor>& interpolator
535  ) const = 0;
536 
537 
538  // Edit
539 
540  //- Rename
541  virtual void rename(const word& newName)
542  {
543  name_ = newName;
544  }
545 
546 
547  // Write
548 
549  //- Print information
550  virtual void print(Ostream& os) const;
551 };
552 
553 
554 // Global Operators
555 
556 //- Ostream operator
557 Ostream& operator<<(Ostream& os, const sampledSurface& s);
558 
559 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
560 
561 } // End namespace Foam
562 
563 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
564 
565 #ifdef NoRepository
566  #include "sampledSurfaceTemplates.C"
567 #endif
568 
569 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
570 
571 #endif
572 
573 // ************************************************************************* //
Foam::sampledSurface::getRegistrySurface
polySurface * getRegistrySurface(const objectRegistry &obr, word lookupName="") const
Get surface from registry if available.
Definition: sampledSurfaceRegister.C:36
volFieldsFwd.H
Foam::sampledSurface::iNewCapture::iNewCapture
iNewCapture(const polyMesh &mesh, DynamicList< dictionary > &capture)
Definition: sampledSurface.H:240
Foam::sampledSurface::New
static autoPtr< sampledSurface > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected surface.
Definition: sampledSurface.C:64
Foam::sampledSurface::iNewCapture::operator()
autoPtr< sampledSurface > operator()(Istream &is) const
Definition: sampledSurface.H:246
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
s
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))
Definition: gmvOutputSpray.H:25
Foam::sampledSurface::faces
virtual const faceList & faces() const =0
Faces of surface.
typeInfo.H
polySurface.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::sampledSurface::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
Foam::sampledSurface::hasFaceIds
virtual bool hasFaceIds() const
If element ids/order of the original surface are available.
Definition: sampledSurface.H:362
Foam::sampledSurface::removeRegistrySurface
bool removeRegistrySurface(objectRegistry &obr, word lookupName="") const
Remove surface from registry.
Definition: sampledSurfaceRegister.C:76
Foam::sampledSurface::area
scalar area() const
The total surface area.
Definition: sampledSurface.C:147
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::surfMesh
A surface mesh consisting of general polygon faces that has IO capabilities and a registry for storin...
Definition: surfMesh.H:63
interpolation.H
Foam::sampledSurface::surfaceFieldTypes
static const wordList surfaceFieldTypes
Class names for surface field types.
Definition: sampledSurface.H:129
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:65
Foam::sampledSurface::enabled
bool enabled() const
Surface is enabled.
Definition: sampledSurface.H:314
polyMesh.H
Foam::sampledSurface::pointAverage
static tmp< GeometricField< Type, fvPatchField, volMesh > > pointAverage(const GeometricField< Type, pointPatchField, pointMesh > &pfld)
Create cell values by averaging the point values.
Foam::sampledSurface::magSf
virtual const scalarField & magSf() const =0
Face area magnitudes.
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sampledSurface::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const =0
Sample volume field onto surface faces.
Foam::sampledSurface::expire
virtual bool expire()=0
Mark the surface as needing an update.
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::sampledSurface::sampleOnFaces
static tmp< Field< Type > > sampleOnFaces(const interpolation< Type > &sampler, const labelUList &elements, const faceList &fcs, const pointField &pts)
General loop for sampling elements to faces.
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:436
Foam::polySurface
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:67
Foam::sampledSurface::points
virtual const pointField & points() const =0
Points of surface.
Foam::sampledSurface::invariant
bool invariant() const
Surface is invariant with geometry change (caution)
Definition: sampledSurface.H:320
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::sampledSurface::rename
virtual void rename(const word &newName)
Rename.
Definition: sampledSurface.H:565
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
Foam::sampledSurface::iNew::operator()
autoPtr< sampledSurface > operator()(Istream &is) const
Definition: sampledSurface.H:218
Foam::sampledSurface::iNewCapture
Definition: sampledSurface.H:230
Foam::sampledSurface::storeRegistryField
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)
Definition: sampledSurfaceTemplates.C:124
Foam::sampledSurface::clone
autoPtr< sampledSurface > clone() const
Clone.
Definition: sampledSurface.H:275
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
Foam::sampledSurface::iNew::iNew
iNew(const polyMesh &mesh)
Definition: sampledSurface.H:213
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:95
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
surfaceMesh.H
surfMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledSurface::Sf
virtual const vectorField & Sf() const =0
Face area vectors.
Foam::sampledSurface::storeRegistrySurface
polySurface * storeRegistrySurface(objectRegistry &obr, word lookupName="") const
Copy surface into registry.
Definition: sampledSurfaceRegister.C:51
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::sampledSurface::TypeName
TypeName("sampledSurface")
Runtime type information.
Foam::sampledSurface::withSurfaceFields
virtual bool withSurfaceFields() const
Can it sample surface-fields?
Definition: sampledSurface.C:158
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::sampledSurface::needsUpdate
virtual bool needsUpdate() const =0
Does the surface need an update?
Foam::List< word >
Foam::sampledSurface::removeSurfMesh
bool removeSurfMesh(word lookupName="") const
Remove surface from registry.
Definition: sampledSurfaceRegister.C:120
Foam::sampledSurface::iNew
PtrList read-construction helper.
Definition: sampledSurface.H:206
Foam::sampledSurface::name
const word & name() const
Name of surface.
Definition: sampledSurface.H:308
Foam::UList< label >
Foam::sampledSurface::~sampledSurface
virtual ~sampledSurface()
Destructor - calls clearGeom()
Definition: sampledSurface.C:139
surfaceFieldsFwd.H
Foam::sampledSurface::getSurfMesh
surfMesh * getSurfMesh(word lookupName="") const
Get surface from registry if available.
Definition: sampledSurfaceRegister.C:86
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:55
Foam::sampledSurface::print
virtual void print(Ostream &os) const
Print information.
Definition: sampledSurface.C:214
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:302
Foam::sampledSurface::update
virtual bool update()=0
Update the surface as required.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
sampledSurfaceTemplates.C
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
Foam::sampledSurface::sampledSurface
sampledSurface(const word &name, std::nullptr_t)
Construct null.
Definition: sampledSurface.C:94
Foam::sampledSurface::Cf
virtual const vectorField & Cf() const =0
Face centres.
Foam::sampledSurface::storeSurfMeshField
bool storeSurfMeshField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values, word lookupName="") const
Copy/store sampled Face field onto surfMesh (if it exists)
Definition: sampledSurfaceTemplates.C:172
autoPtr.H
Foam::sampledSurface::storeSurfMesh
surfMesh * storeSurfMesh(word lookupName="") const
Copy surface into registry.
Definition: sampledSurfaceRegister.C:97