Changeset 5177


Ignore:
Timestamp:
08/12/10 09:43:45 (15 years ago)
Author:
Mathieu Morlighem
Message:

As usual (Added object constructor from matlab structure

Location:
issm/trunk/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp

    r5154 r5177  
    2020
    2121        /*Options*/
    22         BamgOpts bamgopts;
     22        BamgOpts* bamgopts=NULL;
    2323
    2424        // read mesh
     
    2828        //write mesh and geometry
    2929        if (verbose) printf("Write Geometry\n");
    30         Th.Gh.WriteGeometry(bamggeom,&bamgopts);
     30        Th.Gh.WriteGeometry(bamggeom,bamgopts);
    3131        if (verbose) printf("Write Mesh\n");
    32         Th.WriteMesh(bamgmesh,&bamgopts);
     32        Th.WriteMesh(bamgmesh,bamgopts);
     33
     34        //clean up
     35        delete bamgopts;
    3336
    3437        /*No error return*/
  • issm/trunk/src/c/objects/Bamg/BamgGeom.cpp

    r5172 r5177  
    2020}
    2121/*}}}*/
     22/*FUNCTION BamgGeom::BamgGeom(mxArray* matlab_struct){{{1*/
     23#ifdef _SERIAL_
     24BamgGeom::BamgGeom(mxArray* matlab_struct){
     25
     26        int lines,cols;
     27
     28        FetchData(&this->Vertices,        &this->VerticesSize[0],        &this->VerticesSize[1],        mxGetField(matlab_struct,0,"Vertices"));
     29        FetchData(&this->Edges,           &this->EdgesSize[0],           &this->EdgesSize[1],           mxGetField(matlab_struct,0,"Edges"));
     30        FetchData(&this->hVertices,&lines,&cols,mxGetField(matlab_struct,0,"hVertices"));
     31        this->MetricVertices=NULL;
     32        this->TangentAtEdgesSize[0]=0,    this->TangentAtEdgesSize[1]=0;    this->TangentAtEdges=NULL;
     33        FetchData(&this->Corners,         &this->CornersSize[0],         &this->CornersSize[1],         mxGetField(matlab_struct,0,"Corners"));
     34        FetchData(&this->RequiredVertices,&this->RequiredVerticesSize[0],&this->RequiredVerticesSize[1],mxGetField(matlab_struct,0,"RequiredVertices"));
     35        FetchData(&this->RequiredEdges,   &this->RequiredEdgesSize[0],   &this->RequiredEdgesSize[1],   mxGetField(matlab_struct,0,"RequiredEdges"));
     36        FetchData(&this->CrackedEdges,    &this->CrackedEdgesSize[0],    &this->CrackedEdgesSize[1],    mxGetField(matlab_struct,0,"CrackedEdges"));
     37        FetchData(&this->SubDomains,      &this->SubDomainsSize[0],      &this->SubDomainsSize[1],      mxGetField(matlab_struct,0,"SubDomains"));
     38
     39        /*Some checks*/
     40        if (this->hVertices && (cols!=1 || lines!=this->VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",this->VerticesSize[0],1);}
     41
     42}
     43#endif
     44/*}}}*/
    2245/*FUNCTION BamgGeom::~BamgGeom(){{{1*/
    2346BamgGeom::~BamgGeom(){
     
    3861
    3962/*Methods*/
    40 /*FUNCTION BamgGeom::GetMatlabStructureFields{{{1*/
    41 #ifdef _SERIAL_
    42 void BamgGeom::GetMatlabStructureFields(mxArray* matlab_struct){
    43 
    44         int lines,cols;
    45 
    46         FetchData(&this->Vertices,        &this->VerticesSize[0],        &this->VerticesSize[1],        mxGetField(matlab_struct,0,"Vertices"));
    47         FetchData(&this->Edges,           &this->EdgesSize[0],           &this->EdgesSize[1],           mxGetField(matlab_struct,0,"Edges"));
    48         FetchData(&this->Corners,         &this->CornersSize[0],         &this->CornersSize[1],         mxGetField(matlab_struct,0,"Corners"));
    49         FetchData(&this->RequiredVertices,&this->RequiredVerticesSize[0],&this->RequiredVerticesSize[1],mxGetField(matlab_struct,0,"RequiredVertices"));
    50         FetchData(&this->RequiredEdges,   &this->RequiredEdgesSize[0],   &this->RequiredEdgesSize[1],   mxGetField(matlab_struct,0,"RequiredEdges"));
    51         FetchData(&this->CrackedEdges,    &this->CrackedEdgesSize[0],    &this->CrackedEdgesSize[1],    mxGetField(matlab_struct,0,"CrackedEdges"));
    52         FetchData(&this->SubDomains,      &this->SubDomainsSize[0],      &this->SubDomainsSize[1],      mxGetField(matlab_struct,0,"SubDomains"));
    53         FetchData(&this->hVertices,&lines,&cols,mxGetField(matlab_struct,0,"hVertices"));
    54         if (this->hVertices && (cols!=1 || lines!=this->VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",this->VerticesSize[0],1);}
    55 
    56 }
    57 #endif
    58 /*}}}*/
    5963/*FUNCTION BamgGeom::SetMatlabStructureFields{{{1*/
    6064#ifdef _SERIAL_
     
    6266
    6367        /*Intermediary*/
    64         int         i,i1,i2;
    65         mxArray*    pfield=NULL;
    66         mxArray*    pfield2=NULL;
     68        int         i;
    6769        mxArray*    output=NULL;
    6870        int         numfields=7;
    6971        const char* fnames[numfields];
    70         int         fsize[numfields][2];
    71         double**    fpointer[numfields];
    7272        mwSize      ndim=2;
    7373        mwSize      dimensions[2]={1,1};
    7474
    75         /*Build fnames and fsize names and sizes of each field*/
    76         i=-1;
    77         fnames[++i] = "Vertices";        fsize[i][0]=this->VerticesSize[0];        fsize[i][1]=this->VerticesSize[1];        fpointer[i]=&this->Vertices;
    78         fnames[++i] = "Edges";           fsize[i][0]=this->EdgesSize[0];           fsize[i][1]=this->EdgesSize[1];           fpointer[i]=&this->Edges;
    79         fnames[++i] = "TangentAtEdges";  fsize[i][0]=this->TangentAtEdgesSize[0];  fsize[i][1]=this->TangentAtEdgesSize[1];  fpointer[i]=&this->TangentAtEdges;
    80         fnames[++i] = "RequiredVertices";fsize[i][0]=this->RequiredVerticesSize[0];fsize[i][1]=this->RequiredVerticesSize[1];fpointer[i]=&this->RequiredVertices;
    81         fnames[++i] = "RequiredEdges";   fsize[i][0]=this->RequiredEdgesSize[0];   fsize[i][1]=this->RequiredEdgesSize[1];   fpointer[i]=&this->RequiredEdges;
    82         fnames[++i] = "CrackedEdges";    fsize[i][0]=this->CrackedEdgesSize[0];    fsize[i][1]=this->CrackedEdgesSize[1];    fpointer[i]=&this->CrackedEdges;
    83         fnames[++i] = "SubDomains";      fsize[i][0]=this->SubDomainsSize[0];      fsize[i][1]=this->SubDomainsSize[1];      fpointer[i]=&this->SubDomains;
    84         ISSMASSERT(i==numfields-1);
     75        /*Initialize field names*/
     76        i=0;
     77        fnames[i++] = "Vertices";
     78        fnames[i++] = "Edges";
     79        fnames[i++] = "TangentAtEdges";
     80        fnames[i++] = "RequiredVertices";
     81        fnames[i++] = "RequiredEdges";
     82        fnames[i++] = "CrackedEdges";
     83        fnames[i++] = "SubDomains";
     84        ISSMASSERT(i==numfields);
    8585
    8686        /*Initialize Matlab structure*/
    8787        output=mxCreateStructArray(ndim,dimensions,numfields,fnames);
    8888
    89         /*Add every field tu structure*/
    90         for(i=0;i<numfields;i++){
    91 
    92                 /*Copy field*/
    93                 double*  fieldcopy=NULL;
    94                 if (fsize[i][0]*fsize[i][1]){
    95                         fieldcopy=(double*)xmalloc(fsize[i][0]*fsize[i][1]*sizeof(double));
    96                         for(i1=0;i1<fsize[i][0];i1++){
    97                                 for(i2=0;i2<fsize[i][1];i2++){
    98                                         fieldcopy[fsize[i][1]*i1+i2]=*(*fpointer[i] + fsize[i][1]*i1+i2);
    99                                 }
    100                         }
    101                 }
    102 
    103                 /*Set matlab field*/
    104                 pfield=mxCreateDoubleMatrix(0,0,mxREAL);
    105                 mxSetM(pfield,fsize[i][1]);
    106                 mxSetN(pfield,fsize[i][0]);
    107                 mxSetPr(pfield,fieldcopy);
    108                 mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
    109                 mxSetField(output,0,fnames[i],pfield2);
    110         }
     89        /*set each matlab each field*/
     90        i=0;
     91        i++; SetMatlabStructureField(output,"Vertices",        this->VerticesSize[0],        this->VerticesSize[1],        this->Vertices);
     92        i++; SetMatlabStructureField(output,"Edges",           this->EdgesSize[0],           this->EdgesSize[1],           this->Edges);
     93        i++; SetMatlabStructureField(output,"TangentAtEdges",  this->TangentAtEdgesSize[0],  this->TangentAtEdgesSize[1],  this->TangentAtEdges);
     94        i++; SetMatlabStructureField(output,"RequiredVertices",this->RequiredVerticesSize[0],this->RequiredVerticesSize[1],this->RequiredVertices);
     95        i++; SetMatlabStructureField(output,"RequiredEdges",   this->RequiredEdgesSize[0],   this->RequiredEdgesSize[1],   this->RequiredEdges);
     96        i++; SetMatlabStructureField(output,"CrackedEdges",    this->CrackedEdgesSize[0],    this->CrackedEdgesSize[1],    this->CrackedEdges);
     97        i++; SetMatlabStructureField(output,"SubDomains",      this->SubDomainsSize[0],      this->SubDomainsSize[1],      this->SubDomains);
     98        ISSMASSERT(i==numfields);
    11199
    112100        /*Assign output*/
     
    116104#endif
    117105/*}}}*/
     106/*FUNCTION BamgGeom::SetMatlabStructureField{{{1*/
     107#ifdef _SERIAL_
     108void BamgGeom::SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){
     109
     110        /*Intermediary*/
     111        int         i1,i2;
     112        mxArray*    pfield=NULL;
     113        mxArray*    pfield2=NULL;
     114
     115        /*Copy field*/
     116        double*  fieldcopy=NULL;
     117        if (fieldrows*fieldcols){
     118                fieldcopy=(double*)xmalloc(fieldrows*fieldcols*sizeof(double));
     119                for(i1=0;i1<fieldrows;i1++){
     120                        for(i2=0;i2<fieldcols;i2++){
     121                                fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldcols*i1+i2];
     122                        }
     123                }
     124        }
     125
     126        /*Set matlab field*/
     127        pfield=mxCreateDoubleMatrix(0,0,mxREAL);
     128        mxSetM(pfield,fieldcols);
     129        mxSetN(pfield,fieldrows);
     130        mxSetPr(pfield,fieldcopy);
     131        mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
     132        mxSetField(matlab_struct,0,fieldname,pfield2);
     133}
     134#endif
     135/*}}}*/
  • issm/trunk/src/c/objects/Bamg/BamgGeom.h

    r5172 r5177  
    3232
    3333                BamgGeom();
     34                #ifdef _SERIAL_
     35                BamgGeom(mxArray* matlab_struct);
     36                #endif
    3437                ~BamgGeom();
    3538
    3639                #ifdef _SERIAL_
    37                 void GetMatlabStructureFields(mxArray* matlab_struct);
    3840                void SetMatlabStructureFields(mxArray** matlab_struct);
     41                void SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
    3942                #endif
    4043};
  • issm/trunk/src/c/objects/Bamg/BamgMesh.cpp

    r5172 r5177  
    1111        this->TrianglesSize[0]=0,                 this->TrianglesSize[1]=0;                this->Triangles=NULL;
    1212        this->QuadrilateralsSize[0]=0,            this->QuadrilateralsSize[1]=0;           this->Quadrilaterals=NULL;
     13
     14        this->SubDomainsSize[0]=0,                this->SubDomainsSize[1]=0;               this->SubDomains=NULL;
     15        this->SubDomainsFromGeomSize[0]=0,        this->SubDomainsFromGeomSize[1]=0;       this->SubDomainsFromGeom=NULL;
     16        this->CrackedVerticesSize[0]=0,           this->CrackedVerticesSize[1]=0;          this->CrackedVertices=NULL;
     17        this->CrackedEdgesSize[0]=0,              this->CrackedEdgesSize[1]=0;             this->CrackedEdges=NULL;
     18
    1319        this->VerticesOnGeometricVertexSize[0]=0, this->VerticesOnGeometricVertexSize[1]=0;this->VerticesOnGeometricVertex=NULL;
    1420        this->VerticesOnGeometricEdgeSize[0]=0,   this->VerticesOnGeometricEdgeSize[1]=0;  this->VerticesOnGeometricEdge=NULL;
    1521        this->EdgesOnGeometricEdgeSize[0]=0,      this->EdgesOnGeometricEdgeSize[1]=0;     this->EdgesOnGeometricEdge=NULL;
    16         this->SubDomainsSize[0]=0,                this->SubDomainsSize[1]=0;               this->SubDomains=NULL;
    17         this->SubDomainsFromGeomSize[0]=0,        this->SubDomainsFromGeomSize[1]=0;       this->SubDomainsFromGeom=NULL;
     22
    1823        this->hVertices=NULL;
     24
    1925        this->IssmEdgesSize[0]=0,                 this->IssmEdgesSize[1]=0;                this->IssmEdges=NULL;
    2026        this->IssmSegmentsSize[0]=0,              this->IssmSegmentsSize[1]=0;             this->IssmSegments=NULL;
     27
    2128        this->ElementConnectivitySize[0]=0,       this->ElementConnectivitySize[1]=0;      this->ElementConnectivity=NULL;
    2229        this->NodalConnectivitySize[0]=0,         this->NodalConnectivitySize[1]=0;        this->NodalConnectivity=NULL;
    2330        this->NodalElementConnectivitySize[0]=0,  this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
    24         this->CrackedVerticesSize[0]=0,           this->CrackedVerticesSize[1]=0;          this->CrackedVertices=NULL;
    25         this->CrackedEdgesSize[0]=0,              this->CrackedEdgesSize[1]=0;             this->CrackedEdges=NULL;
     31
    2632
    2733}
     34/*}}}*/
     35/*FUNCTION BamgMesh::BamgMesh(mxArray* matlab_struct){{{1*/
     36#ifdef _SERIAL_
     37BamgMesh::BamgMesh(mxArray* matlab_struct){
     38
     39        int lines,cols;
     40
     41        FetchData(&this->Vertices,                 &this->VerticesSize[0],                 &this->VerticesSize[1],                 mxGetField(matlab_struct,0,"Vertices"));
     42        FetchData(&this->Edges,                    &this->EdgesSize[0],                    &this->EdgesSize[1],                    mxGetField(matlab_struct,0,"Edges"));
     43        FetchData(&this->Triangles,                &this->TrianglesSize[0],                &this->TrianglesSize[1],                mxGetField(matlab_struct,0,"Triangles"));
     44        this->QuadrilateralsSize[0]=0,            this->QuadrilateralsSize[1]=0;           this->Quadrilaterals=NULL;
     45
     46        this->SubDomainsSize[0]=0,                this->SubDomainsSize[1]=0;               this->SubDomains=NULL;
     47        this->SubDomainsFromGeomSize[0]=0,        this->SubDomainsFromGeomSize[1]=0;       this->SubDomainsFromGeom=NULL;
     48        this->CrackedVerticesSize[0]=0,           this->CrackedVerticesSize[1]=0;          this->CrackedVertices=NULL;
     49        FetchData(&this->CrackedEdges,            &this->CrackedEdgesSize[0],              &this->CrackedEdgesSize[1],             mxGetField(matlab_struct,0,"CrackedEdges"));
     50
     51        FetchData(&this->VerticesOnGeometricEdge,  &this->VerticesOnGeometricEdgeSize[0],  &this->VerticesOnGeometricEdgeSize[1],  mxGetField(matlab_struct,0,"VerticesOnGeometricEdge"));
     52        FetchData(&this->VerticesOnGeometricVertex,&this->VerticesOnGeometricVertexSize[0],&this->VerticesOnGeometricVertexSize[1],mxGetField(matlab_struct,0,"VerticesOnGeometricVertex"));
     53        FetchData(&this->EdgesOnGeometricEdge,     &this->EdgesOnGeometricEdgeSize[0],     &this->EdgesOnGeometricEdgeSize[1],     mxGetField(matlab_struct,0,"EdgesOnGeometricEdge"));
     54
     55        FetchData(&this->hVertices,                &lines,                                 &cols,                                  mxGetField(matlab_struct,0,"hVertices"));
     56
     57        this->IssmEdgesSize[0]=0,                 this->IssmEdgesSize[1]=0;                this->IssmEdges=NULL;
     58        FetchData(&this->IssmSegments,             &this->IssmSegmentsSize[0],             &this->IssmSegmentsSize[1],             mxGetField(matlab_struct,0,"IssmSegments"));
     59
     60        this->ElementConnectivitySize[0]=0,       this->ElementConnectivitySize[1]=0;      this->ElementConnectivity=NULL;
     61        this->NodalConnectivitySize[0]=0,         this->NodalConnectivitySize[1]=0;        this->NodalConnectivity=NULL;
     62        this->NodalElementConnectivitySize[0]=0,  this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
     63
     64        /*Checks*/
     65        if (this->hVertices && (cols!=1 || lines!=this->VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",this->VerticesSize[0],1);}
     66
     67}
     68#endif
    2869/*}}}*/
    2970/*FUNCTION BamgMesh::~BamgMesh(){{{1*/
     
    3475        xfree((void**)&this->Triangles);
    3576        xfree((void**)&this->Quadrilaterals);
     77
     78        xfree((void**)&this->SubDomains);
     79        xfree((void**)&this->SubDomainsFromGeom);
     80        xfree((void**)&this->CrackedVertices);
     81        xfree((void**)&this->CrackedEdges);
     82
    3683        xfree((void**)&this->VerticesOnGeometricVertex);
    3784        xfree((void**)&this->VerticesOnGeometricEdge);
    3885        xfree((void**)&this->EdgesOnGeometricEdge);
    39         xfree((void**)&this->SubDomains);
    40         xfree((void**)&this->SubDomainsFromGeom);
     86
    4187        xfree((void**)&this->hVertices);
     88
    4289        xfree((void**)&this->IssmEdges);
    4390        xfree((void**)&this->IssmSegments);
     91
    4492        xfree((void**)&this->ElementConnectivity);
    4593        xfree((void**)&this->NodalConnectivity);
    4694        xfree((void**)&this->NodalElementConnectivity);
    47         xfree((void**)&this->CrackedVertices);
    48         xfree((void**)&this->CrackedEdges);
     95
    4996
    5097}
     
    5299
    53100/*Methods*/
    54 /*FUNCTION BamgMesh::GetMatlabStructureFields{{{1*/
    55 #ifdef _SERIAL_
    56 void BamgMesh::GetMatlabStructureFields(mxArray* matlab_struct){
    57 
    58         int lines,cols;
    59 
    60         FetchData(&this->Triangles,                &this->TrianglesSize[0],                &this->TrianglesSize[1],                mxGetField(matlab_struct,0,"Triangles"));
    61         FetchData(&this->Vertices,                 &this->VerticesSize[0],                 &this->VerticesSize[1],                 mxGetField(matlab_struct,0,"Vertices"));
    62         FetchData(&this->Edges,                    &this->EdgesSize[0],                    &this->EdgesSize[1],                    mxGetField(matlab_struct,0,"Edges"));
    63         FetchData(&this->IssmSegments,             &this->IssmSegmentsSize[0],             &this->IssmSegmentsSize[1],             mxGetField(matlab_struct,0,"IssmSegments"));
    64         FetchData(&this->CrackedEdges,            &this->CrackedEdgesSize[0],              &this->CrackedEdgesSize[1],             mxGetField(matlab_struct,0,"CrackedEdges"));
    65         FetchData(&this->EdgesOnGeometricEdge,     &this->EdgesOnGeometricEdgeSize[0],     &this->EdgesOnGeometricEdgeSize[1],     mxGetField(matlab_struct,0,"EdgesOnGeometricEdge"));
    66         FetchData(&this->VerticesOnGeometricEdge,  &this->VerticesOnGeometricEdgeSize[0],  &this->VerticesOnGeometricEdgeSize[1],  mxGetField(matlab_struct,0,"VerticesOnGeometricEdge"));
    67         FetchData(&this->VerticesOnGeometricVertex,&this->VerticesOnGeometricVertexSize[0],&this->VerticesOnGeometricVertexSize[1],mxGetField(matlab_struct,0,"VerticesOnGeometricVertex"));
    68         FetchData(&this->hVertices,                &lines,                                 &cols,                                  mxGetField(matlab_struct,0,"hVertices"));
    69         if (this->hVertices && (cols!=1 || lines!=this->VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",this->VerticesSize[0],1);}
    70 
    71 }
    72 #endif
    73 /*}}}*/
    74101/*FUNCTION BamgMesh::SetMatlabStructureFields{{{1*/
    75102#ifdef _SERIAL_
     
    77104
    78105        /*Intermediary*/
    79         int         i,i1,i2;
    80         mxArray*    pfield=NULL;
    81         mxArray*    pfield2=NULL;
     106        int         i;
    82107        mxArray*    output=NULL;
    83108        int         numfields=16;
    84109        const char* fnames[numfields];
    85         int         fsize[numfields][2];
    86         double**    fpointer[numfields];
    87110        mwSize      ndim=2;
    88111        mwSize      dimensions[2]={1,1};
    89112
    90         /*Build fnames and fsize names and sizes of each field*/
    91         i=-1;
    92         fnames[++i] = "Triangles";                fsize[i][0]=this->TrianglesSize[0];                 fsize[i][1]=this->TrianglesSize[1];                fpointer[i]=&this->Triangles;
    93         fnames[++i] = "Vertices";                 fsize[i][0]=this->VerticesSize[0];                  fsize[i][1]=this->VerticesSize[1];                 fpointer[i]=&this->Vertices;
    94         fnames[++i] = "Edges";                    fsize[i][0]=this->EdgesSize[0];                     fsize[i][1]=this->EdgesSize[1];                    fpointer[i]=&this->Edges;
    95         fnames[++i] = "IssmSegments";             fsize[i][0]=this->IssmSegmentsSize[0];              fsize[i][1]=this->IssmSegmentsSize[1];             fpointer[i]=&this->IssmSegments;
    96         fnames[++i] = "IssmEdges";                fsize[i][0]=this->IssmEdgesSize[0];                 fsize[i][1]=this->IssmEdgesSize[1];                fpointer[i]=&this->IssmEdges;
    97         fnames[++i] = "Quadrilaterals";           fsize[i][0]=this->QuadrilateralsSize[0];            fsize[i][1]=this->QuadrilateralsSize[1];           fpointer[i]=&this->Quadrilaterals;
    98         fnames[++i] = "VerticesOnGeometricVertex";fsize[i][0]=this->VerticesOnGeometricVertexSize[0]; fsize[i][1]=this->VerticesOnGeometricVertexSize[1];fpointer[i]=&this->VerticesOnGeometricVertex;
    99         fnames[++i] = "VerticesOnGeometricEdge";  fsize[i][0]=this->VerticesOnGeometricEdgeSize[0];   fsize[i][1]=this->VerticesOnGeometricEdgeSize[1];  fpointer[i]=&this->VerticesOnGeometricEdge;
    100         fnames[++i] = "EdgesOnGeometricEdge";     fsize[i][0]=this->EdgesOnGeometricEdgeSize[0];      fsize[i][1]=this->EdgesOnGeometricEdgeSize[1];     fpointer[i]=&this->EdgesOnGeometricEdge;
    101         fnames[++i] = "SubDomains";               fsize[i][0]=this->SubDomainsSize[0];                fsize[i][1]=this->SubDomainsSize[1];               fpointer[i]=&this->SubDomains;
    102         fnames[++i] = "SubDomainsFromGeom";       fsize[i][0]=this->SubDomainsFromGeomSize[0];        fsize[i][1]=this->SubDomainsFromGeomSize[1];       fpointer[i]=&this->SubDomainsFromGeom;
    103         fnames[++i] = "ElementConnectivity";      fsize[i][0]=this->ElementConnectivitySize[0];       fsize[i][1]=this->ElementConnectivitySize[1];      fpointer[i]=&this->ElementConnectivity;
    104         fnames[++i] = "NodalConnectivity";        fsize[i][0]=this->NodalConnectivitySize[0];         fsize[i][1]=this->NodalConnectivitySize[1];        fpointer[i]=&this->NodalConnectivity;
    105         fnames[++i] = "NodalElementConnectivity"; fsize[i][0]=this->NodalElementConnectivitySize[0];  fsize[i][1]=this->NodalElementConnectivitySize[1]; fpointer[i]=&this->NodalElementConnectivity;
    106         fnames[++i] = "CrackedVertices";          fsize[i][0]=this->CrackedVerticesSize[0];           fsize[i][1]=this->CrackedVerticesSize[1];          fpointer[i]=&this->CrackedVertices;
    107         fnames[++i] = "CrackedEdges";             fsize[i][0]=this->CrackedEdgesSize[0];              fsize[i][1]=this->CrackedEdgesSize[1];             fpointer[i]=&this->CrackedEdges;
    108         ISSMASSERT(i==numfields-1);
     113        /*Initialize field names*/
     114        i=0;
     115        fnames[i++] = "Triangles";
     116        fnames[i++] = "Vertices";
     117        fnames[i++] = "Edges";
     118        fnames[i++] = "IssmSegments";
     119        fnames[i++] = "IssmEdges";
     120        fnames[i++] = "Quadrilaterals";
     121        fnames[i++] = "VerticesOnGeometricVertex";
     122        fnames[i++] = "VerticesOnGeometricEdge";
     123        fnames[i++] = "EdgesOnGeometricEdge";
     124        fnames[i++] = "SubDomains";
     125        fnames[i++] = "SubDomainsFromGeom";
     126        fnames[i++] = "ElementConnectivity";
     127        fnames[i++] = "NodalConnectivity";
     128        fnames[i++] = "NodalElementConnectivity";
     129        fnames[i++] = "CrackedVertices";
     130        fnames[i++] = "CrackedEdges";
     131        ISSMASSERT(i==numfields);
    109132
    110133        /*Initialize Matlab structure*/
    111134        output=mxCreateStructArray(ndim,dimensions,numfields,fnames);
    112135
    113         /*Add every field tu structure*/
    114         for(i=0;i<numfields;i++){
    115 
    116                 /*Copy field*/
    117                 double*  fieldcopy=NULL;
    118                 if (fsize[i][0]*fsize[i][1]){
    119                         fieldcopy=(double*)xmalloc(fsize[i][0]*fsize[i][1]*sizeof(double));
    120                         for(i1=0;i1<fsize[i][0];i1++){
    121                                 for(i2=0;i2<fsize[i][1];i2++){
    122                                         fieldcopy[fsize[i][1]*i1+i2]=*(*fpointer[i] + fsize[i][1]*i1+i2);
    123                                 }
    124                         }
    125                 }
    126 
    127                 /*Set matlab field*/
    128                 pfield=mxCreateDoubleMatrix(0,0,mxREAL);
    129                 mxSetM(pfield,fsize[i][1]);
    130                 mxSetN(pfield,fsize[i][0]);
    131                 mxSetPr(pfield,fieldcopy);
    132                 mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
    133                 mxSetField(output,0,fnames[i],pfield2);
    134         }
     136        /*set each matlab each field*/
     137        i=0;
     138        i++; SetMatlabStructureField(output,"Triangles",                this->TrianglesSize[0],                this->TrianglesSize[1],                 this->Triangles);
     139        i++; SetMatlabStructureField(output,"Vertices",                 this->VerticesSize[0],                 this->VerticesSize[1],                  this->Vertices);
     140        i++; SetMatlabStructureField(output,"Edges",                    this->EdgesSize[0],                    this->EdgesSize[1],                     this->Edges);
     141        i++; SetMatlabStructureField(output,"IssmSegments",             this->IssmSegmentsSize[0],             this->IssmSegmentsSize[1],              this->IssmSegments);
     142        i++; SetMatlabStructureField(output,"IssmEdges",                this->IssmEdgesSize[0],                this->IssmEdgesSize[1],                 this->IssmEdges);
     143        i++; SetMatlabStructureField(output,"Quadrilaterals",           this->QuadrilateralsSize[0],           this->QuadrilateralsSize[1],            this->Quadrilaterals);
     144        i++; SetMatlabStructureField(output,"VerticesOnGeometricVertex",this->VerticesOnGeometricVertexSize[0],this->VerticesOnGeometricVertexSize[1], this->VerticesOnGeometricVertex);
     145        i++; SetMatlabStructureField(output,"VerticesOnGeometricEdge",  this->VerticesOnGeometricEdgeSize[0],  this->VerticesOnGeometricEdgeSize[1],   this->VerticesOnGeometricEdge);
     146        i++; SetMatlabStructureField(output,"EdgesOnGeometricEdge",     this->EdgesOnGeometricEdgeSize[0],     this->EdgesOnGeometricEdgeSize[1],      this->EdgesOnGeometricEdge);
     147        i++; SetMatlabStructureField(output,"SubDomains",               this->SubDomainsSize[0],               this->SubDomainsSize[1],                this->SubDomains);
     148        i++; SetMatlabStructureField(output,"SubDomainsFromGeom",       this->SubDomainsFromGeomSize[0],       this->SubDomainsFromGeomSize[1],        this->SubDomainsFromGeom);
     149        i++; SetMatlabStructureField(output,"ElementConnectivity",      this->ElementConnectivitySize[0],      this->ElementConnectivitySize[1],       this->ElementConnectivity);
     150        i++; SetMatlabStructureField(output,"NodalConnectivity",        this->NodalConnectivitySize[0],        this->NodalConnectivitySize[1],         this->NodalConnectivity);
     151        i++; SetMatlabStructureField(output,"NodalElementConnectivity", this->NodalElementConnectivitySize[0], this->NodalElementConnectivitySize[1],  this->NodalElementConnectivity);
     152        i++; SetMatlabStructureField(output,"CrackedVertices",          this->CrackedVerticesSize[0],          this->CrackedVerticesSize[1],           this->CrackedVertices);
     153        i++; SetMatlabStructureField(output,"CrackedEdges",             this->CrackedEdgesSize[0],             this->CrackedEdgesSize[1],              this->CrackedEdges);
     154        ISSMASSERT(i==numfields);
    135155
    136156        /*Assign output*/
     
    140160#endif
    141161/*}}}*/
     162/*FUNCTION BamgMesh::SetMatlabStructureField{{{1*/
     163#ifdef _SERIAL_
     164void BamgMesh::SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){
     165
     166        /*Intermediary*/
     167        int         i1,i2;
     168        mxArray*    pfield=NULL;
     169        mxArray*    pfield2=NULL;
     170
     171        /*Copy field*/
     172        double*  fieldcopy=NULL;
     173        if (fieldrows*fieldcols){
     174                fieldcopy=(double*)xmalloc(fieldrows*fieldcols*sizeof(double));
     175                for(i1=0;i1<fieldrows;i1++){
     176                        for(i2=0;i2<fieldcols;i2++){
     177                                fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldcols*i1+i2];
     178                        }
     179                }
     180        }
     181
     182        /*Set matlab field*/
     183        pfield=mxCreateDoubleMatrix(0,0,mxREAL);
     184        mxSetM(pfield,fieldcols);
     185        mxSetN(pfield,fieldrows);
     186        mxSetPr(pfield,fieldcopy);
     187        mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
     188        mxSetField(matlab_struct,0,fieldname,pfield2);
     189}
     190#endif
     191/*}}}*/
  • issm/trunk/src/c/objects/Bamg/BamgMesh.h

    r5172 r5177  
    2121                int     QuadrilateralsSize[2];
    2222                double* Quadrilaterals;
     23
    2324                int     VerticesOnGeometricVertexSize[2];
    2425                double* VerticesOnGeometricVertex;
     
    2728                int     EdgesOnGeometricEdgeSize[2];
    2829                double* EdgesOnGeometricEdge;
     30
    2931                int     SubDomainsSize[2];
    3032                double* SubDomains;
     
    3537                int     CrackedEdgesSize[2];
    3638                double* CrackedEdges;
     39
    3740                double* hVertices;
    3841
     
    5053
    5154                BamgMesh();
     55                #ifdef _SERIAL_
     56                BamgMesh(mxArray* matlab_struct);
     57                #endif
    5258                ~BamgMesh();
    5359
    5460                #ifdef _SERIAL_
    55                 void GetMatlabStructureFields(mxArray* matlab_struct);
    5661                void SetMatlabStructureFields(mxArray** matlab_struct);
     62                void SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
    5763                #endif
    5864
  • issm/trunk/src/c/objects/Bamg/BamgOpts.cpp

    r5154 r5177  
    33#include "../../include/include.h"
    44#include "../objects.h"
     5#include "../../io/io.h"
    56
    67/*Constructors/Destructors*/
     
    89BamgOpts::BamgOpts(){
    910
    10         this->iso=0;
    1111        this->maxnbv=0;
    1212        this->MaxCornerAngle=0;
     13        this->Crack=0;
    1314        this->Hessiantype=0;
    1415        this->Metrictype=0;
    1516        this->KeepVertices=0;
    16         this->Crack=0;
    1717        this->maxsubdiv=0;
    1818        this->power=0;
     
    3838
    3939}
     40/*}}}*/
     41/*FUNCTION BamgOpts::BamgOpts(mxArray* matlab_struct){{{1*/
     42#ifdef _SERIAL_
     43BamgOpts::BamgOpts(mxArray* matlab_struct){
     44
     45        int lines,cols;
     46
     47        FetchData(&this->maxnbv,mxGetField(matlab_struct,0,"maxnbv"));
     48        FetchData(&this->MaxCornerAngle,mxGetField(matlab_struct,0,"MaxCornerAngle"));
     49        FetchData(&this->Crack,mxGetField(matlab_struct,0,"Crack"));
     50        FetchData(&this->Hessiantype,mxGetField(matlab_struct,0,"Hessiantype"));
     51        FetchData(&this->Metrictype,mxGetField(matlab_struct,0,"Metrictype"));
     52        FetchData(&this->KeepVertices,mxGetField(matlab_struct,0,"KeepVertices"));
     53        FetchData(&this->maxsubdiv,mxGetField(matlab_struct,0,"maxsubdiv"));
     54        FetchData(&this->power,mxGetField(matlab_struct,0,"power"));
     55        FetchData(&this->anisomax,mxGetField(matlab_struct,0,"anisomax"));
     56        FetchData(&this->nbsmooth,mxGetField(matlab_struct,0,"nbsmooth"));
     57        FetchData(&this->nbjacobi,mxGetField(matlab_struct,0,"nbjacobi"));
     58        FetchData(&this->omega,mxGetField(matlab_struct,0,"omega"));
     59        FetchData(&this->hmin,mxGetField(matlab_struct,0,"hmin"));
     60        FetchData(&this->hmax,mxGetField(matlab_struct,0,"hmax"));
     61        FetchData(&this->hminVertices,&lines,&cols,mxGetField(matlab_struct,0,"hminVertices"));
     62        FetchData(&this->hmaxVertices,&lines,&cols,mxGetField(matlab_struct,0,"hmaxVertices"));
     63        FetchData(&this->gradation,mxGetField(matlab_struct,0,"gradation"));
     64        FetchData(&this->cutoff,mxGetField(matlab_struct,0,"cutoff"));
     65        FetchData(&this->splitcorners,mxGetField(matlab_struct,0,"splitcorners"));
     66        FetchData(&this->geometricalmetric,mxGetField(matlab_struct,0,"geometricalmetric"));
     67        FetchData(&this->verbose,mxGetField(matlab_struct,0,"verbose"));
     68        FetchData(&this->field,&lines,&this->numfields,mxGetField(matlab_struct,0,"field"));
     69        FetchData(&this->err,NULL,&cols,mxGetField(matlab_struct,0,"err"));
     70        if (this->numfields!=0 && cols!=this->numfields){ISSMERROR("the size of 'err' should be the same as 'field'");}
     71        FetchData(&this->errg,mxGetField(matlab_struct,0,"errg"));
     72        FetchData(&this->coeff,mxGetField(matlab_struct,0,"coeff"));
     73        FetchData(&this->metric,&lines,&cols,mxGetField(matlab_struct,0,"metric"));
     74
     75        /*Additional checks*/
     76        this->Check();
     77
     78}
     79#endif
    4080/*}}}*/
    4181/*FUNCTION BamgOpts::~BamgOpts() {{{1*/
  • issm/trunk/src/c/objects/Bamg/BamgOpts.h

    r5154 r5177  
    66#define _BAMGOPTS_H_
    77
     8#ifdef _SERIAL_
     9#include <mex.h>
     10#endif
     11
    812class BamgOpts{
    913
    1014        public:
    1115
    12                 int     iso;
    1316                int     maxnbv;
    1417                double  MaxCornerAngle;
     
    4043
    4144                BamgOpts();
     45                #ifdef _SERIAL_
     46                BamgOpts(mxArray* matlab_struct);
     47                #endif
    4248                ~BamgOpts();
    4349
  • issm/trunk/src/c/objects/Bamg/Geometry.cpp

    r5154 r5177  
    111111                         * where D is the longest side of the domain (direction x or y)
    112112                         * so that (x-pmin.x)/D is in ]0 1[
     113                         *
     114                         * coefIcoor = (2^30 -1)/D
    113115                         */
    114116                        coefIcoor=(MaxICoor)/(Max(pmax.x-pmin.x,pmax.y-pmin.y));
     
    398400
    399401        /*Methods*/
    400         /*FUNCTION Geometry::AfterRead(){{{1*/
     402        /*FUNCTION Geometry::AfterRead{{{1*/
    401403        void Geometry::AfterRead(){
    402404                /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/AfterRead)*/
    403405
    404                 long int verbose=0;
    405 
    406                 long i,j,k;
    407                 int jj;
    408                 long* head_v=new long[nbv];
    409                 long* next_p=new long[2*nbe];
    410                 float* eangle=new float[nbe];
    411                 double eps=1e-20;
    412                 QuadTree quadtree; // build quadtree to find duplicates
    413                 BamgVertex* v0=vertices;
    414                 GeometricalVertex* v0g=(GeometricalVertex*) (void*)v0;   
     406                long               i,j,k;
     407                int                jj;
     408                long              *head_v   = new long[nbv];
     409                long              *next_p   = new long[2*nbe];
     410                float             *eangle   = new float[nbe];
     411                double             eps      = 1e-20;
     412                QuadTree           quadtree; // build quadtree to find duplicates
     413                BamgVertex        *v0       = vertices;
     414                GeometricalVertex *v0g      = (GeometricalVertex*) (void*)v0;
    415415
    416416                k=0;
     
    424424                        All the coordinates are transformed to ]0,1[^2
    425425                        then, the integer coordinates are computed using
    426                         the transformation ]0,1[^2 -> [0 2^(30-1)[^2 for a quadtree of depth 30*/
     426                        the transformation ]0,1[^2 -> [0 2^30-1[^2 for a quadtree of depth 30*/
    427427                        vertices[i].i=toI2(vertices[i].r);
    428428
    429                         //find nearest vertex already present in the quadtree (NULL if empty)
     429                        /*find nearest vertex already present in the quadtree (NULL if empty)*/
    430430                        BamgVertex* v=quadtree.NearestVertex(vertices[i].i.x,vertices[i].i.y);
    431431
    432                         //if there is a vertex found that is to close to vertices[i] -> error
    433                         if( v && Norme1(v->r - vertices[i]) < eps ){
    434                                 printf("WARNING: two points of the geometry are very closed to each other\n");
    435                         }
    436 
    437                         //Add vertices[i] to the quadtree
     432                        /*if there is a vertex found that is to close to vertices[i] -> error*/
     433                        if( v && Norme1(v->r - vertices[i].r) < eps ){
     434                                ISSMERROR("two points of the geometry are very closed to each other");
     435                        }
     436
     437                        /*Add vertices[i] to the quadtree*/
    438438                        quadtree.Add(vertices[i]);
    439                 }
    440 
    441                 //if k>0, there are some duplicate vertices -> error
    442                 if (k) {
    443                         printf("number of distinct vertices= %i, over %i\n",nbv - k,nbv);
    444                         printf("List of duplicate vertices:\n");
    445                         ISSMERROR("See above");
    446439                }
    447440
     
    767760                nbv=0;
    768761                nbe=0;
    769                 quadtree=0;
    770                 curves=0;
    771                 edges=0;
    772                 vertices=0;
     762                quadtree=NULL;
     763                curves=NULL;
     764                edges=NULL;
     765                vertices=NULL;
    773766                nbsubdomains=0;
    774767                nbcurves=0;
    775                 subdomains=0;
     768                subdomains=NULL;
    776769                MaxCornerAngle = 10*Pi/180; //default is 10 degres
    777770        }
     
    941934        /*FUNCTION Geometry::toI2{{{1*/
    942935        I2 Geometry::toI2(const R2 & P) const {
    943                 return  I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
    944                                         ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );
     936                /*coefIcoor is the coefficient used for integer coordinates:
     937                 *                       (x-pmin.x)
     938                 * Icoor x = (2^30 -1) ------------
     939                 *                          D
     940                 * where D is the longest side of the domain (direction x or y)
     941                 * so that (x-pmin.x)/D is in ]0 1[
     942                 *
     943                 * coefIcoor = (2^30 -1)/D
     944                 */
     945                return  I2( (Icoor1) (coefIcoor*(P.x-pmin.x)) ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );
    945946        }/*}}}*/
    946947        /*FUNCTION Geometry::UnMarkEdges{{{1*/
  • issm/trunk/src/c/objects/Bamg/QuadTree.cpp

    r5150 r5177  
    7272
    7373        /*Constructors/Destructors*/
     74        /*FUNCTION QuadTree::QuadTree(){{{1*/
     75        QuadTree::QuadTree() :
     76                /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/QuadTree)*/
     77
     78                lenStorageQuadTreeBox(100), // by default 100 vertices by box
     79                th(NULL),                   // initial mesh = NULL
     80                NbQuadTreeBox(0),           // initial number of quadtree boxes = 0
     81                NbVertices(0),              // initial number of vertices = 0
     82                NbQuadTreeBoxSearch(0),     // initial ?? = 0
     83                NbVerticesSearch(0){        // initial ?? = 0
     84
     85                        //create lenStorageQuadTreeBox (100) StorageQuadTreeBox elements
     86                        sb  =new StorageQuadTreeBox(lenStorageQuadTreeBox);
     87
     88                        //root=QuadTreeBox* pointer toward next quadtree box
     89                        root=NewQuadTreeBox();
     90
     91                }
     92        /*}}}1*/
    7493        /*FUNCTION QuadTree::QuadTree(Mesh * t,long nbv){{{1*/
    7594        QuadTree::QuadTree(Mesh * t,long nbv) :
     
    84103        {
    85104         if (nbv == -1) nbv = t->nbv;
    86          sb =new StorageQuadTreeBox(lenStorageQuadTreeBox);
     105         sb  = new StorageQuadTreeBox(lenStorageQuadTreeBox);
    87106         root=NewQuadTreeBox();
    88107         if ( MaxISize <= MaxICoor){
     
    93112        }
    94113        /*}}}1*/
    95         /*FUNCTION QuadTree::QuadTree(){{{1*/
    96         QuadTree::QuadTree() :
    97                 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/QuadTree)*/
    98 
    99                 lenStorageQuadTreeBox(100), // by default 100 vertices by box
    100                 th(0),                      // initial mesh = NULL
    101                 NbQuadTreeBox(0),           // initial number of quadtree boxes = 0
    102                 NbVertices(0),              // initial number of vertices = 0
    103                 NbQuadTreeBoxSearch(0),     // initial ?? = 0
    104                 NbVerticesSearch(0){        // initial ?? = 0
    105                         //create lenStorageQuadTreeBox (100) StorageQuadTreeBox elements
    106                         sb  =new StorageQuadTreeBox(lenStorageQuadTreeBox);
    107                         //root=QuadTreeBox* pointer roward ??
    108                         root=NewQuadTreeBox();
    109                 }
    110         /*}}}1*/
    111114        /*FUNCTION QuadTree::~QuadTree(){{{1*/
    112115        QuadTree::~QuadTree() {
     
    115118                delete sb;
    116119                root=0;
     120        }
     121        /*}}}1*/
     122        /*FUNCTION QuadTree::StorageQuadTreeBox::StorageQuadTreeBox{{{1*/
     123        QuadTree::StorageQuadTreeBox::StorageQuadTreeBox(long ll,StorageQuadTreeBox *nn) {
     124                /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/StorageQuadTreeBox)*/
     125
     126                /*Initilalize variables*/
     127                len = ll;                  // number of quadtree boxes
     128                n   = nn;                  // next StorageQuadTreeBox pointer
     129                b   = new QuadTreeBox[ll]; // quadtree boxes
     130                ISSMASSERT(b);             // check allocation
     131
     132                /*Initialize all quadtree boxes (empty)*/
     133                for (int i = 0; i <ll;i++){
     134                        b[i].n=0;
     135                        b[i].b[0]=b[i].b[1]=b[i].b[2]=b[i].b[3]=NULL;
     136                }
     137
     138                bc = b;      //first quadtree box
     139                be = b + ll; //last quadtree box
     140
    117141        }
    118142        /*}}}1*/
     
    123147                /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/Add)*/
    124148
    125                 QuadTreeBox** pb;
    126                 QuadTreeBox*  b;
     149                QuadTreeBox** pb=NULL;
     150                QuadTreeBox*  b=NULL;
     151
     152                /*Get integer coodinate of current point w*/
    127153                register long i=w.i.x, j=w.i.y;
     154
     155                /*Initialize level*/
    128156                register long level=MaxISize;
    129157
    130                 //Get inital box (the largest)
     158                /*Get inital box (the largest)*/
    131159                pb = &root;
    132160
     
    460488        }
    461489        /*}}}1*/
    462         /*FUNCTION QuadTree::StorageQuadTreeBox::StorageQuadTreeBox{{{1*/
    463         QuadTree::StorageQuadTreeBox::StorageQuadTreeBox(long ll,StorageQuadTreeBox *nn) {
    464                 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/StorageQuadTreeBox)*/
    465 
    466                 len = ll;
    467                 n = nn;
    468                 b = new QuadTreeBox[ll];
    469                 for (int i = 0; i <ll;i++)
    470                  b[i].n =0,b[i].b[0]=b[i].b[1]=b[i].b[2]=b[i].b[3]=0;
    471                 bc =b;
    472                 be = b +ll;
    473                 if (!b){
    474                         ISSMERROR("!b");
    475                 }
    476         }
    477         /*}}}1*/
    478490        /*FUNCTION QuadTree::ToClose {{{1*/
    479491        BamgVertex*   QuadTree::ToClose(BamgVertex & v,double seuil,Icoor1 hx,Icoor1 hy){
  • issm/trunk/src/c/objects/Bamg/QuadTree.h

    r5150 r5177  
    77namespace bamg {
    88
    9         const int  MaxDeep = 30;
    10         const long MaxISize = ( 1L << MaxDeep);
     9        const int  MaxDeep  = 30;
     10        const long MaxISize = ( 1L << MaxDeep);  // = 2^30 : 010000000000..000 (bitwise operation)
    1111
    1212        class Mesh;
     
    1818
    1919                        class QuadTreeBox{
     20                                /*A quadtree box contains a maximum of 4 vertices. 4 other quadtree boxes are
     21                                 * created if a fifth vertex is added to the same box. A Quadtree box is therefore
     22                                 * composed of EITHER:
     23                                 * - up to 4 vertices
     24                                 * - 4 "sub" quadtree boxes*/
     25
    2026                                public:
    21                                         long n;
    22                                         //contains only one object form the list (either BamgVertex or QuadTreeBox)
    23                                         // if n < 4 => BamgVertex else =>  QuadTreeBox;
     27
     28                                        int n; // number of current vertices in the box
     29
    2430                                        union{
    2531                                                QuadTreeBox* b[4];
    26                                                 BamgVertex* v[4];
     32                                                BamgVertex*  v[4];
    2733                                        };
    2834                        };
     35
    2936                        class StorageQuadTreeBox{
     37
    3038                                public:
     39
     40                                        /*Fields*/
    3141                                        QuadTreeBox *b,*bc,*be;
    3242                                        long len;
    3343                                        StorageQuadTreeBox* n; // next StorageQuadTreeBox
     44
     45                                        /*Methods*/
    3446                                        StorageQuadTreeBox(long ,StorageQuadTreeBox* =NULL);
    3547                                        ~StorageQuadTreeBox() {
     
    3951                                        long  SizeOf() const {return len*sizeof(QuadTreeBox)+sizeof(StorageQuadTreeBox)+ (n?n->SizeOf():0);}
    4052                        };
     53
     54                        /*QuadTree private Fields*/
    4155                        StorageQuadTreeBox* sb;
    4256                        long                lenStorageQuadTreeBox;
     
    4458                public:
    4559
    46                         //fields
     60                        /*QuadTree public Fields*/
    4761                        QuadTreeBox* root;
    48                         Mesh*   th;
     62                        Mesh*        th;
     63                        long         NbQuadTreeBox,NbVertices;
     64                        long         NbQuadTreeBoxSearch,NbVerticesSearch;
    4965
    50                         //functions
    51                         ~QuadTree();
    5266                        QuadTree(Mesh *t,long nbv=-1);
    5367                        QuadTree();
    54                         long    NbQuadTreeBox,NbVertices;
    55                         long    NbQuadTreeBoxSearch,NbVerticesSearch;
     68                        ~QuadTree();
    5669                        BamgVertex* NearestVertex(Icoor1 i,Icoor1 j);
    5770                        BamgVertex* NearestVertexWithNormal(Icoor1 i,Icoor1 j);
     
    6376                         * a private class and is declared before QuadTree::*/
    6477                        QuadTreeBox* NewQuadTreeBox(void){
    65                                 if(! (sb->bc<sb->be)) sb=new StorageQuadTreeBox(lenStorageQuadTreeBox,sb);
    66                                 if (!sb || (sb->bc->n != 0)){ISSMERROR("!sb || (sb->bc->n != 0)");}
     78
     79                                /*if bc==be or bc>be (we have reach the end of the StorageQuadTreeBox)
     80                                 * create a new StorageQuadTreeBox)*/
     81                                if(!(sb->bc<sb->be)){
     82                                        sb=new StorageQuadTreeBox(lenStorageQuadTreeBox,sb);
     83                                }
     84                                ISSMASSERT(sb && sb->bc->n==0);
     85
     86                                /*Increase counter*/
    6787                                NbQuadTreeBox++;
     88
     89                                /*bc now points toward next quadtree box*/
    6890                                return sb->bc++;
     91
    6992                        }
    7093        };
  • issm/trunk/src/mex/Bamg/Bamg.cpp

    r5172 r5177  
    1111
    1212        /*diverse: */
    13         int   i;
    14         int   lines,cols;
    1513        BamgOpts *bamgopts=NULL;
    1614        BamgMesh *bamgmesh_in=NULL;
     
    2624
    2725        /*Initialize variables*/
    28         bamgopts=new BamgOpts;
    29         bamggeom_in=new BamgGeom;
    30         bamgmesh_in=new BamgMesh;
    31         bamggeom_out=new BamgGeom;
    32         bamgmesh_out=new BamgMesh;
     26        bamgopts   = new BamgOpts(BAMGOPTIONS);
     27        bamggeom_in= new BamgGeom(BAMGGEOMETRY);
     28        bamgmesh_in= new BamgMesh(BAMGMESH);
    3329
    34         /*Build objects from matlab structures*/
    35         bamggeom_in->GetMatlabStructureFields(BAMGGEOMETRY);
    36         bamgmesh_in->GetMatlabStructureFields(BAMGMESH);
    37 
    38         /*create bamg options input*/
    39         FetchData(&bamgopts->coeff,mxGetField(BAMGOPTIONS,0,"coeff"));
    40         FetchData(&bamgopts->maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
    41         FetchData(&bamgopts->Crack,mxGetField(BAMGOPTIONS,0,"Crack"));
    42         FetchData(&bamgopts->Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
    43         FetchData(&bamgopts->Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
    44         FetchData(&bamgopts->KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
    45         FetchData(&bamgopts->power,mxGetField(BAMGOPTIONS,0,"power"));
    46         FetchData(&bamgopts->errg,mxGetField(BAMGOPTIONS,0,"errg"));
    47         FetchData(&bamgopts->nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
    48         FetchData(&bamgopts->nbsmooth,mxGetField(BAMGOPTIONS,0,"nbsmooth"));
    49         FetchData(&bamgopts->omega,mxGetField(BAMGOPTIONS,0,"omega"));
    50         FetchData(&bamgopts->maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
    51         FetchData(&bamgopts->hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
    52         FetchData(&bamgopts->hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
    53         FetchData(&bamgopts->anisomax,mxGetField(BAMGOPTIONS,0,"anisomax"));
    54         FetchData(&bamgopts->gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
    55         FetchData(&bamgopts->cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
    56         FetchData(&bamgopts->verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
    57         FetchData(&bamgopts->splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
    58         FetchData(&bamgopts->geometricalmetric,mxGetField(BAMGOPTIONS,0,"geometricalmetric"));
    59         FetchData(&bamgopts->MaxCornerAngle,mxGetField(BAMGOPTIONS,0,"MaxCornerAngle"));
    60         FetchData(&bamgopts->hminVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hminVertices"));
    61         if (bamgopts->hminVertices && (cols!=1 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'hminVertices' should be [%i %i]",bamgmesh_in->VerticesSize[0],1);}
    62         FetchData(&bamgopts->hmaxVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hmaxVertices"));
    63         if (bamgopts->hmaxVertices && (cols!=1 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'hmaxVertices' should be [%i %i]",bamgmesh_in->VerticesSize[0],1);}
    64         FetchData(&bamgopts->metric,&lines,&cols,mxGetField(BAMGOPTIONS,0,"metric"));
    65         if (bamgopts->metric && (cols!=3 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'metric' should be [%i %i]",bamgmesh_in->VerticesSize[0],3);}
    66         FetchData(&bamgopts->field,&lines,&bamgopts->numfields,mxGetField(BAMGOPTIONS,0,"field"));
    67         if (bamgopts->field && lines!=bamgmesh_in->VerticesSize[0]){ISSMERROR("the size of 'field' should be [%i %i]",bamgmesh_in->VerticesSize[0],bamgopts->numfields);}
    68         FetchData(&bamgopts->err,NULL,&cols,mxGetField(BAMGOPTIONS,0,"err"));
    69         if (bamgopts->numfields!=0 && cols!=bamgopts->numfields){ISSMERROR("the size of 'err' should be the same as 'field'");}
    70         bamgopts->Check();
     30        /*Initialize outputs*/
     31        bamggeom_out=new BamgGeom();
     32        bamgmesh_out=new BamgMesh();
    7133
    7234        /*!Generate internal degree of freedom numbers: */
  • issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.cpp

    r5172 r5177  
    6767        bamgmesh->SetMatlabStructureFields(BAMGMESHOUT);
    6868
     69        /*Clean up*/
     70        delete bamggeom;
     71        delete bamgmesh;
     72
    6973        /*end module: */
    7074        MODULEEND();
Note: See TracChangeset for help on using the changeset viewer.