Changeset 2810
- Timestamp:
- 01/12/10 16:08:25 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/Mesh2.cpp
r2805 r2810 4489 4489 } 4490 4490 4491 double QuadQuality(const Vertex & a,const Vertex &b,const Vertex &c,const Vertex &d) { 4492 // calcul de 4 angles -- 4493 R2 A((R2)a),B((R2)b),C((R2)c),D((R2)d); 4494 R2 AB(B-A),BC(C-B),CD(D-C),DA(A-D); 4495 // Move(A),Line(B),Line(C),Line(D),Line(A); 4496 const Metric & Ma = a; 4497 const Metric & Mb = b; 4498 const Metric & Mc = c; 4499 const Metric & Md = d; 4500 4501 double lAB=Norme2(AB); 4502 double lBC=Norme2(BC); 4503 double lCD=Norme2(CD); 4504 double lDA=Norme2(DA); 4505 AB /= lAB; BC /= lBC; CD /= lCD; DA /= lDA; 4506 // version aniso 4507 double cosDAB= Ma(DA,AB)/(Ma(DA)*Ma(AB)),sinDAB= Det(DA,AB); 4508 double cosABC= Mb(AB,BC)/(Mb(AB)*Mb(BC)),sinABC= Det(AB,BC); 4509 double cosBCD= Mc(BC,CD)/(Mc(BC)*Mc(CD)),sinBCD= Det(BC,CD); 4510 double cosCDA= Md(CD,DA)/(Md(CD)*Md(DA)),sinCDA= Det(CD,DA); 4511 double sinmin=Min(Min(sinDAB,sinABC),Min(sinBCD,sinCDA)); 4512 if (sinmin<=0) return sinmin; 4513 return 1.0-Max(Max(Abs(cosDAB),Abs(cosABC)),Max(Abs(cosBCD),Abs(cosCDA))); 4491 4514 } 4492 4515 4516 } 4517 -
issm/trunk/src/c/Bamgx/Mesh2.h
r2807 r2810 138 138 }; 139 139 #endif 140 141 //class from MeshGeom 142 class DoubleAndInt4 { 143 public: double q; Int4 i3j; 144 int operator<(DoubleAndInt4 a){return q > a.q;} 145 };// to sort by decroissant 146 template<class T> inline void HeapSort(T *c,long n){ 147 long l,j,r,i; 148 T crit; 149 c--; // on decale de 1 pour que le tableau commence a 1 150 if( n <= 1) return; 151 l = n/2 + 1; 152 r = n; 153 while (1) { // label 2 154 if(l <= 1 ) { // label 20 155 crit = c[r]; 156 c[r--] = c[1]; 157 if ( r == 1 ) { c[1]=crit; return;} 158 } else crit = c[--l]; 159 j=l; 160 while (1) {// label 4 161 i=j; 162 j=2*j; 163 if (j>r) {c[i]=crit;break;} // L8 -> G2 164 if ((j<r) && (c[j] < c[j+1])) j++; // L5 165 if (crit < c[j]) c[i]=c[j]; // L6+1 G4 166 else {c[i]=crit;break;} //L8 -> G2 167 } 168 } 169 } 170 //End from MeshGeom 171 140 172 141 173 class Direction { // -
issm/trunk/src/c/Bamgx/Triangles.cpp
r2809 r2810 889 889 } 890 890 /*}}}1*/ 891 /*FUNCTION Triangles::ProjectOnCurve{{{1*/ 892 GeometricalEdge* Triangles::ProjectOnCurve( Edge & BhAB, Vertex & vA, Vertex & vB, 893 Real8 theta,Vertex & R,VertexOnEdge & BR,VertexOnGeom & GR) { 894 void *pA=0,*pB=0; 895 Real8 tA=0,tB=0; 896 R2 A=vA,B=vB; 897 Vertex * pvA=&vA, * pvB=&vB; 898 if (vA.vint == IsVertexOnVertex) 899 { 900 // cout << " Debut vertex = " << BTh.Number(vA.onbv) ; 901 pA=vA.onbv; 902 } 903 else if (vA.vint == IsVertexOnEdge) 904 { 905 pA=vA.onbe->be; 906 tA=vA.onbe->abcisse; 907 // cout << " Debut edge = " << BTh.Number(vA.onbv) << " " << tA ; 908 909 } 910 else 911 {cerr << "ProjectOnCurve On Vertex " << BTh.Number(vA) << " " << endl; 912 cerr << " forget call to SetVertexFieldOnBTh" << endl; 913 MeshError(-1); 914 } 915 916 if (vB.vint == IsVertexOnVertex) 917 { 918 // cout << " Fin vertex = " << BTh.Number(vB.onbv) << endl; 919 pB=vB.onbv; 920 } 921 else if(vB.vint == IsVertexOnEdge) 922 { 923 pB=vB.onbe->be; 924 tB=vB.onbe->abcisse; 925 // cout << " Fin edge = " << BTh.Number(vB.onbe->be) << " " << tB ; 926 927 } 928 else 929 {cerr << "ProjectOnCurve On Vertex " << BTh.Number(vB) << " " << endl; 930 cerr << " forget call to SetVertexFieldOnBTh" << endl; 931 MeshError(-1); 932 } 933 Edge * e = &BhAB; 934 assert( pA && pB && e); 935 // be carefull the back ground edge e is on same geom edge 936 // of the initiale edge def by the 2 vertex A B; 937 assert(e>=BTh.edges && e<BTh.edges+BTh.nbe);// Is a background Mesh; 938 // walk on BTh edge 939 //assert(0 /* not finish ProjectOnCurve with BackGround Mesh*/); 940 // 1 first find a back ground edge contening the vertex A 941 // 2 walk n back gound boundary to find the final vertex B 942 943 if( vA.vint == IsVertexOnEdge) 944 { // find the start edge 945 e = vA.onbe->be; 946 947 } 948 else if (vB.vint == IsVertexOnEdge) 949 { 950 theta = 1-theta; 951 Exchange(tA,tB); 952 Exchange(pA,pB); 953 Exchange(pvA,pvB); 954 Exchange(A,B); 955 e = vB.onbe->be; 956 957 // cout << " EXCHANGE A et B) " << endl; 958 } 959 else 960 { // do the search by walking 961 assert(0 /* A FAIRE */); 962 } 963 964 // find the direction of walking with sens of edge and pA,PB; 965 R2 AB=B-A; 966 967 Real8 cosE01AB = (( (R2) (*e)[1] - (R2) (*e)[0] ) , AB); 968 int kkk=0; 969 int sens = (cosE01AB>0) ? 1 : 0; 970 971 // Real8 l=0; // length of the edge AB 972 Real8 abscisse = -1; 973 974 for (int cas=0;cas<2;cas++) 975 {// 2 times algo: 976 // 1 for computing the length l 977 // 2 for find the vertex 978 int iii; 979 Vertex *v0=pvA,*v1; 980 Edge *neee,*eee; 981 Real8 lg =0; // length of the curve 982 Real8 te0; 983 // we suppose take the curve's abcisse 984 // cout << kkk << " e = " << BTh.Number(e) << " v0= " 985 // << BTh.Number(v0) << " v1 = " << BTh.Number((*e)[sens]) << endl; 986 for ( eee=e,iii=sens,te0=tA; 987 eee && ((( void*) eee) != pB) && (( void*) (v1=&((*eee)[iii]))) != pB ; 988 neee = eee->adj[iii],iii = 1-neee->Intersection(*eee),eee = neee,v0=v1,te0=1-iii ) 989 { 990 // cout << kkk << " eee = " << BTh.Number(eee) << " v0= " 991 // << BTh.Number(v0) << " v1 = " << BTh.Number(v1) << endl; 992 993 assert(kkk++<100); 994 assert(eee); 995 Real8 lg0 = lg; 996 Real8 dp = LengthInterpole(v0->m,v1->m,(R2) *v1 - (R2) *v0); 997 lg += dp; 998 if (cas && abscisse <= lg) 999 { // ok we find the geom edge 1000 Real8 sss = (abscisse-lg0)/dp; 1001 Real8 thetab = te0*(1-sss)+ sss*iii; 1002 assert(thetab>=0 && thetab<=1); 1003 BR = VertexOnEdge(&R,eee,thetab); 1004 1005 // cout << Number(R) << " = " << thetab << " on " << BTh.Number(eee) 1006 // << " = " << R << endl; 1007 1008 return Gh.ProjectOnCurve(*eee,thetab,R,GR); 1009 1010 } 1011 } 1012 // we find the end 1013 if (v1 != pvB) 1014 { 1015 if (( void*) v1 == pB) 1016 tB = iii; 1017 1018 Real8 lg0 = lg; 1019 assert(eee); 1020 v1 = pvB; 1021 Real8 dp = LengthInterpole(v0->m,v1->m,(R2) *v1 - (R2) *v0); 1022 lg += dp; 1023 abscisse = lg*theta; 1024 if (abscisse <= lg && abscisse >= lg0 ) // small optimisation we know the lenght because end 1025 { // ok we find the geom edge 1026 Real8 sss = (abscisse-lg0)/dp; 1027 Real8 thetab = te0*(1-sss)+ sss*tB; 1028 assert(thetab>=0 && thetab<=1); 1029 BR = VertexOnEdge(&R,eee,thetab); 1030 1031 // cout << kkk << " eee = " << BTh.Number(eee) << " v0= " 1032 // << BTh.Number(v0) << " " << te0 1033 // << " v1 = " << BTh.Number(v1) << " " << tB << endl; 1034 1035 //out << Number(R) << " Opt = " << thetab << " on " << BTh.Number(eee) 1036 // << " = " << R << endl; 1037 1038 return Gh.ProjectOnCurve(*eee,thetab,R,GR); 1039 } 1040 } 1041 abscisse = lg*theta; 1042 1043 } 1044 cerr << " Big Bug" << endl; 1045 MeshError(678); 1046 return 0; // just for the compiler 1047 1048 } 1049 /*}}}1*/ 1050 /*FUNCTION Triangles::MakeQuadrangles{{{1*/ 1051 void Triangles::MakeQuadrangles(double costheta){ 1052 long int verbosity=0; 1053 1054 if (verbosity>2) 1055 cout << " -- MakeQuadrangles costheta = " << costheta << endl; 1056 if (verbosity>5) 1057 cout << " (in) Nb of Quadrilaterals = " << NbOfQuad 1058 << " Nb Of Triangles = " << nbt-NbOutT- NbOfQuad*2 1059 << " Nb of outside triangles = " << NbOutT << endl; 1060 1061 if (costheta >1) { 1062 if (verbosity>5) 1063 cout << " do nothing costheta >1 "<< endl; 1064 return;} 1065 1066 1067 Int4 nbqq = (nbt*3)/2; 1068 DoubleAndInt4 *qq = new DoubleAndInt4[nbqq]; 1069 1070 Int4 i,ij; 1071 int j; 1072 Int4 k=0; 1073 for (i=0;i<nbt;i++) 1074 for (j=0;j<3;j++) 1075 if ((qq[k].q=triangles[i].QualityQuad(j))>=costheta) 1076 qq[k++].i3j=i*3+j; 1077 // sort qq 1078 HeapSort(qq,k); 1079 1080 Int4 kk=0; 1081 for (ij=0;ij<k;ij++) 1082 { 1083 // cout << qq[ij].q << " " << endl; 1084 i=qq[ij].i3j/3; 1085 j=(int) (qq[ij].i3j%3); 1086 // optisamition no float computation 1087 if (triangles[i].QualityQuad(j,0) >=costheta) 1088 triangles[i].SetHidden(j),kk++; 1089 } 1090 NbOfQuad = kk; 1091 if (verbosity>2) 1092 { 1093 cout << " (out) Nb of Quadrilaterals = " << NbOfQuad 1094 << " Nb Of Triangles = " << nbt-NbOutT- NbOfQuad*2 1095 << " Nb of outside triangles = " << NbOutT << endl; 1096 } 1097 delete [] qq; 1098 } 1099 /*}}}1*/ 1100 /*FUNCTION Triangles::SplitElement{{{1*/ 1101 int Triangles::SplitElement(int choice){ 1102 long int verbosity=0; 1103 1104 Direction NoDirOfSearch; 1105 const int withBackground = &BTh != this && &BTh; 1106 if (verbosity>2) 1107 cout << " -- SplitElement " << (choice? " Q->4Q and T->4T " : " Q->4Q or T->3Q " ) << endl;; 1108 if (verbosity>5) 1109 cout << endl << " (in) Nb of Quadrilaterals = " << NbOfQuad 1110 << " Nb Of Triangles = " << nbt-NbOutT- NbOfQuad*2 1111 << " Nb of outside triangles = " << NbOutT << endl; 1112 1113 ReNumberingTheTriangleBySubDomain(); 1114 //int nswap =0; 1115 const Int4 nfortria( choice ? 4 : 6); 1116 if(withBackground) 1117 { 1118 BTh.SetVertexFieldOn(); 1119 SetVertexFieldOnBTh(); 1120 } 1121 else 1122 BTh.SetVertexFieldOn(); 1123 1124 Int4 newnbt=0,newnbv=0; 1125 Int4 * kedge = 0; 1126 Int4 newNbOfQuad=NbOfQuad; 1127 Int4 * ksplit= 0, * ksplitarray=0; 1128 Int4 kkk=0; 1129 int ret =0; 1130 if (nbvx<nbv+nbe) return 1;// 1131 Triangles * OCurrentTh= CurrentTh; 1132 CurrentTh = this; 1133 // 1) create the new points by spliting the internal edges 1134 // set the 1135 Int4 nbvold = nbv; 1136 Int4 nbtold = nbt; 1137 Int4 NbOutTold = NbOutT; 1138 Int4 NbEdgeOnGeom=0; 1139 Int4 i; 1140 1141 nbt = nbt - NbOutT; // remove all the the ouside triangles 1142 Int4 nbtsave = nbt; 1143 Triangle * lastT = triangles + nbt; 1144 for (i=0;i<nbe;i++) 1145 if(edges[i].on) NbEdgeOnGeom++; 1146 Int4 newnbe=nbe+nbe; 1147 // Int4 newNbVerticesOnGeomVertex=NbVerticesOnGeomVertex; 1148 Int4 newNbVerticesOnGeomEdge=NbVerticesOnGeomEdge+NbEdgeOnGeom; 1149 // Int4 newNbVertexOnBThVertex=NbVertexOnBThVertex; 1150 Int4 newNbVertexOnBThEdge=withBackground ? NbVertexOnBThEdge+NbEdgeOnGeom:0; 1151 1152 // do allocation for pointeur to the geometry and background 1153 VertexOnGeom * newVerticesOnGeomEdge = new VertexOnGeom[newNbVerticesOnGeomEdge]; 1154 VertexOnEdge *newVertexOnBThEdge = newNbVertexOnBThEdge ? new VertexOnEdge[newNbVertexOnBThEdge]:0; 1155 if (NbVerticesOnGeomEdge) 1156 memcpy(newVerticesOnGeomEdge,VerticesOnGeomEdge,sizeof(VertexOnGeom)*NbVerticesOnGeomEdge); 1157 if (NbVertexOnBThEdge) 1158 memcpy(newVertexOnBThEdge,VertexOnBThEdge,sizeof(VertexOnEdge)*NbVertexOnBThEdge); 1159 Edge *newedges = new Edge [newnbe]; 1160 // memcpy(newedges,edges,sizeof(Edge)*nbe); 1161 SetOfEdges4 * edge4= new SetOfEdges4(nbe,nbv); 1162 Int4 k=nbv; 1163 Int4 kk=0; 1164 Int4 kvb = NbVertexOnBThEdge; 1165 Int4 kvg = NbVerticesOnGeomEdge; 1166 Int4 ie =0; 1167 Edge ** edgesGtoB=0; 1168 if (withBackground) 1169 edgesGtoB= BTh.MakeGeometricalEdgeToEdge(); 1170 Int4 ferr=0; 1171 for (i=0;i<nbe;i++) 1172 newedges[ie].on=0; 1173 1174 for (i=0;i<nbe;i++) 1175 { 1176 GeometricalEdge *ong = edges[i].on; 1177 1178 newedges[ie]=edges[i]; 1179 newedges[ie].adj[0]=newedges+(edges[i].adj[0]-edges) ; 1180 newedges[ie].adj[1]=newedges + ie +1; 1181 R2 A = edges[i][0],B = edges[i][1]; 1182 // cout << " ie = " << ie <<" v0 = " << Number(newedges[ie][0]) << endl; 1183 1184 1185 kk += (i == edge4->addtrie(Number(edges[i][0]),Number(edges[i][1]))); 1186 if (ong) // a geometrical edges 1187 { 1188 if (withBackground) 1189 { 1190 // walk on back ground mesh 1191 // newVertexOnBThEdge[ibe++] = VertexOnEdge(vertices[k],bedge,absicsseonBedge); 1192 // a faire -- difficile 1193 // the first PB is to now a background edge between the 2 vertices 1194 assert(edgesGtoB); 1195 // cout << " ie = " << ie <<" v0 = " << Number(newedges[ie][0]) << endl; 1196 ong= ProjectOnCurve(*edgesGtoB[Gh.Number(edges[i].on)], 1197 edges[i][0],edges[i][1],0.5,vertices[k], 1198 newVertexOnBThEdge[kvb], 1199 newVerticesOnGeomEdge[kvg++]); 1200 vertices[k].ReferenceNumber= edges[i].ref; 1201 vertices[k].DirOfSearch = NoDirOfSearch; 1202 ; 1203 // get the Info on background mesh 1204 Real8 s = newVertexOnBThEdge[kvb]; 1205 Vertex & bv0 = newVertexOnBThEdge[kvb][0]; 1206 Vertex & bv1 = newVertexOnBThEdge[kvb][1]; 1207 // compute the metrix of the new points 1208 vertices[k].m = Metric(1-s,bv0,s,bv1); 1209 kvb++; 1210 // cout << " ie = " << ie <<" v0 = " << Number(newedges[ie][0]) << endl; 1211 } 1212 else 1213 { 1214 ong=Gh.ProjectOnCurve(edges[i], 1215 0.5,vertices[k],newVerticesOnGeomEdge[kvg++]); 1216 // vertices[k].i = toI2( vertices[k].r); 1217 vertices[k].ReferenceNumber = edges[i].ref; 1218 vertices[k].DirOfSearch = NoDirOfSearch; 1219 vertices[k].m = Metric(0.5,edges[i][0],0.5,edges[i][1]); 1220 } 1221 } 1222 else // straigth line edge --- 1223 { 1224 vertices[k].r = ((R2) edges[i][0] + (R2) edges[i][1] )*0.5; 1225 vertices[k].m = Metric(0.5,edges[i][0],0.5,edges[i][1]); 1226 vertices[k].on = 0; 1227 } 1228 //vertices[k].i = toI2( vertices[k].r); 1229 R2 AB = vertices[k].r; 1230 R2 AA = (A+AB)*0.5; 1231 R2 BB = (AB+B)*0.5; 1232 vertices[k].ReferenceNumber = edges[i].ref; 1233 vertices[k].DirOfSearch = NoDirOfSearch; 1234 1235 newedges[ie].on = Gh.Contening(AA,ong); 1236 newedges[ie++].v[1]=vertices+k; 1237 1238 newedges[ie]=edges[i]; 1239 newedges[ie].adj[0]=newedges + ie -1; 1240 newedges[ie].adj[1]=newedges+(edges[i].adj[1]-edges) ; 1241 newedges[ie].on = Gh.Contening(BB,ong); 1242 newedges[ie++].v[0]=vertices+k; 1243 // cout << " ie = " << ie-2 << " vm " << k << " v0 = " << Number(newedges[ie-2][0]) 1244 // << " v1 = " << Number(newedges[ie-1][1]) 1245 // << " ong =" << ong-Gh.edges 1246 // << " on 0 =" << newedges[ie-2].on -Gh.edges << AA 1247 // << " on 1 =" << newedges[ie-1].on -Gh.edges << BB 1248 // << endl; 1249 k++; 1250 } 1251 if (edgesGtoB) delete [] edgesGtoB; 1252 edgesGtoB=0; 1253 1254 newnbv=k; 1255 newNbVerticesOnGeomEdge=kvg; 1256 if (newnbv> nbvx) goto Error;// bug 1257 1258 nbv = k; 1259 1260 1261 kedge = new Int4[3*nbt+1]; 1262 ksplitarray = new Int4[nbt+1]; 1263 ksplit = ksplitarray +1; // because ksplit[-1] == ksplitarray[0] 1264 1265 for (i=0;i<3*nbt;i++) 1266 kedge[i]=-1; 1267 1268 // 1269 1270 for (i=0;i<nbt;i++) 1271 { 1272 1273 Triangle & t = triangles[i]; 1274 assert(t.link); 1275 for(int j=0;j<3;j++) 1276 { 1277 const TriangleAdjacent ta = t.Adj(j); 1278 const Triangle & tt = ta; 1279 if (&tt >= lastT) 1280 t.SetAdj2(j,0,0);// unset adj 1281 const Vertex & v0 = t[VerticesOfTriangularEdge[j][0]]; 1282 const Vertex & v1 = t[VerticesOfTriangularEdge[j][1]]; 1283 Int4 ke =edge4->findtrie(Number(v0),Number(v1)); 1284 if (ke>0) 1285 { 1286 Int4 ii = Number(tt); 1287 int jj = ta; 1288 Int4 ks = ke + nbvold; 1289 kedge[3*i+j] = ks; 1290 if (ii<nbt) // good triangle 1291 kedge[3*ii+jj] = ks; 1292 Vertex &A=vertices[ks]; 1293 Real8 aa,bb,cc,dd; 1294 if ((dd=Area2(v0.r,v1.r,A.r)) >=0) 1295 { // warning PB roundoff error 1296 if (t.link && ( (aa=Area2( A.r , t[1].r , t[2].r )) < 0.0 1297 || (bb=Area2( t[0].r , A.r , t[2].r )) < 0.0 1298 || (cc=Area2( t[0].r , t[1].r , A.r )) < 0.0)) 1299 ferr++, cerr << " Error : " << ke + nbvold << " not in triangle " 1300 << i << " In=" << !!t.link 1301 << " " << aa << " " << bb << " " << cc << " " << dd << endl; 1302 1303 } 1304 1305 else 1306 { 1307 if (tt.link && ( (aa=Area2( A.r , tt[1].r , tt[2].r )) < 0 1308 || (bb=Area2( tt[0].r , A.r , tt[2].r )) < 0 1309 || (cc=Area2( tt[0].r , tt[1].r , A.r )) < 0)) 1310 ferr++, cerr << " Warning : " << ke + nbvold << " not in triangle " << ii 1311 << " In=" << !!tt.link 1312 << " " << aa << " " << bb << " " << cc << " " << dd << endl; 1313 1314 } 1315 1316 } 1317 } 1318 } 1319 if(ferr) 1320 { 1321 cerr << " Number of triangles with P2 interpolation Probleme " << ferr << endl;; 1322 MeshError(9); 1323 } 1324 1325 for (i=0;i<nbt;i++) 1326 { 1327 ksplit[i]=1; // no split by default 1328 const Triangle & t = triangles[ i]; 1329 // cout << " Triangle " << i << " " << t << !!t.link << ":: " ; 1330 int nbsplitedge =0; 1331 int nbinvisible =0; 1332 int invisibleedge=0; 1333 int kkk[3]; 1334 for (int j=0;j<3;j++) 1335 { 1336 if (t.Hidden(j)) invisibleedge=j,nbinvisible++; 1337 1338 const TriangleAdjacent ta = t.Adj(j); 1339 const Triangle & tt = ta; 1340 1341 1342 const Vertex & v0 = t[VerticesOfTriangularEdge[j][0]]; 1343 const Vertex & v1 = t[VerticesOfTriangularEdge[j][1]]; 1344 // cout << " ke = " << kedge[3*i+j] << " " << Number(v0) << " " << Number(v1) << "/ "; 1345 if ( kedge[3*i+j] < 0) 1346 { 1347 Int4 ke =edge4->findtrie(Number(v0),Number(v1)); 1348 // cout << ":" << ke << "," << !!t.link << " " << &tt ; 1349 if (ke<0) // new 1350 { 1351 if (&tt) // internal triangles all the boundary 1352 { // new internal edges 1353 Int4 ii = Number(tt); 1354 int jj = ta; 1355 1356 kedge[3*i+j]=k;// save the vertex number 1357 kedge[3*ii+jj]=k; 1358 if (k<nbvx) 1359 { 1360 vertices[k].r = ((R2) v0+(R2) v1 )/2; 1361 //vertices[k].i = toI2( vertices[k].r); 1362 vertices[k].ReferenceNumber=0; 1363 vertices[k].DirOfSearch =NoDirOfSearch; 1364 vertices[k].m = Metric(0.5,v0,0.5,v1); 1365 } 1366 k++; 1367 kkk[nbsplitedge++]=j; 1368 } // tt 1369 else 1370 cerr <<endl << " Bug " <<i<< " " << j << " t=" << t << endl; 1371 1372 } // ke<0 1373 else 1374 { // ke >=0 1375 kedge[3*i+j]=nbvold+ke; 1376 kkk[nbsplitedge++]=j;// previously splited 1377 } 1378 } 1379 else 1380 kkk[nbsplitedge++]=j;// previously splited 1381 1382 } 1383 assert (nbinvisible<2); 1384 // cout << " " << nbinvisible << " " << nbsplitedge << endl; 1385 switch (nbsplitedge) { 1386 case 0: ksplit[i]=10; newnbt++; break; // nosplit 1387 case 1: ksplit[i]=20+kkk[0];newnbt += 2; break; // split in 2 1388 case 2: ksplit[i]=30+3-kkk[0]-kkk[1];newnbt += 3; break; // split in 3 1389 case 3: 1390 if (nbinvisible) ksplit[i]=40+invisibleedge,newnbt += 4; 1391 else ksplit[i]=10*nfortria,newnbt+=nfortria; 1392 break; 1393 } 1394 assert(ksplit[i]>=40); 1395 } 1396 // now do the element split 1397 newNbOfQuad = 4*NbOfQuad; 1398 nbv = k; 1399 // cout << " Nbv = " << nbv << endl; 1400 kkk = nbt; 1401 ksplit[-1] = nbt; 1402 // look on old true triangles 1403 1404 for (i=0;i<nbtsave;i++) 1405 { 1406 // cout << "Triangle " << i << " " << ksplit[i] << ":" << triangles[i] 1407 // << " ----------------------------------------------- " <<endl; 1408 // Triangle * tc=0; 1409 int nbmkadj=0; 1410 Int4 mkadj [100]; 1411 mkadj[0]=i; 1412 Int4 kk=ksplit[i]/10; 1413 int ke=(int) (ksplit[i]%10); 1414 assert(kk<7 && kk >0); 1415 1416 // def the numbering k (edge) i vertex 1417 int k0 = ke; 1418 int k1 = NextEdge[k0]; 1419 int k2 = PreviousEdge[k0]; 1420 int i0 = OppositeVertex[k0]; 1421 int i1 = OppositeVertex[k1]; 1422 int i2 = OppositeVertex[k2]; 1423 1424 Triangle &t0=triangles[i]; 1425 Vertex * v0=t0(i0); 1426 Vertex * v1=t0(i1); 1427 Vertex * v2=t0(i2); 1428 1429 // cout << "nbmkadj " << nbmkadj << " it=" << i <<endl; 1430 assert(nbmkadj< 10); 1431 // -------------------------- 1432 TriangleAdjacent ta0(t0.Adj(i0)),ta1(t0.Adj(i1)),ta2(t0.Adj(i2)); 1433 // save the flag Hidden 1434 int hid[]={t0.Hidden(0),t0.Hidden(1),t0.Hidden(2)}; 1435 // un set all adj -- save Hidden flag -- 1436 t0.SetAdj2(0,0,hid[0]); 1437 t0.SetAdj2(1,0,hid[1]); 1438 t0.SetAdj2(2,0,hid[2]); 1439 // -- remake 1440 switch (kk) { 1441 case 1: break;// nothing 1442 case 2: // 1443 { 1444 Triangle &t1=triangles[kkk++]; 1445 t1=t0; 1446 assert (kedge[3*i+i0]>=0); 1447 Vertex * v3 = vertices + kedge[3*i+k0]; 1448 1449 t0(i2) = v3; 1450 t1(i1) = v3; 1451 t0.SetAllFlag(k2,0); 1452 t1.SetAllFlag(k1,0); 1453 } 1454 break; 1455 case 3: // 1456 { 1457 Triangle &t1=triangles[kkk++]; 1458 Triangle &t2=triangles[kkk++]; 1459 t2=t1=t0; 1460 assert (kedge[3*i+k1]>=0); 1461 assert (kedge[3*i+k2]>=0); 1462 1463 Vertex * v01 = vertices + kedge[3*i+k2]; 1464 Vertex * v02 = vertices + kedge[3*i+k1]; 1465 t0(i1) = v01; 1466 t0(i2) = v02; 1467 t1(i2) = v02; 1468 t1(i0) = v01; 1469 t2(i0) = v02; 1470 t0.SetAllFlag(k0,0); 1471 t1.SetAllFlag(k1,0); 1472 t1.SetAllFlag(k0,0); 1473 t2.SetAllFlag(k2,0); 1474 } 1475 break; 1476 case 4: // 1477 case 6: // split in 4 1478 { 1479 Triangle &t1=triangles[kkk++]; 1480 Triangle &t2=triangles[kkk++]; 1481 Triangle &t3=triangles[kkk++]; 1482 t3=t2=t1=t0; 1483 assert(kedge[3*i+k0] >=0 && kedge[3*i+k1] >=0 && kedge[3*i+k2] >=0); 1484 Vertex * v12 = vertices + kedge[3*i+k0]; 1485 Vertex * v02 = vertices + kedge[3*i+k1]; 1486 Vertex * v01 = vertices + kedge[3*i+k2]; 1487 // cout << Number(t0(i0)) << " " << Number(t0(i1)) 1488 // << " " << Number(t0(i2)) 1489 // << " " << kedge[3*i+k0] 1490 // << " " << kedge[3*i+k1] 1491 // << " " << kedge[3*i+k2] << endl; 1492 t0(i1) = v01; 1493 t0(i2) = v02; 1494 t0.SetAllFlag(k0,hid[k0]); 1495 1496 t1(i0) = v01; 1497 t1(i2) = v12; 1498 t0.SetAllFlag(k1,hid[k1]); 1499 1500 t2(i0) = v02; 1501 t2(i1) = v12; 1502 t2.SetAllFlag(k2,hid[k2]); 1503 1504 t3(i0) = v12; 1505 t3(i1) = v02; 1506 t3(i2) = v01; 1507 1508 t3.SetAllFlag(0,hid[0]); 1509 t3.SetAllFlag(1,hid[1]); 1510 t3.SetAllFlag(2,hid[2]); 1511 1512 if ( kk == 6) 1513 { 1514 1515 Triangle &t4=triangles[kkk++]; 1516 Triangle &t5=triangles[kkk++]; 1517 1518 t4 = t3; 1519 t5 = t3; 1520 1521 t0.SetHidden(k0); 1522 t1.SetHidden(k1); 1523 t2.SetHidden(k2); 1524 t3.SetHidden(0); 1525 t4.SetHidden(1); 1526 t5.SetHidden(2); 1527 1528 if (nbv < nbvx ) 1529 { 1530 vertices[nbv].r = ((R2) *v01 + (R2) *v12 + (R2) *v02 ) / 3.0; 1531 vertices[nbv].ReferenceNumber =0; 1532 vertices[nbv].DirOfSearch =NoDirOfSearch; 1533 //vertices[nbv].i = toI2(vertices[nbv].r); 1534 Real8 a3[]={1./3.,1./3.,1./3.}; 1535 vertices[nbv].m = Metric(a3,v0->m,v1->m,v2->m); 1536 Vertex * vc = vertices +nbv++; 1537 t3(i0) = vc; 1538 t4(i1) = vc; 1539 t5(i2) = vc; 1540 1541 } 1542 else 1543 goto Error; 1544 } 1545 1546 } 1547 break; 1548 } 1549 1550 // cout << " -- " << i << " " << nbmkadj << " " << kkk << " " << tc << endl; 1551 // t0.SetDetf(); 1552 // save all the new triangles 1553 mkadj[nbmkadj++]=i; 1554 Int4 jj; 1555 if (t0.link) 1556 for (jj=nbt;jj<kkk;jj++) 1557 { 1558 triangles[jj].link=t0.link; 1559 t0.link= triangles+jj; 1560 mkadj[nbmkadj++]=jj; 1561 // triangles[jj].SetDet(); 1562 } 1563 // cout << " -- " << i << " " << nbmkadj << endl; 1564 assert(nbmkadj<=13);// 13 = 6 + 4 + 3 1565 1566 if (kk==6) newNbOfQuad+=3; 1567 // triangles[i].Draw(); 1568 1569 for (jj=ksplit[i-1];jj<kkk;jj++) 1570 // triangles[jj].SetDet(); 1571 // triangles[jj].Draw(); 1572 1573 1574 1575 nbt = kkk; 1576 ksplit[i]= nbt; // save last adresse of the new triangles 1577 kkk = nbt; 1578 1579 } 1580 1581 // cout << " nv = " << nbv << " nbt = " << nbt << endl; 1582 for (i=0;i<nbv;i++) 1583 vertices[i].m = vertices[i].m*2.; 1584 // 1585 if(withBackground) 1586 for (i=0;i<BTh.nbv;i++) 1587 BTh.vertices[i].m = BTh.vertices[i].m*2.; 1588 1589 1590 ret = 2; 1591 if (nbt>= nbtx) goto Error; // bug 1592 if (nbv>= nbvx) goto Error; // bug 1593 // generation of the new triangles 1594 1595 SetIntCoor("In SplitElement"); 1596 1597 ReMakeTriangleContainingTheVertex(); 1598 if(withBackground) 1599 BTh.ReMakeTriangleContainingTheVertex(); 1600 1601 delete [] edges; 1602 edges = newedges; 1603 nbe = newnbe; 1604 NbOfQuad = newNbOfQuad; 1605 1606 for (i=0;i<NbSubDomains;i++) 1607 { 1608 Int4 k = subdomains[i].edge- edges; 1609 subdomains[i].edge = edges+2*k; // spilt all edge in 2 1610 } 1611 1612 if (ksplitarray) delete [] ksplitarray; 1613 if (kedge) delete [] kedge; 1614 if (edge4) delete edge4; 1615 if (VerticesOnGeomEdge) delete [] VerticesOnGeomEdge; 1616 VerticesOnGeomEdge= newVerticesOnGeomEdge; 1617 if(VertexOnBThEdge) delete [] VertexOnBThEdge; 1618 VertexOnBThEdge = newVertexOnBThEdge; 1619 NbVerticesOnGeomEdge = newNbVerticesOnGeomEdge; 1620 NbVertexOnBThEdge=newNbVertexOnBThEdge; 1621 // ReMakeTriangleContainingTheVertex(); 1622 1623 FillHoleInMesh(); 1624 1625 if (verbosity>2) 1626 cout << " (out) Nb of Quadrilaterals = " << NbOfQuad 1627 << " Nb Of Triangles = " << nbt-NbOutT- NbOfQuad*2 1628 << " Nb of outside triangles = " << NbOutT << endl; 1629 1630 CurrentTh=OCurrentTh; 1631 return 0; //ok 1632 1633 Error: 1634 nbv = nbvold; 1635 nbt = nbtold; 1636 NbOutT = NbOutTold; 1637 // cleaning memory --- 1638 delete newedges; 1639 if (ksplitarray) delete [] ksplitarray; 1640 if (kedge) delete [] kedge; 1641 if (newVerticesOnGeomEdge) delete [] newVerticesOnGeomEdge; 1642 if (edge4) delete edge4; 1643 if(newVertexOnBThEdge) delete [] newVertexOnBThEdge; 1644 1645 1646 CurrentTh= OCurrentTh; 1647 return ret; // ok 1648 } 1649 /*}}}1*/ 891 1650 892 1651 } // end of namespace bamg -
issm/trunk/src/c/Makefile.am
r2809 r2810 323 323 ./Bamgx/Mesh2.h \ 324 324 ./Bamgx/GeometricalEdge.cpp \ 325 ./Bamgx/MeshQuad.cpp \326 325 ./Bamgx/meshtype.h \ 327 326 ./Bamgx/Triangles.cpp \ … … 663 662 ./Bamgx/Mesh2.h \ 664 663 ./Bamgx/GeometricalEdge.cpp \ 665 ./Bamgx/MeshQuad.cpp \666 664 ./Bamgx/meshtype.h \ 667 665 ./Bamgx/Triangles.cpp \
Note:
See TracChangeset
for help on using the changeset viewer.