Changeset 22086


Ignore:
Timestamp:
09/15/17 18:50:36 (8 years ago)
Author:
Eric.Larour
Message:

CHG: new bamg code

Location:
issm/branches/trunk-larour-NatGeoScience2016/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-NatGeoScience2016/src/c/modules/Bamgx/Bamgx.cpp

    r21759 r22086  
    149149                }
    150150
    151                 //Add geometry metric if provided
    152                 if(bamgopts->geometricalmetric) BTh.AddGeometryMetric(bamgopts);
    153 
    154151                //Smoothe metric
    155152                BTh.SmoothMetric(bamgopts->gradation);
  • issm/branches/trunk-larour-NatGeoScience2016/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp

    r21759 r22086  
    2424        R2     r;
    2525        I2     I;
    26         int    i,j;
     26        int    i,j,k;
    2727        int    it;
    2828        int    i0,i1,i2;
    2929        double areacoord[3];
    3030        double aa,bb;
    31         Icoor2 dete[3];
     31        long long dete[3];
    3232
    3333        /*Checks*/
     
    6666        }
    6767
     68        /*Create Single vertex to element connectivity*/
     69        int* connectivity = xNew<int>(nods_data);
     70        for(i=0;i<nels_data;i++){
     71                for(j=0;j<3;j++){
     72                        k = index_data[i*3+j]-1;
     73                        _assert_(k>=0 & k<nods_data);
     74                        connectivity[k]=i;
     75                }
     76        }
     77
    6878        /*Loop over output nodes*/
    6979        for(i=0;i<N_interp;i++){
     
    8898
    8999                        /*Area coordinates*/
    90                         areacoord[0]= (double) dete[0]/tb.det;
    91                         areacoord[1]= (double) dete[1]/tb.det;
    92                         areacoord[2]= (double) dete[2]/tb.det;
     100                        areacoord[0]= reCast<double>(dete[0])/reCast<double>(tb.det);
     101                        areacoord[1]= reCast<double>(dete[1])/reCast<double>(tb.det);
     102                        areacoord[2]= reCast<double>(dete[2])/reCast<double>(tb.det);
    93103                        /*3 vertices of the triangle*/
    94104                        i0=Th->GetId(tb[0]);
     
    137147                        /*If we fall outside of the convex or outside of the mesh, return NaN*/
    138148                        if(tb.det<0 || reft[it]<0){
    139                                 for (j=0;j<N_data;j++){
    140                                         data_interp[i*N_data+j]=NAN;
    141                                 }
     149                                _assert_(i0>=0 & i0<nods_data);
     150                                it=connectivity[i0]; //or i1 or i2
     151                                _assert_(it>=0 && it<nels_data);
     152                                for(j=0;j<N_data;j++) data_interp[i*N_data+j]=data[N_data*it+j];
    142153                        }
    143154                        else{
     155                                /*Inside the mesh!*/
    144156                                if(it<0 || it>=nels_data){
    145157                                        _error_("Triangle number " << it << " not in [0 " << nels_data
    146158                                                                << "], report bug to developers (interpolation point: " <<x_interp[i]<<" "<<y_interp[i]<<")");
    147159                                }
    148                                 for (j=0;j<N_data;j++){
    149 
    150                                         data_interp[i*N_data+j]=data[N_data*it+j];
    151                                 }
     160                                for (j=0;j<N_data;j++) data_interp[i*N_data+j]=data[N_data*it+j];
    152161                        }
    153162                }
     
    158167        delete Th;
    159168        xDelete<long>(reft);
     169        xDelete<int>(connectivity);
    160170        *pdata_interp=data_interp;
    161171        return 1;
  • issm/branches/trunk-larour-NatGeoScience2016/src/m/modules/ContourToMesh.m

    r20875 r22086  
    66%       
    77%   index,x,y: mesh triangulation
    8 %   contourname: name of .exp file containing the contours.
     8%   contourname: name of .exp or .shp file containing the contours.
    99%   interptype: string defining type of interpolation ('element', or 'node').
    1010%   edgevalue: integer (0, 1, or 2) defining the value associated to the nodes on the edges of the polygons.
     
    2525end
    2626
     27%Some conversion of files:
     28[path,name,ext]=fileparts(contourname);
     29if strcmpi(ext,'.shp'),
     30        %read contour from shapefile:
     31        contour=shpread(contourname);
     32
     33        %write it to a temporary filename:
     34        contourname=tempname;
     35        expwrite(contour,contourname);
     36end
     37
    2738%Call mex module
    2839[in_nod,in_elem] = ContourToMesh_matlab(index,x,y,contourname,interptype,edgevalue);
  • issm/branches/trunk-larour-NatGeoScience2016/src/m/modules/ContourToNodes.m

    r22038 r22086  
    66%
    77%   x,y: list of nodes
    8 %   contourname: name of .exp file containing the contours, or resulting structure from call to expread
     8%   contourname: name of Argus or Shape file containing the contours, or resulting structure from call to expread
    99%   edgevalue: integer (0, 1 or 2) defining the value associated to the nodes on the edges of the polygons
    1010%   flags: vector of flags (0 or 1), of size nodes
     
    1616end
    1717
    18 %Some conversion of files:
    19 [path,name,ext]=fileparts(contourname);
    20 if strcmpi(ext,'.shp'),
    21         %read contour from shapefile:
    22         contour=shpread(contourname);
     18%Some conversion of files: 
     19if ischar(contourname),
     20        [path,name,ext]=fileparts(contourname);
     21        if strcmpi(ext,'.shp'),
     22                %read contour from shapefile:
     23                contour=shpread(contourname);
    2324
    24         %write it to a temporary filename:
    25         contourname=tempname;
    26         expwrite(contour,contourname);
     25                %write it to a temporary filename:
     26                contourname=tempname;
     27                expwrite(contour,contourname);
     28        end
    2729end
    2830
  • issm/branches/trunk-larour-NatGeoScience2016/src/m/modules/MeshProfileIntersection.m

    r20875 r22086  
    77%          input:
    88%               index,x,y is a triangulation
    9 %               filename: name of Argus style .exp file containing the segments (can be groups of disconnected segments)
     9%               filename: name of Argus or Shape file containing the segments (can be groups of disconnected segments)
    1010%          output:
    1111%               segments: array made of x1,y1,x2,y2,element_id lines (x1,y1) and (x2,y2) are segment extremities for a segment
     
    1919end
    2020
     21[path,name,ext]=fileparts(filename);
     22if strcmpi(ext,'.shp'),
     23       
     24        %convert to expfile and store in a temporary directory:
     25        oldfilename=filename;
     26        filename=[tempname '.exp'];
     27        shp2exp(oldfilename,filename);
     28end
     29
    2130% Call mex module
    2231[segments] = MeshProfileIntersection_matlab(index,x,y,filename);
  • issm/branches/trunk-larour-NatGeoScience2016/src/wrappers/matlab/io/FetchMatlabData.cpp

    r16968 r22086  
    537537        FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation"));
    538538        FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype"));
    539         FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle"));
    540539        FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv"));
    541540        FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv"));
     
    545544        FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega"));
    546545        FetchData(&bamgopts->power,mxGetField(dataref,0,"power"));
    547         FetchData(&bamgopts->random,mxGetField(dataref,0,"random"));
    548546        FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose"));
    549547
    550548        FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack"));
    551         FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric"));
    552549        FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices"));
    553550        FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners"));
     
    999996mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){
    1000997
    1001         //output
    1002         mxArray* mxfield=NULL;
    1003 
    1004         //input
    1005         mxArray    *inputs[2];
    1006         mxArray    *pindex      = NULL;
    1007         const char *fnames[2];
    1008         mwSize      ndim        = 2;
    1009         mwSize      onebyone[2] = {1,1};
    1010 
    1011         //We want to call the subsasgn method, and get the returned array.This ensures that if we are running
    1012         //large sized problems, the data is truly loaded from disk by the model subsasgn class method.
    1013         inputs[0]=(mxArray*)pmxa_array; //this is the model
    1014 
    1015         //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex)
    1016         fnames[0] = "type";
    1017         fnames[1] = "subs";
    1018         pindex=mxCreateStructArray( ndim,onebyone,2,fnames);
    1019         mxSetField( pindex, 0, "type",mxCreateString("."));
    1020         mxSetField( pindex, 0, "subs",mxCreateString(field));
    1021         inputs[1]=pindex;
    1022 
    1023         mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref");
     998        /*Output*/
     999        mxArray *mxfield = NULL;
     1000
     1001        if(mxIsStruct(pmxa_array)){
     1002                mxfield = mxGetField(pmxa_array,number,field);
     1003        }
     1004        else{
     1005                /*This is an object, mxGetField returns NULL in old version of matlab (we do not have access to them)*/
     1006
     1007                /*Intermediaries*/
     1008                mxArray    *inputs[2];
     1009                mwSize      ndim        = 2;
     1010                mwSize      onebyone[2] = {1,1};
     1011
     1012                /*create index structure used in the assignment (index.type='.' and index.subs='x' for field x*/
     1013                const char *fnames[2];
     1014                fnames[0] = "type"; fnames[1] = "subs";
     1015                mxArray* pindex=mxCreateStructArray( ndim,onebyone,2,fnames);
     1016                mxSetField( pindex, 0, "type",mxCreateString("."));
     1017                mxSetField( pindex, 0, "subs",mxCreateString(field));
     1018                inputs[0]=(mxArray*)pmxa_array; //this is the model
     1019                inputs[1]=pindex;
     1020
     1021                mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref");
     1022        }
     1023
     1024        if(mxfield == NULL) _error_("Could not find field "<< field <<" in structure");
    10241025
    10251026        return mxfield;
     
    10911092
    10921093        return(ochar);
    1093 }/*}}}*/
    1094 GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]){ /*{{{*/
    1095 
    1096         int            i;
    1097         char           namei[161];
    1098         Option*                   option      = NULL;
    1099         GenericOption<Options**>  *ostruct    = NULL;
    1100         const mwSize  *ipt        = NULL;
    1101         const mxArray *structi;
    1102         mwIndex        sindex;
    1103 
    1104         /*check and parse the name  */
    1105         ostruct=new GenericOption<Options**>();
    1106         ostruct->name =xNew<char>(strlen(name)+1);
    1107         memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char));
    1108 
    1109         /*check and parse the value  */
    1110         if (!mxIsClass(prhs[0],"struct")){
    1111                 _error_("Value of option \"" << ostruct->name  << "\" must be class \"struct\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
    1112         }
    1113         ostruct->numel=mxGetNumberOfElements(prhs[0]);
    1114         ostruct->ndims=mxGetNumberOfDimensions(prhs[0]);
    1115         ipt           =mxGetDimensions(prhs[0]);
    1116         ostruct->size =xNew<int>(ostruct->ndims);
    1117         for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i];
    1118         if (ostruct->numel) ostruct->value=xNew<Options*>(ostruct->numel);
    1119 
    1120         /*loop through and process each element of the struct array  */
    1121         for (sindex=0; sindex<ostruct->numel; sindex++) {
    1122                 ostruct->value[sindex]=new Options;
    1123 
    1124                 /*loop through and process each field for the element  */
    1125                 for (i=0; i<mxGetNumberOfFields(prhs[0]); i++) {
    1126                         sprintf(namei,"%s.%s",name,mxGetFieldNameByNumber(prhs[0],i));
    1127                         structi=mxGetFieldByNumber(prhs[0],sindex,i);
    1128 
    1129                         option=(Option*)OptionParse(namei,&structi);
    1130                         ostruct->value[sindex]->AddObject((Object*)option);
    1131                         option=NULL;
    1132                 }
    1133         }
    1134 
    1135         return(ostruct);
    1136 }/*}}}*/
    1137 GenericOption<Options*>* OptionCellParse( char* name, const mxArray* prhs[]){ /*{{{*/
    1138 
    1139         int            i;
    1140         int           *dims;
    1141         char           namei[161];
    1142         char           cstr[81];
    1143         GenericOption<Options*> *ocell      = NULL;
    1144         Option        *option     = NULL;
    1145         const mwSize  *ipt        = NULL;
    1146         const mxArray *celli;
    1147         mwIndex        cindex;
    1148 
    1149         /*check and parse the name  */
    1150         ocell=new GenericOption<Options*>();
    1151         ocell->name =xNew<char>(strlen(name)+1);
    1152         memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char));
    1153 
    1154         /*check and parse the value  */
    1155         if (!mxIsClass(prhs[0],"cell")){
    1156                 _error_("Value of option \"" << ocell->name  << "\" must be class \"cell\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
    1157         }
    1158 
    1159         ocell->numel=mxGetNumberOfElements(prhs[0]);
    1160         ocell->ndims=mxGetNumberOfDimensions(prhs[0]);
    1161         ipt         =mxGetDimensions(prhs[0]);
    1162         ocell->size =xNew<int>(ocell->ndims);
    1163         for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i];
    1164         ocell->value=new Options;
    1165 
    1166         /*loop through and process each element of the cell array  */
    1167         dims=xNew<int>(ocell->ndims);
    1168         for (cindex=0; cindex<ocell->numel; cindex++) {
    1169                 ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims);
    1170                 StringFromDims(cstr,dims,ocell->ndims);
    1171                 #ifdef _INTEL_WIN_
    1172                         _snprintf(namei,161,"%s%s",name,cstr);
    1173                 #else
    1174                         snprintf(namei,161,"%s%s",name,cstr);
    1175                 #endif
    1176                 celli=mxGetCell(prhs[0],cindex);
    1177 
    1178                 option=(Option*)OptionParse(namei,&celli);
    1179                 ocell->value->AddObject((Object*)option);
    1180                 option=NULL;
    1181         }
    1182         xDelete<int>(dims);
    1183 
    1184         return(ocell);
    11851094}/*}}}*/
    11861095Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/
     
    11981107        else if(mxIsClass(prhs[0],"char"))
    11991108         option=(Option*)OptionCharParse(name,prhs);
    1200         else if(mxIsClass(prhs[0],"struct"))
    1201          option=(Option*)OptionStructParse(name,prhs);
    1202         else if(mxIsClass(prhs[0],"cell"))
    1203          option=(Option*)OptionCellParse(name,prhs);
    12041109        else {
    1205                 _printf0_("  Converting value of option \"" << name << "\" from unrecognized class \"" << mxGetClassName(prhs[0]) << "\" to class \"" << "struct" << "\".\n");
    1206                 if (!mexCallMATLAB(1,lhs,1,(mxArray**)prhs,"struct")) {
    1207                         option=(Option*)OptionStructParse(name,(const mxArray**)lhs);
    1208                         mxDestroyArray(lhs[0]);
    1209                 }
    1210                 else _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\".");
     1110                _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\".");
    12111111        }
    12121112
Note: See TracChangeset for help on using the changeset viewer.