1 | #ifndef _MESH_H_
|
---|
2 | #define _MESH_H_
|
---|
3 |
|
---|
4 | #include "./include.h"
|
---|
5 | #include "./BamgOpts.h"
|
---|
6 | #include "./BamgMesh.h"
|
---|
7 | #include "./BamgGeom.h"
|
---|
8 | #include "./Triangle.h"
|
---|
9 | #include "./VertexOnGeom.h"
|
---|
10 | #include "./VertexOnVertex.h"
|
---|
11 | #include "./VertexOnEdge.h"
|
---|
12 | #include "./ListofIntersectionTriangles.h"
|
---|
13 |
|
---|
14 | namespace bamg {
|
---|
15 |
|
---|
16 | //classes
|
---|
17 | class Geometry;
|
---|
18 | class CrackedEdge;
|
---|
19 | class QuadTree;
|
---|
20 | class SubDomain;
|
---|
21 |
|
---|
22 | class Mesh {
|
---|
23 |
|
---|
24 | public:
|
---|
25 |
|
---|
26 | Geometry & Gh; // Geometry
|
---|
27 | Mesh & BTh; // Background Mesh Bth== *this =>no background
|
---|
28 | BamgVertex *vertices;
|
---|
29 | Triangle *triangles;
|
---|
30 | Edge *edges;
|
---|
31 | QuadTree *quadtree;
|
---|
32 | BamgVertex **ordre;
|
---|
33 | SubDomain *subdomains;
|
---|
34 | long NbRef; // counter of ref on the this class if 0 we can delete
|
---|
35 | long maxnbv,maxnbt; // nombre max de sommets , de triangles
|
---|
36 | long nbv,nbt,nbe,nbq; // nb of vertices, of triangles, of edges and quadrilaterals
|
---|
37 | long nbsubdomains;
|
---|
38 | long nbtout; // Nb of oudeside triangle
|
---|
39 |
|
---|
40 | R2 pmin,pmax; // extrema
|
---|
41 | double coefIcoor; // coef to integer Icoor1;
|
---|
42 | ListofIntersectionTriangles lIntTria;
|
---|
43 |
|
---|
44 | long NbVerticesOnGeomVertex;
|
---|
45 | VertexOnGeom *VerticesOnGeomVertex;
|
---|
46 | long NbVerticesOnGeomEdge;
|
---|
47 | VertexOnGeom *VerticesOnGeomEdge;
|
---|
48 | long NbVertexOnBThVertex;
|
---|
49 | VertexOnVertex *VertexOnBThVertex;
|
---|
50 | long NbVertexOnBThEdge;
|
---|
51 | VertexOnEdge *VertexOnBThEdge;
|
---|
52 | long NbCrackedVertices;
|
---|
53 | long *CrackedVertices;
|
---|
54 | long NbCrackedEdges;
|
---|
55 | CrackedEdge *CrackedEdges;
|
---|
56 |
|
---|
57 | //Constructors/Destructors
|
---|
58 | Mesh(BamgGeom* bamggeom,BamgMesh* bamgmesh,BamgOpts* bamgopts);
|
---|
59 | Mesh(double* index,double* x,double* y,int nods,int nels);
|
---|
60 | Mesh(Mesh &,Geometry * pGh=0,Mesh* pBTh=0,long maxnbv_in=0 ); //copy operator
|
---|
61 | Mesh(const Mesh &,const int *flag,const int *bb,BamgOpts* bamgopts); // truncature
|
---|
62 | Mesh(long maxnbv,Mesh & BT,BamgOpts* bamgopts,int keepBackVertices=1);
|
---|
63 | Mesh(long maxnbv,Geometry & G,BamgOpts* bamgopts);
|
---|
64 | ~Mesh();
|
---|
65 |
|
---|
66 | //Operators
|
---|
67 | const BamgVertex &operator[](long i) const { return vertices[i]; };
|
---|
68 | BamgVertex &operator[](long i) { return vertices[i]; };
|
---|
69 | const Triangle &operator()(long i) const { return triangles[i]; };
|
---|
70 | Triangle &operator()(long i) { return triangles[i]; };
|
---|
71 |
|
---|
72 | //Methods
|
---|
73 | void SetIntCoor(const char * from =0);
|
---|
74 | double MinimalHmin();
|
---|
75 | double MaximalHmax();
|
---|
76 | I2 R2ToI2(const R2 & P) const;
|
---|
77 | R2 I2ToR2(const I2 & P) const;
|
---|
78 | void AddVertex(BamgVertex & s,Triangle * t,Icoor2 * =0) ;
|
---|
79 | void Insert();
|
---|
80 | void Echo(void);
|
---|
81 | void ForceBoundary();
|
---|
82 | void FindSubDomain(int OutSide=0);
|
---|
83 | long TriangleReferenceList(long*) const;
|
---|
84 | void TriangleIntNumbering(long* renumbering);
|
---|
85 | void ShowHistogram() const;
|
---|
86 | void CrackMesh(BamgOpts* bamgopts);
|
---|
87 | void ShowRegulaty() const;
|
---|
88 | void SmoothMetric(double raisonmax) ;
|
---|
89 | void BoundAnisotropy(double anisomax,double hminaniso= 1e-100) ;
|
---|
90 | void MaxSubDivision(double maxsubdiv);
|
---|
91 | Edge** MakeGeometricalEdgeToEdge();
|
---|
92 | long SplitInternalEdgeWithBorderVertices();
|
---|
93 | void MakeQuadrangles(double costheta);
|
---|
94 | int SplitElement(int choice);
|
---|
95 | void MakeQuadTree();
|
---|
96 | void NewPoints(Mesh &,BamgOpts* bamgopts,int KeepVertices=1);
|
---|
97 | long InsertNewPoints(long nbvold,long & NbTSwap) ;
|
---|
98 | void TrianglesRenumberBySubDomain(bool justcompress=false);
|
---|
99 | void VerticesRenumber(long * renu);
|
---|
100 | void SmoothingVertex(int =3,double=0.3);
|
---|
101 | Metric MetricAt (const R2 &) const;
|
---|
102 | GeometricalEdge* ProjectOnCurve( Edge & AB, BamgVertex & A, BamgVertex & B,double theta, BamgVertex & R,VertexOnEdge & BR,VertexOnGeom & GR);
|
---|
103 | long GetId(const Triangle & t) const;
|
---|
104 | long GetId(const Triangle * t) const;
|
---|
105 | long GetId(const BamgVertex & t) const;
|
---|
106 | long GetId(const BamgVertex * t) const;
|
---|
107 | long GetId(const Edge & t) const;
|
---|
108 | long GetId(const Edge * t) const;
|
---|
109 | long Number2(const Triangle * t) const;
|
---|
110 | BamgVertex* NearestVertex(Icoor1 i,Icoor1 j) ;
|
---|
111 | Triangle* TriangleFindFromCoord(const I2 & ,Icoor2 [3],Triangle *tstart=0) const;
|
---|
112 | void ReadMesh(double* index,double* x,double* y,int nods,int nels);
|
---|
113 | void ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);
|
---|
114 | void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts);
|
---|
115 | void ReadMetric(const BamgOpts* bamgopts);
|
---|
116 | void WriteMetric(BamgOpts* bamgopts);
|
---|
117 | void AddMetric(BamgOpts* bamgopts);
|
---|
118 | void BuildMetric0(BamgOpts* bamgopts);
|
---|
119 | void BuildMetric1(BamgOpts* bamgopts);
|
---|
120 | void AddGeometryMetric(BamgOpts* bamgopts);
|
---|
121 | int isCracked() const;
|
---|
122 | void BuildGeometryFromMesh(BamgOpts* bamgopts=NULL);
|
---|
123 | void ReconstructExistingMesh();
|
---|
124 |
|
---|
125 | //Inline methods
|
---|
126 | inline void CreateSingleVertexToTriangleConnectivity(){
|
---|
127 | for (int i=0;i<nbv;i++) vertices[i].vint=0, vertices[i].t=NULL;
|
---|
128 | for (int i=0;i<nbt;i++) triangles[i].SetSingleVertexToTriangleConnectivity();
|
---|
129 | }
|
---|
130 | inline void UnMarkUnSwapTriangle(){
|
---|
131 | for (int i=0;i<nbt;i++)
|
---|
132 | for(int j=0;j<3;j++)
|
---|
133 | triangles[i].SetUnMarkUnSwap(j);
|
---|
134 | }
|
---|
135 | inline void SetVertexFieldOn(){
|
---|
136 | for (int i=0;i<nbv;i++) vertices[i].GeometricalEdgeHook=NULL;
|
---|
137 | for (int j=0;j<NbVerticesOnGeomVertex;j++) VerticesOnGeomVertex[j].SetOn();
|
---|
138 | for (int k=0;k<NbVerticesOnGeomEdge;k++ ) VerticesOnGeomEdge[k].SetOn();
|
---|
139 | }
|
---|
140 | inline void SetVertexFieldOnBTh(){
|
---|
141 | for (int i=0;i<nbv;i++) vertices[i].GeometricalEdgeHook=NULL;
|
---|
142 | for (int j=0;j<NbVertexOnBThVertex;j++) VertexOnBThVertex[j].SetOnBTh();
|
---|
143 | for (int k=0;k<NbVertexOnBThEdge;k++ ) VertexOnBThEdge[k].SetOnBTh();
|
---|
144 | }
|
---|
145 |
|
---|
146 | private:
|
---|
147 | void TriangulateFromGeom1(long maxnbv,BamgOpts* bamgopts,int KeepVertices=1);// the real constructor mesh adaption
|
---|
148 | void TriangulateFromGeom0(long maxnbv,BamgOpts* bamgopts);// the real constructor mesh generator
|
---|
149 | void Init(long);
|
---|
150 | };
|
---|
151 |
|
---|
152 | /*Intermediary*/
|
---|
153 | AdjacentTriangle CloseBoundaryEdge(I2 ,Triangle *, double &,double &) ;
|
---|
154 | AdjacentTriangle CloseBoundaryEdgeV2(I2 A,Triangle *t, double &a,double &b);
|
---|
155 | void swap(Triangle *t1,short a1,
|
---|
156 | Triangle *t2,short a2,
|
---|
157 | BamgVertex *s1,BamgVertex *s2,Icoor2 det1,Icoor2 det2);
|
---|
158 | int SwapForForcingEdge(BamgVertex * & pva ,BamgVertex * & pvb ,
|
---|
159 | AdjacentTriangle & tt1,Icoor2 & dets1,
|
---|
160 | Icoor2 & detsa,Icoor2 & detsb, int & nbswap);
|
---|
161 | int ForceEdge(BamgVertex &a, BamgVertex & b,AdjacentTriangle & taret) ;
|
---|
162 | inline AdjacentTriangle Previous(const AdjacentTriangle & ta){
|
---|
163 | return AdjacentTriangle(ta.t,PreviousEdge[ta.a]);
|
---|
164 | }
|
---|
165 | inline AdjacentTriangle Next(const AdjacentTriangle & ta){
|
---|
166 | return AdjacentTriangle(ta.t,NextEdge[ta.a]);
|
---|
167 | }
|
---|
168 | inline AdjacentTriangle Adj(const AdjacentTriangle & a){
|
---|
169 | return a.Adj();
|
---|
170 | }
|
---|
171 | inline void Adj(GeometricalEdge * & on,int &i){
|
---|
172 | int j=i;i=on->AdjVertexNumber[i];on=on->Adj[j];
|
---|
173 | }
|
---|
174 | inline double qualite(const BamgVertex &va,const BamgVertex &vb,const BamgVertex &vc){
|
---|
175 | double ret;
|
---|
176 | I2 ia=va,ib=vb,ic=vc;
|
---|
177 | I2 ab=ib-ia,bc=ic-ib,ac=ic-ia;
|
---|
178 | Icoor2 deta=Det(ab,ac);
|
---|
179 | if (deta <=0) ret = -1;
|
---|
180 | else {
|
---|
181 | double a = sqrt((double) (ac,ac)),
|
---|
182 | b = sqrt((double) (bc,bc)),
|
---|
183 | c = sqrt((double) (ab,ab)),
|
---|
184 | p = a+b+c;
|
---|
185 | double h= Max(Max(a,b),c),ro=deta/p;
|
---|
186 | ret = ro/h;
|
---|
187 | }
|
---|
188 | return ret;
|
---|
189 | }
|
---|
190 |
|
---|
191 | }
|
---|
192 | #endif
|
---|