CV2D.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 | Copyright (C) 2013-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::CV2D
26 
27 Description
28  Conformal-Voronoi 2D automatic mesher with grid or read initial points
29  and point position relaxation with optional "squarification".
30 
31  There are a substantial number of options to this mesher read from
32  CV2DMesherDict file e.g.:
33 
34  // Min cell size used in tolerances when inserting points for
35  // boundary conforming.
36  // Also used to as the grid spacing usind in insertGrid.
37  minCellSize 0.05;
38 
39  // Feature angle used to inser feature points
40  // 0 = all features, 180 = no features
41  featureAngle 45;
42 
43  // Maximum quadrant angle allowed at a concave corner before
44  // additional "mitering" lines are added
45  maxQuadAngle 110;
46 
47  // Should the mesh be square-dominated or of unbiased hexagons
48  squares yes;
49 
50  // Near-wall region where cells are aligned with the wall specified as a
51  // number of cell layers
52  nearWallAlignedDist 3;
53 
54  // Chose if the cell orientation should relax during the iterations
55  // or remain fixed to the x-y directions
56  relaxOrientation no;
57 
58  // Insert near-boundary point mirror or point-pairs
59  insertSurfaceNearestPointPairs yes;
60 
61  // Mirror near-boundary points rather than insert point-pairs
62  mirrorPoints no;
63 
64  // Insert point-pairs vor dual-cell vertices very near the surface
65  insertSurfaceNearPointPairs yes;
66 
67  // Choose if to randomise the initial grid created by insertGrid.
68  randomiseInitialGrid yes;
69 
70  // Perturbation fraction, 1 = cell-size.
71  randomPurturbation 0.1;
72 
73  // Number of relaxation iterations.
74  nIterations 5;
75 
76  // Relaxation factor at the start of the iteration sequence.
77  // 0.5 is a sensible maximum and < 0.2 converges better.
78  relaxationFactorStart 0.8;
79 
80  // Relaxation factor at the end of the iteration sequence.
81  // Should be <= relaxationFactorStart
82  relaxationFactorEnd 0;
83 
84  writeInitialTriangulation no;
85  writeFeatureTriangulation no;
86  writeNearestTriangulation no;
87  writeInsertedPointPairs no;
88  writeFinalTriangulation yes;
89 
90  // Maximum number of iterations used in boundaryConform.
91  maxBoundaryConformingIter 5;
92 
93  minEdgeLenCoeff 0.5;
94  maxNotchLenCoeff 0.3;
95  minNearPointDistCoeff 0.25;
96  ppDistCoeff 0.05;
97 
98 SourceFiles
99  CGALTriangulation2Ddefs.H
100  indexedVertex.H
101  indexedFace.H
102  CV2DI.H
103  CV2D.C
104  CV2DIO.C
105  tolerances.C
106  controls.C
107  insertFeaturePoints.C
108  insertSurfaceNearestPointPairs.C
109  insertSurfaceNearPointPairs.C
110  insertBoundaryConformPointPairs.C
111 
112 \*---------------------------------------------------------------------------*/
113 
114 #ifndef CV2D_H
115 #define CV2D_H
117 #define CGAL_INEXACT
118 #define CGAL_HIERARCHY
119 
120 #include "CGALTriangulation2Ddefs.H"
121 #include "Time.H"
122 #include "point2DFieldFwd.H"
123 #include "dictionary.H"
124 #include "Switch.H"
125 #include "PackedBoolList.H"
126 #include "EdgeMap.H"
127 #include "cv2DControls.H"
128 #include "tolerances.H"
129 #include "meshTools.H"
130 #include "triSurface.H"
131 #include "searchableSurfaces.H"
132 #include "conformationSurfaces.H"
133 #include "relaxationModel.H"
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 namespace Foam
139 {
140 
141 /*---------------------------------------------------------------------------*\
142  Class CV2D Declaration
143 \*---------------------------------------------------------------------------*/
145 class CV2D
146 :
147  public Delaunay
148 {
149 
150 private:
151 
152  // Private data
153 
154  //- The time registry of the application
155  const Time& runTime_;
156 
157  mutable Random rndGen_;
158 
159  //- The surface to mesh
160  //const querySurface& qSurf_;
161  //- All geometry of the meshing process, including surfaces to be
162  // conformed to and those to be used for refinement
163  searchableSurfaces allGeometry_;
164 
165  conformationSurfaces qSurf_;
166 
167  //- Meshing controls
168  cv2DControls controls_;
169 
170  //- The cell size control object
171  cellSizeAndAlignmentControls cellSizeControl_;
172 
173  //- Relaxation coefficient model. Runtime selectable.
174  autoPtr<relaxationModel> relaxationModel_;
175 
176  //- z-level
177  scalar z_;
178 
179  //- Keep track of the start of the internal points
180  label startOfInternalPoints_;
181 
182  //- Keep track of the start of the surface point-pairs
183  label startOfSurfacePointPairs_;
184 
185  //- Keep track of the boundary conform point-pairs
186  // stored after the insertion of the surface point-pairs in case
187  // the boundary conform function is called more than once without
188  // removing and insertin the surface point-pairs
189  label startOfBoundaryConformPointPairs_;
190 
191  //- Store the feature points
192  std::list<Vb> featurePoints_;
193 
194  //- Temporary storage for a dual-cell
195  static const label maxNvert = 20;
196  mutable point2D vertices[maxNvert+1];
197  mutable vector2D edges[maxNvert+1];
198 
199 
200  // Private Member Functions
201 
202  //- Disallow default bitwise copy construct
203  CV2D(const CV2D&);
204 
205  //- Disallow default bitwise assignment
206  void operator=(const CV2D&);
207 
208 
209  //- Insert point and return it's index
210  inline label insertPoint
211  (
212  const point2D& pt,
213  const label type
214  );
215 
216  //- Insert point and return it's index
217  inline label insertPoint
218  (
219  const point2D& pt,
220  const label index,
221  const label type
222  );
223 
224  inline label insertPoint
225  (
226  const Point& p,
227  const label index,
228  const label type
229  );
230 
231  inline bool insertMirrorPoint
232  (
233  const point2D& nearSurfPt,
234  const point2D& surfPt
235  );
236 
237  //- Insert a point-pair at a distance ppDist either side of
238  // surface point point surfPt in the direction n
239  inline void insertPointPair
240  (
241  const scalar mirrorDist,
242  const point2D& surfPt,
243  const vector2D& n
244  );
245 
246  //- Create the initial mesh from the bounding-box
247  void insertBoundingBox();
248 
249  //- Check if a point is within a line.
250  bool on2DLine(const point2D& p, const linePointRef& line);
251 
252  //- Insert point groups at the feature points.
253  void insertFeaturePoints();
254 
255  //- Re-insert point groups at the feature points.
256  void reinsertFeaturePoints();
257 
258  //- Insert point-pairs at the given set of points using the surface
259  // normals corresponding to the given set of surface triangles
260  // and write the inserted point locations to the given file.
261  void insertPointPairs
262  (
263  const DynamicList<point2D>& nearSurfacePoints,
264  const DynamicList<point2D>& surfacePoints,
265  const DynamicList<label>& surfaceTris,
266  const DynamicList<label>& surfaceHits,
267  const fileName fName
268  );
269 
270  //- Check to see if dual cell specified by given vertex iterator
271  // intersects the boundary and hence reqires a point-pair.
272  bool dualCellSurfaceIntersection
273  (
274  const Triangulation::Finite_vertices_iterator& vit
275  ) const;
276 
277  //- Insert point-pairs at the nearest points on the surface to the
278  // control vertex of dual-cells which intersect the boundary in order
279  // to provide a boundary-layer mesh.
280  // NB: This is not guaranteed to close the boundary
281  void insertSurfaceNearestPointPairs();
282 
283  //- Insert point-pairs at small dual-cell edges on the surface in order
284  // to improve the boundary-layer mesh generated by
285  // insertSurfaceNearestPointPairs.
286  void insertSurfaceNearPointPairs();
287 
288  //- Insert point-pair and correcting the Finite_vertices_iterator
289  // to account for the additional vertices
290  void insertPointPair
291  (
292  Triangulation::Finite_vertices_iterator& vit,
293  const point2D& p,
294  const label trii,
295  const label hitSurface
296  );
297 
298  //- Insert point-pair at the best intersection point between the lines
299  // from the dual-cell real centroid and it's vertices and the surface.
300  bool insertPointPairAtIntersection
301  (
302  Triangulation::Finite_vertices_iterator& vit,
303  const point2D& defVert,
304  const point2D vertices[],
305  const scalar maxProtSize
306  );
307 
308  //- Insert point-pairs corresponding to dual-cells which intersect
309  // the boundary surface
310  label insertBoundaryConformPointPairs(const fileName& fName);
311 
312  void markNearBoundaryPoints();
313 
314  //- Restore the Delaunay contraint
315  void fast_restore_Delaunay(Vertex_handle vh);
316 
317  // Flip operations used by fast_restore_Delaunay
318  void external_flip(Face_handle& f, int i);
319  bool internal_flip(Face_handle& f, int i);
320 
321  //- Write all the faces and all the triangles at a particular stage.
322  void write(const word& stage) const;
323 
324 
325 public:
326 
327  //- Runtime type information
328  ClassName("CV2D");
329 
330 
331  // Constructors
332 
333  //- Construct for given surface
334  CV2D(const Time& runTime, const dictionary& controlDict);
335 
336 
337  //- Destructor
338  ~CV2D();
339 
340 
341  // Member Functions
342 
343  // Access
344 
345  inline const cv2DControls& meshControls() const;
346 
347 
348  // Conversion functions between point2D, point and Point
349 
350  inline const point2D& toPoint2D(const point&) const;
351  inline const point2DField toPoint2D(const pointField&) const;
352  inline point toPoint3D(const point2D&) const;
353 
354  #ifdef CGAL_INEXACT
355  typedef const point2D& point2DFromPoint;
356  typedef const Point& PointFromPoint2D;
357  #else
358  typedef point2D point2DFromPoint;
359  typedef Point PointFromPoint2D;
360  #endif
361 
362  inline point2DFromPoint toPoint2D(const Point&) const;
363  inline PointFromPoint2D toPoint(const point2D&) const;
364  inline point toPoint3D(const Point&) const;
365 
366 
367  // Point insertion
368 
369  //- Create the initial mesh from the given internal points.
370  // Points must be inside the boundary by at least nearness
371  // otherwise they are ignored.
372  void insertPoints
373  (
374  const point2DField& points,
375  const scalar nearness
376  );
377 
378  //- Create the initial mesh from the internal points in the given
379  // file. Points outside the geometry are ignored.
380  void insertPoints(const fileName& pointFileName);
381 
382  //- Create the initial mesh as a regular grid of points.
383  // Points outside the geometry are ignored.
384  void insertGrid();
385 
386  //- Insert all surface point-pairs from
387  // insertSurfaceNearestPointPairs and
388  // findIntersectionForOutsideCentroid
390 
391  //- Insert point-pairs where there are protrusions into
392  // or out of the surface
393  void boundaryConform();
394 
395 
396  // Point removal
397 
398  //- Remove the point-pairs introduced by insertSurfacePointPairs
399  // and boundaryConform
401 
402 
403  // Point motion
404 
405  inline void movePoint(const Vertex_handle& vh, const Point& P);
406 
407  //- Move the internal points to the given new locations and update
408  // the triangulation to ensure it is Delaunay
409  // void moveInternalPoints(const point2DField& newPoints);
410 
411  //- Calculate the displacements to create the new points
412  void newPoints();
413 
414  //- Extract patch names and sizes.
415  void extractPatches
416  (
418  labelList& patchSizes,
419  EdgeMap<label>& mapEdgesRegion,
420  EdgeMap<label>& indirectPatchEdge
421  ) const;
422 
423 
424  // Write
425 
426  //- Write internal points to .obj file
427  void writePoints(const fileName& fName, bool internalOnly) const;
428 
429  //- Write triangles as .obj file
430  void writeTriangles(const fileName& fName, bool internalOnly) const;
431 
432  //- Write dual faces as .obj file
433  void writeFaces(const fileName& fName, bool internalOnly) const;
434 
435  //- Calculates dual points (circumcentres of tets) and faces
436  // (point-cell walk of tets).
437  // Returns:
438  // - dualPoints (in triangle ordering)
439  // - dualFaces (compacted)
440  void calcDual
441  (
442  point2DField& dualPoints,
443  faceList& dualFaces,
445  labelList& patchSizes,
446  EdgeMap<label>& mapEdgesRegion,
447  EdgeMap<label>& indirectPatchEdge
448  ) const;
449 
450  //- Write patch
451  void writePatch(const fileName& fName) const;
452 
453  void write() const;
454 };
455 
456 
457 inline bool boundaryTriangle(const CV2D::Face_handle fc);
458 inline bool outsideTriangle(const CV2D::Face_handle fc);
459 
460 
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 
463 } // End namespace Foam
464 
465 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
466 
467 #include "CV2DI.H"
468 
469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
470 
471 #endif
472 
473 // ************************************************************************* //
CGAL::Delaunay_triangulation_3< K, Tds, CompactLocator > Delaunay
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A line primitive.
Definition: line.H:56
A class for handling file names.
Definition: fileName.H:69
void writePatch(const fileName &fName) const
Write patch.
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
~CV2D()
Destructor.
void insertSurfacePointPairs()
Insert all surface point-pairs from.
point toPoint3D(const point2D &) const
Definition: CV2DI.H:141
bool outsideTriangle(const CV2D::Face_handle fc)
Definition: CV2DI.H:216
const cv2DControls & meshControls() const
Definition: CV2DI.H:118
void newPoints()
Move the internal points to the given new locations and update.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const point2D & toPoint2D(const point &) const
Definition: CV2DI.H:124
void insertGrid()
Create the initial mesh as a regular grid of points.
void writeFaces(const fileName &fName, bool internalOnly) const
Write dual faces as .obj file.
PointFromPoint2D toPoint(const point2D &) const
Definition: CV2DI.H:168
const pointField & points
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
wordList patchNames(nPatches)
Container for searchableSurfaces.
Simple random number generator.
Definition: Random.H:49
const point2D & point2DFromPoint
Definition: CV2D.H:354
void calcDual(point2DField &dualPoints, faceList &dualFaces, wordList &patchNames, labelList &patchSizes, EdgeMap< label > &mapEdgesRegion, EdgeMap< label > &indirectPatchEdge) const
Calculates dual points (circumcentres of tets) and faces.
void insertPoints(const point2DField &points, const scalar nearness)
Create the initial mesh from the given internal points.
void write() const
labelList f(nPoints)
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:485
Controls for the 2D CV mesh generator.
Definition: cv2DControls.H:58
void extractPatches(wordList &patchNames, labelList &patchSizes, EdgeMap< label > &mapEdgesRegion, EdgeMap< label > &indirectPatchEdge) const
Extract patch names and sizes.
void writeTriangles(const fileName &fName, bool internalOnly) const
Write triangles as .obj file.
ClassName("CV2D")
Runtime type information.
void movePoint(const Vertex_handle &vh, const Point &P)
Definition: CV2DI.H:182
label n
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition: CV2D.H:144
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
bool boundaryTriangle(const CV2D::Face_handle fc)
Definition: CV2DI.H:205
CGAL data structures used for 2D Delaunay meshing.
volScalarField & p
const Point & PointFromPoint2D
Definition: CV2D.H:355
void removeSurfacePointPairs()
Remove the point-pairs introduced by insertSurfacePointPairs.
void boundaryConform()
Insert point-pairs where there are protrusions into.
Namespace for OpenFOAM.
void writePoints(const fileName &fName, bool internalOnly) const
Write internal points to .obj file.