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