Changeset 3211


Ignore:
Timestamp:
03/08/10 11:43:51 (15 years ago)
Author:
Mathieu Morlighem
Message:

cleaned up MEX/Bamg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/mex/Bamg/Bamg.cpp

    r3022 r3211  
    1515        BamgGeom bamggeom;
    1616
    17         /*Mesh inputs*/
    18         int     NumVerticesMesh;
    19         double* VerticesMesh=NULL;
    20         int     NumTrianglesMesh;
    21         double* TrianglesMesh=NULL;
    22         double* hVerticesMesh=NULL;
    23         int     NumCrackedEdgesMesh;
    24         double* CrackedEdgesMesh=NULL;
    25 
    26         /*Geom inputs: */
    27         int     NumVerticesGeom;
    28         double* VerticesGeom=NULL;
    29         int     NumEdgesGeom;
    30         double* EdgesGeom=NULL;
    31         int     NumCrackedEdgesGeom;
    32         double* CrackedEdgesGeom=NULL;
    33         double* hVerticesGeom=NULL;
    34         double  MaximalAngleOfCorner;
    35         int     NumSubDomainsGeom;
    36         double* SubDomainsGeom=NULL;
    37 
    38         /*Options inputs*/
    39         int    maxnbv,verbose,splitcorners;
    40         double hmin,hmax,anisomax;
    41         double coef,maxsubdiv;
    42         double power;
    43         int    Hessiantype,Metrictype,NbSmooth;
    44         int    nbjacobi,KeepVertices,renumber;
    45         double omega;
    46         double gradation,errg;
    47         double cutoff;
    48         double* metric=NULL;
    49         double* field=NULL;
    50         double* err;
    51         int     numfields=0,numerr=0;
    52 
    5317        /*Boot module: */
    5418        MODULEBOOT();
     
    5822
    5923        /*create bamg geometry input*/
    60         FetchData(&NumVerticesGeom,mxGetField(BAMGGEOMETRY,0,"NumVertices"));
    61         bamggeom.NumVertices=NumVerticesGeom;
    62         FetchData(&VerticesGeom,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"Vertices"));
    63         bamggeom.Vertices=VerticesGeom;
    64         FetchData(&NumEdgesGeom,mxGetField(BAMGGEOMETRY,0,"NumEdges"));
    65         bamggeom.NumEdges=NumEdgesGeom;
    66         FetchData(&EdgesGeom,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"Edges"));
    67         bamggeom.Edges=EdgesGeom;
    68         FetchData(&hVerticesGeom,&lines,&cols,mxGetField(BAMGGEOMETRY,0,"hVertices"));
    69         if (hVerticesGeom && (cols!=1 || lines!=NumVerticesGeom)){throw ErrorException(__FUNCT__,exprintf("the size of 'hVertices' should be [%i %i]",NumVerticesGeom,1));}
    70         bamggeom.hVertices=hVerticesGeom;
    71         bamggeom.MetricVertices=NULL;
    72         bamggeom.h1h2VpVertices=NULL;
    73         bamggeom.NumTangentAtEdges=0;
    74         bamggeom.TangentAtEdges=NULL;
    75         bamggeom.NumCorners=0;
    76         bamggeom.Corners=NULL;
    77         bamggeom.NumRequiredVertices=0;
    78         bamggeom.RequiredVertices=NULL;
    79         bamggeom.NumRequiredEdges=0;
    80         bamggeom.RequiredEdges=NULL;
    81         FetchData(&NumCrackedEdgesGeom,mxGetField(BAMGGEOMETRY,0,"NumCrackedEdges"));
    82         bamggeom.NumCrackedEdges=NumCrackedEdgesGeom;
    83         FetchData(&CrackedEdgesGeom,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"CrackedEdges"));
    84         bamggeom.CrackedEdges=CrackedEdgesGeom;
    85         FetchData(&NumSubDomainsGeom,mxGetField(BAMGGEOMETRY,0,"NumSubDomains"));
    86         bamggeom.NumSubDomains=NumSubDomainsGeom;
    87         FetchData(&SubDomainsGeom,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"SubDomains"));
    88         bamggeom.SubDomains=SubDomainsGeom;
     24        BamgGeomInit(&bamggeom);
     25        FetchData(&bamggeom.NumVertices,mxGetField(BAMGGEOMETRY,0,"NumVertices"));
     26        FetchData(&bamggeom.Vertices,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"Vertices"));
     27        FetchData(&bamggeom.NumEdges,mxGetField(BAMGGEOMETRY,0,"NumEdges"));
     28        FetchData(&bamggeom.Edges,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"Edges"));
     29        FetchData(&bamggeom.hVertices,&lines,&cols,mxGetField(BAMGGEOMETRY,0,"hVertices"));
     30        FetchData(&bamggeom.NumCrackedEdges,mxGetField(BAMGGEOMETRY,0,"NumCrackedEdges"));
     31        FetchData(&bamggeom.CrackedEdges,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"CrackedEdges"));
     32        FetchData(&bamggeom.NumSubDomains,mxGetField(BAMGGEOMETRY,0,"NumSubDomains"));
     33        FetchData(&bamggeom.SubDomains,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"SubDomains"));
     34        if (bamggeom.hVertices && (cols!=1 || lines!=bamggeom.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'hVertices' should be [%i %i]",bamggeom.NumVertices,1));}
    8935
    9036        /*create bamg mesh input*/
    91         FetchData(&NumVerticesMesh,mxGetField(BAMGMESH,0,"NumVertices"));
    92         bamgmesh.NumVertices=NumVerticesMesh;
    93         FetchData(&VerticesMesh,NULL,NULL,mxGetField(BAMGMESH,0,"Vertices"));
    94         bamgmesh.Vertices=VerticesMesh;
    95         FetchData(&NumTrianglesMesh,mxGetField(BAMGMESH,0,"NumTriangles"));
    96         bamgmesh.NumTriangles=NumTrianglesMesh;
    97         FetchData(&TrianglesMesh,NULL,NULL,mxGetField(BAMGMESH,0,"Triangles"));
    98         bamgmesh.Triangles=TrianglesMesh;
    99         FetchData(&hVerticesMesh,&lines,&cols,mxGetField(BAMGMESH,0,"hVertices"));
    100         if (hVerticesMesh && (cols!=1 || lines!=NumVerticesMesh)){throw ErrorException(__FUNCT__,exprintf("the size of 'hVertices' should be [%i %i]",NumVerticesMesh,1));}
    101         bamgmesh.hVertices=hVerticesMesh;
    102         bamgmesh.NumQuadrilaterals=0;
    103         bamgmesh.Quadrilaterals=NULL;
    104         bamgmesh.NumVerticesOnGeometricVertex=0;
    105         bamgmesh.VerticesOnGeometricVertex=NULL;
    106         bamgmesh.NumVerticesOnGeometricEdge=0;
    107         bamgmesh.VerticesOnGeometricEdge=NULL;
    108         bamgmesh.NumEdgesOnGeometricEdge=0;
    109         bamgmesh.EdgesOnGeometricEdge=NULL;
    110         bamgmesh.NumEdges=0;
    111         bamgmesh.Edges=NULL;
    112         bamgmesh.NumSegments=0;
    113         bamgmesh.Segments=NULL;
    114         bamgmesh.SegmentsMarkers=NULL;
    115         FetchData(&NumCrackedEdgesMesh,mxGetField(BAMGMESH,0,"NumCrackedEdges"));
    116         bamgmesh.NumCrackedEdges=NumCrackedEdgesMesh;
    117         FetchData(&CrackedEdgesMesh,NULL,NULL,mxGetField(BAMGMESH,0,"CrackedEdges"));
    118         bamgmesh.CrackedEdges=CrackedEdgesMesh;
    119         bamgmesh.NumSubDomains=0;
    120         bamgmesh.SubDomains=NULL;
    121         bamgmesh.NumSubDomainsFromGeom=0;
    122         bamgmesh.SubDomainsFromGeom=NULL;
     37        BamgMeshInit(&bamgmesh);
     38        FetchData(&bamgmesh.NumVertices,mxGetField(BAMGMESH,0,"NumVertices"));
     39        FetchData(&bamgmesh.Vertices,NULL,NULL,mxGetField(BAMGMESH,0,"Vertices"));
     40        FetchData(&bamgmesh.NumTriangles,mxGetField(BAMGMESH,0,"NumTriangles"));
     41        FetchData(&bamgmesh.Triangles,NULL,NULL,mxGetField(BAMGMESH,0,"Triangles"));
     42        FetchData(&bamgmesh.hVertices,&lines,&cols,mxGetField(BAMGMESH,0,"hVertices"));
     43        FetchData(&bamgmesh.NumCrackedEdges,mxGetField(BAMGMESH,0,"NumCrackedEdges"));
     44        FetchData(&bamgmesh.CrackedEdges,NULL,NULL,mxGetField(BAMGMESH,0,"CrackedEdges"));
     45        if (bamgmesh.hVertices && (cols!=1 || lines!=bamgmesh.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'hVertices' should be [%i %i]",bamgmesh.NumVertices,1));}
    12346
    12447        /*create bamg options input*/
    125         FetchData(&coef,mxGetField(BAMGOPTIONS,0,"coef"));
    126         if (coef==0) throw ErrorException(__FUNCT__,exprintf("'coef' should be positive"));
    127         bamgopts.coef=coef;
    128         FetchData(&maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
    129         if (maxsubdiv<1) throw ErrorException(__FUNCT__,exprintf("'maxsubdiv' should be >=1"));
    130         bamgopts.maxsubdiv=maxsubdiv;
    131         FetchData(&Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
    132         if (Hessiantype!=0 && Hessiantype!=1) throw ErrorException(__FUNCT__,exprintf("'Hessiantype' supported options are 0 and 1"));
    133         bamgopts.Hessiantype=Hessiantype;
    134         FetchData(&Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
    135         if (Metrictype!=0 && Metrictype!=1 && Metrictype!=2) throw ErrorException(__FUNCT__,exprintf("'Metrictype' supported options are 0, 1 and 2"));
    136         bamgopts.Metrictype=Metrictype;
    137         FetchData(&KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
    138         if (KeepVertices!=0 && KeepVertices!=1) throw ErrorException(__FUNCT__,exprintf("'KeepVertices' supported options are 0 and 1"));
    139         bamgopts.KeepVertices=KeepVertices;
    140         FetchData(&renumber,mxGetField(BAMGOPTIONS,0,"renumber"));
    141         if (renumber!=0 && renumber!=1 && renumber!=2) throw ErrorException(__FUNCT__,exprintf("'renumber' supported options are 0, 1 and 2"));
    142         bamgopts.renumber=renumber;
    143         FetchData(&power,mxGetField(BAMGOPTIONS,0,"power"));
    144         bamgopts.power=power;
    145         FetchData(&errg,mxGetField(BAMGOPTIONS,0,"errg"));
    146         if (errg<0) throw ErrorException(__FUNCT__,exprintf("'errg' option should be >0"));
    147         bamgopts.errg=errg;
    148         FetchData(&nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
    149         if (nbjacobi<=0) throw ErrorException(__FUNCT__,exprintf("'nbjacobi' option should be >0"));
    150         bamgopts.nbjacobi=nbjacobi;
    151         FetchData(&NbSmooth,mxGetField(BAMGOPTIONS,0,"NbSmooth"));
    152         if (NbSmooth<=0) throw ErrorException(__FUNCT__,exprintf("'NbSmooth' option should be >0"));
    153         bamgopts.NbSmooth=NbSmooth;
    154         FetchData(&omega,mxGetField(BAMGOPTIONS,0,"omega"));
    155         bamgopts.omega=omega;
    156         FetchData(&maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
    157         if (maxnbv<3) throw ErrorException(__FUNCT__,exprintf("'maxnbv' option should be >3"));
    158         bamgopts.maxnbv=maxnbv;
    159         FetchData(&hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
    160         if (hmin<=0) throw ErrorException(__FUNCT__,exprintf("'hmin' option should be >0"));
    161         bamgopts.hmin=hmin;
    162         FetchData(&hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
    163         if (hmax<=0 || hmax<hmin) throw ErrorException(__FUNCT__,exprintf("'hmax' option should be between 0 and hmin=%g",hmin));
    164         bamgopts.hmax=hmax;
    165         FetchData(&anisomax,mxGetField(BAMGOPTIONS,0,"anisomax"));
    166         if (anisomax<1) throw ErrorException(__FUNCT__,exprintf("'anisomax' option should be >=1"));
    167         bamgopts.anisomax=anisomax;
    168         FetchData(&gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
    169         if (anisomax<1) throw ErrorException(__FUNCT__,exprintf("'anisomax' option should be >=1"));
    170         bamgopts.gradation=gradation;
    171         FetchData(&cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
    172         bamgopts.cutoff=cutoff;
    173         FetchData(&verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
    174         bamgopts.verbose=verbose;
    175         FetchData(&splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
    176         bamgopts.splitcorners=splitcorners;
    177         FetchData(&MaximalAngleOfCorner,mxGetField(BAMGOPTIONS,0,"MaximalAngleOfCorner"));
    178         bamgopts.MaximalAngleOfCorner=MaximalAngleOfCorner;
    179         FetchData(&metric,&lines,&cols,mxGetField(BAMGOPTIONS,0,"metric"));
    180         if (metric && (cols!=3 || lines!=NumVerticesMesh)){throw ErrorException(__FUNCT__,exprintf("the size of 'metric' should be [%i %i]",NumVerticesMesh,3));}
    181         bamgopts.metric=metric;
    182         FetchData(&field,&lines,&numfields,mxGetField(BAMGOPTIONS,0,"field"));
    183         if (field && lines!=NumVerticesMesh){throw ErrorException(__FUNCT__,exprintf("the size of 'field' should be [%i %i]",NumVerticesMesh,numfields));}
    184         bamgopts.numfields=numfields;
    185         bamgopts.field=field;
    186         FetchData(&err,NULL,&cols,mxGetField(BAMGOPTIONS,0,"err"));
    187         if (numfields!=0 && cols!=numfields){throw ErrorException(__FUNCT__,exprintf("the size of 'err' should be the same as 'field'"));}
    188         for (i=0;i<numfields;i++) {if (err[i]<=0) throw ErrorException(__FUNCT__,exprintf("'err' option should be >0"));};
    189         bamgopts.err=err;
     48        BamgOptsInit(&bamgopts);
     49        FetchData(&bamgopts.coef,mxGetField(BAMGOPTIONS,0,"coef"));
     50        if (bamgopts.coef==0) throw ErrorException(__FUNCT__,exprintf("'coef' should be positive"));
     51        FetchData(&bamgopts.maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
     52        if (bamgopts.maxsubdiv<1) throw ErrorException(__FUNCT__,exprintf("'maxsubdiv' should be >=1"));
     53        FetchData(&bamgopts.Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
     54        if (bamgopts.Hessiantype!=0 && bamgopts.Hessiantype!=1) throw ErrorException(__FUNCT__,exprintf("'Hessiantype' supported options are 0 and 1"));
     55        FetchData(&bamgopts.Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
     56        if (bamgopts.Metrictype!=0 && bamgopts.Metrictype!=1 && bamgopts.Metrictype!=2) throw ErrorException(__FUNCT__,exprintf("'Metrictype' supported options are 0, 1 and 2"));
     57        FetchData(&bamgopts.KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
     58        if (bamgopts.KeepVertices!=0 && bamgopts.KeepVertices!=1) throw ErrorException(__FUNCT__,exprintf("'KeepVertices' supported options are 0 and 1"));
     59        FetchData(&bamgopts.renumber,mxGetField(BAMGOPTIONS,0,"renumber"));
     60        if (bamgopts.renumber!=0 && bamgopts.renumber!=1 && bamgopts.renumber!=2) throw ErrorException(__FUNCT__,exprintf("'renumber' supported options are 0, 1 and 2"));
     61        FetchData(&bamgopts.power,mxGetField(BAMGOPTIONS,0,"power"));
     62        FetchData(&bamgopts.errg,mxGetField(BAMGOPTIONS,0,"errg"));
     63        if (bamgopts.errg<0) throw ErrorException(__FUNCT__,exprintf("'errg' option should be >0"));
     64        FetchData(&bamgopts.nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
     65        if (bamgopts.nbjacobi<=0) throw ErrorException(__FUNCT__,exprintf("'nbjacobi' option should be >0"));
     66        FetchData(&bamgopts.NbSmooth,mxGetField(BAMGOPTIONS,0,"NbSmooth"));
     67        if (bamgopts.NbSmooth<=0) throw ErrorException(__FUNCT__,exprintf("'NbSmooth' option should be >0"));
     68        FetchData(&bamgopts.omega,mxGetField(BAMGOPTIONS,0,"omega"));
     69        FetchData(&bamgopts.maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
     70        if (bamgopts.maxnbv<3) throw ErrorException(__FUNCT__,exprintf("'maxnbv' option should be >3"));
     71        FetchData(&bamgopts.hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
     72        if (bamgopts.hmin<=0) throw ErrorException(__FUNCT__,exprintf("'hmin' option should be >0"));
     73        FetchData(&bamgopts.hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
     74        if (bamgopts.hmax<=0 || bamgopts.hmax<bamgopts.hmin) throw ErrorException(__FUNCT__,exprintf("'hmax' option should be between 0 and hmin=%g",bamgopts.hmin));
     75        FetchData(&bamgopts.anisomax,mxGetField(BAMGOPTIONS,0,"anisomax"));
     76        if (bamgopts.anisomax<1) throw ErrorException(__FUNCT__,exprintf("'anisomax' option should be >=1"));
     77        FetchData(&bamgopts.gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
     78        if (bamgopts.gradation<1) throw ErrorException(__FUNCT__,exprintf("'gradation' option should be >=1"));
     79        FetchData(&bamgopts.cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
     80        FetchData(&bamgopts.verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
     81        FetchData(&bamgopts.splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
     82        FetchData(&bamgopts.MaximalAngleOfCorner,mxGetField(BAMGOPTIONS,0,"MaximalAngleOfCorner"));
     83        FetchData(&bamgopts.metric,&lines,&cols,mxGetField(BAMGOPTIONS,0,"metric"));
     84        if (bamgopts.metric && (cols!=3 || lines!=bamgmesh.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'metric' should be [%i %i]",bamgmesh.NumVertices,3));}
     85        FetchData(&bamgopts.field,&lines,&bamgopts.numfields,mxGetField(BAMGOPTIONS,0,"field"));
     86        if (bamgopts.field && lines!=bamgmesh.NumVertices){throw ErrorException(__FUNCT__,exprintf("the size of 'field' should be [%i %i]",bamgmesh.NumVertices,bamgopts.numfields));}
     87        FetchData(&bamgopts.err,NULL,&cols,mxGetField(BAMGOPTIONS,0,"err"));
     88        if (bamgopts.numfields!=0 && cols!=bamgopts.numfields){throw ErrorException(__FUNCT__,exprintf("the size of 'err' should be the same as 'field'"));}
     89        for (i=0;i<bamgopts.numfields;i++) {if (bamgopts.err[i]<=0) throw ErrorException(__FUNCT__,exprintf("'err' option should be >0"));};
    19090
    19191        /*!Generate internal degree of freedom numbers: */
Note: See TracChangeset for help on using the changeset viewer.