Changeset 5448


Ignore:
Timestamp:
08/20/10 11:22:07 (15 years ago)
Author:
Mathieu Morlighem
Message:

As usual

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Bamg/Mesh.cpp

    r5447 r5448  
    48754875                /*Generate mesh from geometry*/
    48764876
    4877                 Gh.NbRef++;// add a ref to GH
    4878 
    4879                 int i,j,k;
    4880                 int nbcurves=0,NbNewPoints,NbEdgeCurve;
    4881                 double lcurve,lstep,s;
    4882                 const int MaxSubEdge = 10;
    4883 
    4884                 R2 AB;
    4885                 GeometricalVertex *a,*b;
    4886                 BamgVertex *va,*vb;
    4887                 GeometricalEdge *e;
     4877                /*Intermediaries*/
     4878                int                i,j,k;
     4879                int                nbcurves    = 0;
     4880                int                NbNewPoints,NbEdgeCurve;
     4881                double             lcurve,lstep,s;
     4882                const int          MaxSubEdge  = 10;
     4883
     4884                R2                 AB;
     4885                GeometricalVertex *a, *b;
     4886                BamgVertex        *va, *vb;
     4887                GeometricalEdge   *e;
     4888
     4889                // add a ref to GH to make sure that it is not destroyed by mistake
     4890                Gh.NbRef++;
    48884891
    48894892                /*Get options*/
    48904893                int verbose=bamgopts->verbose;
    48914894
    4892                 //initialize this
    4893                 if (verbose>3) printf("      Generating Boundary vertices\n");
     4895                //initialize Mesh
    48944896                Init(imaxnbv);
    48954897                nbv=0;
     
    48984900
    48994901                //build background mesh flag (1 if background, else 0)
    4900                 int  background=(&BTh != this);
    4901 
    4902                 //Compute number of vertices on geometrical vertex
     4902                bool background=(&BTh != this);
     4903
     4904                /*Build VerticesOnGeomVertex*/
     4905
     4906                //Compute the number of geometrical vertices that we are going to use to mesh
    49034907                for (i=0;i<Gh.nbv;i++){
    49044908                        if (Gh[i].Required()) NbVerticesOnGeomVertex++;
    49054909                }
    4906 
    4907                 //initialize VerticesOnGeomVertex
     4910                //allocate
    49084911                VerticesOnGeomVertex = new VertexOnGeom[NbVerticesOnGeomVertex]; 
    4909                 if( NbVerticesOnGeomVertex >= maxnbv) {
    4910                         ISSMERROR("too many vertices on geometry: %i >= %i",NbVerticesOnGeomVertex,maxnbv);
    4911                 }
    4912 
    4913                 //Add all the geometrical vertices to the mesh
     4912                if(NbVerticesOnGeomVertex >= maxnbv) ISSMERROR("too many vertices on geometry: %i >= %i",NbVerticesOnGeomVertex,maxnbv);
     4913                //Build VerticesOnGeomVertex
    49144914                nbv=0;
    49154915                for (i=0;i<Gh.nbv;i++){
     
    49174917                        if (Gh[i].Required()) {//Gh  vertices Required
    49184918
    4919                                 //Add the vertex (provided that nbv<maxnbv)
    4920                                 if (nbv<maxnbv){
    4921                                         vertices[nbv]=Gh[i];
    4922                                 }
    4923                                 else{
    4924                                         ISSMERROR("Maximum number of vertices (maxnbv = %i) too small",maxnbv);
    4925                                 }
     4919                                //Add the vertex
     4920                                ISSMASSERT(nbv<maxnbv);
     4921                                vertices[nbv]=Gh[i];
    49264922                               
    49274923                                //Add pointer from geometry (Gh) to vertex from mesh (Th)
     
    49294925
    49304926                                //Build VerticesOnGeomVertex for current point
    4931                                 VerticesOnGeomVertex[nbv]= VertexOnGeom(*Gh[i].to,Gh[i]);
     4927                                VerticesOnGeomVertex[nbv]=VertexOnGeom(*Gh[i].to,Gh[i]);
    49324928
    49334929                                //nbv increment
     
    49364932                }
    49374933
    4938                 //check that edges has been allocated
    4939                 if (edges){
    4940                         ISSMERROR("edges is empty");
    4941                 }
     4934                /*Build VerticesOnGeomEdge*/
     4935
     4936                //check that edges is still empty (Init)
     4937                ISSMASSERT(!edges);
    49424938
    49434939                /* Now we are going to create the first edges corresponding
     
    49574953
    49584954                        //go through the edges of the geometry
    4959                         for (i=0;i<Gh.nbe;i++) {
     4955                        for (i=0;i<Gh.nbe;i++){
    49604956
    49614957                                //ei = current Geometrical edge
    49624958                                GeometricalEdge &ei=Gh.edges[i];   
    49634959
     4960                                //loop over the two vertices of the edge ei
    49644961                                for(int j=0;j<2;j++) {
    49654962
    4966                                         /*The first time, no edge is marked but this might change during the loop*/
     4963                                        /*Take only required vertices (corner)*/
    49674964                                        if (!ei.Mark() && ei[j].Required()){
    49684965
    49694966                                                long  nbvend=0;
    49704967                                                Edge* PreviousNewEdge=NULL;
    4971 
    49724968                                                lstep = -1;
    49734969
    4974                                                 /*If Edge is required*/
    4975                                                 if(ei.Required()){
     4970                                                /*If Edge is required (do that only once for the 2 vertices)*/
     4971                                                if(ei.Required() && j==0){
    49764972                                                        //do not create internal points if required (take it as is)
    4977                                                         if (j==0){
    4978                                                                 if(step==0) nbe++;
    4979                                                                 else{
    4980                                                                         e=&ei;
    4981                                                                         a=ei(0);
    4982                                                                         b=ei(1);
    4983 
    4984                                                                         //check that edges has been allocated
    4985                                                                         if (!edges) ISSMERROR("edges has not been allocated...");
    4986                                                                         edges[nbe].v[0]=a->to;
    4987                                                                         edges[nbe].v[1]=b->to;;
    4988                                                                         edges[nbe].ReferenceNumber = e->ReferenceNumber;
    4989                                                                         edges[nbe].GeometricalEdgeHook = e;
    4990                                                                         edges[nbe].adj[0] = 0;
    4991                                                                         edges[nbe].adj[1] = 0;
    4992                                                                         nbe++;
    4993                                                                 }
     4973                                                        if(step==0) nbe++;
     4974                                                        else{
     4975                                                                e=&ei;
     4976                                                                a=ei(0);
     4977                                                                b=ei(1);
     4978
     4979                                                                //check that edges has been allocated
     4980                                                                ISSMASSERT(edges);
     4981                                                                edges[nbe].v[0]=a->to;
     4982                                                                edges[nbe].v[1]=b->to;;
     4983                                                                edges[nbe].ReferenceNumber = e->ReferenceNumber;
     4984                                                                edges[nbe].GeometricalEdgeHook = e;
     4985                                                                edges[nbe].adj[0] = 0;
     4986                                                                edges[nbe].adj[1] = 0;
     4987                                                                nbe++;
    49944988                                                        }
    49954989                                                }
    49964990
    4997                                                 /*If Edge is not required: on a curve*/
     4991                                                /*If Edge is not required: we are on a curve*/
    49984992                                                else {
    49994993                                                        for (int kstep=0;kstep<=step;kstep++){
    5000                                                                 //step=0, do nothing
    5001                                                                 //step=1, compute the length of the curve
    5002                                                                 //step=2  create the points and edge
     4994                                                                //kstep=0, do nothing
     4995                                                                //kstep=1, compute the length of the curve
     4996                                                                //kstep=2  create the points and edge
    50034997                                                                PreviousNewEdge=0;
    50044998                                                                NbNewPoints=0;
     
    50085002                                                                s = lstep;
    50095003
    5010                                                                 // i = edge number, j=[0;1] vertex number in edge
    5011 
    5012                                                                 k=j;            // k = vertex number in edge (0 or 1)
     5004                                                                /*reminder: i = edge number, j=[0;1] vertex index in edge*/
     5005                                                                k=j;            // k = vertex index in edge (0 or 1)
    50135006                                                                e=&ei;          // e = reference of current edge
    50145007                                                                a=ei(k);        // a = pointer toward the kth vertex of the current edge
    5015                                                                 va = a->to;     // va = pointer toward vertex associated
     5008                                                                va = a->to;     // va = pointer toward mesh vertex associated
    50165009                                                                e->SetMark();   // Mark edge
    50175010
    5018                                                                 //if SameGeo We have go to the background geometry
    5019                                                                 //to find the discretisation of the curve
     5011                                                                /*If we have a Background mesh, we can use it to discretize the curve*/
    50205012                                                                for(;;){
    5021                                                                         k = 1-k;
    5022                                                                         b = (*e)(k);// b = pointer toward the other vertex of the current edge
     5013                                                                        k = 1-k;            // other vertx index of the curve
     5014                                                                        b = (*e)(k);        // b = pointer toward the other vertex of the current edge
    50235015                                                                        AB= b->r - a->r;   // AB = vector of the current edge
    50245016                                                                        Metric MA = background ? BTh.MetricAt(a->r) :a->m ;  //Get metric associated to A
    5025                                                                         Metric MB =  background ? BTh.MetricAt(b->r) :b->m ; //Get metric associated to B
    5026                                                                         double ledge = (MA(AB) + MB(AB))/2;                   //Get edge length in metric
    5027 
    5028                                                                         /* We are now creating the edges of the mesh from the
    5029                                                                          * geometrical edge selected above.
    5030                                                                          * The edge will be divided according to the metric
    5031                                                                          * previously computed and cannot be divided more
    5032                                                                          * than 10 times (MaxSubEdge). */
     5017                                                                        Metric MB = background ? BTh.MetricAt(b->r) :b->m ; //Get metric associated to B
     5018                                                                        double ledge = (MA(AB) + MB(AB))/2;                 //Get edge length in metric
     5019
     5020                                                                        /* We are now creating the mesh edges from the geometrical edge selected above.
     5021                                                                         * The edge will be divided according to the metric previously computed and cannot
     5022                                                                         * be divided more than 10 times (MaxSubEdge). */
    50335023
    50345024                                                                        //By default, there is only one subedge that is the geometrical edge itself
     
    50395029
    50405030                                                                        //Build Subedges according to the edge length
    5041                                                                         //if ledge < 1.5 (between one and 2), take the edge as is
    5042                                                                         if (ledge < 1.5) lSubEdge[0] = ledge;
     5031                                                                        if (ledge < 1.5){
     5032                                                                                //if ledge < 1.5 (between one and 2), take the edge as is
     5033                                                                                lSubEdge[0] = ledge;
     5034                                                                        }
    50435035                                                                        //else, divide the edge
    50445036                                                                        else {
     
    50545046                                                                                        x += xstep;
    50555047                                                                                        B =  e->F(k ? x : 1-x);
    5056                                                                                         MBs= background ? BTh.MetricAt(B) :Metric(1-x, MA, x ,MB);
     5048                                                                                        MBs= background ? BTh.MetricAt(B) : Metric(1-x, MA, x ,MB);
    50575049                                                                                        AB = A-B;
    50585050                                                                                        lSubEdge[kk]= (ledge += (MAs(AB)+MBs(AB))/2);
     
    51385130                        } // for (i=0;i<nbe;i++)
    51395131                        if(!step) {
    5140                                 if (edges){
    5141                                         ISSMERROR("edges");
    5142                                 }
    5143                                 if (VerticesOnGeomEdge){
    5144                                         ISSMERROR("VerticesOnGeomEdge");
    5145                                 }
     5132                                ISSMASSERT(!edges);
     5133                                ISSMASSERT(!VerticesOnGeomEdge);
     5134
    51465135                                edges = new Edge[nbex=nbe];
    5147                                 if(NbVerticesOnGeomEdge0)
    5148                                  VerticesOnGeomEdge = new VertexOnGeom[NbVerticesOnGeomEdge0];
    5149                                 if (!VerticesOnGeomEdge && NbVerticesOnGeomEdge0!=0){
    5150                                         ISSMERROR("!VerticesOnGeomEdge && NbVerticesOnGeomEdge0!=0");
    5151                                 }
     5136                                if(NbVerticesOnGeomEdge0) VerticesOnGeomEdge = new VertexOnGeom[NbVerticesOnGeomEdge0];
     5137
    51525138                                // do the vertex on a geometrical vertex
     5139                                ISSMASSERT(VerticesOnGeomEdge || NbVerticesOnGeomEdge0==0);
    51535140                                NbVerticesOnGeomEdge0 = NbVerticesOnGeomEdge;       
    51545141                        }
    5155                         else if (NbVerticesOnGeomEdge != NbVerticesOnGeomEdge0){
    5156                                 ISSMERROR("NbVerticesOnGeomEdge != NbVerticesOnGeomEdge0");
     5142                        else{
     5143                                ISSMASSERT(NbVerticesOnGeomEdge==NbVerticesOnGeomEdge0);
    51575144                        }
    51585145                }
Note: See TracChangeset for help on using the changeset viewer.