Changeset 3322
- Timestamp:
- 03/23/10 08:26:51 (15 years ago)
- Location:
- issm/trunk/src/c/Bamgx/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/objects/Geometry.cpp
r3312 r3322 355 355 BamgGeomInit(bamggeom); 356 356 357 / /Vertices357 /*Vertices*/ 358 358 if(verbose>5) printf(" writing Vertices\n"); 359 359 bamggeom->VerticesSize[0]=nbv; … … 370 370 } 371 371 } 372 else{ 373 bamggeom->Vertices=NULL; 374 } 375 376 //Edges 372 373 /*Edges*/ 377 374 if(verbose>5) printf(" writing Edges\n"); 378 375 bamggeom->EdgesSize[0]=nbe; … … 394 391 } 395 392 } 396 else{ 397 bamggeom->Edges=NULL; 398 } 399 400 //CrackedEdges 393 394 /*CrackedEdges*/ 401 395 if(verbose>5) printf(" writing CrackedEdges\n"); 402 396 bamggeom->CrackedEdgesSize[0]=nbcracked; … … 415 409 } 416 410 } 417 else{ 418 bamggeom->CrackedEdges=NULL; 419 } 420 421 //RequiredEdges 411 412 /*RequiredEdges*/ 422 413 if(verbose>5) printf(" writing %i RequiredEdges\n",nbreq); 423 414 bamggeom->RequiredEdgesSize[0]=nbreq; … … 433 424 } 434 425 } 435 else{436 bamggeom->RequiredEdges=NULL;437 }438 426 439 427 //No corners 440 428 441 / /RequiredVertices429 /*RequiredVertices*/ 442 430 if(verbose>5) printf(" writing %i RequiredVertices\n",nbreqv); 443 431 bamggeom->RequiredVerticesSize[0]=nbreqv; … … 453 441 } 454 442 } 455 else{ 456 bamggeom->RequiredVertices=NULL; 457 } 458 459 //SubDomains 443 444 /*SubDomains*/ 460 445 if(verbose>5) printf(" writing SubDomains\n"); 461 446 bamggeom->SubDomainsSize[0]=NbSubDomains; … … 470 455 } 471 456 } 472 else{ 473 bamggeom->SubDomains=NULL; 474 } 475 476 //TangentAtEdges 457 458 /*TangentAtEdges*/ 477 459 if(verbose>5) printf(" writing TangentAtEdges\n"); 478 460 bamggeom->TangentAtEdgesSize[0]=nbtan; … … 496 478 count=count+1; 497 479 } 498 }499 else{500 bamggeom->TangentAtEdges=NULL;501 480 } 502 481 } -
issm/trunk/src/c/Bamgx/objects/Triangles.cpp
r3315 r3322 554 554 void Triangles::WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts){ 555 555 556 /*Intermediary*/ 556 557 int i,j,k,num,i1,i2; 557 558 long n; 559 int* head_1=NULL; 560 int* next_1=NULL; 561 int* connectivitysize_1=NULL; 562 int connectivitymax_1=0; 563 558 564 /*Get options*/ 559 565 int verbose=bamgopts->verbose; … … 562 568 BamgMeshInit(bamgmesh); 563 569 564 / /Build reft that holds the number the subdomain number of each triangle570 /*Build reft that holds the number the subdomain number of each triangle*/ 565 571 long* reft = new long[nbt]; 566 572 long nbInT = TriangleReferenceList(reft); 567 573 568 //Vertices 574 /*Chaining algorithm used to generate connectivity tables and other outputs*/ 575 576 //Memory Allocation 577 head_1=(int*)xmalloc(nbv*sizeof(int)); 578 next_1=(int*)xmalloc(3*nbt*sizeof(int)); 579 connectivitysize_1=(int*)xmalloc(nbv*sizeof(int)); 580 581 //Initialization 582 for (i=0;i<nbv;i++) head_1[i]=-1; 583 for (i=0;i<nbv;i++) connectivitysize_1[i]=0; 584 k=0; 585 //Chains generation 586 for (i=0;i<nbt;i++) { 587 //Do not take into account outside triangles (reft<0) 588 if (reft[i]>=0){ 589 for (j=0;j<3;j++){ 590 int v=Number(triangles[i][j]); //jth vertex of the ith triangle 591 if (k>3*nbt-1 || k<0) throw ErrorException(__FUNCT__,exprintf("k = %i, nbt = %i",k,nbt)); 592 next_1[k]=head_1[v]; 593 if (v>nbv-1 || v<0) throw ErrorException(__FUNCT__,exprintf("v = %i, nbv = %i",v,nbv)); 594 head_1[v]=k++; 595 connectivitysize_1[v]+=1; 596 } 597 } 598 } 599 //Get maximum connectivity 600 connectivitymax_1=0; 601 for (i=0;i<nbv;i++){ 602 if (connectivitysize_1[i]>connectivitymax_1) connectivitymax_1=connectivitysize_1[i]; 603 } 604 605 /*OK, now build outputs*/ 606 607 /*Vertices*/ 569 608 if(verbose>5) printf(" writing Vertices\n"); 570 609 bamgmesh->VerticesSize[0]=nbv; … … 578 617 } 579 618 } 580 else{ 581 bamgmesh->Vertices=NULL; 582 } 583 584 //Edges 619 620 /*Edges*/ 585 621 if(verbose>5) printf(" writing Edges\n"); 586 622 bamgmesh->EdgesSize[0]=nbe; … … 598 634 } 599 635 } 600 else{ 601 bamgmesh->Edges=NULL; 602 } 603 604 //Element Connectivity 605 if(verbose>5) printf(" writing Element connectivity\n"); 606 bamgmesh->ElementConnectivitySize[0]=nbt-NbOutT; 607 bamgmesh->ElementConnectivitySize[1]=3; 608 bamgmesh->ElementConnectivity=(double*)xmalloc(3*(nbt-NbOutT)*sizeof(double)); 609 for (i=0;i<3*(nbt-NbOutT);i++) bamgmesh->ElementConnectivity[i]=NAN; 610 num=0; 611 for (i=0;i<nbt;i++){ 612 if (reft[i]>=0){ 613 for (j=0;j<3;j++){ 614 k=Number(triangles[i].TriangleAdj(j)); 615 if (reft[k]>=0){ 616 assert(3*num+j<3*(nbt-NbOutT)); 617 bamgmesh->ElementConnectivity[3*num+j]=k+1; // back to Matlab indexing 618 } 619 } 620 num+=1; 621 } 622 } 623 624 //ElementNodal Connectivity 625 if(verbose>5) printf(" writing Nodal element connectivity\n"); 626 //chaining algorithm to get nodal connectivity 627 int* head_v=NULL; 628 head_v=(int*)xmalloc(nbv*sizeof(int)); 629 int* next_p=NULL; 630 next_p=(int*)xmalloc(3*nbt*sizeof(int)); 631 int* connectivitysize=NULL; 632 connectivitysize=(int*)xmalloc(nbv*sizeof(int)); 633 for (i=0;i<nbv;i++) head_v[i]=-1; 634 for (i=0;i<nbv;i++) connectivitysize[i]=0; 635 k=0; 636 for (i=0;i<nbt;i++) { 637 //Do not take into account outside triangles (reft<0) 638 if (reft[i]>=0){ 639 for (j=0;j<3;j++){ 640 int v=Number(triangles[i][j]); //jth vertex of the ith triangle 641 if (k>3*nbt-1 || k<0) throw ErrorException(__FUNCT__,exprintf("k = %i, nbt = %i",k,nbt)); 642 next_p[k]=head_v[v]; 643 if (v>nbv-1 || v<0) throw ErrorException(__FUNCT__,exprintf("v = %i, nbv = %i",v,nbv)); 644 head_v[v]=k++; 645 connectivitysize[v]+=1; 646 } 647 } 648 } 649 int max=0; 650 for (i=0;i<nbv;i++){ 651 if (connectivitysize[i]>max) max=connectivitysize[i]; 652 } 653 //Build output 654 bamgmesh->NodalElementConnectivitySize[0]=nbv; 655 bamgmesh->NodalElementConnectivitySize[1]=max; 656 bamgmesh->NodalElementConnectivity=(double*)xmalloc(max*nbv*sizeof(double)); 657 for (i=0;i<max*nbv;i++) bamgmesh->NodalElementConnectivity[i]=NAN; 658 for (i=0;i<nbv;i++){ 659 k=0; 660 for(j=head_v[i];j!=-1;j=next_p[j]){ 661 assert(max*i+k < max*nbv); 662 bamgmesh->NodalElementConnectivity[max*i+k]=floor(j/3)+1; 663 k++; 664 } 665 } 666 //clean up (do not erase head_v and next_p-> used and destroyed by segments) 667 xfree((void**)&connectivitysize); 668 669 //Build Unique edges 636 637 /*Element edges*/ 670 638 if(verbose>5) printf(" writing element edges\n"); 671 639 SetOfEdges4* edge4=new SetOfEdges4(nbt*3,nbv); … … 707 675 xfree((void**)&elemedge); 708 676 709 / /Segments677 /*Segments*/ 710 678 if(verbose>5) printf(" writing Segments\n"); 711 679 bamgmesh->SegmentsSize[0]=NumSegments; … … 719 687 int i2=Number(edges[i][1]); 720 688 bool stop=false; 721 for(j=head_ v[i1];j!=-1;j=next_p[j]){689 for(j=head_1[i1];j!=-1;j=next_1[j]){ 722 690 for(k=0;k<3;k++){ 723 691 if (Number(triangles[(int)j/3][k])==i1){ … … 749 717 } 750 718 } 751 //clean up 752 xfree((void**)&head_v); 753 xfree((void**)&next_p); 754 755 //CrackedEdges 719 720 /*CrackedEdges*/ 756 721 if(verbose>5) printf(" writing CrackedEdges\n"); 757 722 bamgmesh->CrackedEdgesSize[0]=NbCrackedEdges; … … 764 729 } 765 730 } 766 else{ 767 bamgmesh->CrackedEdges=NULL; 768 } 769 770 //Triangles 731 732 /*Triangles*/ 771 733 if(verbose>5) printf(" writing Triangles\n"); 772 734 k=nbInT-NbOfQuad*2; … … 788 750 } 789 751 } 790 else{ 791 bamgmesh->Triangles=NULL; 792 } 793 794 //Quadrilaterals 752 753 /*Quadrilaterals*/ 795 754 if(verbose>5) printf(" writing Quadrilaterals\n"); 796 755 bamgmesh->QuadrilateralsSize[0]=NbOfQuad; … … 812 771 } 813 772 } 814 else{ 815 bamgmesh->Quadrilaterals=NULL; 816 } 817 818 //SubDomains 773 774 /*SubDomains*/ 819 775 if(verbose>5) printf(" writing SubDomains\n"); 820 776 bamgmesh->SubDomainsSize[0]=NbSubDomains; … … 829 785 } 830 786 } 831 else{ 832 bamgmesh->SubDomains=NULL; 833 } 834 835 //SubDomainsFromGeom 787 788 /*SubDomainsFromGeom*/ 836 789 if(verbose>5) printf(" writing SubDomainsFromGeom\n"); 837 790 bamgmesh->SubDomainsFromGeomSize[0]=Gh.NbSubDomains; … … 846 799 } 847 800 } 848 else{ 849 bamgmesh->SubDomainsFromGeom=NULL; 850 } 851 852 //VerticesOnGeomVertex 801 802 /*VerticesOnGeomVertex*/ 853 803 if(verbose>5) printf(" writing VerticesOnGeometricVertex\n"); 854 804 bamgmesh->VerticesOnGeometricVertexSize[0]=NbVerticesOnGeomVertex; … … 863 813 } 864 814 } 865 else{ 866 bamgmesh->VerticesOnGeometricVertex=NULL; 867 } 868 869 //VertexOnGeometricEdge 815 816 /*VertexOnGeometricEdge*/ 870 817 if(verbose>5) printf(" writing VerticesOnGeometricEdge\n"); 871 818 bamgmesh->VerticesOnGeometricEdgeSize[0]=NbVerticesOnGeomEdge; … … 883 830 } 884 831 } 885 else{ 886 bamgmesh->VerticesOnGeometricEdge=NULL; 887 } 888 889 //EdgesOnGeometricEdge 832 833 /*EdgesOnGeometricEdge*/ 890 834 if(verbose>5) printf(" writing EdgesOnGeometricEdge\n"); 891 835 k=0; … … 906 850 } 907 851 } 908 else{ 909 bamgmesh->EdgesOnGeometricEdge=NULL; 910 } 911 852 853 /*Element Connectivity*/ 854 if(verbose>5) printf(" writing Element connectivity\n"); 855 bamgmesh->ElementConnectivitySize[0]=nbt-NbOutT; 856 bamgmesh->ElementConnectivitySize[1]=3; 857 bamgmesh->ElementConnectivity=(double*)xmalloc(3*(nbt-NbOutT)*sizeof(double)); 858 for (i=0;i<3*(nbt-NbOutT);i++) bamgmesh->ElementConnectivity[i]=NAN; 859 num=0; 860 for (i=0;i<nbt;i++){ 861 if (reft[i]>=0){ 862 for (j=0;j<3;j++){ 863 k=Number(triangles[i].TriangleAdj(j)); 864 if (reft[k]>=0){ 865 assert(3*num+j<3*(nbt-NbOutT)); 866 bamgmesh->ElementConnectivity[3*num+j]=k+1; // back to Matlab indexing 867 } 868 } 869 num+=1; 870 } 871 } 872 873 /*ElementNodal Connectivity*/ 874 if(verbose>5) printf(" writing Nodal element connectivity\n"); 875 bamgmesh->NodalElementConnectivitySize[0]=nbv; 876 bamgmesh->NodalElementConnectivitySize[1]=connectivitymax_1; 877 bamgmesh->NodalElementConnectivity=(double*)xmalloc(connectivitymax_1*nbv*sizeof(double)); 878 for (i=0;i<connectivitymax_1*nbv;i++) bamgmesh->NodalElementConnectivity[i]=NAN; 879 for (i=0;i<nbv;i++){ 880 k=0; 881 for(j=head_1[i];j!=-1;j=next_1[j]){ 882 assert(connectivitymax_1*i+k < connectivitymax_1*nbv); 883 bamgmesh->NodalElementConnectivity[connectivitymax_1*i+k]=floor(j/3)+1; 884 k++; 885 } 886 } 887 888 /*Nodal Connectivity*/ 889 if(verbose>5) printf(" writing Nodal connectivity\n"); 890 //chaining algorithm (again...) 891 int* head_2=NULL; 892 int* next_2=NULL; 893 int* connectivitysize_2=NULL; 894 int connectivitymax_2=0; 895 i1=bamgmesh->ElementEdgesSize[0]; 896 i2=bamgmesh->ElementEdgesSize[1]; 897 head_2=(int*)xmalloc(nbv*sizeof(int)); 898 next_2=(int*)xmalloc(2*i1*sizeof(int)); 899 connectivitysize_2=(int*)xmalloc(nbv*sizeof(int)); 900 //Initialization 901 for (i=0;i<nbv;i++) head_2[i]=-1; 902 for (i=0;i<nbv;i++) connectivitysize_2[i]=0; 903 k=0; 904 //Chains generation 905 for (i=0;i<i1;i++) { 906 for (j=0;j<2;j++){ 907 int v=(int)bamgmesh->ElementEdges[i*i2+j]-1; //back to C indexing 908 if (k>2*i1-1 || k<0) throw ErrorException(__FUNCT__,exprintf("Index exceed matrix dimensions (k=%i not in [0 %i]",k,2*i1-1)); 909 next_2[k]=head_2[v]; 910 if (v>nbv-1 || v<0) throw ErrorException(__FUNCT__,exprintf("Index exceed matrix dimensions (v=%i not in [0 %i])",v,nbv-1)); 911 head_2[v]=k++; 912 connectivitysize_2[v]+=1; 913 } 914 } 915 //Get maximum connectivity 916 for (i=0;i<nbv;i++){ 917 if (connectivitysize_2[i]>connectivitymax_2) connectivitymax_2=connectivitysize_2[i]; 918 } 919 //Build output 920 bamgmesh->NodalConnectivitySize[0]=nbv; 921 bamgmesh->NodalConnectivitySize[1]=connectivitymax_2; 922 bamgmesh->NodalConnectivity=(double*)xmalloc(connectivitymax_2*nbv*sizeof(double)); 923 for (i=0;i<connectivitymax_2*nbv;i++) bamgmesh->NodalConnectivity[i]=NAN; 924 for (i=0;i<nbv;i++){ 925 k=0; 926 for(j=head_2[i];j!=-1;j=next_2[j]){ 927 assert(connectivitymax_2*i+k < connectivitymax_2*nbv); 928 num=(int)bamgmesh->ElementEdges[int(j/2)*i2+0]; 929 if (i+1==num){ //carefull, ElementEdge is in M indexing 930 //i is the first vertex of the edge, it is therefore connected to the second vertex 931 bamgmesh->NodalConnectivity[connectivitymax_2*i+k]=bamgmesh->ElementEdges[int(j/2)*i2+1]; 932 } 933 else{ 934 bamgmesh->NodalConnectivity[connectivitymax_2*i+k]=num; 935 } 936 k++; 937 } 938 } 912 939 913 940 //clean up 941 xfree((void**)&connectivitysize_1); 942 xfree((void**)&head_1); 943 xfree((void**)&next_1); 944 xfree((void**)&connectivitysize_2); 945 xfree((void**)&head_2); 946 xfree((void**)&next_2); 914 947 delete [] reft; 915 948 }
Note:
See TracChangeset
for help on using the changeset viewer.