source: issm/trunk/src/c/objects/Bamg/Mesh.h@ 5095

Last change on this file since 5095 was 5095, checked in by Mathieu Morlighem, 15 years ago

moved Triangles class to Mesh (makes more sense)

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