1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329 | #ifndef REFINE_H
#define REFINE_H
#include <bitset>
#include "meshkit/Mesh.hpp"
#include "meshkit/SwapEdges.hpp"
#include "meshkit/basic_math.hpp"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////
// MeshRefine2D:
// LongestEdgeRefine2D: ConsistencyRefine2D
// ObtuseRefine2D: ConsistencyRefine2D
// GradeRefine2D: ConsistencyRefine2D
// Refine2D14: ConsistencyRefine2D
// CentroidRefine2D
// DelaunayRefine2D
// Square3SubDivision
////////////////////////////////////////////////////////////////////////////////
//Class Refine, refines an existing triangulation. This class works for 2D cases
//or the parametric domain of 3D surface triangulation. The user need to provide
//which cells need to be refined. There could be many criteria for deviding the
//cell, so this is not part of the class.
//
//Input : Connection : Connectivity of the triangulation ( 1D array)
// : ParamCoords: parametric coordinates of the vertices.
// : markFace : Faces which are marked for refinement.
//
//Output: Connection :
// ParamCoords:
//
//If the user is working with 3D triangulated surface, it is assumed that he
//has some representation ( example NURBS ) from which he can calculate the
//physical Coordinates from the paramCoords. Again this is not the responsiblity
//of the class.
//
//------------------------------------------------------------------------------
//Number of Division : New Vertices : New Faces
//------------------------------------------------------------------------------
// 2 : 1 : 1
// 3 : 0 : 2
// 4 : 3 : 3
//------------------------------------------------------------------------------
// Default Number of Subdivisions is 2, which is conservative approach, but
// good at equalizing the aspect ratio with respect to neighbouring triangles.
//
// Programmer : Chaman Singh Verma
// Place : Argonne National Lab.
// Argonne, IL, USA
//
//
////////////////////////////////////////////////////////////////////////////////
//
/**
* REFINE AREA : Increase the density where grid cells have high area/volume
* REFINE ASPECT_RATIO : Increase the aspect Ratio
* REFINE CURVATURE : Create high density mesh near high curvature.
*/
namespace Jaal
{
enum RefinePolicy { CENTROID_PLACEMENT, CIRCUMCENTER_PLACEMENT, LONGEST_EDGE_BISECTION};
enum RefineObjective {REFINE_AREA, REFINE_ASPECT_RATIO, REFINE_CURVATURE};
///////////////////////////////////////////////////////////////////////////////
//! \brief 2D Mesh Refinement class.
class MeshRefine2D
{
public:
MeshRefine2D() { <--- Member variable 'MeshRefine2D::mesh' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::edgemap' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::numfacesRefined' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::desiredAspectRatio' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::desiredArea' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::desiredMinAngle' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::desiredMaxAngle' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::featureAngle' is not initialized in the constructor.<--- Member variable 'MeshRefine2D::maxAllowedCells' is not initialized in the constructor.
boundary_split_flag = 0;
numIterations = 1;
}
virtual ~MeshRefine2D() {}
void setMesh( Mesh *m ) { mesh = m; }
// void setGeometry( const iGeom_Instance &g ) { geom = g; }
void setBoundarySplitFlag( bool f ) { boundary_split_flag = f; }
const NodeSequence &getNewNodes() const { return insertedNodes; }
const FaceSequence &getNewFaces() const { return insertedFaces; }
size_t getNumFacesRefined() const { return numfacesRefined; }
virtual int execute() = 0;
virtual int initialize();
void setNumOfIterations( int i ) { numIterations = i; }
// Set Desired Mesh Quality
void setAspectRatio( double a ) { desiredAspectRatio = a; }
void setDesiredArea( double a ) { desiredArea = a; }
void setMinimumAngle( double a ) { desiredMinAngle = a; }
void setMaximumAngle( double a ) { desiredMaxAngle = a; }
void setFeatureAngle( double a ) { featureAngle = a; }
void setMaximumCells( size_t a ) { maxAllowedCells = a; }
protected:
Mesh *mesh;
class RefinedEdgeMap
{
public:
void clear();
bool hasEdge( Vertex *v1, Vertex *v2) const;
bool allow_edge_refinement( const Edge *edge) const;
Vertex* setVertexOnEdge(Vertex *v1, Vertex *v2);
Vertex* getVertexOnEdge(Vertex *v1, Vertex *v2) const;
bool boundary_split_flag;
// Get All the inserted vertices on the edges..
NodeSequence getInsertedNodes() const
{
NodeSequence result;
std::map<Vertex*, vector<RefinedEdge> >::const_iterator it;
for( it = refined_edges.begin(); it != refined_edges.end(); ++it)
{
const vector<RefinedEdge> &refedges = it->second;
for( size_t i = 0; i < refedges.size(); i++)
result.push_back( refedges[i].midVertex );
}
return result;
}
private:
struct RefinedEdge
{
Edge *edge;
Vertex *midVertex;
};
Edge* create_new_edge( const Vertex *v1, const Vertex *v2 );
std::map<Vertex*, vector<RefinedEdge> > refined_edges;
};
RefinedEdgeMap *edgemap;
FaceSequence insertedFaces;
NodeSequence hangingVertex, insertedNodes;
int numIterations;
bool boundary_split_flag;
size_t numfacesRefined;
double desiredAspectRatio, desiredArea;
double desiredMinAngle, desiredMaxAngle;
double featureAngle;
size_t maxAllowedCells;
int finalize();
void append_new_node( Vertex *v0 );
Face* append_new_triangle(Vertex *v0, Vertex *v1, Vertex *v2);
Face* append_new_quad(Vertex *v0, Vertex *v1, Vertex *v2, Vertex *v3);
void remove_it(Face *face) {
face->setStatus( MeshEntity::REMOVE);
}
};
///////////////////////////////////////////////////////////////////////////////
struct Sqrt3Refine2D : public MeshRefine2D
{
Sqrt3Refine2D() {}
Sqrt3Refine2D(Mesh *m) { setMesh(m); }
int execute();
};
///////////////////////////////////////////////////////////////////////////////
class CentroidRefine2D : public MeshRefine2D
{
public:
CentroidRefine2D() {}
CentroidRefine2D( Mesh *m ) { setMesh(m); }
void refine( Face *f ) {
atomicOp( f );
mesh->prune();
}
void refine( Mesh *m ) {
setMesh( m );
size_t nSize = mesh->getSize(2);
for( size_t i = 0; i < nSize; i++)
atomicOp( mesh->getFaceAt(i) );
mesh->prune();
}
int execute();
private:
int atomicOp( Face *f);
int refine_tri( Face *f);
int refine_quad( Face *f);
};
///////////////////////////////////////////////////////////////////////////////
class LongestEdgeRefine2D : public MeshRefine2D
{
public:
LongestEdgeRefine2D()
{
cutOffAspectRatio = 0.50;
}
LongestEdgeRefine2D(Mesh *m) {
setMesh(m);
cutOffAspectRatio = 0.50;
}
~LongestEdgeRefine2D() {}
void setCutOffAspectRatio(double asp) { cutOffAspectRatio = asp;}
int execute();
private:
double cutOffAspectRatio;
int atomicOp( const Face *face);
};
///////////////////////////////////////////////////////////////////////////////
class ConsistencyRefine2D : public MeshRefine2D
{
public:
ConsistencyRefine2D() { }
ConsistencyRefine2D( Mesh *m, RefinedEdgeMap *emap)
{ setMesh(m); edgemap = emap;}
~ConsistencyRefine2D() {}
int execute();
private:
bitset<3> edge0, edge1, edge2, bitvec;
int atomicOp( Face *f);
void refineEdge0(const Face *f);
void refineEdge1(const Face *f);
void refineEdge2(const Face *f);
void subDivideQuad2Tri( const NodeSequence &qnodes);
void makeConsistent1( Face *f );
void makeConsistent2( Face *f );
void makeConsistent3( Face *f );
void makeConsistent();
void checkFaceConsistency( Face *f);
};
///////////////////////////////////////////////////////////////////////////////
class Refine2D14 : public MeshRefine2D
{
public:
~Refine2D14() {}
int initialize() { return 0; }
int execute();
private:
int atomicOp( Face *f);
int refine_tri( Face *f);
int refine_quad( Face *f);
};
///////////////////////////////////////////////////////////////////////////////
struct DelaunayRefinement2D : public MeshRefine2D
{
~DelaunayRefinement2D() {}
int initialize();
int finalize();
int execute() {
return 0;
}
};
///////////////////////////////////////////////////////////////////////////////
class ObtuseRefine2D : public MeshRefine2D
{
public:
ObtuseRefine2D( ) { cutoffAngle = 90.0;}
void setCutOffAngle( double a ) { cutoffAngle = std::max(90.0, a); }
int initialize();
int execute();
private:
double cutoffAngle;
int atomicOp(const Face *f);
};
///////////////////////////////////////////////////////////////////////////////
class GradeRefine2D : public MeshRefine2D
{
public:
int initialize();
int finalize();
int execute();
private:
int atomicOp( const Vertex *v);
};
///////////////////////////////////////////////////////////////////////////////
}
#endif
|