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  //- List of element ids/order of the original surface,
344  //- when hasFaceIds is true.
345  virtual const labelList& originalIds() const
346  {
347  return labelList::null();
348  }
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
357  polySurface* getRegistrySurface
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>
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  // Specialized surfMesh storage (optional)
407 
408  //- Get surface from registry if available.
409  // \param lookupName Optional lookup name, use surface name if empty
410  // \return surface or nullptr
411  surfMesh* getSurfMesh(word lookupName = "") const;
412 
413  //- Copy surface into registry.
414  // \param lookupName Optional lookup name, use surface name if empty
415  // \return surface or nullptr it surface should not be stored
416  surfMesh* storeSurfMesh(word lookupName = "") const;
417 
418  //- Remove surface from registry.
419  // \param lookupName Optional lookup name, use surface name if empty
420  // \return True if surface existed and was removed
421  bool removeSurfMesh(word lookupName = "") const;
422 
423  //- Copy/store sampled Face field onto surfMesh (if it exists)
424  template<class Type, class GeoMeshType>
425  bool storeSurfMeshField
426  (
427  const word& fieldName,
428  const dimensionSet& dims,
429  const Field<Type>& values,
430  word lookupName = ""
431  ) const;
432 
433  //- Move/store sampled Face field onto surfMesh (if it exists)
434  template<class Type, class GeoMeshType>
435  bool storeSurfMeshField
436  (
437  const word& fieldName,
438  const dimensionSet& dims,
440  word lookupName = ""
441  ) const;
442 
443 
444  // Sample (faces)
445 
446  //- Sample volume field onto surface faces
447  virtual tmp<scalarField> sample
448  (
449  const interpolation<scalar>& sampler
450  ) const = 0;
451 
452  //- Sample volume field onto surface faces
453  virtual tmp<vectorField> sample
454  (
455  const interpolation<vector>& sampler
456  ) const = 0;
457 
458  //- Sample volume field onto surface faces
460  (
461  const interpolation<sphericalTensor>& sampler
462  ) const = 0;
463 
464  //- Sample volume field onto surface faces
466  (
467  const interpolation<symmTensor>& sampler
468  ) const = 0;
469 
470  //- Sample volume field onto surface faces
471  virtual tmp<tensorField> sample
472  (
473  const interpolation<tensor>& sampler
474  ) const = 0;
475 
476 
477  //- Can it sample surface-fields?
478  virtual bool withSurfaceFields() const;
479 
480 
481  //- Sample surface field onto surface
482  virtual tmp<scalarField> sample
483  (
484  const surfaceScalarField& sField
485  ) const;
486 
487  //- Sample surface field onto surface
488  virtual tmp<vectorField> sample
489  (
490  const surfaceVectorField& sField
491  ) const;
492 
493  //- Sample surface field onto surface
495  (
496  const surfaceSphericalTensorField& sField
497  ) const;
498 
499  //- Sample surface field onto surface
501  (
502  const surfaceSymmTensorField& sField
503  ) const;
504 
505  //- Sample surface field onto surface
506  virtual tmp<tensorField> sample
507  (
508  const surfaceTensorField& sField
509  ) const;
510 
511 
512  // Interpolate (points)
513 
514  //- Interpolate volume field onto surface points
516  (
517  const interpolation<scalar>& interpolator
518  ) const = 0;
519 
520  //- Interpolate volume field onto surface points
522  (
523  const interpolation<vector>& interpolator
524  ) const = 0;
525 
526  //- Interpolate volume field onto surface points
528  (
529  const interpolation<sphericalTensor>& interpolator
530  ) const = 0;
531 
532  //- Interpolate volume field onto surface points
534  (
535  const interpolation<symmTensor>& interpolator
536  ) const = 0;
537 
538  //- Interpolate volume field onto surface points
540  (
541  const interpolation<tensor>& interpolator
542  ) const = 0;
543 
544 
545  // Edit
546 
547  //- Rename
548  virtual void rename(const word& newName)
549  {
550  name_ = newName;
551  }
552 
553 
554  // Write
555 
556  //- Print information
557  virtual void print(Ostream& os) const;
558 };
559 
560 
561 // Global Operators
562 
563 //- Ostream operator
564 Ostream& operator<<(Ostream& os, const sampledSurface& s);
565 
566 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
567 
568 } // End namespace Foam
569 
570 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
571 
572 #ifdef NoRepository
573  #include "sampledSurfaceTemplates.C"
574 #endif
575 
576 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
577 
578 #endif
579 
580 // ************************************************************************* //
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::List< label >::null
static const List< label > & null()
Return a null List.
Definition: ListI.H:108
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:57
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.
Definition: surfMesh.H:64
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.
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:419
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:572
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::originalIds
virtual const labelList & originalIds() const
Definition: sampledSurface.H:369
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::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
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