isoSurfacePoint.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::isoSurfacePoint
29 
30 Description
31  A surface formed by the iso value.
32  After "Regularised Marching Tetrahedra: improved iso-surface extraction",
33  G.M. Treece, R.W. Prager and A.H. Gee.
34 
35  Note:
36  - does tets without using cell centres/cell values. Not tested.
37  - regularisation can create duplicate triangles/non-manifold surfaces.
38  Current handling of those is bit ad-hoc for now and not perfect.
39  - regularisation does not do boundary points so as to preserve the
40  boundary perfectly.
41  - uses geometric merge with fraction of bounding box as distance.
42  - triangles can be between two cell centres so constant sampling
43  does not make sense.
44  - on empty patches behaves like zero gradient.
45  - does not do 2D correctly, creates non-flat iso surface.
46  - on processor boundaries might two overlapping (identical) triangles
47  (one from either side)
48 
49  The handling on coupled patches is a bit complex. All fields
50  (values and coordinates) get rewritten so
51  - empty patches get zerogradient (value) and facecentre (coordinates)
52  - separated processor patch faces get interpolate (value) and facecentre
53  (coordinates). (this is already the default for cyclics)
54  - non-separated processor patch faces keep opposite value and cell centre
55 
56  Now the triangle generation on non-separated processor patch faces
57  can use the neighbouring value. Any separated processor face or cyclic
58  face gets handled just like any boundary face.
59 
60 SourceFiles
61  isoSurfacePoint.C
62  isoSurfacePointTemplates.C
63 
64 \*---------------------------------------------------------------------------*/
65 
66 #ifndef isoSurfacePoint_H
67 #define isoSurfacePoint_H
68 
69 #include "bitSet.H"
70 #include "volFields.H"
71 #include "slicedVolFields.H"
72 #include "isoSurfaceBase.H"
73 
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
76 namespace Foam
77 {
78 
79 // Forward Declarations
80 class plane;
81 class treeBoundBox;
82 class triSurface;
83 
84 /*---------------------------------------------------------------------------*\
85  Class isoSurfacePoint Declaration
86 \*---------------------------------------------------------------------------*/
87 
88 class isoSurfacePoint
89 :
90  public isoSurfaceBase
91 {
92  // Private Data
93 
94  //- Cell values.
95  //- Input volScalarField with separated coupled patches rewritten
97 
98  //- When to merge points
99  const scalar mergeDistance_;
100 
101  //- Whether face might be cut
102  List<cutType> faceCutType_;
103 
104  //- Whether cell might be cut
105  List<cutType> cellCutType_;
106 
107  //- Estimated number of cut cells
108  label nCutCells_;
109 
110  //- For every unmerged triangle point the point in the triSurface
111  labelList triPointMergeMap_;
112 
113  //- triSurface points that have weighted interpolation
114  DynamicList<label> interpolatedPoints_;
115 
116  //- corresponding original, unmerged points
117  DynamicList<FixedList<label, 3>> interpolatedOldPoints_;
118 
119  //- corresponding weights
120  DynamicList<FixedList<scalar, 3>> interpolationWeights_;
121 
122 
123  // Private Member Functions
124 
125  // Point synchronisation
126 
127  //- Does tensor differ (to within mergeTolerance) from identity
128  bool noTransform(const tensor& tt) const;
129 
130  //- Per face whether is collocated
131  static bitSet collocatedFaces(const coupledPolyPatch& cpp);
132 
133  //- Synchronise points on all non-separated coupled patches
134  void syncUnseparatedPoints
135  (
136  pointField& collapsedPoint,
137  const point& nullValue
138  ) const;
139 
140 
141  //- Get location of iso value as fraction inbetween s0,s1
142  scalar isoFraction
143  (
144  const scalar s0,
145  const scalar s1
146  ) const;
147 
148  //- Check if any edge of a face is cut
149  bool isEdgeOfFaceCut
150  (
151  const scalarField& pVals,
152  const face& f,
153  const bool ownLower,
154  const bool neiLower
155  ) const;
156 
157  //- Get neighbour value and position.
158  void getNeighbour
159  (
160  const labelList& boundaryRegion,
161  const volVectorField& meshC,
162  const volScalarField& cVals,
163  const label celli,
164  const label facei,
165  scalar& nbrValue,
166  point& nbrPoint
167  ) const;
168 
169  //- Determine for every face/cell whether it (possibly) generates
170  // triangles.
171  void calcCutTypes
172  (
173  const labelList& boundaryRegion,
174  const volVectorField& meshC,
175  const volScalarField& cVals,
176  const scalarField& pVals
177  );
178 
179  static point calcCentre(const triSurface&);
180 
181  //- Determine per cc whether all near cuts can be snapped to single
182  // point.
183  void calcSnappedCc
184  (
185  const labelList& boundaryRegion,
186  const volVectorField& meshC,
187  const volScalarField& cVals,
188  const scalarField& pVals,
189  DynamicList<point>& snappedPoints,
190  labelList& snappedCc
191  ) const;
192 
193  //- Determine per point whether all near cuts can be snapped to single
194  // point.
195  void calcSnappedPoint
196  (
197  const bitSet& isBoundaryPoint,
198  const labelList& boundaryRegion,
199  const volVectorField& meshC,
200  const volScalarField& cVals,
201  const scalarField& pVals,
202  DynamicList<point>& snappedPoints,
203  labelList& snappedPoint
204  ) const;
205 
206 
207  //- Return input field with coupled (and empty) patch values rewritten
208  template<class Type>
211  adaptPatchFields
212  (
214  ) const;
215 
216  //- Generate single point by interpolation or snapping
217  template<class Type>
218  Type generatePoint
219  (
220  const scalar s0,
221  const Type& p0,
222  const bool hasSnap0,
223  const Type& snapP0,
224 
225  const scalar s1,
226  const Type& p1,
227  const bool hasSnap1,
228  const Type& snapP1
229  ) const;
230 
231 
232  //- Note: cannot use simpler isoSurfaceCell::generateTriPoints since
233  // the need here to sometimes pass in remote 'snappedPoints'
234  template<class Type>
235  void generateTriPoints
236  (
237  const scalar s0,
238  const Type& p0,
239  const bool hasSnap0,
240  const Type& snapP0,
241 
242  const scalar s1,
243  const Type& p1,
244  const bool hasSnap1,
245  const Type& snapP1,
246 
247  const scalar s2,
248  const Type& p2,
249  const bool hasSnap2,
250  const Type& snapP2,
251 
252  const scalar s3,
253  const Type& p3,
254  const bool hasSnap3,
255  const Type& snapP3,
256 
257  DynamicList<Type>& pts
258  ) const;
259 
260  template<class Type>
261  label generateFaceTriPoints
262  (
263  const volScalarField& cVals,
264  const scalarField& pVals,
265 
267  const Field<Type>& pCoords,
268 
269  const DynamicList<Type>& snappedPoints,
270  const labelList& snappedCc,
271  const labelList& snappedPoint,
272  const label facei,
273 
274  const scalar neiVal,
275  const Type& neiPt,
276  const bool hasNeiSnap,
277  const Type& neiSnapPt,
278 
280  DynamicList<label>& triMeshCells
281  ) const;
282 
283  template<class Type>
284  void generateTriPoints
285  (
286  const volScalarField& cVals,
287  const scalarField& pVals,
288 
290  const Field<Type>& pCoords,
291 
292  const DynamicList<Type>& snappedPoints,
293  const labelList& snappedCc,
294  const labelList& snappedPoint,
295 
297  DynamicList<label>& triMeshCells
298  ) const;
299 
300  template<class Type>
301  static tmp<Field<Type>> interpolate
302  (
303  const label nPoints,
304  const labelList& triPointMergeMap,
305  const labelList& interpolatedPoints,
306  const List<FixedList<label, 3>>& interpolatedOldPoints,
308  const DynamicList<Type>& unmergedValues
309  );
310 
311  triSurface stitchTriPoints
312  (
313  const bool checkDuplicates,
314  const List<point>& triPoints,
315  labelList& triPointReverseMap, // unmerged to merged point
316  labelList& triMap // merged to unmerged triangle
317  ) const;
318 
319  //- Trim triangle to planes
320  static void trimToPlanes
321  (
322  const PtrList<plane>& planes,
323  const triPointRef& tri,
324  DynamicList<point>& newTriPoints
325  );
326 
327  //- Trim all triangles to box
328  static void trimToBox
329  (
330  const treeBoundBox& bb,
332  DynamicList<label>& triMeshCells
333  );
334 
335  //- Trim all triangles to box. Determine interpolation
336  // for existing and new points
337  static void trimToBox
338  (
339  const treeBoundBox& bb,
341  DynamicList<label>& triMap,
342  labelList& triPointMap,
343  labelList& interpolatedPoints,
344  List<FixedList<label, 3>>& interpolatedOldPoints,
346  );
347 
348  static triSurface subsetMesh
349  (
350  const triSurface&,
351  const labelList& newToOldFaces,
352  labelList& oldToNewPoints,
353  labelList& newToOldPoints
354  );
355 
356 
357  //- Interpolates cCoords, pCoords.
358  // Uses the references to the original fields used to create the
359  // iso surface.
360  template<class Type>
361  tmp<Field<Type>> interpolateTemplate
362  (
364  const Field<Type>& pCoords
365  ) const;
366 
367 
368 public:
369 
370  //- Declare friendship to share some functionality
371  friend class isoSurfaceCell;
372  friend class isoSurfaceTopo;
373 
374 
375  //- Runtime type information
376  TypeName("isoSurfacePoint");
377 
378 
379  // Constructors
380 
381  //- Construct from cell values and point values.
382  // Uses boundaryField for boundary values.
383  // Holds reference to cellIsoVals and pointIsoVals.
384  //
385  // Control parameters include
386  // - bounds optional bounding box for trimming
387  // - mergeTol fraction of mesh bounding box for merging points
389  (
390  const volScalarField& cellValues,
391  const scalarField& pointValues,
392  const scalar iso,
393  const isoSurfaceParams& params = isoSurfaceParams(),
394  const bitSet& ignoreCells = bitSet()
395  );
396 
397 
398  //- Destructor
399  virtual ~isoSurfacePoint() = default;
400 
401 
402  // Member Functions
403 
404  // Sampling
405 
411 };
412 
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 } // End namespace Foam
417 
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 
420 #ifdef NoRepository
421  #include "isoSurfacePointTemplates.C"
422 #endif
423 
424 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
425 
426 #endif
427 
428 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFields.H
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::isoSurfacePoint::TypeName
TypeName("isoSurfacePoint")
Runtime type information.
Foam::isoSurfacePoint::isoSurfacePoint
isoSurfacePoint(const volScalarField &cellValues, const scalarField &pointValues, const scalar iso, const isoSurfaceParams &params=isoSurfaceParams(), const bitSet &ignoreCells=bitSet())
Construct from cell values and point values.
Definition: isoSurfacePoint.C:1336
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
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList< label >
slicedVolFields.H
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:50
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
declareIsoSurfaceInterpolateMethod
#define declareIsoSurfaceInterpolateMethod(Type)
Definition: isoSurfaceBase.H:291
Foam::boundaryRegion
The boundaryRegion persistent data saved as a Map<dictionary>.
Definition: boundaryRegion.H:72
Foam::coupledPolyPatch
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Definition: coupledPolyPatch.H:53
bitSet.H
Foam::isoSurfacePoint::~isoSurfacePoint
virtual ~isoSurfacePoint()=default
Destructor.
isoSurfaceBase.H
Foam::isoSurfaceCell
A surface formed by the iso value. After "Polygonising A Scalar Field Using Tetrahedrons",...
Definition: isoSurfaceCell.H:66
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::isoSurfacePoint
A surface formed by the iso value. After "Regularised Marching Tetrahedra: improved iso-surface extra...
Definition: isoSurfacePoint.H:87
Foam::triangle
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:61
Foam::triPoints
Triangle storage. Null constructable (unfortunately triangle<point, point> is not)
Definition: triPoints.H:52
Foam::Field< vector >
Foam::isoSurfaceParams::isoSurfaceParams
isoSurfaceParams(const algorithmType algo=algorithmType::ALGO_DEFAULT, const filterType filter=filterType::DIAGCELL) noexcept
Default construct, or with specified algorithm.
Definition: isoSurfaceParams.C:133
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
fld
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;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::interpolationWeights
Abstract base class for interpolating in 1D.
Definition: interpolationWeights.H:58
Foam::isoSurfaceParams
Preferences for controlling iso-surface algorithms.
Definition: isoSurfaceParams.H:91
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
isoSurfacePointTemplates.C
Foam::SphericalTensor< scalar >
Foam::slicedFvPatchField
Specialization of fvPatchField which creates the underlying fvPatchField as a slice of the given comp...
Definition: slicedFvPatchField.H:64
Foam::isoSurfaceBase::cellValues
const scalarField & cellValues() const noexcept
The mesh cell values used for creating the iso-surface.
Definition: isoSurfaceBase.H:220
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List< cutType >
Foam::FixedList< label, 3 >
Foam::SlicedGeometricField
Specialization of GeometricField which holds slices of given complete fields in a form that they act ...
Definition: slicedSurfaceFieldsFwd.H:58
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
p0
const volScalarField & p0
Definition: EEqn.H:36
Foam::isoSurfaceTopo
Marching tet iso surface algorithm with optional filtering to keep only points originating from mesh ...
Definition: isoSurfaceTopo.H:58
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::isoSurfaceBase::pointValues
const scalarField & pointValues() const noexcept
The mesh point values used for creating the iso-surface.
Definition: isoSurfaceBase.H:226