Changeset 2941


Ignore:
Timestamp:
02/01/10 14:57:22 (15 years ago)
Author:
Mathieu Morlighem
Message:

now different errors must be used to compute metric

Location:
issm/trunk/src
Files:
7 edited

Legend:

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

    r2937 r2941  
    3333
    3434        /*Bamg options*/
    35         int    iso;
     35        double anisomax;
    3636        int    maxnbv;
    3737        double hmin,hmax;
    38         double err,errg,coef;
     38        double coef;
    3939        int    verbosity;
    4040        int    NbSmooth;
     
    4646        int allquad=0;
    4747        double costheta=2;
    48         double anisomax = 1e6;
    4948        int KeepBackVertices=1;
    5049        double hminaniso=1e-100;
     
    5655
    5756        /*Bamg options*/
    58         iso=bamgopts->iso;
    59         err=bamgopts->err;
    60         errg=bamgopts->errg;
     57        anisomax=bamgopts->anisomax;
    6158        NbSmooth=bamgopts->NbSmooth;
    6259        omega=bamgopts->omega;
     
    7168                throw ErrorException(__FUNCT__,exprintf("maxsubdiv %g is should be in ]1,%g]",maxsubdiv,boundmaxsubdiv));
    7269        }
    73         // if iso, then anisomax = 1;
    74         if (iso) anisomax=1;
    7570        // no metric -> no smoothing
    7671        if (bamgopts->metric==NULL){
     
    159154                }
    160155
    161                 BTh.IntersectGeomMetric(errg,iso);
     156                BTh.IntersectGeomMetric(bamgopts);
    162157                if (verbosity>1) printf("   Smoothing Metric...");
    163158                if(bamgopts->gradation) BTh.SmoothMetric(bamgopts->gradation);
  • issm/trunk/src/c/Bamgx/Mesh2.h

    r2940 r2941  
    137137                //  ~Vertex(){}
    138138                Real8  Smoothing(Triangles & ,const Triangles & ,Triangle  * & ,Real8 =1);
    139                 void MetricFromHessian(const double Hxx,const double Hyx, const double Hyy, const double smin,const double smax,const double s,BamgOpts* bamgopts);
     139                void MetricFromHessian(const double Hxx,const double Hyx, const double Hyy, const double smin,const double smax,const double s,const double err,BamgOpts* bamgopts);
    140140                void Echo();
    141141                int ref() const { return ReferenceNumber;}
     
    802802                                                 void BuildMetric0(BamgOpts* bamgopts);
    803803                                                 void BuildMetric1(BamgOpts* bamgopts);
    804                                                  void IntersectGeomMetric(const Real8 err,const int iso);
     804                                                 void IntersectGeomMetric(BamgOpts* bamgopts);
    805805
    806806
     
    10781078          }
    10791079
    1080         inline  void   Triangles::SetVertexFieldOn()
    1081           {
     1080        inline  void   Triangles::SetVertexFieldOn(){
    10821081                for (Int4 i=0;i<nbv;i++)
    10831082                 vertices[i].on=0;
     
    10871086                 VerticesOnGeomEdge[k].SetOn();
    10881087          }           
    1089         inline  void   Triangles::SetVertexFieldOnBTh()
    1090           {
     1088        inline  void   Triangles::SetVertexFieldOnBTh(){
    10911089                for (Int4 i=0;i<nbv;i++)
    10921090                 vertices[i].on=0;
  • issm/trunk/src/c/Bamgx/objects/Triangles.cpp

    r2940 r2941  
    712712                int i;
    713713                xfree((void**)&bamgopts->metric);
    714                 if (bamgopts->iso){
    715                         bamgopts->metric=(double*)xmalloc(1*nbv*sizeof(double));
    716                         for (i=0;i<nbv;i++){
    717                                 MatVVP2x2 V=vertices[i].m;
    718                                 bamgopts->metric[i]=V.hmin();
    719                         }
    720                 }
    721                 else {
    722                         bamgopts->metric=(double*)xmalloc(3*nbv*sizeof(double));
    723                         for (i=0;i<nbv;i++){
    724                                 bamgopts->metric[i*3+0]=vertices[i].m.a11;
    725                                 bamgopts->metric[i*3+1]=vertices[i].m.a21;
    726                                 bamgopts->metric[i*3+2]=vertices[i].m.a22;
    727                         }
     714                bamgopts->metric=(double*)xmalloc(3*nbv*sizeof(double));
     715                for (i=0;i<nbv;i++){
     716                        bamgopts->metric[i*3+0]=vertices[i].m.a11;
     717                        bamgopts->metric[i*3+1]=vertices[i].m.a21;
     718                        bamgopts->metric[i*3+2]=vertices[i].m.a22;
    728719                }
    729720        }
     
    10681059                        /*Compute Metric from Hessian*/
    10691060                        for ( iv=0;iv<nbv;iv++){
    1070                                 vertices[iv].MetricFromHessian(dxdx_vertex[iv],dxdy_vertex[iv],dydy_vertex[iv],smin,smax,ss[iv*nbsol+nusol],bamgopts);
     1061                                vertices[iv].MetricFromHessian(dxdx_vertex[iv],dxdy_vertex[iv],dydy_vertex[iv],smin,smax,ss[iv*nbsol+nusol],bamgopts->err[nusol],bamgopts);
    10711062                        }
    10721063
     
    13611352                                /*Compute Metric from Hessian*/
    13621353                                for ( iv=0;iv<nbv;iv++){
    1363                                         vertices[iv].MetricFromHessian(dxdx[iv],dxdy[iv],dydy[iv],smin,smax,ss[iv*nbsol+nusol],bamgopts);
     1354                                        vertices[iv].MetricFromHessian(dxdx[iv],dxdy[iv],dydy[iv],smin,smax,ss[iv*nbsol+nusol],bamgopts->err[nusol],bamgopts);
    13641355                                }
    13651356
     
    32423233/*FUNCTION Triangles::IntersectConsMetric{{{1*/
    32433234void Triangles::IntersectConsMetric(BamgOpts* bamgopts){
    3244         //  the array of solution s is store   
    3245         // sol0,sol1,...,soln    on vertex 0
    3246         //  sol0,sol1,...,soln   on vertex 1
    3247         //  etc.
    3248         //  Hessiantype = 0 =>  H is computed with green formula
    3249         //  Hessiantype = 1 =>  H is computed from P2 on 4T
     3235        //  Hessiantype = 0 =>  H is computed using double P2 projection
     3236        //  Hessiantype = 1 =>  H is computed with green formula
    32503237
    32513238        /*Options*/
     
    32643251/*}}}1*/
    32653252/*FUNCTION Triangles::IntersectGeomMetric{{{1*/
    3266 void Triangles::IntersectGeomMetric(const Real8 err=1,const int iso=0){
    3267         long int verbosity=0;
     3253void Triangles::IntersectGeomMetric(BamgOpts* bamgopts){
     3254
     3255        /*Get options*/
     3256        int    verbosity=bamgopts->verbose;
     3257        double anisomax =bamgopts->anisomax;
     3258        double err      =bamgopts->err[0]; //to be changed...
     3259
    32683260        Real8 ss[2]={0.00001,0.99999};
    32693261        Real8 errC = 2*sqrt(2*err);
    32703262        Real8 hmax = Gh.MaximalHmax();
    32713263        Real8 hmin = Gh.MinimalHmin();
    3272         Real8 maxaniso = 1e6;
     3264
     3265        //check that hmax is positive
    32733266        if (hmax<=0){
    32743267                throw ErrorException(__FUNCT__,exprintf("hmax<=0"));
    32753268        }
     3269
     3270        //errC cannot be higher than 1
     3271        if (errC > 1) errC = 1;
     3272
     3273        //Set all vertices to "on"
    32763274        SetVertexFieldOn();
    3277         if (errC > 1) errC = 1;
    3278         for (Int4  i=0;i<nbe;i++)
    3279          for (int j=0;j<2;j++)
    3280                 {
    3281 
    3282                  Vertex V;
    3283                  VertexOnGeom GV;
    3284                  Gh.ProjectOnCurve(edges[i],ss[j],V,GV);
    3285                         {
    3286                          GeometricalEdge * eg = GV;
    3287                          Real8 s = GV;
    3288                          R2 tg;
    3289                          Real8  R1= eg->R1tg(s,tg);
    3290                          Real8 ht = hmax;
    3291                          if (R1>1.0e-20) {  // err relative to the length of the edge
    3292                                  ht = Min(Max(errC/R1,hmin),hmax);
    3293                          }
    3294                          Real8 hn = iso? ht : Min(hmax,ht*maxaniso);
    3295                          if (ht<=0 || hn<=0){
    3296                                  throw ErrorException(__FUNCT__,exprintf("ht<=0 || hn<=0"));
    3297                          }
    3298                          MatVVP2x2 Vp(1/(ht*ht),1/(hn*hn),tg);
    3299                          Metric MVp(Vp);
    3300                          edges[i][j].m.IntersectWith(MVp);
    3301                         }
    3302 
    3303                 }
     3275
     3276        //loop over all the vertices on edges
     3277        for (Int4  i=0;i<nbe;i++){
     3278                for (int j=0;j<2;j++){
     3279
     3280                        Vertex V;
     3281                        VertexOnGeom GV;
     3282                        Gh.ProjectOnCurve(edges[i],ss[j],V,GV);
     3283
     3284                        GeometricalEdge * eg = GV;
     3285                        Real8 s = GV;
     3286                        R2 tg;
     3287                        Real8  R1= eg->R1tg(s,tg);
     3288                        Real8  ht=hmax;
     3289                        // err relative to the length of the edge
     3290                        if (R1>1.0e-20) { 
     3291                                ht = Min(Max(errC/R1,hmin),hmax);
     3292                        }
     3293                        Real8 hn=Min(hmax,ht*anisomax);
     3294                        if (ht<=0 || hn<=0){
     3295                                throw ErrorException(__FUNCT__,exprintf("ht<=0 || hn<=0"));
     3296                        }
     3297                        MatVVP2x2 Vp(1/(ht*ht),1/(hn*hn),tg);
     3298                        Metric MVp(Vp);
     3299                        edges[i][j].m.IntersectWith(MVp);
     3300                }
     3301        }
    33043302        // the problem is for the vertex on vertex
    33053303}
  • issm/trunk/src/c/Bamgx/objects/Vertex.cpp

    r2940 r2941  
    128128        /*}}}1*/
    129129        /*FUNCTION Vertex::MetricFromHessian{{{1*/
    130         void Vertex::MetricFromHessian(const double Hxx,const double Hyx, const double Hyy,const double smin,const double smax,const double s,BamgOpts* bamgopts){
     130        void Vertex::MetricFromHessian(const double Hxx,const double Hyx, const double Hyy,const double smin,const double smax,const double s,double err,BamgOpts* bamgopts){
    131131                /*Compute Metric from Hessian*/
    132132
     
    152152                 */
    153153                if (Metrictype==0){
    154                         ci= 2.0/9.0 * 1/(bamgopts->err*coef*coef);
     154                        ci= 2.0/9.0 * 1/(err*coef*coef);
    155155                }
    156156
     
    163163                 */
    164164                else if (Metrictype==1){
    165                         ci= 2.0/9.0 * 1/(bamgopts->err*coef*coef) * 1/Max( Abs(s), CutOff*(Max(Abs(smin),Abs(smax))));
     165                        ci= 2.0/9.0 * 1/(err*coef*coef) * 1/Max( Abs(s), CutOff*(Max(Abs(smin),Abs(smax))));
    166166                }
    167167
     
    173173                 */
    174174                else if (Metrictype==2){
    175                         ci= 2.0/9.0 * 1/(bamgopts->err*coef*coef) * 1/(smax-smin);
     175                        ci= 2.0/9.0 * 1/(err*coef*coef) * 1/(smax-smin);
    176176                }
    177177                else{
  • issm/trunk/src/c/objects/BamgOpts.h

    r2938 r2941  
    1717        int     Metrictype;
    1818        int     nbjacobi;
    19         int     AbsError;
    2019        double  omega;
    2120        double  hmin;
     
    2524        int     splitcorners;
    2625        int     verbose;
    27         double  err;
    28         double  errg;
     26        double*  err;
    2927        double  coef;
    3028        double* metric;
  • issm/trunk/src/m/classes/public/bamg.m

    r2940 r2941  
    7676
    7777% Bamg Options {{{1
    78 bamg_options.iso=getfieldvalue(options,'iso',0);
    7978bamg_options.err=getfieldvalue(options,'err',0.01);
    80 bamg_options.errg=getfieldvalue(options,'errg',0.1);
    8179bamg_options.coef=getfieldvalue(options,'coef',1);
    8280bamg_options.power=getfieldvalue(options,'power',1);
    8381bamg_options.nbjacobi=getfieldvalue(options,'nbjacobi',1);
    84 bamg_options.AbsError=getfieldvalue(options,'AbsError',0);
    8582bamg_options.Hessiantype=getfieldvalue(options,'Hessiantype',0);
    8683bamg_options.Metrictype=getfieldvalue(options,'Metrictype',0);
     
    10097%}}}
    10198
     99%check bamg options
     100fieldsize=size(bamg_options.field);
     101if fieldsize(1),
     102        if fieldsize(1)~=md.numberofgrids,
     103                error(['bamg error message, ''field'' should have ' num2str(md.numberofgrids) ' lines (numberofgrids)']);
     104        end
     105        if (fieldsize(2)~=0 & length(bamg_options.err)~=fieldsize(2)),
     106                error(['bamg error message, ''err'' should be of length ' num2str(fieldsize(2)) ' (As many as fields)']);
     107        end
     108end
     109
     110
    102111%call Bamg
    103112[triangles vertices metric]=Bamg(bamg_mesh,bamg_geometry,bamg_options);
  • issm/trunk/src/mex/Bamg/Bamg.cpp

    r2940 r2941  
    3232
    3333        /*Options inputs*/
    34         int    iso,maxnbv,verbose,splitcorners;
     34        int    maxnbv,verbose,splitcorners;
    3535        double hmin,hmax,anisomax;
    36         double err,errg,coef;
     36        double coef;
    3737        double power;
    3838        int    Hessiantype,Metrictype,NbSmooth;
    39         int    nbjacobi,AbsError;
     39        int    nbjacobi;
    4040        double omega;
    4141        double gradation;
     
    4343        double* metric=NULL;
    4444        double* field=NULL;
    45         int     numfields=0;
     45        double* err;
     46        int     numfields=0,numerr=0;
    4647
    4748        /*Boot module: */
     
    108109
    109110        /*create bamg options input*/
    110         FetchData(&iso,mxGetField(BAMGOPTIONS,0,"iso"));
    111         bamgopts.iso=iso;
    112         FetchData(&err,mxGetField(BAMGOPTIONS,0,"err"));
    113         bamgopts.err=err;
    114         FetchData(&errg,mxGetField(BAMGOPTIONS,0,"errg"));
    115         bamgopts.errg=errg;
    116111        FetchData(&coef,mxGetField(BAMGOPTIONS,0,"coef"));
    117112        bamgopts.coef=coef;
     
    124119        FetchData(&nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
    125120        bamgopts.nbjacobi=nbjacobi;
    126         FetchData(&AbsError,mxGetField(BAMGOPTIONS,0,"AbsError"));
    127         bamgopts.AbsError=AbsError;
    128121        FetchData(&NbSmooth,mxGetField(BAMGOPTIONS,0,"NbSmooth"));
    129122        bamgopts.NbSmooth=NbSmooth;
     
    153146        bamgopts.numfields=numfields;
    154147        bamgopts.field=field;
     148        FetchData(&err,NULL,&numerr,mxGetField(BAMGOPTIONS,0,"err"));
     149        bamgopts.err=err;
     150
     151        /*Some checks*/
     152        if (numfields!=0 && numerr!=numfields){
     153                throw ErrorException(__FUNCT__,exprintf("the size of 'err' should be the same as 'field'"));
     154        }
    155155
    156156        /*!Generate internal degree of freedom numbers: */
Note: See TracChangeset for help on using the changeset viewer.