Changeset 3148


Ignore:
Timestamp:
03/02/10 10:14:45 (15 years ago)
Author:
Mathieu Morlighem
Message:

minor

Location:
issm/trunk/src/c/Bamgx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/Bamgx/Bamgx.cpp

    r3126 r3148  
    9595                if(bamgopts->splitcorners) Th.SplitInternalEdgeWithBorderVertices();
    9696                Th.ReNumberingTheTriangleBySubDomain();
    97                 //if(NbSmooth>0) Th.SmoothingVertex(NbSmooth,omega);
    98                 Th.SmoothingVertex(3,omega);
    9997
    10098                //Build output
     
    159157                if (verbosity>1) printf("   Generating Mesh...\n");
    160158                Thr=&BTh,Thb=0;
    161                 Triangles & Th( *(0 ?  new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) :  new Triangles(maxnbv,BTh,bamgopts->KeepVertices)));
     159                Triangles & Th( *(0 ?  new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) :  new Triangles(maxnbv,BTh,bamgopts,bamgopts->KeepVertices)));
    162160                if (Thr != &BTh) delete Thr;
    163161                if(costheta<=1.0) Th.MakeQuadrangles(costheta);
  • issm/trunk/src/c/Bamgx/Mesh2.h

    r3126 r3148  
    367367                class IntersectionTriangles {
    368368                        public:
    369                                 Triangle *t;
     369                                Triangle* t;
    370370                                Real8  bary[3];  // use if t != 0
    371371                                R2 x;
    372372                                Metric m;
    373                                 Real8 s;// abscisse curviline
    374                                 Real8 sp; // len of the previous seg in m
    375                                 Real8 sn;// len of the  next seg in m
     373                                Real8 s; // curvilinear coordinate
     374                                Real8 sp;// length of the previous segment in m
     375                                Real8 sn;// length of the next segment in m
    376376                };
    377377
     
    380380                                GeometricalEdge * e;
    381381                                Real8 sBegin,sEnd; // abscisse of the seg on edge parameter
    382                                 Real8 lBegin,lEnd; // length abscisse  set in ListofIntersectionTriangles::Length
     382                                Real8 lBegin,lEnd; // length abscisse set in ListofIntersectionTriangles::Length
    383383                                int last;// last index  in ListofIntersectionTriangles for this Sub seg of edge
    384384                                R2 F(Real8 s){
     
    390390                };
    391391
    392                 int MaxSize; //
    393                 int Size; //
    394                 Real8 len; //
     392                int MaxSize;
     393                int Size;
     394                Real8 len;
    395395                int state;
    396396                IntersectionTriangles * lIntTria;
     
    403403
    404404                ListofIntersectionTriangles(int n=256,int m=16)
    405                   :   MaxSize(n), Size(0), len(-1),state(-1),lIntTria(new IntersectionTriangles[n]) ,
    406                   NbSeg(0), MaxNbSeg(m), lSegsI(new SegInterpolation[m]) 
    407                 {
    408                  long int verbosity=0;
    409                  if (verbosity>9) printf("   construct ListofIntersectionTriangles %i %i\n",MaxSize,MaxNbSeg);
     405                  : MaxSize(n), Size(0), len(-1),state(-1),lIntTria(new IntersectionTriangles[n]) ,
     406                  NbSeg(0), MaxNbSeg(m), lSegsI(new SegInterpolation[m]){
     407                          long int verbosity=0;
     408                          if (verbosity>9) printf("   construct ListofIntersectionTriangles %i %i\n",MaxSize,MaxNbSeg);
    410409                };
    411410
     
    417416                        int NewItem(Triangle * tt,Real8 d0,Real8 d1,Real8 d2);
    418417                        int NewItem(R2,const Metric & );
    419                         void NewSubSeg(GeometricalEdge *e,Real8 s0,Real8 s1)
    420                           {
     418                        void NewSubSeg(GeometricalEdge *e,Real8 s0,Real8 s1){
    421419                                long int verbosity=0;
    422420
     
    436434                                        lSegsI = lEn;       
    437435                                }
    438                                 if (NbSeg)
    439                                  lSegsI[NbSeg-1].last=Size;
     436                                if (NbSeg) lSegsI[NbSeg-1].last=Size;
    440437                                lSegsI[NbSeg].e=e;
    441438                                lSegsI[NbSeg].sBegin=s0;
     
    443440                                NbSeg++;           
    444441                          }
    445 
    446                         //  void CopyMetric(int i,int j){ lIntTria[j].m=lIntTria[i].m;}
    447                         //  void CopyMetric(const Metric & mm,int j){ lIntTria[j].m=mm;}
    448442
    449443                        void ReShape() {
     
    453447                                        throw ErrorException(__FUNCT__,exprintf("!nw"));
    454448                                }
    455                                 for (int i=0;i<MaxSize;i++) // recopy
    456                                 nw[i] = lIntTria[i];       
     449                                // recopy
     450                                for (int i=0;i<MaxSize;i++) nw[i] = lIntTria[i];       
    457451                                long int verbosity=0;
    458452                                if(verbosity>3) printf("   ListofIntersectionTriangles  ReShape Maxsize %i -> %i\n",MaxSize,MaxNbSeg);
     
    597591                public:
    598592
    599                         int static counter; // to kown the number of mesh in memory
    600593                        Geometry & Gh;   // Geometry
    601594                        Triangles & BTh; // Background Mesh Bth==*this =>no  background
     
    650643                        Triangles(double* index,double* x,double* y,int nods,int nels);
    651644
    652                         Triangles(Int4 nbvx,Triangles & BT,int keepBackVertices=1) :Gh(BT.Gh),BTh(BT) {
    653                                 try {GeomToTriangles1(nbvx,keepBackVertices);}
     645                        Triangles(Int4 nbvx,Triangles & BT,BamgOpts* bamgopts,int keepBackVertices=1) :Gh(BT.Gh),BTh(BT) {
     646                                try {GeomToTriangles1(nbvx,bamgopts,keepBackVertices);}
    654647                                catch(...) { this->~Triangles(); throw; }
    655648                        }
     
    700693                        int SplitElement(int choice);
    701694                        void MakeQuadTree();
    702                         void NewPoints( Triangles &,int KeepVertices =1 );
     695                        void NewPoints(Triangles &,BamgOpts* bamgopts,int KeepVertices=1);
    703696                        Int4 InsertNewPoints(Int4 nbvold,Int4 & NbTSwap) ;
    704                         void NewPoints(int KeepVertices=1){ NewPoints(*this,KeepVertices);}
    705697                        void ReNumberingTheTriangleBySubDomain(bool justcompress=false);
    706698                        void ReNumberingVertex(Int4 * renu);
     
    744736                        int  CrackMesh();
    745737                private:
    746                         void GeomToTriangles1(Int4 nbvx,int KeepVertices=1);// the real constructor mesh adaption
     738                        void GeomToTriangles1(Int4 nbvx,BamgOpts* bamgopts,int KeepVertices=1);// the real constructor mesh adaption
    747739                        void GeomToTriangles0(Int4 nbvx,BamgOpts* bamgopts);// the real constructor mesh generator
    748740                        void PreInit(Int4);
  • issm/trunk/src/c/Bamgx/objects/ListofIntersectionTriangles.cpp

    r2965 r3148  
    263263        /*FUNCTION ListofIntersectionTriangles::Length{{{1*/
    264264        Real8  ListofIntersectionTriangles::Length(){
     265                // computation of the length
     266
     267                // check Size
    265268                if (Size<=0){
    266269                        throw ErrorException(__FUNCT__,exprintf("Size<=0"));
    267270                }
    268                 // computation of the length     
    269                 R2 C;
     271
    270272                Metric Mx,My;
    271273                int ii,jj;
    272274                R2 x,y,xy;
    273275
    274                 SegInterpolation *SegI=lSegsI;
     276                SegInterpolation* SegI=lSegsI;
    275277                SegI=lSegsI;
    276                 lSegsI[NbSeg].last=Size;// improvement
    277 
     278                lSegsI[NbSeg].last=Size;
    278279                int EndSeg=Size;
    279280
     
    285286                for (jj=0,ii=1;ii<Size;jj=ii++) { 
    286287                        // seg jj,ii
    287                         x=y;
    288                         y = lIntTria[ii].x;
     288                        x  = y;
     289                        y  = lIntTria[ii].x;
    289290                        xy = y-x;
    290291                        Mx = lIntTria[ii].m;
    291292                        My = lIntTria[jj].m;
    292                         sxy = LengthInterpole(Mx,My,xy);
     293                        sxy= LengthInterpole(Mx,My,xy);
    293294                        s += sxy;
    294295                        lIntTria[ii].s = s;
    295                         if (ii == EndSeg) 
    296                          SegI->lEnd=s,
    297                                 SegI++,
    298                                 EndSeg=SegI->last,
     296                        if (ii == EndSeg){
     297                                SegI->lEnd=s;
     298                                SegI++;
     299                                EndSeg=SegI->last;
    299300                                SegI->lBegin=s;
    300 
    301                   }
     301                        }
     302                }
    302303                len = s;
    303304                SegI->lEnd=s;
     
    307308        /*}}}1*/
    308309        /*FUNCTION ListofIntersectionTriangles::NewPoints{{{1*/
    309         Int4 ListofIntersectionTriangles::NewPoints(Vertex * vertices,Int4 & nbv,Int4  nbvx){
    310                 long int verbosity=0;
    311 
    312 
    313                 const Int4 nbvold = nbv;
    314                 Real8 s = Length();
    315                 if (s <  1.5 ) return 0;
    316                 //////////////////////   
     310        Int4 ListofIntersectionTriangles::NewPoints(Vertex* vertices,Int4 &nbv,Int4 nbvx){
     311
     312                //If length<1.5, do nothing
     313                Real8 s=Length();
     314                if (s<1.5) return 0;
     315
     316                const Int4 nbvold=nbv;
    317317                int ii = 1 ;
    318318                R2 y,x;
    319319                Metric My,Mx ;
    320320                Real8 sx =0,sy;
    321                 int nbi = Max(2,(int) (s+0.5));
    322                 Real8 sint = s/nbi;
    323                 Real8 si = sint;
     321                int nbi=Max(2,(int) (s+0.5));
     322                Real8 sint=s/nbi;
     323                Real8 si  =sint;
    324324
    325325                int EndSeg=Size;
    326                 SegInterpolation *SegI=0;
    327                 if (NbSeg)
    328                  SegI=lSegsI,EndSeg=SegI->last;
    329 
    330                 for (int k=1;k<nbi;k++)
    331                   {
    332                         while ((ii < Size) && ( lIntTria[ii].s <= si ))
    333                          if (ii++ == EndSeg)
    334                           SegI++,EndSeg=SegI->last;
     326                SegInterpolation* SegI=NULL;
     327                if (NbSeg) SegI=lSegsI,EndSeg=SegI->last;
     328
     329                for (int k=1;k<nbi;k++){
     330                        while ((ii < Size) && ( lIntTria[ii].s <= si )){
     331                                if (ii++ == EndSeg){
     332                                        SegI++;
     333                                        EndSeg=SegI->last;
     334                                }
     335                        }
    335336
    336337                        int ii1=ii-1;
     
    347348                        Real8 cx = 1-cy;
    348349                        C = SegI ? SegI->F(si): x * cx + y *cy;
     350                        //C.Echo();
     351                        //x.Echo();
     352                        //y.Echo();
     353                        //printf("cx = %g, cy=%g\n",cx,cy);
    349354
    350355                        si += sint;
  • issm/trunk/src/c/Bamgx/objects/Triangle.cpp

    r2970 r3148  
    9898        /*FUNCTION Triangle::Optim{{{1*/
    9999        Int4  Triangle::Optim(Int2 i,int koption) {
    100                 // turne around in positif sens
     100                // turn around (positive direction)
     101                Triangle *t=this;
    101102                Int4 NbSwap =0;
    102                 Triangle  *t = this;
    103                 int k=0,j =OppositeEdge[i];
    104                 int jp = PreviousEdge[j];
    105                 // initialise   tp, jp the previous triangle & edge
    106                 Triangle *tp= TriaAdjTriangles[jp];
     103                int  k = 0;
     104                int  j = OppositeEdge[i];
     105                int  jp= PreviousEdge[j];
     106
     107                // initialize tp, jp the previous triangle & edge
     108                Triangle *tp=TriaAdjTriangles[jp];
    107109                jp = TriaAdjSharedEdge[jp]&3;
    108110                do {
    109                         while (t->swap(j,koption))
    110                           {
     111                        while (t->swap(j,koption)){
     112                                if (k>=20000) throw ErrorException(__FUNCT__,exprintf("k>=20000"));
    111113                                NbSwap++;
    112114                                k++;
    113                                 if (k>=20000){
    114                                         throw ErrorException(__FUNCT__,exprintf("k>=20000"));
    115                                 }
    116115                                t=  tp->TriaAdjTriangles[jp];      // set unchange t qnd j for previous triangles
    117116                                j=  NextEdge[tp->TriaAdjSharedEdge[jp]&3];
    118                           }
     117                        }
    119118                        // end on this  Triangle
    120119                        tp = t;
     
    187186                                                 break;
    188187                                         }
    189                                          else
    190                                                 {       
     188                                         else {
    191189                                                 // critere de Delaunay anisotrope
    192190                                                 Real8 som;
  • issm/trunk/src/c/Bamgx/objects/Triangles.cpp

    r3126 r3148  
    1919        static const  Direction NoDirOfSearch=Direction();
    2020        long NbUnSwap =0;
    21         int  Triangles::counter = 0;
    2221
    2322        /*Constructors/Destructors*/
     
    31513150                if (verbose>4) printf("      -- current number of vertices = %i\n",nbv);
    31523151                if (verbose>3) printf("      Creating initial Constrained Delaunay Triangulation...\n");
    3153                 if (verbose>3) printf("         Inserting points\n");
     3152                if (verbose>3) printf("         Inserting boundary points\n");
    31543153                Insert();
    31553154
     
    31643163                // NewPointsOld(*this) ;
    31653164                if (verbose>3) printf("      Inserting internal points\n");
    3166                 NewPoints(*this,0) ;
     3165                NewPoints(*this,bamgopts,0) ;
    31673166                if (verbose>4) printf("      -- current number of vertices = %i\n",nbv);
    31683167        }
    31693168        /*}}}1*/
    31703169        /*FUNCTION Triangles::GeomToTriangles1{{{1*/
    3171         void Triangles::GeomToTriangles1(Int4 inbvx,int KeepVertices) {
     3170        void Triangles::GeomToTriangles1(Int4 inbvx,BamgOpts* bamgopts,int KeepVertices){
     3171
     3172                /*Get options*/
     3173                int verbosity=bamgopts->verbose;
     3174
    31723175                Gh.NbRef++;// add a ref to Gh
    31733176
     
    31943197                }
    31953198
    3196                 long int verbosity=0;
    31973199                BTh.NbRef++; // add a ref to BackGround Mesh
    31983200                PreInit(inbvx);
     
    35013503                FindSubDomain();
    35023504
    3503                 NewPoints(BTh,KeepVertices) ;
     3505                NewPoints(BTh,bamgopts,KeepVertices) ;
    35043506        }
    35053507        /*}}}1*/
     
    39733975/*}}}1*/
    39743976        /*FUNCTION Triangles::NewPoints{{{1*/
    3975         void  Triangles::NewPoints(Triangles & Bh,int KeepVertices) {
    3976 
    3977                 long int verbosity=2;
    3978                 Int4 nbtold(nbt),nbvold(nbv);
    3979                 Int4 i,k;
    3980                 int j;
    3981                 Int4 *first_np_or_next_t = new Int4[nbtx];
    3982                 Int4 NbTSwap =0;
    3983 
    3984                 //display info
    3985                 if (verbosity>2)  printf("   Triangles::NewPoints\n");
    3986 
    3987                 /*First, insert old points*/
    3988 
    3989                 nbtold = nbt;
    3990 
     3977        void  Triangles::NewPoints(Triangles & Bh,BamgOpts* bamgopts,int KeepVertices){
     3978
     3979                int i,j,k;
     3980                Int4 NbTSwap=0;
     3981                Int4 nbtold=nbt;
     3982                Int4 nbvold=nbv;
     3983                Int4 Headt=0;
     3984                Int4 next_t;
     3985                Int4* first_np_or_next_t=new Int4[nbtx];
     3986                Triangle* t=NULL;
     3987
     3988                /*Recover options*/
     3989                int verbosity=bamgopts->verbose;
     3990
     3991                /*First, insert old points if requested*/
    39913992                if (KeepVertices && (&Bh != this) && (nbv+Bh.nbv< nbvx)){
    3992                         //   Bh.SetVertexFieldOn();
     3993                        if (verbosity>5) printf("         Inserting initial mesh points\n");
    39933994                        for (i=0;i<Bh.nbv;i++){
    39943995                                Vertex &bv=Bh[i];
    39953996                                if (!bv.onGeometry){
    3996                                         vertices[nbv].r = bv.r;
     3997                                        vertices[nbv].r   = bv.r;
    39973998                                        vertices[nbv++].m = bv.m;
    39983999                                }
    39994000                        }
    4000                         int nbv1=nbv;
    40014001                        Bh.ReMakeTriangleContainingTheVertex();     
    40024002                        InsertNewPoints(nbvold,NbTSwap)   ;           
     
    40044004                else Bh.ReMakeTriangleContainingTheVertex();     
    40054005
    4006                 Triangle *t;
    40074006                // generation of the list of next Triangle
    4008                 // at 1 time we test all the triangles
    4009                 Int4 Headt =0,next_t;
    4010                 for(i=0;i<nbt;i++)
    4011                  first_np_or_next_t[i]=-(i+1);
    4012                 // end list i >= nbt
    4013                 // the list of test triangle is
    4014                 // the next traingle on i is  -first_np_or_next_t[i]
     4007                for(i=0;i<nbt;i++) first_np_or_next_t[i]=-(i+1);
     4008                // the next traingle of i is -first_np_or_next_t[i]
     4009
     4010                // Big loop (most time consuming)
    40154011                int iter=0;
    4016 
    4017                 // Big loop (most time consuming)
     4012                if (verbosity>5) printf("         Big loop\n");
    40184013                do {
     4014                        /*Update variables*/
    40194015                        iter++;
    4020                         nbtold = nbt;
    4021                         nbvold = nbv;
    4022 
    4023                         // default size of  IntersectionTriangle
     4016                        nbtold=nbt;
     4017                        nbvold=nbv;
     4018
     4019                        /*We test all triangles*/
    40244020                        i=Headt;
    40254021                        next_t=-first_np_or_next_t[i];
    40264022                        for(t=&triangles[i];i<nbt;t=&triangles[i=next_t],next_t=-first_np_or_next_t[i]){
    4027                                 // for each triangle  t
    4028                                 // we can change first_np_or_next_t[i]
     4023
     4024                                //check i
    40294025                                if (i<0 || i>=nbt ){
    4030                                         throw ErrorException(__FUNCT__,exprintf("i<0 || i>=nbt"));
    4031                                 }
     4026                                        throw ErrorException(__FUNCT__,exprintf("Index problem in NewPoints (i=%i not in [0 %i])",i,nbt-1));
     4027                                }
     4028                                //change first_np_or_next_t[i]
    40324029                                first_np_or_next_t[i] = iter;
     4030
     4031                                //Loop over the edges of t
    40334032                                for(j=0;j<3;j++){
    4034                                         // for each edge
    40354033                                        TriangleAdjacent tj(t,j);
    4036                                         Vertex & vA = * tj.EdgeVertex(0);
    4037                                         Vertex & vB = * tj.EdgeVertex(1);
    4038 
    4039                                         if (!t->link) continue;// boundary
    4040                                         if (t->det <0) continue;
     4034                                        Vertex &vA = *tj.EdgeVertex(0);
     4035                                        Vertex &vB = *tj.EdgeVertex(1);
     4036
     4037                                        //if t is a boundary triangle, or tj locked, continue
     4038                                        if (!t->link)     continue;
     4039                                        if (t->det <0)    continue;
    40414040                                        if (t->Locked(j)) continue;
    40424041
    40434042                                        TriangleAdjacent tadjj = t->Adj(j);       
    4044                                         Triangle * ta= tadjj;
    4045 
    4046                                         if (ta->det <0) continue;         
    4047 
    4048                                         R2 A = vA;
    4049                                         R2 B = vB;
    4050 
     4043                                        Triangle* ta=tadjj;
     4044
     4045                                        //if the adjacent triangle is a boundary triangle, continur
     4046                                        if (ta->det<0) continue;         
     4047
     4048                                        R2 A=vA;
     4049                                        R2 B=vB;
    40514050                                        k=Number(ta);
    40524051
    4053                                         if(first_np_or_next_t[k]==iter)  // this edge is done before
    4054                                          continue; // next edge of the triangle
    4055 
    4056                                         //const Int4 NbvOld = nbv;
     4052                                        //if this edge has already been done, go to next edge of triangle
     4053                                        if(first_np_or_next_t[k]==iter) continue;
     4054
    40574055                                        lIntTria.SplitEdge(Bh,A,B);
    40584056                                        lIntTria.NewPoints(vertices,nbv,nbvx);
    40594057                                  } // end loop for each edge
    4060 
    40614058                          }// for triangle   
    40624059
    4063                         if (!InsertNewPoints(nbvold,NbTSwap))
    4064                          break;
    4065 
     4060                        if (!InsertNewPoints(nbvold,NbTSwap)) break;
    40664061                        for (i=nbtold;i<nbt;i++) first_np_or_next_t[i]=iter;
    4067 
    40684062                        Headt = nbt; // empty list
    40694063
    4070                         // for all the triangle contening the vertex i
     4064                        // for all the triangle containing the vertex i
    40714065                        for (i=nbvold;i<nbv;i++){
    40724066                                Vertex*          s  = vertices + i;
     
    40854079                                        ta = Next(Adj(ta));
    40864080                                } while ( (tbegin != (Triangle*) ta));
    4087                         }   
     4081                        }
    40884082
    40894083                } while (nbv!=nbvold);
Note: See TracChangeset for help on using the changeset viewer.