distanceSurface.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-2020 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::distanceSurface
29 
30 Description
31  A surface defined by a distance from an input searchable surface.
32  Uses an iso-surface algorithm (cell, topo, point) for constructing the
33  distance surface.
34 
35  For a zero-distance surface, it performs additional checks and supports
36  filtering to handle the surface boundaries.
37 
38 Usage
39  Example of function object partial specification:
40  \verbatim
41  surfaces
42  {
43  surface1
44  {
45  type distanceSurface;
46  surfaceType triSurfaceMesh;
47  surfaceName something.obj;
48  topology proximity;
49  }
50 
51  surface2
52  {
53  type distanceSurface;
54  surfaceType triSurfaceMesh;
55  surfaceName other.obj;
56 
57  topology nearestPoints;
58  nearestPoints
59  (
60  (0 0 0)
61  (10 10 0)
62  );
63 
64  // Max search distance for nearestPoints
65  maxDistance 0.005;
66  }
67  }
68  \endverbatim
69 
70  Dictionary controls:
71  \table
72  Property | Description | Required | Default
73  distance | distance from surface | no | 0
74  signed | Use sign when distance is positive | no | true
75  isoMethod | Iso-algorithm (cell/topo/point) | no | default
76  regularise | Face simplification (enum or bool) | no | true
77  bounds | Limit with bounding box | no |
78  surfaceType | Type of surface | yes |
79  surfaceName | Name of surface in \c triSurface/ | no | dict name
80  topology | Topology filter (none/largestRegion/nearestPoints/proximity) | no | none
81  nearestPoints | Points for point-based segmentation | no |
82  maxDistance | Max search distance for nearestPoints | no | GREAT
83  absProximity | Max proximity of face centres | no | 1e-5
84  \endtable
85 
86  Filtering (for zero-distance only)
87 
88  - \c largestRegion (pre-filter):
89  The cut cells are checked for topological connectivity and the
90  region with the most number of cut cells is retained.
91  This handles the "ragged" edge problem.
92 
93  - \c nearestPoints (pre-filter):
94  The cut cells split into regions, the regions closest to the
95  user-defined points are retained.
96  Uses \c maxDistance for additional control.
97 
98  - \c proximity (post-filter):
99  Checks the resulting faces against the original search surface
100  and rejects faces with a distance greater than \c absProximity.
101  .
102 
103 Note
104  For distance = 0, some special adjustments.
105  - Always signed (ignoring the input value).
106  - Use normal distance from surface (for better treatment of open edges).
107  - Additional checks for open surfaces edges are used to limit the extend
108  of resulting distance surface.
109  The resulting surface elements will, however, contain partial cell
110  coverage. NB: Not applicable if the \c point isoMethod is used.
111 
112 The keyword \c cell (bool value) which was use in 1906 and earlier to switch
113 between point/cell algorithms is now ignored (2020-12).
114 
115 Changed default algorithm from cell to topo (2020-12).
116 
117 SourceFiles
118  distanceSurface.C
119 
120 \*---------------------------------------------------------------------------*/
121 
122 #ifndef distanceSurface_H
123 #define distanceSurface_H
124 
125 #include "sampledSurface.H"
126 #include "searchableSurface.H"
127 #include "isoSurfaceBase.H"
128 #include "pointIndexHit.H"
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 namespace Foam
133 {
134 
135 /*---------------------------------------------------------------------------*\
136  Class distanceSurface Declaration
137 \*---------------------------------------------------------------------------*/
138 
139 class distanceSurface
140 {
141  // Data Types
142 
143  //- The type of pre/post face-filtering
144  enum class topologyFilterType : uint8_t
145  {
146  NONE,
147  LARGEST_REGION,
148  NEAREST_POINTS,
149  PROXIMITY
150  };
151 
152  //- Names for the topology filter
153  static const Enum<topologyFilterType> topoFilterNames_;
154 
155 
156  // Private Data
157 
158  //- Reference to mesh
159  const polyMesh& mesh_;
160 
161  //- Searchable surface
162  const autoPtr<searchableSurface> geometryPtr_;
163 
164  //- Distance value
165  const scalar distance_;
166 
167  //- Distance is zero. Implies signed and additional optimizations
168  const bool withZeroDistance_;
169 
170  //- Use signed distance
171  const bool withSignDistance_;
172 
173  //- Parameters for iso-surface (algorithm, filter, mergeTol, etc)
174  isoSurfaceParams isoParams_;
175 
176  //- Optional topology face-filtering
177  topologyFilterType topoFilter_;
178 
179  //- Points for nearest-points segmentation
180  pointField nearestPoints_;
181 
182  //- Max search distance squared (for nearestPoints)
183  scalar maxDistanceSqr_;
184 
185  //- Max distance for proximity check (post-filtering)
186  scalar absProximity_;
187 
188  //- Distance to cell centres
189  autoPtr<volScalarField> cellDistancePtr_;
190 
191  //- Distance to points
192  scalarField pointDistance_;
193 
194 
195  // Sampling geometry. Directly stored or via an iso-surface (ALGO_POINT)
196 
197  //- The extracted surface (direct storage)
198  mutable meshedSurface surface_;
199 
200  //- For every face the original cell in mesh (direct storage)
201  mutable labelList meshCells_;
202 
203  //- Extracted iso-surface, for interpolators
204  mutable autoPtr<isoSurfaceBase> isoSurfacePtr_;
205 
206 
207  // Private Member Functions
208 
209  //- Absolute distances from hit points
210  // Hit/miss checks have been done elsewhere.
211  static inline void calcAbsoluteDistance
212  (
214  const pointField& points,
215  const List<pointIndexHit>& nearest
216  )
217  {
218  forAll(nearest, i)
219  {
220  distance[i] = Foam::mag(points[i] - nearest[i].point());
221  }
222  }
223 
224 
225 protected:
226 
227  // Protected Member Functions
228 
229  //- Is currently backed by an isoSurfacePtr_
230  bool hasIsoSurface() const
231  {
232  return bool(isoSurfacePtr_);
233  }
234 
235  //- Interpolate volume field onto surface points
236  template<class Type>
237  tmp<Field<Type>> isoSurfaceInterpolate
238  (
239  const GeometricField<Type, fvPatchField, volMesh>& cellValues,
240  const Field<Type>& pointValues
241  ) const
242  {
243  if (isoSurfacePtr_)
244  {
245  return isoSurfacePtr_->interpolate(cellValues, pointValues);
246  }
247 
248  return nullptr;
249  }
250 
251 
252  // Private Member Functions
253 
254  //- Re-filter the blocked cells based on the anticipated cuts
255  // Uses a lightweight variant of cutting.
256  bool refineBlockedCells
257  (
258  bitSet& ignoreCells,
259  const isoSurfaceBase& isoContext
260  ) const;
261 
262  //- Prepare blockedFaces for region split
263  bitSet filterPrepareRegionSplit(const bitSet& ignoreCells) const;
264 
265  //- Adjust extracted iso-surface to remove far faces
266  void filterByProximity();
267 
268  //- Keep region with the most cuts (after region split)
269  void filterKeepLargestRegion(bitSet& ignoreCells) const;
270 
271  //- Keep region(s) closest to the nearest points
272  void filterKeepNearestRegions(bitSet& ignoreCells) const;
273 
274 
275 public:
276 
277  //- Runtime type information
278  TypeName("distanceSurface");
279 
280 
281  // Constructors
282 
283  //- Construct from dictionary
285  (
286  const word& defaultSurfaceName,
287  const polyMesh& mesh,
288  const dictionary& dict
289  );
290 
291  //- Construct from components with zero-distanced
293  (
294  const polyMesh& mesh,
295  const word& surfaceType,
296  const word& surfaceName,
298  const bool interpolate = false
299  );
300 
301  //- Construct from components
303  (
304  const polyMesh& mesh,
305  const bool interpolate,
306  const word& surfaceType,
307  const word& surfaceName,
308  const scalar distance,
309  const bool useSignedDistance,
310  const isoSurfaceParams& params = isoSurfaceParams()
311  );
312 
313 
314  //- Destructor
315  virtual ~distanceSurface() = default;
316 
317 
318  // Member Functions
319 
320  //- Create/recreate the distance surface
321  void createGeometry();
322 
323  //- The name of the underlying searchableSurface
324  const word& surfaceName() const
325  {
326  return geometryPtr_->name();
327  }
328 
329  //- The distance to the underlying searchableSurface
330  scalar distance() const noexcept
331  {
332  return distance_;
333  }
334 
335  //- The underlying surface
336  const meshedSurface& surface() const
337  {
338  if (isoSurfacePtr_)
339  {
340  return *isoSurfacePtr_;
341  }
342  return surface_;
343  }
344 
345  //- The underlying surface
347  {
348  if (isoSurfacePtr_)
349  {
350  return *isoSurfacePtr_;
351  }
352  return surface_;
353  }
354 
355  //- For each face, the original cell in mesh
356  const labelList& meshCells() const
357  {
358  if (isoSurfacePtr_)
359  {
360  return isoSurfacePtr_->meshCells();
361  }
362  return meshCells_;
363  }
364 
365  //- For each face, the original cell in mesh
367  {
368  if (isoSurfacePtr_)
369  {
370  return isoSurfacePtr_->meshCells();
371  }
372  return meshCells_;
373  }
374 
375 
376  // Output
377 
378  //- Print information
379  void print(Ostream& os) const;
380 };
381 
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 } // End namespace Foam
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #endif
390 
391 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
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
Foam::Enum< topologyFilterType >
pointIndexHit.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::isoSurfaceBase
Low-level components common to various iso-surface algorithms.
Definition: isoSurfaceBase.H:66
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
searchableSurface.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::distanceSurface::hasIsoSurface
bool hasIsoSurface() const
Is currently backed by an isoSurfacePtr_.
Definition: distanceSurface.H:289
Foam::distanceSurface::distanceSurface
distanceSurface(const word &defaultSurfaceName, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: distanceSurface.C:246
Foam::distanceSurface::filterKeepNearestRegions
void filterKeepNearestRegions(bitSet &ignoreCells) const
Keep region(s) closest to the nearest points.
Definition: distanceSurfaceFilter.C:186
Foam::distanceSurface::distance
scalar distance() const noexcept
The distance to the underlying searchableSurface.
Definition: distanceSurface.H:389
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
isoSurfaceBase.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::distanceSurface::refineBlockedCells
bool refineBlockedCells(bitSet &ignoreCells, const isoSurfaceBase &isoContext) const
Re-filter the blocked cells based on the anticipated cuts.
Definition: distanceSurfaceFilter.C:36
Foam::distanceSurface::isoSurfaceInterpolate
tmp< Field< Type > > isoSurfaceInterpolate(const GeometricField< Type, fvPatchField, volMesh > &cellValues, const Field< Type > &pointValues) const
Interpolate volume field onto surface points.
Definition: distanceSurface.H:297
Foam::distanceSurface
A surface defined by a distance from an input searchable surface. Uses an iso-surface algorithm (cell...
Definition: distanceSurface.H:198
Foam::parsing::errorType::NONE
No error encountered.
Foam::distanceSurface::meshCells
const labelList & meshCells() const
For each face, the original cell in mesh.
Definition: distanceSurface.H:415
Foam::interpolate
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
Foam::Field< vector >
sampledSurface.H
Foam::distanceSurface::surfaceName
const word & surfaceName() const
The name of the underlying searchableSurface.
Definition: distanceSurface.H:383
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
Foam::isoSurfaceParams
Preferences for controlling iso-surface algorithms.
Definition: isoSurfaceParams.H:91
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::distanceSurface::print
void print(Ostream &os) const
Print information.
Definition: distanceSurface.C:694
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::distanceSurface::~distanceSurface
virtual ~distanceSurface()=default
Destructor.
Foam::meshedSurface
MeshedSurface< face > meshedSurface
Definition: MeshedSurfacesFwd.H:41
Foam::distanceSurface::surface
const meshedSurface & surface() const
The underlying surface.
Definition: distanceSurface.H:395
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
bool
bool
Definition: EEqn.H:20
Foam::distanceSurface::filterKeepLargestRegion
void filterKeepLargestRegion(bitSet &ignoreCells) const
Keep region with the most cuts (after region split)
Definition: distanceSurfaceFilter.C:119
Foam::distanceSurface::meshCells
labelList & meshCells()
For each face, the original cell in mesh.
Definition: distanceSurface.H:425
Foam::distanceSurface::createGeometry
void createGeometry()
Create/recreate the distance surface.
Definition: distanceSurface.C:388
Foam::distanceSurface::TypeName
TypeName("distanceSurface")
Runtime type information.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::distanceSurface::filterPrepareRegionSplit
bitSet filterPrepareRegionSplit(const bitSet &ignoreCells) const
Prepare blockedFaces for region split.
Definition: distanceSurfaceFilter.C:68
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::distanceSurface::filterByProximity
void filterByProximity()
Adjust extracted iso-surface to remove far faces.
Definition: distanceSurfaceFilter.C:309
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::MeshedSurface< face >
Foam::distanceSurface::surface
meshedSurface & surface()
The underlying surface.
Definition: distanceSurface.H:405