sampledIsoSurface.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-2021 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::sampledIsoSurface
29 
30 Description
31  A sampledSurface defined by a surface of iso value.
32  It only recalculates the iso-surface if time changes.
33  To be used in sampleSurfaces / functionObjects.
34 
35 Usage
36  Example of function object partial specification:
37  \verbatim
38  surfaces
39  {
40  surface1
41  {
42  type isoSurface;
43  isoField T;
44  isoValue 373;
45  isoMethod topo;
46  }
47  }
48  \endverbatim
49 
50  Where the sub-entries comprise:
51  \table
52  Property | Description | Required | Default
53  type | isoSurface | yes |
54  isoField | field name for obtaining iso-surface | yes |
55  isoValue | value of iso-surface | yes |
56  isoValues| values for iso-surfaces | yes |
57  isoMethod | Iso-algorithm (cell/topo/point) | no | topo
58  average | cell values from averaged point values | no | false
59  bounds | limit with bounding box | no |
60  zone | limit to cell zone (name or regex) | no |
61  zones | limit to cell zones (names, regexs) | no |
62  simpleSubMesh | Simple sub-meshing in algorithm itself | no | false
63  exposedPatchName | name for zone subset | optional |
64  regularise | point snapping (bool or enum) | no | true
65  triangulate | triangulate faces (if regularise) | no | false
66  mergeTol | tolerance for merging points | no | 1e-6
67  \endtable
68 
69  Some options are limited to particular algorithms.
70  - triangulate is topo-only
71  - simpleSubMesh and multiple isoValues are not available for point.
72 
73 Note
74  For the isoMethod \b point should use a "cellPoint" sampleScheme
75  since the triangles generated with this algorithm span across cells.
76 
77 SourceFiles
78  sampledIsoSurface.C
79  sampledIsoSurfaceTemplates.C
80 
81 \*---------------------------------------------------------------------------*/
82 
83 #ifndef sampledIsoSurface_H
84 #define sampledIsoSurface_H
85 
86 #include "sampledSurface.H"
87 #include "fvMeshSubset.H"
88 #include "isoSurfaceBase.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 
95 /*---------------------------------------------------------------------------*\
96  Class sampledIsoSurface Declaration
97 \*---------------------------------------------------------------------------*/
98 
99 class sampledIsoSurface
100 :
101  public sampledSurface
102 {
103  // Private Data
104 
105  //- Field to get isoSurface of
106  const word isoField_;
107 
108  //- The iso-value(s)
109  List<scalar> isoValues_;
110 
111  //- Parameters (filtering etc) for iso-surface
112  isoSurfaceParams isoParams_;
113 
114  //- Whether to recalculate cell values as average of point values
115  bool average_;
116 
117  //- Whether to triangulate ALGO_TOPO (after filtering)
118  bool triangulate_;
119 
120  //- Use simple sub-meshing in algorithm itself
121  bool simpleSubMesh_;
122 
123  //- The zone or zones for the iso-surface
124  wordRes zoneNames_;
125 
126  //- For zones: patch to put exposed faces into
127  mutable word exposedPatchName_;
128 
129 
130  // Sampling geometry. Directly stored or via an iso-surface (ALGO_POINT)
131 
132  //- Time at last call, also track if surface needs an update
133  mutable label prevTimeIndex_;
134 
135  //- The extracted surface (direct storage)
136  mutable meshedSurface surface_;
137 
138  //- For every face the original cell in mesh (direct storage)
139  mutable labelList meshCells_;
140 
141  //- Extracted iso-surface, for interpolators
142  mutable autoPtr<isoSurfaceBase> isoSurfacePtr_;
143 
144 
145  // Mesh Subsetting
146 
147  //- Cached subMesh for (pre-)subset of cell zones
148  mutable autoPtr<fvMeshSubset> subMeshPtr_;
149 
150  //- Cached ignore cells for (post-)subset of cell zones
151  mutable autoPtr<bitSet> ignoreCellsPtr_;
152 
153 
154  // Fields
155 
156  //- Cached volfield
157  mutable autoPtr<volScalarField> storedVolFieldPtr_;
158  mutable const volScalarField* volFieldPtr_;
159 
160  //- Cached pointfield
161  mutable const pointScalarField* pointFieldPtr_;
162 
163 
164  // And on (pre-)subsetted mesh
165 
166  //- Cached volfield
167  mutable autoPtr<volScalarField> storedVolSubFieldPtr_;
168  mutable const volScalarField* volSubFieldPtr_;
169 
170  //- Cached pointfield
171  mutable const pointScalarField* pointSubFieldPtr_;
172 
173 
174  // Private Member Functions
175 
176  //- Get fields needed to recreate iso surface.
177  void getIsoFields() const;
178 
179  //- Collect iso-surfaces into a single surface (No point merging)
180  void combineSurfaces(PtrList<isoSurfaceBase>& isoSurfPtrs);
181 
182  //- Create iso surface (if time has changed)
183  // Do nothing (and return false) if no update was needed
184  bool updateGeometry() const;
185 
186  //- Sample volume field onto surface faces
187  template<class Type>
188  tmp<Field<Type>> sampleOnFaces
189  (
190  const interpolation<Type>& sampler
191  ) const;
192 
193  //- Interpolate volume field onto surface points
194  template<class Type>
195  tmp<Field<Type>> sampleOnPoints
196  (
197  const interpolation<Type>& interpolator
198  ) const;
199 
200  //- Use isoSurfacePtr_ for point interpolation
201  template<class Type>
202  tmp<Field<Type>> sampleOnIsoSurfacePoints
203  (
204  const interpolation<Type>& interpolator
205  ) const;
206 
207 
208 protected:
209 
210  // Protected Member Functions
211 
212  //- Is currently backed by an isoSurfacePtr_
213  bool hasIsoSurface() const
214  {
215  return bool(isoSurfacePtr_);
216  }
217 
218 
219 public:
220 
221  //- Runtime type information
222  TypeName("sampledIsoSurface");
223 
224 
225  // Constructors
226 
227  //- Construct from dictionary
229  (
230  const isoSurfaceParams& params,
231  const word& name,
232  const polyMesh& mesh,
233  const dictionary& dict
234  );
235 
236  //- Construct from dictionary
238  (
239  const word& name,
240  const polyMesh& mesh,
241  const dictionary& dict
242  );
243 
244 
245  //- Destructor
246  virtual ~sampledIsoSurface();
247 
248 
249  // Member Functions
250 
251  //- Does the surface need an update?
252  virtual bool needsUpdate() const;
253 
254  //- Mark the surface as needing an update.
255  // May also free up unneeded data.
256  // Return false if surface was already marked as expired.
257  virtual bool expire();
258 
259  //- Update the surface as required.
260  // Do nothing (and return false) if no update was needed
261  virtual bool update();
262 
263  //- The currently created surface geometry
264  const meshedSurface& surface() const
265  {
266  if (isoSurfacePtr_)
267  {
268  return *isoSurfacePtr_;
269  }
270  return surface_;
271  }
272 
273  //- For each face, the original cell in mesh
274  const labelList& meshCells() const
275  {
276  if (isoSurfacePtr_)
277  {
278  return isoSurfacePtr_->meshCells();
279  }
280  return meshCells_;
281  }
282 
283  //- Points of surface
284  virtual const pointField& points() const
285  {
286  return surface().points();
287  }
288 
289  //- Faces of surface
290  virtual const faceList& faces() const
291  {
292  return surface().surfFaces();
293  }
294 
295  //- Per-face zone/region information
296  virtual const labelList& zoneIds() const
297  {
298  return labelList::null();
299  }
300 
301  //- Face area magnitudes
302  virtual const vectorField& Sf() const
303  {
304  return surface().Sf();
305  }
306 
307  //- Face area magnitudes
308  virtual const scalarField& magSf() const
309  {
310  return surface().magSf();
311  }
312 
313  //- Face centres
314  virtual const vectorField& Cf() const
315  {
316  return surface().Cf();
317  }
318 
319 
320  // Sample
321 
322  //- Sample volume field onto surface faces
323  virtual tmp<scalarField> sample
324  (
325  const interpolation<scalar>& sampler
326  ) const;
327 
328  //- Sample volume field onto surface faces
329  virtual tmp<vectorField> sample
330  (
331  const interpolation<vector>& sampler
332  ) const;
333 
334  //- Sample volume field onto surface faces
335  virtual tmp<sphericalTensorField> sample
336  (
337  const interpolation<sphericalTensor>& sampler
338  ) const;
339 
340  //- Sample volume field onto surface faces
342  (
343  const interpolation<symmTensor>& sampler
344  ) const;
345 
346  //- Sample volume field onto surface faces
347  virtual tmp<tensorField> sample
348  (
349  const interpolation<tensor>& sampler
350  ) const;
351 
352 
353  // Interpolate
354 
355  //- Interpolate volume field onto surface points
357  (
358  const interpolation<scalar>& interpolator
359  ) const;
360 
361  //- Interpolate volume field onto surface points
363  (
364  const interpolation<vector>& interpolator
365  ) const;
366 
367  //- Interpolate volume field onto surface points
369  (
370  const interpolation<sphericalTensor>& interpolator
371  ) const;
372 
373  //- Interpolate volume field onto surface points
375  (
376  const interpolation<symmTensor>& interpolator
377  ) const;
378 
379  //- Interpolate volume field onto surface points
381  (
382  const interpolation<tensor>& interpolator
383  ) const;
384 
385 
386  // Output
387 
388  //- Print information
389  virtual void print(Ostream& os, int level=0) const;
390 };
391 
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 } // End namespace Foam
396 
397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
398 
399 #ifdef NoRepository
401 #endif
402 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 #endif
406 
407 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
sampledIsoSurfaceTemplates.C
Foam::List::null
static const List< T > & null()
Return a null List.
Definition: ListI.H:109
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::sampledIsoSurface::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledIsoSurface.C:722
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
fvMeshSubset.H
Foam::sampledIsoSurface::Cf
virtual const vectorField & Cf() const
Face centres.
Definition: sampledIsoSurface.H:388
Foam::MeshedSurface::Sf
const vectorField & Sf() const
Face area vectors (normals)
Definition: MeshedSurface.H:435
Foam::MeshedSurface::surfFaces
const List< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurface.H:413
Foam::sampledIsoSurface::points
virtual const pointField & points() const
Points of surface.
Definition: sampledIsoSurface.H:358
Foam::sampledIsoSurface::update
virtual bool update()
Update the surface as required.
Definition: sampledIsoSurface.C:752
Foam::sampledIsoSurface::hasIsoSurface
bool hasIsoSurface() const
Is currently backed by an isoSurfacePtr_.
Definition: sampledIsoSurface.H:287
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sampledIsoSurface::meshCells
const labelList & meshCells() const
For each face, the original cell in mesh.
Definition: sampledIsoSurface.H:348
isoSurfaceBase.H
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::sampledIsoSurface::surface
const meshedSurface & surface() const
The currently created surface geometry.
Definition: sampledIsoSurface.H:338
Foam::sampledIsoSurface::zoneIds
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: sampledIsoSurface.H:370
Foam::MeshedSurface::magSf
const scalarField & magSf() const
Face area magnitudes.
Definition: MeshedSurface.H:441
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::Field< vector >
Foam::sampledIsoSurface::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledIsoSurface.C:760
Foam::sampledIsoSurface::sampledIsoSurface
sampledIsoSurface(const isoSurfaceParams &params, const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: sampledIsoSurface.C:583
sampledSurface.H
Foam::sampledIsoSurface
A sampledSurface defined by a surface of iso value. It only recalculates the iso-surface if time chan...
Definition: sampledIsoSurface.H:173
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:96
Foam::sampledIsoSurface::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledIsoSurface.C:730
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:123
Foam::isoSurfaceParams
Preferences for controlling iso-surface algorithms.
Definition: isoSurfaceParams.H:107
os
OBJstream os(runTime.globalPath()/outputName)
Foam::sampledIsoSurface::magSf
virtual const scalarField & magSf() const
Face area magnitudes.
Definition: sampledIsoSurface.H:382
Foam::sampledSurface::name
const word & name() const noexcept
Name of surface.
Definition: sampledSurface.H:322
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::meshedSurface
MeshedSurface< face > meshedSurface
Definition: MeshedSurfacesFwd.H:41
Foam::sampledIsoSurface::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledIsoSurface.C:857
Foam::List< scalar >
Foam::sampledIsoSurface::faces
virtual const faceList & faces() const
Faces of surface.
Definition: sampledIsoSurface.H:364
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
bool
bool
Definition: EEqn.H:20
Foam::MeshedSurface::Cf
const vectorField & Cf() const
Face centres.
Definition: MeshedSurface.H:447
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::MeshedSurface< face >
Foam::sampledIsoSurface::~sampledIsoSurface
virtual ~sampledIsoSurface()
Destructor.
Definition: sampledIsoSurface.C:716
Foam::sampledIsoSurface::Sf
virtual const vectorField & Sf() const
Face area magnitudes.
Definition: sampledIsoSurface.H:376
Foam::sampledIsoSurface::TypeName
TypeName("sampledIsoSurface")
Runtime type information.
Foam::pointScalarField
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
Definition: pointFieldsFwd.H:56