Changeset 3277
- Timestamp:
- 03/15/10 10:33:22 (15 years ago)
- Location:
- issm/trunk/src
- Files:
-
- 10 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/meshtype.h
r3243 r3277 118 118 } 119 119 } 120 template<class T> inline void HeapSort(long** porder,T* c,int n){ 121 long l,j,r,i; 122 T crit; 123 long pos; 124 long* order=NULL; 125 order=(long*)xmalloc(n*sizeof(int)); 126 for(i=0;i<n;i++) order[i]=i+1; 127 c--; //the array must starts at 1 and not 0 128 order--; 129 if(n<=1) return; //return if size <=1 130 l=n/2+1; //initialize l and r 131 r=n; 132 for(;;){ 133 if(l<=1){ 134 crit =c[r]; pos=order[r]; 135 c[r--]=c[1]; order[r+1]=order[1]; 136 if (r==1){ 137 c[1]=crit; order[1]=pos; 138 order++; 139 *porder=order; 140 return; 141 } 142 } 143 else {crit=c[--l]; pos=order[l];} 144 j=l; 145 for(;;){ 146 i=j; 147 j=2*j; 148 if (j>r) {c[i]=crit;order[i]=pos;break;} 149 if ((j<r) && (c[j] < c[j+1]))j++; 150 if (crit < c[j]) {c[i]=c[j];order[i]=order[j];} 151 else{c[i]=crit;order[i]=pos;break;} 152 } 153 } 154 } 120 155 121 156 //Inline functions -
issm/trunk/src/c/Bamgx/objects/Geometry.cpp
r3275 r3277 929 929 /*}}}1*/ 930 930 /*FUNCTION Geometry::ProjectOnCurve {{{1*/ 931 GeometricalEdge* Geometry::ProjectOnCurve(const Edge & e,double s,Vertex &V,VertexOnGeom &GV) const {931 GeometricalEdge* Geometry::ProjectOnCurve(const Edge &e,double s,Vertex &V,VertexOnGeom &GV) const { 932 932 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/ProjectOnCurve)*/ 933 933 934 934 double save_s=s; 935 935 int NbTry=0; 936 retry: 936 retry: 937 937 s=save_s; 938 GeometricalEdge* on =e.onGeometry;938 GeometricalEdge* on=e.onGeometry; 939 939 if (!on){ 940 throw ErrorException(__FUNCT__,exprintf(" !on"));940 throw ErrorException(__FUNCT__,exprintf("ProjectOnCurve error message: edge provided shonld be on geometry")); 941 941 } 942 942 if (!e[0].onGeometry || !e[1].onGeometry){ 943 throw ErrorException(__FUNCT__,exprintf(" !e[0].on || !e[1].on"));943 throw ErrorException(__FUNCT__,exprintf("ProjectOnCurve error message: at least one of the vertex of the edge provided is not on geometry")); 944 944 } 945 945 const Vertex &v0=e[0],&v1=e[1]; … … 969 969 printf("Fatal Error: on the class triangles before call Geometry::ProjectOnCurve\n"); 970 970 printf("That bug might come from:\n"); 971 printf(" 1) a mesh edge cont ening more than %i geometrical edges\n",mxe/2);971 printf(" 1) a mesh edge containing more than %i geometrical edges\n",mxe/2); 972 972 printf(" 2) code bug : be sure that we call Triangles::SetVertexFieldOn() before\n"); 973 973 printf("To solve the problem do a coarsening of the geometrical mesh or change the constant value of mxe (dangerous)\n"); -
issm/trunk/src/c/Bamgx/objects/Triangles.cpp
r3276 r3277 401 401 } 402 402 403 //Ver VerticesOnGeometricEdge403 //VerticesOnGeometricEdge 404 404 if(bamgmesh->VerticesOnGeometricEdge){ 405 405 if(verbose>5) printf(" processing VerticesOnGeometricEdge\n"); … … 419 419 } 420 420 421 //VerticesOnGeometricVertex 422 if(bamgmesh->NumVerticesOnGeometricVertex){ 423 if(verbose>5) printf(" processing VerticesOnGeometricVertex\n"); 424 NbVerticesOnGeomVertex=bamgmesh->NumVerticesOnGeometricVertex; 425 VerticesOnGeomVertex = new VertexOnGeom[NbVerticesOnGeomVertex] ; 426 for (i=0;i<NbVerticesOnGeomVertex;i++){ 427 long i1,i2; 428 i1=(long)bamgmesh->VerticesOnGeometricVertex[i*2+0]-1; //for C indexing 429 i2=(long)bamgmesh->VerticesOnGeometricVertex[i*2+1]-1; //for C indexing 430 VerticesOnGeomVertex[i]=VertexOnGeom(vertices[i1],Gh.vertices[i2]); 431 } 432 } 433 else{ 434 if(verbose>5) printf(" no VertexOnGeometricVertex found\n"); 435 } 436 421 437 //Edges 422 438 if (bamgmesh->Edges){ 423 439 int i1,i2; 424 R2 zero2(0,0); 425 double *len =0; 440 double* len=NULL; 426 441 427 442 if(verbose>5) printf(" processing Edges\n"); 428 443 nbe=bamgmesh->NumEdges; 429 edges 444 edges= new Edge[nbe]; 430 445 431 446 if (!hvertices) { 432 len 447 len= new double[nbv]; 433 448 for(i=0;i<nbv;i++) 434 449 len[i]=0; … … 442 457 edges[i].adj[0]=NULL; 443 458 edges[i].adj[1]=NULL; 444 R2 x12 =vertices[i2].r-vertices[i1].r;445 double l12=sqrt( (x12,x12));446 447 if (!hvertices) 459 R2 x12=vertices[i2].r-vertices[i1].r; 460 double l12=sqrt((x12,x12)); 461 462 if (!hvertices){ 448 463 vertices[i1].color++; 449 464 vertices[i2].color++; 450 len[i1]+= 451 len[i2] +=l12;465 len[i1]+=l12; 466 len[i2]+=l12; 452 467 } 453 468 Hmin = Min(Hmin,l12); … … 458 473 for (i=0;i<nbv;i++) 459 474 if (vertices[i].color > 0) 460 vertices[i].m= 475 vertices[i].m=Metric(len[i] /(double) vertices[i].color); 461 476 else 462 vertices[i].m= 477 vertices[i].m=Metric(Hmin); 463 478 delete [] len; 464 479 } … … 476 491 } 477 492 else if (i0>=0) {// i and i0 edge are adjacent by the vertex v 478 j0 = i0%2; 479 i0 = i0/2; 480 if (v!=edges[i0 ].v[j0]){ 481 throw ErrorException(__FUNCT__,exprintf("v!=edges[i0 ].v[j0]")); 482 } 483 edges[i ].adj[ j ] =edges +i0; 484 edges[i0].adj[ j0] =edges +i ; 493 j0 = i0%2; 494 i0 = i0/2; 495 assert(v==edges[i0 ].v[j0]); 496 edges[i ].adj[j ] =edges +i0; 497 edges[i0].adj[j0] =edges +i ; 485 498 v->color = -3; 486 499 } … … 513 526 i2=bamgmesh->NumEdgesOnGeometricEdge; 514 527 for (i1=0;i1<i2;i1++) { 515 i=(int)bamgmesh->EdgesOnGeometricEdge[i1*2+0]; 516 j=(int)bamgmesh->EdgesOnGeometricEdge[i1*2+1]; 517 if(!(i>0 && j >0 && i <= nbe && j <= Gh.nbe)) { 518 throw ErrorException(__FUNCT__,exprintf("ReadMesh error: EdgesOnGeometricEdge edge provided (line %i: [%i %i]) is incorrect (must be positive, [0<i<nbe=%i 0<j<Gh.nbe=%i]",i1+1,i,j,nbe,Gh.nbe)); 519 } 520 edges[i-1].onGeometry = Gh.edges + j-1; 528 i=(int)bamgmesh->EdgesOnGeometricEdge[i1*2+0]-1; //C indexing 529 j=(int)bamgmesh->EdgesOnGeometricEdge[i1*2+1]-1; //C indexing 530 //Check value 531 if(!(i>=0 && j>=0 && i<nbe && j<Gh.nbe)) { 532 throw ErrorException(__FUNCT__,exprintf("ReadMesh error: EdgesOnGeometricEdge edge provided (line %i: [%i %i]) is incorrect (must be positive, [0<i<nbe=%i 0<j<Gh.nbe=%i]",i1+1,i+1,j+1,nbe,Gh.nbe)); 533 } 534 edges[i].onGeometry=Gh.edges+j; 521 535 } 522 536 } … … 555 569 /*Initialize output*/ 556 570 BamgMeshInit(bamgmesh); 557 558 559 //renumber560 if (bamgopts->renumber){561 if(verbose>5) printf(" Renumbering...");562 Renumber(bamgopts);563 if(verbose>5) printf(" done\n");564 }565 571 566 572 //Build reft that holds the number the subdomain number of each triangle … … 769 775 for (i=0;i<NbVerticesOnGeomVertex;i++){ 770 776 VertexOnGeom &v=VerticesOnGeomVertex[i]; 771 if (!v.OnGeomVertex()){ 772 throw ErrorException(__FUNCT__,exprintf("A vertices supposed to be OnGeometricVertex is actually not")); 773 } 777 assert(v.OnGeomVertex()); 774 778 bamgmesh->VerticesOnGeometricVertex[i*2+0]=Number((Vertex*)v)+1; //back to Matlab indexing 775 bamgmesh->VerticesOnGeometricVertex[i*2+1]=Gh.Number(( 779 bamgmesh->VerticesOnGeometricVertex[i*2+1]=Gh.Number((GeometricalVertex*)v)+1; //back to Matlab indexing 776 780 } 777 781 } … … 4312 4316 } 4313 4317 /*}}}1*/ 4314 /*FUNCTION Triangles::Renumber {{{1*/4315 void Triangles::Renumber(BamgOpts* bamgopts){4316 4317 /*Intermediary*/4318 int i,j,k;4319 int* r=NULL;4320 int* rprime=NULL;4321 rprime =(int*) xmalloc(nbv*sizeof(int));4322 4323 //renumbering with respect to lower left corner4324 if (bamgopts->renumber==1){4325 4326 //compute distance to pmin4327 double* distance;4328 distance=(double*)xmalloc(nbv*sizeof(double));4329 for (i=0;i<nbv;i++) distance[i]=pow(vertices[i].r.x - pmin.x,2)+pow(vertices[i].r.y - pmin.y,2);4330 4331 //get ordering4332 HeapSort(&r,distance,nbv);4333 xfree((void**)&distance);4334 }4335 //renumbering randomly4336 else if (bamgopts->renumber==2){4337 4338 //allocate memory to r4339 r=(int*)xmalloc(nbv*sizeof(int));4340 int PrimeNumber= BigPrimeNumber(nbv) ;4341 int k0=rand()%nbv;4342 for (int i=0; i<nbv; i++){4343 r[i]=(k0=(k0+PrimeNumber)%nbv)+1;4344 }4345 }4346 //else: error4347 else{4348 throw ErrorException(__FUNCT__,exprintf("renumbering option %i not supported yet",bamgopts->renumber));4349 }4350 4351 //Keep copy of old vertices4352 Vertex* oldvertices=NULL;4353 oldvertices=(Vertex*)xmalloc(nbv*sizeof(Vertex));4354 for (i=0;i<nbv;i++){4355 oldvertices[i]=vertices[i];4356 }4357 4358 //renumber vertices4359 for (i=0;i<nbv;i++){4360 //check r[i]4361 if (r[i]>nbv){4362 throw ErrorException(__FUNCT__,exprintf("r[i]>nbv (r[i]=%i and nbv=%i)",r[i],nbv));4363 }4364 if (r[i]<=0){4365 throw ErrorException(__FUNCT__,exprintf("r[i]<=0 (r[i]=%i)",r[i]));4366 }4367 vertices[i]=oldvertices[r[i]-1];4368 rprime[r[i]-1]=i+1;4369 }4370 //clean up4371 xfree((void**)&oldvertices);4372 4373 //renumber triangles4374 for (i=0; i<nt;i++){4375 for (j=0;j<3;j++){4376 if (triangles[i](j)){4377 triangles[i](j)=&vertices[rprime[Number(triangles[i](j))] -1 ];4378 }4379 }4380 }4381 4382 //renumber edges4383 for (i=0; i<nbe;i++){4384 for (j=0;j<2;j++){4385 edges[i].v[j]=&vertices[rprime[Number(edges[i].v[j])] -1 ];4386 }4387 }4388 4389 //clean up4390 xfree((void**)&r);4391 xfree((void**)&rprime);4392 }4393 /*}}}1*/4394 4318 /*FUNCTION Triangles::ReNumberingTheTriangleBySubDomain{{{1*/ 4395 4319 void Triangles::ReNumberingTheTriangleBySubDomain(bool justcompress) { … … 4466 4390 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ReNumberingVertex)*/ 4467 4391 4468 // warning be carfull because pointe ur4392 // warning be carfull because pointer 4469 4393 // from on mesh to over mesh 4470 // -- so do ReNumbering a the beginning4394 // -- so do ReNumbering at the beginning 4471 4395 Vertex * ve = vertices+nbv; 4472 4396 long it,ie,i; 4473 4397 4398 printf("renumbering triangles\n"); 4474 4399 for ( it=0;it<nbt;it++) 4475 4400 triangles[it].ReNumbering(vertices,ve,renu); 4476 4401 4402 printf("renumbering edges\n"); 4477 4403 for ( ie=0;ie<nbe;ie++) 4478 4404 edges[ie].ReNumbering(vertices,ve,renu); 4479 4405 4406 printf("renumbering vertices on geom\n"); 4480 4407 for (i=0;i< NbVerticesOnGeomVertex;i++) 4481 4408 { … … 4485 4412 } 4486 4413 4414 printf("renumbering vertices on edge\n"); 4487 4415 for (i=0;i< NbVerticesOnGeomEdge;i++) 4488 4416 { … … 4492 4420 } 4493 4421 4422 printf("renumbering vertices on Bth vertex\n"); 4494 4423 for (i=0;i< NbVertexOnBThVertex;i++) 4495 4424 { … … 4514 4443 i=it; 4515 4444 Vertex ti=vertices[i],tj; 4516 while ( (j=renu[i]) >= 0) 4517 {// i is old, and j is new4445 while ( (j=renu[i]) >= 0){ 4446 // i is old, and j is new 4518 4447 renu[i] = -1-renu[i]; // mark 4519 tj = vertices[j]; // save new4520 vertices[j]= ti; // new <- old4448 tj = vertices[j]; // save new 4449 vertices[j]= ti; // new <- old 4521 4450 i=j; // next 4522 4451 ti = tj; 4523 4452 } 4524 4453 } 4525 if (quadtree) 4526 { delete quadtree; 4454 if (quadtree) {delete quadtree; 4527 4455 quadtree = new QuadTree(this); 4528 4529 for ( it=0;it<nbv;it++) 4530 renu[i]= -renu[i]-1;4531 4456 } 4457 4458 for ( it=0;it<nbv;it++) renu[i]= -renu[i]-1; 4459 printf("end renumbervertex\n"); 4532 4460 } 4533 4461 /*}}}1*/ -
issm/trunk/src/c/Bamgx/objects/Triangles.h
r3267 r3277 101 101 void Insert(); 102 102 void ForceBoundary(); 103 void Renumber(BamgOpts* bamgopts);104 103 void FindSubDomain(int OutSide=0); 105 104 long TriangleReferenceList(long *) const; … … 159 158 } 160 159 inline void SetVertexFieldOn(){ 161 for (int i=0;i<nbv;i++) vertices[i].onGeometry= 0;160 for (int i=0;i<nbv;i++) vertices[i].onGeometry=NULL; 162 161 for (int j=0;j<NbVerticesOnGeomVertex;j++) VerticesOnGeomVertex[j].SetOn(); 163 162 for (int k=0;k<NbVerticesOnGeomEdge;k++ ) VerticesOnGeomEdge[k].SetOn(); -
issm/trunk/src/c/Bamgx/objects/VertexOnGeom.h
r3272 r3277 34 34 35 35 //Operators 36 operator Vertex *() const {return mv;}36 operator Vertex*() const {return mv;} 37 37 operator GeometricalVertex * () const {return gv;} 38 38 operator GeometricalEdge * () const {return ge;} -
issm/trunk/src/c/objects/BamgMesh.cpp
r3274 r3277 146 146 147 147 pfield=mxCreateDoubleMatrix(0,0,mxREAL); 148 mxSetM(pfield, 2);148 mxSetM(pfield,3); 149 149 mxSetN(pfield,bamgmesh->NumVerticesOnGeometricEdge); 150 150 mxSetPr(pfield,bamgmesh->VerticesOnGeometricEdge); -
issm/trunk/src/c/objects/BamgOpts.cpp
r3213 r3277 11 11 bamgopts->Metrictype=0; 12 12 bamgopts->KeepVertices=0; 13 bamgopts->renumber=0;14 13 bamgopts->maxsubdiv=0; 15 14 bamgopts->power=0; … … 42 41 if (bamgopts->Metrictype!=0 && bamgopts->Metrictype!=1 && bamgopts->Metrictype!=2) throw ErrorException(__FUNCT__,exprintf("'Metrictype' supported options are 0, 1 and 2")); 43 42 if (bamgopts->KeepVertices!=0 && bamgopts->KeepVertices!=1) throw ErrorException(__FUNCT__,exprintf("'KeepVertices' supported options are 0 and 1")); 44 if (bamgopts->renumber!=0 && bamgopts->renumber!=1 && bamgopts->renumber!=2) throw ErrorException(__FUNCT__,exprintf("'renumber' supported options are 0, 1 and 2"));45 43 if (bamgopts->errg<0) throw ErrorException(__FUNCT__,exprintf("'errg' option should be >0")); 46 44 if (bamgopts->nbjacobi<=0) throw ErrorException(__FUNCT__,exprintf("'nbjacobi' option should be >0")); -
issm/trunk/src/c/objects/BamgOpts.h
r3213 r3277 14 14 int Metrictype; 15 15 int KeepVertices; 16 int renumber;17 16 double maxsubdiv; 18 17 double power; -
issm/trunk/src/m/classes/public/bamg.m
r3273 r3277 31 31 % - omega : relaxation parameter of the smoothing procedure (default is 1.8) 32 32 % - power : power applied to the metric (default is 1) 33 % - renumber : 0 -> no renumbering34 % 1 -> renumber by distance to lower left corner (default)35 % 2 -> random renumbering36 33 % - splitcorner : split triangles whuch have 3 vertices on the outline (default is 1) 37 34 % - verbose : level of verbosity (default is 1) … … 48 45 %initialize the structures required as input of Bamg 49 46 bamg_options=struct(); 50 bamg_geometry= struct();51 bamg_mesh= struct();47 bamg_geometry=bamggeom; 48 bamg_mesh=bamgmesh; 52 49 53 50 % Bamg Geometry parameters {{{1 54 bamg_geometry.NumVertices=0;55 bamg_geometry.Vertices=zeros(0,3);56 bamg_geometry.NumEdges=0;57 bamg_geometry.Edges=zeros(0,3);58 bamg_geometry.NumCrackedEdges=0;59 bamg_geometry.CrackedEdges=zeros(0,1);60 bamg_geometry.hVertices=zeros(0,1);61 bamg_geometry.NumSubDomains=0;62 bamg_geometry.SubDomains=zeros(0,3);63 51 if exist(options,'domain'), 64 52 … … 187 175 end 188 176 177 elseif isstruct(md.bamg), 178 179 bamg_geometry=bamggeom(md.bamg.geometry); %TEST 180 189 181 else 190 182 191 %Use segments as the geometry 192 %bamg_geometry.Vertices=[md.x md.y ones(md.numberofgrids,1)]; 193 %bamg_geometry.Edges=[md.segments(:,1:2) md.segmentmarkers]; 194 %bamg_geometry.Edges 183 %do nothing... 195 184 196 185 end … … 203 192 204 193 % Bamg Mesh parameters {{{1 205 bamg_mesh.NumVertices=0;206 bamg_mesh.Vertices=[];207 bamg_mesh.NumTriangles=0;208 bamg_mesh.Triangles=[];209 bamg_mesh.NumEdges=0;210 bamg_mesh.Edges=zeros(0,3);211 bamg_mesh.NumEdgesOnGeometricEdge=0;212 bamg_mesh.EdgesOnGeometricEdge=zeros(0,2);213 bamg_mesh.NumVerticesOnGeometricEdge=0;214 bamg_mesh.VerticesOnGeometricEdge=zeros(0,2);215 bamg_mesh.hVertices=[];216 bamg_mesh.NumCrackedEdges=0;217 bamg_mesh.CrackedEdges=zeros(0,2);218 194 if (~exist(options,'domain') & md.numberofgrids~=0 & strcmpi(md.type,'2d')), 219 bamg_mesh.NumVertices=md.numberofgrids; 220 bamg_mesh.Vertices=[md.x md.y ones(md.numberofgrids,1)]; 221 bamg_mesh.NumTriangles=md.numberofelements; 222 bamg_mesh.Triangles=[md.elements ones(md.numberofelements,1)]; 195 196 if isstruct(md.bamg),%TEST 197 bamg_mesh=bamgmesh(md.bamg.mesh); 198 else 199 bamg_mesh.NumVertices=md.numberofgrids; 200 bamg_mesh.Vertices=[md.x md.y ones(md.numberofgrids,1)]; 201 bamg_mesh.NumTriangles=md.numberofelements; 202 bamg_mesh.Triangles=[md.elements ones(md.numberofelements,1)]; 203 end 204 223 205 if exist(options,'hVertices'), 224 206 bamg_mesh.hVertices=getfieldvalueerr(options,'hVertices'); … … 255 237 bamg_options.omega=getfieldvalue(options,'omega',1.8); 256 238 bamg_options.power=getfieldvalue(options,'power',1); 257 bamg_options.renumber=getfieldvalue(options,'renumber',1);258 239 bamg_options.splitcorners=getfieldvalue(options,'splitcorners',1); 259 240 bamg_options.verbose=getfieldvalue(options,'verbose',1); … … 271 252 end 272 253 273 274 254 %call Bamg 275 255 [bamgmesh_out bamggeom_out]=Bamg(bamg_mesh,bamg_geometry,bamg_options); … … 277 257 % plug results onto model 278 258 md.bamg=struct(); 279 md.bamg.mesh=bamgmesh _out;280 md.bamg.geometry=bamggeom _out;259 md.bamg.mesh=bamgmesh(bamgmesh_out); 260 md.bamg.geometry=bamggeom(bamggeom_out); 281 261 md.x=bamgmesh_out.Vertices(:,1); 282 262 md.y=bamgmesh_out.Vertices(:,2); -
issm/trunk/src/mex/Bamg/Bamg.cpp
r3273 r3277 52 52 FetchData(&bamgmesh_in.NumVerticesOnGeometricEdge,mxGetField(BAMGMESH,0,"NumVerticesOnGeometricEdge")); 53 53 FetchData(&bamgmesh_in.VerticesOnGeometricEdge,NULL,NULL,mxGetField(BAMGMESH,0,"VerticesOnGeometricEdge")); 54 FetchData(&bamgmesh_in.NumVerticesOnGeometricVertex,mxGetField(BAMGMESH,0,"NumVerticesOnGeometricVertex")); 55 FetchData(&bamgmesh_in.VerticesOnGeometricVertex,NULL,NULL,mxGetField(BAMGMESH,0,"VerticesOnGeometricVertex")); 54 56 if (bamgmesh_in.hVertices && (cols!=1 || lines!=bamgmesh_in.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'hVertices' should be [%i %i]",bamgmesh_in.NumVertices,1));} 55 57 … … 61 63 FetchData(&bamgopts.Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype")); 62 64 FetchData(&bamgopts.KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices")); 63 FetchData(&bamgopts.renumber,mxGetField(BAMGOPTIONS,0,"renumber"));64 65 FetchData(&bamgopts.power,mxGetField(BAMGOPTIONS,0,"power")); 65 66 FetchData(&bamgopts.errg,mxGetField(BAMGOPTIONS,0,"errg"));
Note:
See TracChangeset
for help on using the changeset viewer.