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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::distanceSurface
29
30Description
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
38Usage
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 proximityFaces;
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 name | 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 Topology/Filtering (for zero-distance only).
87 These represent different ways to tackle the "ragged edge" problem.
88
89 - \c none :
90 No filtering
91
92 - \c proximityFaces or \c proximity (post-filter):
93 Checks the resulting faces against the original search surface
94 and rejects faces with a distance greater than \c absProximity.
95
96 - \c proximityRegions (post-filter):
97 Checks the distance of the resulting faces against the original
98 search surface. Filters based on the area-weighted distance
99 of each topologically connected region.
100 If the area-weighted distance of a region is greater than
101 \c absProximity, the entire region is rejected.
102
103 - \c largestRegion (pre-filter):
104 The cut cells are checked for topological connectivity and the
105 region with the most number of cut cells is retained.
106
107 - \c nearestPoints (pre-filter):
108 The cut cells split into regions, the regions closest to the
109 user-defined points are retained.
110 Uses \c maxDistance for additional control.
111 .
112
113Note
114 For distance = 0, some special adjustments.
115 - Always signed (ignoring the input value).
116 - Use normal distance from surface (for better treatment of open edges).
117 - Additional checks for open surfaces edges are used to limit the extend
118 of resulting distance surface.
119 The resulting surface elements will, however, contain partial cell
120 coverage. NB: Not applicable if the \c point isoMethod is used.
121
122The keyword \c cell (bool value) which was use in 1906 and earlier to switch
123between point/cell algorithms is now ignored (2020-12).
124
125Changed default algorithm from cell to topo (2020-12).
126
127SourceFiles
128 distanceSurface.C
129 distanceSurfaceFilter.C
130
131\*---------------------------------------------------------------------------*/
132
133#ifndef Foam_distanceSurface_H
134#define Foam_distanceSurface_H
135
136#include "sampledSurface.H"
137#include "searchableSurface.H"
138#include "isoSurfaceBase.H"
139#include "pointIndexHit.H"
140
141// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142
143namespace Foam
144{
145
146/*---------------------------------------------------------------------------*\
147 Class distanceSurface Declaration
148\*---------------------------------------------------------------------------*/
149
150class distanceSurface
151{
152 // Data Types
153
154 //- The type of pre/post face-filtering
155 enum class topologyFilterType : uint8_t
156 {
157 NONE,
158 LARGEST_REGION,
159 NEAREST_POINTS,
160 PROXIMITY_REGIONS,
161 PROXIMITY_FACES,
162 PROXIMITY = PROXIMITY_FACES
163 };
164
165 //- Names for the topology filter
166 static const Enum<topologyFilterType> topoFilterNames_;
167
168
169 // Private Data
170
171 //- Reference to mesh
172 const polyMesh& mesh_;
173
174 //- Searchable surface
175 const autoPtr<searchableSurface> geometryPtr_;
176
177 //- Distance value
178 const scalar distance_;
179
180 //- Distance is zero. Implies signed and additional optimizations
181 const bool withZeroDistance_;
182
183 //- Use signed distance
184 const bool withSignDistance_;
185
186 //- Parameters for iso-surface (algorithm, filter, mergeTol, etc)
187 isoSurfaceParams isoParams_;
188
189 //- Optional topology face-filtering
190 topologyFilterType topoFilter_;
191
192 //- Points for nearest-points segmentation
193 pointField nearestPoints_;
194
195 //- Max search distance squared (for nearestPoints)
196 scalar maxDistanceSqr_;
197
198 //- Max distance for proximity check (post-filtering)
199 scalar absProximity_;
200
201 //- Distance to cell centres
202 autoPtr<volScalarField> cellDistancePtr_;
203
204 //- Distance to points
205 scalarField pointDistance_;
206
207
208 // Sampling geometry. Directly stored or via an iso-surface (ALGO_POINT)
210 //- The extracted surface (direct storage)
211 mutable meshedSurface surface_;
212
213 //- For every face the original cell in mesh (direct storage)
214 mutable labelList meshCells_;
215
216 //- Extracted iso-surface, for interpolators
217 mutable autoPtr<isoSurfaceBase> isoSurfacePtr_;
218
219
220 // Private Member Functions
221
222 //- Absolute distances from hit points
223 // Hit/miss checks have been done elsewhere.
224 static inline void calcAbsoluteDistance
225 (
227 const pointField& points,
228 const List<pointIndexHit>& nearest
229 )
230 {
231 forAll(nearest, i)
232 {
233 distance[i] = Foam::mag(points[i] - nearest[i].point());
234 }
235 }
236
237
238protected:
239
240 // Protected Member Functions
241
242 //- Is currently backed by an isoSurfacePtr_
243 bool hasIsoSurface() const
244 {
245 return bool(isoSurfacePtr_);
246 }
247
248 //- Interpolate volume field onto surface points
249 template<class Type>
250 tmp<Field<Type>> isoSurfaceInterpolate
251 (
252 const VolumeField<Type>& cellValues,
253 const Field<Type>& pointValues
254 ) const
255 {
256 if (isoSurfacePtr_)
257 {
258 return isoSurfacePtr_->interpolate(cellValues, pointValues);
259 }
260
261 return nullptr;
262 }
263
264
265 // Private Member Functions
266
267 //- Re-filter the blocked cells based on the anticipated cuts
268 // Uses a lightweight variant of cutting.
270 (
271 bitSet& ignoreCells,
272 const isoSurfaceBase& isoContext
273 ) const;
274
275 //- Prepare blockedFaces for region split
276 bitSet filterPrepareRegionSplit(const bitSet& ignoreCells) const;
277
278 //- Keep region with the most cuts (after region split)
279 void filterKeepLargestRegion(bitSet& ignoreCells) const;
280
281 //- Keep region(s) closest to the nearest points
282 void filterKeepNearestRegions(bitSet& ignoreCells) const;
283
284 //- Remove region(s) that have far faces
285 void filterRegionProximity(bitSet& ignoreCells) const;
286
287 //- Adjust extracted iso-surface to remove far faces
288 void filterFaceProximity();
289
290
291public:
292
293 //- Runtime type information
294 TypeName("distanceSurface");
295
296
297 // Constructors
298
299 //- Construct from dictionary
301 (
302 const word& defaultSurfaceName,
303 const polyMesh& mesh,
304 const dictionary& dict
305 );
306
307 //- Construct from components with zero-distanced
310 const polyMesh& mesh,
311 const word& surfaceType,
312 const word& surfaceName,
313 const isoSurfaceParams& params = isoSurfaceParams(),
314 const bool interpolate = false
315 );
316
317 //- Construct from components
319 (
320 const polyMesh& mesh,
321 const bool interpolate,
322 const word& surfaceType,
323 const word& surfaceName,
324 const scalar distance,
325 const bool useSignedDistance,
326 const isoSurfaceParams& params = isoSurfaceParams()
327 );
328
330 (
331 const polyMesh& mesh,
332 const bool interpolate,
334 const scalar distance,
335 const bool useSignedDistance,
336 const isoSurfaceParams& params = isoSurfaceParams()
337 );
338
339
340 //- Destructor
341 virtual ~distanceSurface() = default;
342
343
344 // Member Functions
345
346 //- Create/recreate the distance surface
347 void createGeometry();
348
349 //- The name of the underlying searchableSurface
350 const word& surfaceName() const
351 {
352 return geometryPtr_->name();
354
355 //- The distance to the underlying searchableSurface
356 scalar distance() const noexcept
357 {
358 return distance_;
359 }
360
361 //- The underlying surface
362 const meshedSurface& surface() const
363 {
364 if (isoSurfacePtr_)
365 {
366 return *isoSurfacePtr_;
367 }
368 return surface_;
369 }
370
371 //- The underlying surface
373 {
374 if (isoSurfacePtr_)
375 {
376 return *isoSurfacePtr_;
377 }
378 return surface_;
379 }
380
381 //- For each face, the original cell in mesh
382 const labelList& meshCells() const
383 {
384 if (isoSurfacePtr_)
385 {
386 return isoSurfacePtr_->meshCells();
387 }
388 return meshCells_;
389 }
390
391 //- For each face, the original cell in mesh
393 {
394 if (isoSurfacePtr_)
395 {
396 return isoSurfacePtr_->meshCells();
397 }
398 return meshCells_;
399 }
401
402 // Output
403
404 //- Print information
405 void print(Ostream& os, int level=0) const;
406};
407
408
409// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410
411} // End namespace Foam
412
413// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
414
415#endif
416
417// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Generic GeometricField class.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A surface defined by a distance from an input searchable surface. Uses an iso-surface algorithm (cell...
void filterFaceProximity()
Adjust extracted iso-surface to remove far faces.
void createGeometry()
Create/recreate the distance surface.
meshedSurface & surface()
The underlying surface.
bitSet filterPrepareRegionSplit(const bitSet &ignoreCells) const
Prepare blockedFaces for region split.
void filterRegionProximity(bitSet &ignoreCells) const
Remove region(s) that have far faces.
virtual ~distanceSurface()=default
Destructor.
scalar distance() const noexcept
The distance to the underlying searchableSurface.
distanceSurface(const word &defaultSurfaceName, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
void print(Ostream &os, int level=0) const
Print information.
void filterKeepNearestRegions(bitSet &ignoreCells) const
Keep region(s) closest to the nearest points.
const meshedSurface & surface() const
The underlying surface.
labelList & meshCells()
For each face, the original cell in mesh.
bool refineBlockedCells(bitSet &ignoreCells, const isoSurfaceBase &isoContext) const
Re-filter the blocked cells based on the anticipated cuts.
void filterKeepLargestRegion(bitSet &ignoreCells) const
Keep region with the most cuts (after region split)
const labelList & meshCells() const
For each face, the original cell in mesh.
const word & surfaceName() const
The name of the underlying searchableSurface.
bool hasIsoSurface() const
Is currently backed by an isoSurfacePtr_.
tmp< Field< Type > > isoSurfaceInterpolate(const VolumeField< Type > &cellValues, const Field< Type > &pointValues) const
Interpolate volume field onto surface points.
TypeName("distanceSurface")
Runtime type information.
Low-level components common to various iso-surface algorithms.
Preferences for controlling iso-surface algorithms.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
bool
Definition: EEqn.H:20
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
@ NONE
No type, or default initialized type.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
vector point
Point is a vector.
Definition: point.H:43
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
MeshedSurface< face > meshedSurface
const direction noexcept
Definition: Scalar.H:223
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73