Changeset 2809
- Timestamp:
- 01/12/10 15:55:27 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 1 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/Geometry.cpp
r2806 r2809 433 433 /*}}}1*/ 434 434 435 /*Other*/ 436 437 void Geometry::EmptyGeometry() // empty geometry 438 { 439 OnDisk=0; 440 NbRef=0; 441 name =0; 442 quadtree=0; 443 curves=0; 444 // edgescomponante=0; 445 triangles=0; 446 edges=0; 447 vertices=0; 448 NbSubDomains=0; 449 // nbtf=0; 450 // BeginOfCurve=0; 451 nbiv=nbv=nbvx=0; 452 nbe=nbt=nbtx=0; 453 NbOfCurves=0; 454 // BeginOfCurve=0; 455 subdomains=0; 456 MaximalAngleOfCorner = 10*Pi/180; 457 } 458 459 460 461 Geometry::Geometry(const Geometry & Gh) 462 { Int4 i; 463 *this = Gh; 464 NbRef =0; 465 quadtree=0; 466 name = new char[strlen(Gh.name)+4]; 467 strcpy(name,"cp:"); 468 strcat(name,Gh.name); 469 vertices = nbv ? new GeometricalVertex[nbv] : NULL; 470 triangles = nbt ? new Triangle[nbt]:NULL; 471 edges = nbe ? new GeometricalEdge[nbe]:NULL; 472 curves= NbOfCurves ? new Curve[NbOfCurves]:NULL; 473 subdomains = NbSubDomains ? new GeometricalSubDomain[NbSubDomains]:NULL; 474 for (i=0;i<nbv;i++) 475 vertices[i].Set(Gh.vertices[i],Gh,*this); 476 for (i=0;i<nbe;i++) 477 edges[i].Set(Gh.edges[i],Gh,*this); 478 for (i=0;i<NbOfCurves;i++) 479 curves[i].Set(Gh.curves[i],Gh,*this); 480 for (i=0;i<NbSubDomains;i++) 481 subdomains[i].Set(Gh.subdomains[i],Gh,*this); 482 483 // for (i=0;i<nbt;i++) 484 // triangles[i].Set(Gh.triangles[i],Gh,*this); 485 assert(!nbt); 486 } 487 488 489 GeometricalEdge* Geometry::Contening(const R2 P, GeometricalEdge * start) const 490 { 491 GeometricalEdge* on =start,* pon=0; 492 // walk with the cos on geometry 493 // cout << P ; 494 int k=0; 495 while(pon != on) 496 { 497 pon = on; 498 assert(k++<100); 499 R2 A= (*on)[0]; 500 R2 B= (*on)[1]; 501 R2 AB = B-A; 502 R2 AP = P-A; 503 R2 BP = P-B; 504 // cout << ":: " << on - edges << " " << AB*AP << " " << AB*BP << " " << A << B << endl; 505 if ( (AB,AP) < 0) 506 on = on->Adj[0]; 507 else if ( (AB,BP) > 0) 508 on = on->Adj[1]; 509 else 510 return on; 511 } 512 return on; 513 } 514 GeometricalEdge* Geometry::ProjectOnCurve(const Edge & e,Real8 s,Vertex &V,VertexOnGeom &GV ) const 515 { 516 Real8 save_s=s; 517 int NbTry=0; 518 retry: 519 s=save_s; 520 GeometricalEdge * on = e.on; 521 assert(on); 522 assert( e[0].on && e[1].on); 523 const Vertex &v0=e[0],&v1=e[1]; 524 V.m = Metric(1.0-s, v0,s, v1); 525 #define MXE__LINE __LINE__+1 526 const int mxe =100; 527 GeometricalEdge *ge[mxe+1]; 528 int sensge[mxe+1]; 529 Real8 lge[mxe+1]; 530 int bge=mxe/2,tge=bge; 531 ge[bge] = e.on; 532 sensge[bge]=1; 533 534 R2 V0 = v0,V1=v1,V01=V1-V0; 535 VertexOnGeom vg0= *v0.on, vg1=*v1.on; 536 if(NbTry) cout << "bug: s==== " << s << " e=" << V0 << " " << V1 << endl; 537 538 // GeometricalEdge * eg0 = e.on,* eg1 = e.on, *eg=NULL; 539 GeometricalEdge * eg0=on, *eg1=on; 540 R2 Ag=(R2) (*on)[0],Bg=(R2)(*on)[1],AB=Bg-Ag; 541 if(NbTry) cout <<" G edge= " << Ag << Bg << endl << " v edge" << V01 << " v geom " << AB << (V01,AB) <<endl; 542 int OppositeSens = (V01,AB) < 0; 543 int sens0=0,sens1=1; 544 if (OppositeSens) 545 s=1-s,Exchange(vg0,vg1),Exchange(V0,V1); 546 if(NbTry) cout << "bug: edge = " << v0.r << " -> " << v1.r << endl 547 << "sg 0 = " << vg0 548 << " on = " << Number(on) << ":" << Ag << Bg << "; " 549 << " sg 1= " << vg1 550 << "--------------------------------------------" << endl; 551 while (eg0 != (GeometricalEdge*) vg0 && (*eg0)(sens0) != (GeometricalVertex*) vg0) 552 { 553 if (bge<=0) { 554 // int kkk; 555 // if (NbTry) cout <<"Read (int) to Show Sioux window", cin >> kkk ; 556 if(NbTry) 557 { 558 cerr << " -- Fatal Error: on the class triangles before call Geometry::ProjectOnCurve" << endl; 559 cerr << " The mesh of the Geometry is to fine: "; 560 cerr << " 1) a mesh edge contening more than "<< mxe/2 << " geometrical edges." << endl; 561 cerr << " 2) code bug : be sure that we call Triangles::SetVertexFieldOn() before " << endl; 562 cerr << " To solve the problem do a coarsening of the geometrical mesh " << endl; 563 cerr << " or change the constant value of mxe in " << __FILE__ << " line " << MXE__LINE << "( dangerous way )" << endl; 564 MeshError(222); 565 } 566 NbTry++; 567 goto retry;} 568 GeometricalEdge* tmpge = eg0; 569 if(NbTry) 570 cout << "bug: --Edge @" << Number(tmpge) << " = "<< Number(eg0) << ":" <<Number(eg0->Adj[0]) << "," << 571 Number(eg0->Adj[1]) <<"," ; 572 ge[--bge] =eg0 = eg0->Adj[sens0]; 573 assert(bge>=0 && bge <= mxe); 574 sens0 = 1-( sensge[bge] = tmpge->SensAdj[sens0]); 575 if(NbTry) 576 cout << "bug: Edge " << Number(eg0) << " "<< 1-sens0 << " S " 577 << Number((*eg0)[1-sens0]) <<":" << Number(eg0->Adj[0]) << "," 578 << Number(eg0->Adj[1]) <<"," << endl 579 <<Number(eg0)<< (*eg0)[sens0].r << "v = " << Number((*eg1)(sens0)) << " e = " << eg0 << endl; 580 } 581 if(NbTry) cout << Number((GeometricalEdge*) vg1) << " " << Number((GeometricalVertex*) vg1) << endl; 582 while (eg1 != (GeometricalEdge*) vg1 && (*eg1)(sens1) != (GeometricalVertex*) vg1) 583 { 584 if(tge>=mxe ) { 585 cerr << " --Fatal Error: on the class triangles before call Geometry::ProjectOnCurve" << endl; 586 NbTry++; 587 if (NbTry<2) goto retry; 588 cerr << " The mesh of the Geometry is to fine:" ; 589 cerr << " 1) a mesh edge contening more than "<< mxe/2 << " geometrical edges." << endl; 590 cerr << " 2) code bug : be sure that we call Triangles::SetVertexFieldOn() before " << endl; 591 cerr << " To solve the problem do a coarsening of the geometrical mesh " << endl; 592 cerr << " or change the constant value of mxe in " << __FILE__ << " line " << MXE__LINE << "( dangerous way )" << endl; 593 MeshError(223); 594 } 595 596 GeometricalEdge* tmpge = eg1; 597 if(NbTry) 598 cout << "++Edge @" << tmpge << " = " << Number(eg1) <<"%" << Number(eg1->Adj[0]) << "," 599 << Number(eg1->Adj[1]) <<"," ; 600 ge[++tge] =eg1 = eg1->Adj[sens1]; 601 sensge[tge]= sens1 = 1-tmpge->SensAdj[sens1]; 602 assert(tge>=0 && tge <= mxe); 603 if(NbTry) 604 cout << " Edge " << Number(eg1) << " " << sens1 << " S " 605 <<Number((*eg1)[sens1]) <<"%"<< Number(eg1->Adj[0]) << "," << Number(eg1->Adj[1]) <<"," 606 <<Number(eg1)<< (*eg1)[sens1].r << "v = " << Number((*eg1)(sens1)) << " e = " << Number(eg1) << endl; 607 } 608 609 if(NbTry) cout << endl; 610 611 612 if ( (*eg0)(sens0) == (GeometricalVertex*) vg0 ) 613 vg0 = VertexOnGeom( *(Vertex *) vg0,*eg0,sens0); 614 615 if ( (*eg1)(sens1) == (GeometricalVertex*) vg1) 616 vg1 = VertexOnGeom( *(Vertex *) vg1,*eg1,sens1); 617 618 Real8 sg; 619 // cout << " " << Number(on) << " " << Number(eg0) << " " << Number(eg1) << " " ; 620 if (eg0 == eg1) { 621 register Real8 s0= vg0,s1=vg1; 622 sg = s0 * (1.0-s) + s * s1; 623 // cout <<" s0=" << s0 << " s1=" << s1 624 // << " s = " << s << " sens= " << OppositeSens << "\t\t sg = " << sg << endl ; 625 on=eg0;} 626 else { 627 R2 AA=V0,BB; 628 Real8 s0,s1; 629 630 //cout << endl << "s= " << s << Number(eg0) << " " << (Real8) vg0 << " " 631 // << Number(eg1) << " " << (Real8) vg1 << V0 << V1 << " Interpol = " 632 // << V0*(1-s)+V1*s << ";;; " << endl; 633 int i=bge; 634 Real8 ll=0; 635 for(i=bge;i<tge;i++) 636 { 637 assert( i>=0 && i <= mxe); 638 BB = (*ge[i])[sensge[i]]; 639 lge[i]=ll += Norme2(AA-BB); 640 // cout << " ll " << i << BB << ll << " " <<sensge[i] <<" on = " << 641 // Number(ge[i]) << " sens= " << sensge[i] ; 642 AA=BB ;} 643 lge[tge]=ll+=Norme2(AA-V1); 644 // cout << " ll " << tge << " " << ll << sensge[tge] 645 // <<" on = " << Number(ge[tge]) << " sens= " << sensge[tge] << endl; 646 // search the geometrical edge 647 assert(s <= 1.0); 648 Real8 ls= s*ll; 649 on =0; 650 s0 = vg0; 651 s1= sensge[bge]; 652 Real8 l0=0,l1; 653 i=bge; 654 while ( (l1=lge[i]) < ls ) { 655 assert(i >= 0 && i <= mxe); 656 i++,s0=1-(s1=sensge[i]),l0=l1;} 657 on=ge[i]; 658 if (i==tge) 659 s1=vg1; 660 661 s=(ls-l0)/(l1-l0); 662 // cout << "on =" << Number(on) << sens0 << sens1 << "s0 " << s0 << " s1 =" 663 // << s1 << " l0 =" << l0 << " ls= " << ls << " l1= " << l1 << " s= " << s; 664 sg = s0 * (1.0-s) + s * s1; 665 } 666 assert(on); 667 // assert(sg && sg-1); 668 V.r= on->F(sg); 669 // if (eg0 != eg1) 670 // cout << "----- sg = "<< sg << " Sens =" << OppositeSens << " Edge = " 671 // << Number(on) <<" V=" << V << endl; 672 GV=VertexOnGeom(V,*on,sg); 673 return on; 674 } 675 676 void Geometry::AfterRead() 677 {// ----------------- 678 long int verbosity=0; 679 680 if (verbosity>20) 681 cout << "Geometry::AfterRead()" << nbv << " " << nbe << endl; 682 Int4 i,k=0; ; 683 int jj; // jj in [0,1] 684 Int4 * hv = new Int4 [ nbv]; 685 Int4 * ev = new Int4 [ 2 * nbe ]; 686 float * eangle = new float[ nbe ]; 687 { 688 double eps = 1e-20; 689 QuadTree quadtree; // to find same vertices 690 Vertex * v0 = vertices; 691 GeometricalVertex * v0g = (GeometricalVertex *) (void *) v0; 692 int k=0; 693 for (i=0;i<nbv;i++) 694 vertices[i].link = vertices +i; 695 for (i=0;i<nbv;i++) 696 { 697 vertices[i].i = toI2(vertices[i].r); // set integer coordinate 698 Vertex *v= quadtree.NearestVertex(vertices[i].i.x,vertices[i].i.y); 699 if( v && Norme1(v->r - vertices[i]) < eps ) 700 { // link v & vertices[i] 701 // vieille ruse pour recuperer j 702 GeometricalVertex * vg = (GeometricalVertex *) (void *) v; 703 int j = vg-v0g; 704 assert( v == & (Vertex &) vertices[j]); 705 vertices[i].link = vertices + j; 706 k++; 707 } 708 else quadtree.Add(vertices[i]); 709 } 710 if (k) { 711 cout << " Number of distinte vertices " << nbv - k << " Over " << nbv << endl; 712 //if (verbosity>10) 713 { 714 cout << " The duplicate vertex " << endl; 715 for (i=0;i<nbv;i++) 716 if (!vertices[i].IsThe()) 717 cout << " " << i << " and " << Number(vertices[i].The()) << endl; 718 MeshError(102); 719 //throw(ErrorExec("exit",1)); 720 } 721 } 722 723 // verification of cracked edge 724 int err =0; 725 for (i=0;i<nbe;i++) 726 if (edges[i].Cracked() ) 727 { 728 // verification of crack 729 GeometricalEdge & e1=edges[i]; 730 GeometricalEdge & e2=*e1.link; 731 cerr << i << " " << e1[0].The() << " " << e2[0].The() << " " << e1[1].The() << " " << e2[1].The() << endl; 732 if ( e1[0].The() == e2[0].The() && e1[1].The() == e2[1].The() ) 733 { 734 } 735 else 736 if ( e1[0].The() == e2[1].The() && e1[1].The() == e2[0].The() ) 737 { 738 } 739 else 740 { 741 err++; 742 cerr << " Cracked edges with no same vertex " << &e1-edges << " " << &e2 -edges << endl; 743 } 744 } 745 else 746 { 747 // if (!edges[i][0].IsThe()) err++; 748 // if (!edges[i][1].IsThe()) err++; 749 } 750 if (err) 751 { 752 cerr << " Some vertex was not distint and not on cracked edge " << err<< endl; 753 MeshError(222); 754 } 755 } 756 if(verbosity>7) 757 for (i=0;i<nbv;i++) 758 if (vertices[i].Required()) 759 cout << " The geo vertices " << i << " is required" << endl; 760 761 for (i=0;i<nbv;i++) 762 hv[i]=-1;// empty list 763 764 for (i=0;i<nbe;i++) 765 { 766 R2 v10 = edges[i].v[1]->r - edges[i].v[0]->r; 767 Real8 lv10 = Norme2(v10); 768 if(lv10 == 0) { 769 cerr << "The length of " <<i<< "th Egde is 0 " << endl ; 770 MeshError(1);} 771 eangle[i] = atan2(v10.y,v10.x) ; // angle in [ -Pi,Pi ] 772 if(verbosity>9) 773 cout << " angle edge " << i <<" " << eangle[i]*180/Pi<< v10<<endl; 774 for (jj=0;jj<2;jj++) 775 { // generation of list 776 Int4 v = Number(edges[i].v[jj]); 777 ev[k] = hv[v]; 778 hv[v] = k++; 779 } 780 } 781 // bulle sort on the angle of edge 782 for (i=0;i<nbv;i++) { 783 int exch = 1,ord =0; 784 while (exch) { 785 exch = 0; 786 Int4 *p = hv + i, *po = p; 787 Int4 n = *p; 788 register float angleold = -1000 ; // angle = - infini 789 ord = 0; 790 while (n >=0) 791 { 792 ord++; 793 register Int4 i1= n /2; 794 register Int4 j1 = n % 2; 795 register Int4 *pn = ev + n; 796 float angle = j1 ? OppositeAngle(eangle[i1]): eangle[i1]; 797 n = *pn; 798 if (angleold > angle) // exch to have : po -> pn -> p 799 exch=1,*pn = *po,*po=*p,*p=n,po = pn; 800 else // to have : po -> p -> pn 801 angleold = angle, po = p,p = pn; 802 } 803 } // end while (exch) 804 805 if (ord >= 1 ) 806 { /* 807 Int4 n = hv[i]; 808 while ( n >=0) 809 { Int4 i1 = n/2,j1 = n%2; 810 //float a = 180*(j1 ? OppositeAngle(eangle[i1]): eangle[i1])/Pi; 811 n = ev[n]; 812 } 813 */ 814 } 815 if(ord == 2) { // angulare test to find a corner 816 Int4 n1 = hv[i]; 817 Int4 n2 = ev[n1]; 818 Int4 i1 = n1 /2, i2 = n2/2; // edge number 819 Int4 j1 = n1 %2, j2 = n2%2; // vertex in the edge 820 float angle1= j1 ? OppositeAngle(eangle[i1]) : eangle[i1]; 821 float angle2= !j2 ? OppositeAngle(eangle[i2]) : eangle[i2]; 822 float da12 = Abs(angle2-angle1); 823 if(verbosity>9) 824 cout <<" check angle " << i << " " << i1 << " " << i2 << " " << 180*(da12)/Pi 825 << " " << 180*MaximalAngleOfCorner/Pi << vertices[i] << endl; 826 827 if (( da12 >= MaximalAngleOfCorner ) 828 && (da12 <= 2*Pi -MaximalAngleOfCorner)) { 829 vertices[i].SetCorner() ; 830 if(verbosity>7) 831 cout << " The vertex " << i << " is a corner (angle) " 832 << 180*(da12)/ Pi<< " " << 180*MaximalAngleOfCorner/Pi << endl;} 833 // if the ref a changing then is SetRequired(); 834 835 if (edges[i1].flag != edges[i2].flag || edges[i1].Required()) 836 { 837 vertices[i].SetRequired(); 838 if(verbosity>7) 839 cout << " The vertex " << i << " is Required the flag change (crack or equi, or require)" << endl;} 840 841 if (edges[i1].ref != edges[i2].ref) { 842 vertices[i].SetRequired(); 843 if(verbosity>7) 844 cout << " The vertex " << i << " is Required ref" << endl;} 845 } ; 846 847 if(ord != 2) { 848 vertices[i].SetCorner(); 849 if(verbosity>7) 850 cout << " the vertex " << i << " is a corner ordre = " << ord << endl; 851 } 852 // close the liste around the vertex 853 { Int4 no=-1, ne = hv[i]; 854 while ( ne >=0) 855 ne = ev[no=ne]; 856 if(no>=0) 857 ev[no] = hv[i]; 858 } // now the list around the vertex is circular 859 860 } // end for (i=0;i<nbv;i++) 861 862 k =0; 863 for (i=0;i<nbe;i++) 864 for (jj=0;jj<2;jj++){ 865 Int4 n1 = ev[k++]; 866 Int4 i1 = n1/2 ,j1=n1%2; 867 if( edges[i1].v[j1] != edges[i].v[jj]) 868 { cerr << " Bug Adj edge " << i << " " << jj << 869 " et " << i1 << " " << j1 << " k=" << k; 870 cerr << Number(edges[i].v[jj]) <<" <> " 871 << Number(edges[i1].v[j1]) <<endl; 872 cerr << "edge " << Number(edges[i].v[0]) << " " 873 << Number(edges[i].v[1]) << endl; 874 // cerr << "in file " <<filename <<endl; 875 MeshError(1); 876 } 877 edges[i1].Adj[j1] = edges + i; 878 edges[i1].SensAdj[j1] = jj; 879 if (verbosity>10) 880 cout << " edges. Adj " << i1 << " " << j1 << " <--- " << i << " " << jj << endl; 881 } 882 883 // generation of all the tangente 884 for (i=0;i<nbe;i++) { 885 R2 AB = edges[i].v[1]->r -edges[i].v[0]->r; 886 Real8 lAB = Norme2(AB); // length of current edge AB 887 Real8 ltg2[2]; 888 ltg2[0]=0;ltg2[1]=0; 889 for (jj=0;jj<2;jj++) { 890 R2 tg = edges[i].tg[jj]; 891 Real8 ltg = Norme2(tg); // length of tg 892 if(ltg == 0) {// no tg 893 if( ! edges[i].v[jj]->Corner()) { // not a Corner 894 tg = edges[i].v[1-jj]->r 895 - edges[i].Adj[jj]->v[1-edges[i].SensAdj[jj]]->r; 896 ltg = Norme2(tg); 897 tg = tg *(lAB/ltg),ltg=lAB; 898 /* 899 if(edges[i].ref >=4) 900 cout << " tg " << tg.x << " "<< tg.y << " " << edges[i].v[1-jj]->r << edges[i].Adj[jj]->v[1-edges[i].SensAdj[jj]]->r << " y-y = " 901 << edges[i].v[1-jj]->r.y -edges[i].Adj[jj]->v[1-edges[i].SensAdj[jj]]->r.y << endl; 902 */ 903 } 904 905 //else ;// a Corner with no tangent => nothing to do 906 } // a tg 907 else 908 tg = tg *(lAB/ltg),ltg=lAB; 909 ltg2[jj] = ltg; 910 if ( (tg,AB) < 0) 911 tg = -tg; 912 //if(edges[i].ref >=4) cout << " tg = " << tg << endl; 913 edges[i].tg[jj] = tg; 914 } // for (jj=0;jj<2;jj++) 915 916 if (ltg2[0]!=0) edges[i].SetTgA(); 917 if (ltg2[1]!=0) edges[i].SetTgB(); 918 } // for (i=0;i<nbe;i++) 919 920 if(verbosity>7) 921 for (i=0;i<nbv;i++) 922 if (vertices[i].Required()) 923 cout << " The geo vertices " << i << " is required " << endl; 924 925 for (int step=0;step<2;step++) 926 { 927 for (i=0;i<nbe;i++) 928 edges[i].SetUnMark(); 929 930 NbOfCurves = 0; 931 Int4 nbgem=0; 932 for (int level=0;level < 2 && nbgem != nbe;level++) 933 for (i=0;i<nbe;i++) { 934 GeometricalEdge & ei = edges[i]; 935 for(jj=0;jj<2;jj++) 936 if (!ei.Mark() && (level || ei[jj].Required())) { 937 // warning ei.Mark() can be change in loop for(jj=0;jj<2;jj++) 938 int k0=jj,k1; 939 GeometricalEdge *e = & ei; 940 GeometricalVertex *a=(*e)(k0); // begin 941 if(curves) { 942 curves[NbOfCurves].be=e; 943 curves[NbOfCurves].kb=k0; 944 } 945 int nee=0; 946 for(;;) { 947 nee++; 948 k1 = 1-k0; // next vertex of the edge 949 e->SetMark(); 950 nbgem++; 951 e->CurveNumber=NbOfCurves; 952 if(curves) { 953 curves[NbOfCurves].ee=e; 954 curves[NbOfCurves].ke=k1; 955 } 956 957 GeometricalVertex *b=(*e)(k1); 958 if (a == b || b->Required() ) break; 959 k0 = e->SensAdj[k1];// vertex in next edge 960 e = e->Adj[k1]; // next edge 961 962 }// for(;;) 963 if(verbosity>10 && curves==0) cout << NbOfCurves <<" curve : nb edges= "<< nee<< endl; 964 NbOfCurves++; 965 if(level) { 966 if(verbosity>4) 967 cout << " Warning: Curve "<< NbOfCurves << " without required vertex " 968 << "so the vertex " << Number(a) << " become required " <<endl; 969 a->SetRequired(); 970 } 971 972 }} 973 assert(nbgem && nbe); 974 975 if(step==0) { 976 curves = new Curve[NbOfCurves]; 977 } 978 } 979 for(int i=0;i<NbOfCurves ;i++) 980 { 981 GeometricalEdge * be=curves[i].be, *eqbe=be->link; 982 //GeometricalEdge * ee=curves[i].ee, *eqee=be->link; 983 curves[i].master=true; 984 if(be->Equi() || be->ReverseEqui() ) 985 { 986 assert(eqbe); 987 int nc = eqbe->CurveNumber; 988 assert(i!=nc); 989 curves[i].next=curves[nc].next; 990 curves[i].master=false; 991 curves[nc].next=curves+i; 992 if(be->ReverseEqui()) 993 curves[i].Reverse(); 994 } 995 } 996 997 if(verbosity>3) 998 cout << " End ReadGeometry: Number of curves in geometry is " << NbOfCurves <<endl; 999 if(verbosity>4) 1000 for(int i=0;i<NbOfCurves ;i++) 1001 { 1002 cout << " Curve " << i << " begin e=" << Number(curves[i].be) << " k=" << curves[i].kb 1003 << " end e= " << Number(curves[i].ee) << " k=" << curves[i].ke << endl; 1004 } 1005 delete []ev; 1006 delete []hv; 1007 delete []eangle; 1008 1009 } 1010 Geometry::~Geometry() 1011 { 1012 long int verbosity=0; 1013 1014 assert(NbRef<=0); 1015 if(verbosity>9) 1016 cout << "DELETE ~Geometry "<< this << endl; 1017 if(vertices) delete [] vertices;vertices=0; 1018 if(edges) delete [] edges;edges=0; 1019 // if(edgescomponante) delete [] edgescomponante; edgescomponante=0; 1020 if(triangles) delete [] triangles;triangles=0; 1021 if(quadtree) delete quadtree;quadtree=0; 1022 if(curves) delete []curves;curves=0;NbOfCurves=0; 1023 if(name) delete [] name;name=0; 1024 if(subdomains) delete [] subdomains;subdomains=0; 1025 // if(ordre) delete [] ordre; 1026 EmptyGeometry(); 1027 1028 } 1029 1030 435 1031 } -
issm/trunk/src/c/Bamgx/Triangles.cpp
r2807 r2809 461 461 /*}}}1*/ 462 462 463 /*Others*/ 464 /*FUNCTION Triangles::ConsGeometry{{{1*/ 465 void Triangles::ConsGeometry(Real8 cutoffradian,int *equiedges) // construct a geometry if no geo 466 { 467 // if equiedges existe taille nbe 468 // equiedges[i]/2 == i original 469 // equiedges[i]/2 = j => equivalence entre i et j => meme maillage 470 // equiedges[i]%2 : 0 meme sens , 1 pas meme sens 471 // 472 // -------------------------- 473 long int verbosity=0; 474 if (verbosity>1) 475 cout << " -- construction of the geometry from the 2d mesh " << endl; 476 if (nbt<=0 || nbv <=0 ) { MeshError(101);} 477 478 // construction of the edges 479 // Triangles * OldCurrentTh =CurrentTh; 480 CurrentTh=this; 481 // Int4 NbTold = nbt; 482 // generation of the integer coor 483 // generation of the adjacence of the triangles 484 if (cutoffradian>=0) 485 Gh.MaximalAngleOfCorner = cutoffradian; 486 SetOfEdges4 * edge4= new SetOfEdges4(nbt*3,nbv); 487 Int4 * st = new Int4[nbt*3]; 488 Int4 i,k; 489 int j; 490 if (Gh.name) delete Gh.name; 491 Gh.name = new char [ name ? strlen(name) + 15 : 50 ]; 492 Gh.name[0]=0; 493 strcat(Gh.name,"cons from: "); 494 if (name) strcat(Gh.name,name); 495 else strcat(Gh.name," a mesh with no name"); 496 for (i=0;i<nbt*3;i++) 497 st[i]=-1; 498 Int4 kk =0; 499 500 Int4 nbeold = nbe; 501 for (i=0;i<nbe;i++) 502 { 503 // cout << i << " " << Number(edges[i][0]) << " " << Number(edges[i][1]) << endl; 504 edge4->addtrie(Number(edges[i][0]),Number(edges[i][1])); 505 } 506 if (nbe != edge4->nb()) 507 { 508 cerr << " Some Double edge in the mesh, the number is " << nbe 509 << " nbe4=" << edge4->nb() << endl; 510 MeshError(1002); 511 } 512 for (i=0;i<nbt;i++) 513 for (j=0;j<3;j++) 514 { 515 // Int4 i0,i1; 516 Int4 k =edge4->addtrie(Number(triangles[i][VerticesOfTriangularEdge[j][0]]), 517 Number(triangles[i][VerticesOfTriangularEdge[j][1]])); 518 Int4 invisible = triangles[i].Hidden(j); 519 if(st[k]==-1) 520 st[k]=3*i+j; 521 else if(st[k]>=0) { 522 assert( ! triangles[i].TriangleAdj(j) && !triangles[st[k] / 3].TriangleAdj((int) (st[k]%3))); 523 524 triangles[i].SetAdj2(j,triangles + st[k] / 3,(int) (st[k]%3)); 525 if (invisible) triangles[i].SetHidden(j); 526 if (k<nbe) { 527 triangles[i].SetLocked(j); 528 } 529 st[k]=-2-st[k]; } 530 else { 531 cerr << " The edge (" 532 << Number(triangles[i][VerticesOfTriangularEdge[j][0]]) 533 << " , " 534 << Number(triangles[i][VerticesOfTriangularEdge[j][1]]) 535 << " ) is in more than 2 triangles " <<k <<endl; 536 cerr << " Edge " << j << " Of Triangle " << i << endl; 537 cerr << " Edge " << (-st[k]+2)%3 << " Of Triangle " << (-st[k]+2)/3 << endl; 538 cerr << " Edge " << triangles[(-st[k]+2)/3].NuEdgeTriangleAdj((int)((-st[k]+2)%3)) 539 << " Of Triangle " << Number(triangles[(-st[k]+2)/3].TriangleAdj((int)((-st[k]+2)%3))) 540 << endl; 541 MeshError(9999);} 542 543 544 } 545 Int4 nbedges = edge4->nb(); // the total number of edges 546 delete edge4; 547 edge4 =0; 548 549 if(verbosity>5) { 550 if (name) 551 cout << " On Mesh " << name << endl; 552 cout << " - The number of Vertices = " << nbv << endl; 553 cout << " - The number of Triangles = " << nbt << endl; 554 cout << " - The number of given edge = " << nbe << endl; 555 cout << " - The number of all edges = " << nbedges << endl; 556 cout << " - The Euler number = 1-Nb Of Hole = " << nbt-nbedges+nbv << endl; } 557 558 559 // check the consistant of edge[].adj and the geometrical required vertex 560 k=0; 561 kk=0; 562 Int4 it; 563 564 for (i=0;i<nbedges;i++) 565 if (st[i] <-1) // edge internal 566 { 567 it = (-2-st[i])/3; 568 j = (int) ((-2-st[i])%3); 569 Triangle & tt = * triangles[it].TriangleAdj(j); 570 //cout << it << " c=" << triangles[it].color << " " << Number(tt) << " c=" << tt.color << endl; 571 if (triangles[it].color != tt.color|| i < nbeold) // Modif FH 06122055 // between 2 sub domai 572 k++; 573 } 574 else if (st[i] >=0) // edge alone 575 // if (i >= nbeold) 576 kk++; 577 578 if(verbosity>4 && (k+kk) ) 579 cout << " Nb of ref edge " << kk+k << " (internal " << k << ")" 580 << " in file " << nbe << endl; 581 k += kk; 582 kk=0; 583 if (k) 584 { 585 586 // if (nbe) { 587 // cerr << k << " boundary edges are not defined as edges " << endl; 588 // MeshError(9998); 589 // } 590 // construction of the edges 591 nbe = k; 592 Edge * edgessave = edges; 593 edges = new Edge[nbe]; 594 k =0; 595 // construction of the edges 596 if(verbosity>4) 597 cout << " Construction of the edges " << nbe << endl; 598 599 for (i=0;i<nbedges;i++) 600 { 601 Int4 add= -1; 602 603 if (st[i] <-1) // edge internal 604 { 605 it = (-2-st[i])/3; 606 j = (int) ((-2-st[i])%3); 607 Triangle & tt = * triangles[it].TriangleAdj(j); 608 if (triangles[it].color != tt.color || i < nbeold) // Modif FH 06122055 609 add=k++; 610 } 611 else if (st[i] >=0) // edge alone 612 { 613 it = st[i]/3; 614 j = (int) (st[i]%3); 615 add=k++; 616 } 617 618 if (add>=0 && add < nbe) 619 { 620 621 edges[add].v[0] = &triangles[it][VerticesOfTriangularEdge[j][0]]; 622 edges[add].v[1] = &triangles[it][VerticesOfTriangularEdge[j][1]]; 623 edges[add].on=0; 624 if (i<nbeold) // in file edge // Modif FH 06122055 625 { 626 edges[add].ref = edgessave[i].ref; 627 edges[add].on = edgessave[i].on; // HACK pour recuperer les aretes requise midf FH avril 2006 ???? 628 } 629 else 630 edges[add].ref = Min(edges[add].v[0]->ref(),edges[add].v[1]->ref()); // no a good choice 631 } 632 } 633 assert(k==nbe); 634 if (edgessave) delete [] edgessave; 635 } 636 637 // construction of edges[].adj 638 for (i=0;i<nbv;i++) 639 vertices[i].color =0; 640 for (i=0;i<nbe;i++) 641 for (j=0;j<2;j++) 642 edges[i].v[j]->color++; 643 644 for (i=0;i<nbv;i++) 645 vertices[i].color = (vertices[i].color ==2) ? -1 : -2; 646 for (i=0;i<nbe;i++) 647 for (j=0;j<2;j++) 648 { 649 Vertex *v=edges[i].v[j]; 650 Int4 i0=v->color,j0; 651 if(i0<0) 652 edges[i ].adj[ j ]=0; // Add FH Jan 2008 653 if(i0==-1) 654 v->color=i*2+j; 655 else if (i0>=0) {// i and i0 edge are adjacent by the vertex v 656 j0 = i0%2; 657 i0 = i0/2; 658 assert( v == edges[i0 ].v[j0]); 659 edges[i ].adj[ j ] =edges +i0; 660 edges[i0].adj[ j0] =edges +i ; 661 assert(edges[i0].v[j0] == v); 662 // if(verbosity>8) 663 // cout << " edges adj " << i0 << " "<< j0 << " <--> " << i << " " << j << endl; 664 v->color = -3;} 665 } 666 // now reconstruct the sub domain info 667 assert(!NbSubDomains); 668 NbSubDomains=0; 669 670 { 671 Int4 it; 672 // find all the sub domain 673 Int4 *colorT = new Int4[nbt]; 674 Triangle *tt,*t; 675 Int4 k; 676 for ( it=0;it<nbt;it++) 677 colorT[it]=-1; 678 for (it=0;it<nbt;it++) 679 { 680 if (colorT[it]<0) 681 { 682 colorT[it]=NbSubDomains; 683 Int4 level =1,j,jt,kolor=triangles[it].color; 684 st[0]=it; // stack 685 st[1]=0; 686 k=1; 687 while (level>0) 688 if( ( j=st[level]++) <3) 689 { 690 t = &triangles[st[level-1]]; 691 tt=t->TriangleAdj((int)j); 692 693 if ( ! t->Locked(j) && tt && (colorT[jt = Number(tt)] == -1) && ( tt->color==kolor)) 694 { 695 colorT[jt]=NbSubDomains; 696 st[++level]=jt; 697 st[++level]=0; 698 k++; 699 } 700 } 701 else 702 level-=2; 703 if (verbosity>5) 704 cout << " Nb of triangles " << k << " of Subdomain " 705 << NbSubDomains << " " << kolor << endl; 706 NbSubDomains++; 707 } 708 } 709 if (verbosity> 3) 710 cout << " The Number of sub domain = " << NbSubDomains << endl; 711 712 Int4 isd; 713 subdomains = new SubDomain[NbSubDomains]; 714 for (isd=0;isd<NbSubDomains;isd++) 715 { 716 subdomains[isd].head =0; 717 } 718 k=0; 719 for (it=0;it<nbt;it++) 720 for (int j=0;j<3;j++) 721 { 722 tt=triangles[it].TriangleAdj(j); 723 if ((!tt || tt->color != triangles[it].color) && !subdomains[isd=colorT[it]].head) 724 { 725 subdomains[isd].head = triangles+it; 726 subdomains[isd].ref = triangles[it].color; 727 subdomains[isd].sens = j; // hack 728 subdomains[isd].edge = 0; 729 k++; 730 } 731 } 732 assert(k== NbSubDomains); 733 734 delete [] colorT; 735 736 737 } 738 delete [] st; 739 // now make the geometry 740 // 1 compress the vertices 741 Int4 * colorV = new Int4[nbv]; 742 for (i=0;i<nbv;i++) 743 colorV[i]=-1; 744 for (i=0;i<nbe;i++) 745 for ( j=0;j<2;j++) 746 colorV[Number(edges[i][j])]=0; 747 k=0; 748 for (i=0;i<nbv;i++) 749 if(!colorV[i]) 750 colorV[i]=k++; 751 752 Gh.nbv=k; 753 Gh.nbe = nbe; 754 Gh.vertices = new GeometricalVertex[k]; 755 Gh.edges = new GeometricalEdge[nbe]; 756 Gh.NbSubDomains = NbSubDomains; 757 Gh.subdomains = new GeometricalSubDomain[NbSubDomains]; 758 if (verbosity>3) 759 cout << " Nb of vertices = " << Gh.nbv << " Nb of edges = " << Gh.nbe << endl; 760 NbVerticesOnGeomVertex = Gh.nbv; 761 VerticesOnGeomVertex = new VertexOnGeom[NbVerticesOnGeomVertex]; 762 NbVerticesOnGeomEdge =0; 763 VerticesOnGeomEdge =0; 764 { 765 Int4 j; 766 for (i=0;i<nbv;i++) 767 if((j=colorV[i])>=0) 768 { 769 770 Vertex & v = Gh.vertices[j]; 771 v = vertices[i]; 772 v.color =0; 773 VerticesOnGeomVertex[j] = VertexOnGeom(vertices[i], Gh.vertices[j]); 774 } 775 776 } 777 edge4= new SetOfEdges4(nbe,nbv); 778 779 Real4 * len = new Real4[Gh.nbv]; 780 for(i=0;i<Gh.nbv;i++) 781 len[i]=0; 782 783 Gh.pmin = Gh.vertices[0].r; 784 Gh.pmax = Gh.vertices[0].r; 785 // recherche des extrema des vertices pmin,pmax 786 for (i=0;i<Gh.nbv;i++) { 787 Gh.pmin.x = Min(Gh.pmin.x,Gh.vertices[i].r.x); 788 Gh.pmin.y = Min(Gh.pmin.y,Gh.vertices[i].r.y); 789 Gh.pmax.x = Max(Gh.pmax.x,Gh.vertices[i].r.x); 790 Gh.pmax.y = Max(Gh.pmax.y,Gh.vertices[i].r.y); 791 } 792 793 R2 DD05 = (Gh.pmax-Gh.pmin)*0.05; 794 Gh.pmin -= DD05; 795 Gh.pmax += DD05; 796 797 Gh.coefIcoor= (MaxICoor)/(Max(Gh.pmax.x-Gh.pmin.x,Gh.pmax.y-Gh.pmin.y)); 798 assert(Gh.coefIcoor >0); 799 800 Real8 hmin = HUGE_VAL; 801 int kreq=0; 802 for (i=0;i<nbe;i++) 803 { 804 Int4 i0 = Number(edges[i][0]); 805 Int4 i1 = Number(edges[i][1]); 806 Int4 j0 = colorV[i0]; 807 Int4 j1 = colorV[i1]; 808 809 Gh.edges[i].v[0] = Gh.vertices + j0; 810 Gh.edges[i].v[1] = Gh.vertices + j1; 811 Gh.edges[i].flag = 0; 812 Gh.edges[i].tg[0]=R2(); 813 Gh.edges[i].tg[1]=R2(); 814 bool requis= edges[i].on; 815 if(requis) kreq++; 816 edges[i].on = Gh.edges + i; 817 if(equiedges && i < nbeold ) { 818 int j=equiedges[i]/2; 819 int sens=equiedges[i]%2; 820 if(i!=j && equiedges[i]>=0) { 821 if(verbosity>9) 822 cout << " Edges Equi " << i << " <=> " << j << " sens = " << sens << endl; 823 if( sens==0) 824 Gh.edges[i].SetEqui(); 825 else 826 Gh.edges[i].SetReverseEqui(); 827 Gh.edges[i].link= & Gh.edges[j]; 828 //assert(sens==0);// meme sens pour l'instant 829 } 830 831 } 832 if(requis) { // correction fevr 2009 JYU ... 833 Gh.edges[i].v[0]->SetRequired(); 834 Gh.edges[i].v[1]->SetRequired(); 835 Gh.edges[i].SetRequired(); // fin modif ... 836 } 837 R2 x12 = Gh.vertices[j0].r-Gh.vertices[j1].r; 838 Real8 l12=Norme2(x12); 839 hmin = Min(hmin,l12); 840 841 Gh.vertices[j1].color++; 842 Gh.vertices[j0].color++; 843 844 len[j0]+= l12; 845 len[j1] += l12; 846 hmin = Min(hmin,l12); 847 848 Gh.edges[i].ref = edges[i].ref; 849 850 k = edge4->addtrie(i0,i1); 851 852 assert(k == i); 853 854 } 855 856 857 for (i=0;i<Gh.nbv;i++) 858 if (Gh.vertices[i].color > 0) 859 Gh.vertices[i].m= Metric(len[i] /(Real4) Gh.vertices[i].color); 860 else 861 Gh.vertices[i].m= Metric(hmin); 862 delete [] len; 863 for (i=0;i<NbSubDomains;i++) 864 { 865 Int4 it = Number(subdomains[i].head); 866 int j = subdomains[i].sens; 867 Int4 i0 = Number(triangles[it][VerticesOfTriangularEdge[j][0]]); 868 Int4 i1 = Number(triangles[it][VerticesOfTriangularEdge[j][1]]); 869 k = edge4->findtrie(i0,i1); 870 if(k>=0) 871 { 872 subdomains[i].sens = (vertices + i0 == edges[k].v[0]) ? 1 : -1; 873 subdomains[i].edge = edges+k; 874 Gh.subdomains[i].edge = Gh.edges + k; 875 Gh.subdomains[i].sens = subdomains[i].sens; 876 Gh.subdomains[i].ref = subdomains[i].ref; 877 } 878 else 879 MeshError(103); 880 } 881 882 delete edge4; 883 delete [] colorV; 884 // -- unset adj 885 for (i=0;i<nbt;i++) 886 for ( j=0;j<3;j++) 887 triangles[i].SetAdj2(j,0,triangles[i].GetAllflag(j)); 888 889 } 890 /*}}}1*/ 891 463 892 } // end of namespace bamg -
issm/trunk/src/c/Makefile.am
r2806 r2809 322 322 ./Bamgx/Mesh2.cpp \ 323 323 ./Bamgx/Mesh2.h \ 324 ./Bamgx/ MeshGeom.cpp \324 ./Bamgx/GeometricalEdge.cpp \ 325 325 ./Bamgx/MeshQuad.cpp \ 326 326 ./Bamgx/meshtype.h \ … … 662 662 ./Bamgx/Mesh2.cpp \ 663 663 ./Bamgx/Mesh2.h \ 664 ./Bamgx/ MeshGeom.cpp \664 ./Bamgx/GeometricalEdge.cpp \ 665 665 ./Bamgx/MeshQuad.cpp \ 666 666 ./Bamgx/meshtype.h \
Note:
See TracChangeset
for help on using the changeset viewer.