source: issm/oecreview/Archive/22819-23185/ISSM-23045-23046.diff

Last change on this file was 23186, checked in by Mathieu Morlighem, 7 years ago

CHG: added Archive/22819-23185

File size: 62.9 KB
  • ../trunk-jpl/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp

     
    11/*!\file:  InterpFromGridToMeshx.cpp
    22 * \brief  "c" core code for interpolating values from a structured grid.
    3  */ 
     3 */
    44
    55#ifdef HAVE_CONFIG_H
    66        #include <config.h>
     
    2424        double* y=NULL;
    2525        int     i;
    2626
    27         // TEST
    28         _printf_("\r      N: "<<N<<" M:"<<M<<"\n");
    29 
    3027        /*Some checks on arguments: */
    3128        if ((M<2) || (N<2) || (nods<=0)){
    3229                _error_("nothing to be done according to the dimensions of input matrices and vectors.");
     
    150147                         *    |         |     |
    151148                         *    |         |     |
    152149                         * y1 x---------+-----x Q21
    153                          *    x1                 x2       
     150                         *    x1                 x2
    154151                         *
    155152                         */
    156153                        x1=x[n]; x2=x[n+1];
     
    224221double triangleinterp(double x1,double x2,double y1,double y2,double Q11,double Q12,double Q21,double Q22,double x,double y){
    225222        /*split the rectangle in 2 triangle and
    226223         * use Lagrange P1 interpolation
    227          *       
     224         *
    228225         *   +3----+2,3' Q12----Q22
    229226         *   |    /|     |    /|
    230227         *   |   / |     |   / |
     
    281278        _assert_(x2>x1 && y2>y1);
    282279        _assert_(x<=x2 && x>=x1 && y<=y2 && y>=y1);
    283280
    284         return 
     281        return
    285282          +Q11*(x2-x)*(y2-y)/((x2-x1)*(y2-y1))
    286283          +Q21*(x-x1)*(y2-y)/((x2-x1)*(y2-y1))
    287284          +Q12*(x2-x)*(y-y1)/((x2-x1)*(y2-y1))
     
    300297         *    |        |         |
    301298         *    |        |         |
    302299         * y1 x--------x---------x Q21
    303          *    x1       xm        x2 
     300         *    x1       xm        x2
    304301         *
    305302         */
    306303        /*Checks*/
  • ../trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.js

     
    55 *
    66 * Usage:
    77 *      var data_mesh=InterpFromGridToMesh(xIn,yIn,dataIn,xMeshIn,yMeshIn,defaultValue,interpType);\
    8  * 
     8 *
    99 *      xIn,yIn                                         : coordinates of matrix data. (x and y must be in increasing order)
    1010 *      dataIn                                          : matrix holding the data to be interpolated onto the mesh
    1111 *      xMeshIn,yMeshIn                         : coordinates of the points onto which we interpolate
     
    5050        var y                           = {};
    5151        var yMesh                       = {};
    5252        //}}}
    53        
    5453
     54
    5555        /*
    5656                Dynamic allocations
    5757        */
    5858        //{{{
    59        
     59
    6060        /*
    6161                Input
    6262        */
     
    6767        dxHeap          = new Uint8Array(Module.HEAPU8.buffer, dxPtr, nx);
    6868        dxHeap.set(new Uint8Array(dx.buffer));
    6969        x                       = dxHeap.byteOffset;
    70        
     70
    7171        dy                      = new Float64Array(yIn);
    7272        ny                      = dy.length * dy.BYTES_PER_ELEMENT;
    7373        dyPtr           = Module._malloc(ny);
     
    7474        dyHeap          = new Uint8Array(Module.HEAPU8.buffer, dyPtr, ny);
    7575        dyHeap.set(new Uint8Array(dy.buffer));
    7676        y                       = dyHeap.byteOffset;
    77        
     77
    7878        ddata           = new Float64Array(dataIn);
    7979        ndata           = ddata.length * ddata.BYTES_PER_ELEMENT;
    8080        ddataPtr        = Module._malloc(ndata);
     
    8181        ddataHeap       = new Uint8Array(Module.HEAPU8.buffer, ddataPtr, ndata);
    8282        ddataHeap.set(new Uint8Array(ddata.buffer));
    8383        data            = ddataHeap.byteOffset;
    84        
     84
    8585        dxMesh          = new Float64Array(xMeshIn);
    8686        nxMesh          = dxMesh.length * dxMesh.BYTES_PER_ELEMENT;
    8787        dxMeshPtr       = Module._malloc(nxMesh);
     
    8888        dxMeshHeap      = new Uint8Array(Module.HEAPU8.buffer, dxMeshPtr, nxMesh);
    8989        dxMeshHeap.set(new Uint8Array(dxMesh.buffer));
    9090        xMesh           = dxMeshHeap.byteOffset;
    91        
     91
    9292        dyMesh          = new Float64Array(yMeshIn);
    9393        nyMesh          = dyMesh.length * dyMesh.BYTES_PER_ELEMENT;
    9494        dyMeshPtr       = Module._malloc(nyMesh);
     
    9595        dyMeshHeap      = new Uint8Array(Module.HEAPU8.buffer, dyMeshPtr, nyMesh);
    9696        dyMeshHeap.set(new Uint8Array(dyMesh.buffer));
    9797        yMesh           = dyMeshHeap.byteOffset;
    98        
     98
    9999        nods            = xMeshIn.length;
    100100        meshNumRows     = xMeshIn.length;
    101         console.log('InterpFromGridToMesh.js: meshNumRows => ' + meshNumRows);
    102        
    103        
     101
     102
    104103        /*
    105104                Retrieve interpolation type
    106105        */
     
    111110                interpType = 'bilinear';
    112111        }
    113112        //}}}
    114        
     113
    115114        /*
    116115                Output
    117116        */
    118117        pdataMesh = Module._malloc(4);
    119118        //}}}
    120        
     119
    121120        //}}}
    122        
    123        
     121
     122
    124123        /*
    125124                Declare InterpFromGridToMesh module
    126125        */
    127126        //{{{
    128127        InterpFromGridToMeshModule = Module.cwrap(
    129                 'InterpFromGridToMeshModule', 
    130                 'number', 
     128                'InterpFromGridToMeshModule',
     129                'number',
    131130                [
    132131                        'number', // output : pdataMesh
    133132                        'number', // input      : x
     
    144143                ]
    145144        );
    146145        //}}}
    147        
    148        
     146
     147
    149148        /*
    150149                Call InterpFromGridToMesh module
    151150        */
    152151        //{{{
    153152        InterpFromGridToMeshModule(
    154                 pdataMesh, 
    155                 x, 
    156                 y, 
    157                 data, 
    158                 xMesh, 
    159                 yMesh, 
    160                 defaultValue, 
     153                pdataMesh,
     154                x,
     155                y,
     156                data,
     157                xMesh,
     158                yMesh,
     159                defaultValue,
    161160                nods,
    162161                dataNumRowsIn,
    163162                dataNumColsIn,
     
    165164                interpType
    166165        );
    167166        //}}}
    168        
    169        
     167
     168
    170169        /*
    171170                Dynamic copying from heap
    172171        */
     
    174173        dataMeshPtr     = Module.getValue(pdataMesh, 'i32');
    175174        dataMesh        = Module.HEAPF64.slice(dataMeshPtr / 8, dataMeshPtr / 8 + nods);
    176175        //}}}
    177        
    178        
     176
     177
    179178        /*
    180179                Free resources
    181180        */
     
    182181        //{{{
    183182        Module._free(pdataMesh);
    184183        //}}}
    185        
    186        
     184
     185
    187186        return dataMesh;
    188187}
  • ../trunk-jpl/jenkins/macosx_pine-island

     
    44#-------------------------------#
    55
    66#MATLAB path
    7 MATLAB_PATH="/Applications/MATLAB_R2017b.app/"
     7MATLAB_PATH="/Applications/MATLAB_R2015b.app/"
    88
    9 #ISSM CONFIGURATION 
     9#ISSM CONFIGURATION
    1010ISSM_CONFIG='--prefix=$ISSM_DIR \
    1111        --with-matlab-dir=$MATLAB_PATH \
    1212        --with-triangle-dir=$ISSM_DIR/externalpackages/triangle/install \
     
    5353#as follows: runme($MATLAB_NROPTIONS). The options must be understandable
    5454#by Matlab and runme.m
    5555#ex: "'id',[101 102 103]"
    56 ##                           FS                     
     56##                           FS
    5757PYTHON_NROPTIONS=""
    5858MATLAB_NROPTIONS="'exclude',[701,702,703,435,IdFromString('Dakota')]"
  • ../trunk-jpl/jenkins/macosx_pine-island_static

     
    44#-------------------------------#
    55
    66#MATLAB path
    7 MATLAB_PATH="/Applications/MATLAB_R2017b.app/"
     7MATLAB_PATH="/Applications/MATLAB_R2015b.app/"
    88
    9 #ISSM CONFIGURATION 
     9#ISSM CONFIGURATION
    1010ISSM_CONFIG='--prefix=$ISSM_DIR \
    1111        --disable-static \
    1212        --enable-standalone-executables \
     
    2222        --with-metis-dir=$ISSM_DIR/externalpackages/petsc/install \
    2323        --with-m1qn3-dir=$ISSM_DIR/externalpackages/m1qn3/install \
    2424        --with-math77-dir=$ISSM_DIR/externalpackages/math77/install \
    25         --with-fortran-lib="/usr/local/gfortran/lib/libgfortran.a /usr/local/gfortran/lib/libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0/libgcc.a" \
     25        --with-fortran-lib="/usr/local/gfortran/lib/libgfortran.a /usr/local/gfortran/lib/libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0/libgcc.a" \
    2626        --with-numthreads=4'
    2727
    2828#PYTHON and MATLAB testing
     
    6060#as follows: runme($MATLAB_NROPTIONS). The options must be understandable
    6161#by Matlab and runme.m
    6262#ex: "'id',[101 102 103]"
    63 ##                           bamg mesh   FS                     
     63##                           bamg mesh   FS
    6464#PYTHON_NROPTIONS=""
    6565#MATLAB_NROPTIONS="'exclude',[119,243,514,701,702,703,435,IdFromString('Dakota')]"
  • ../trunk-jpl/src/c/classes/FemModel.cpp

     
    14631463
    14641464        /*Figure out maximum across the cluster: */
    14651465        ISSM_MPI_Reduce(&maxvy,&node_maxvy,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1466         ISSM_MPI_Bcast(&node_maxvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1466        ISSM_MPI_Bcast(&node_maxvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    14671467        maxvy=node_maxvy;
    14681468
    14691469        /*Assign output pointers:*/
     
    14871487
    14881488        /*Figure out maximum across the cluster: */
    14891489        ISSM_MPI_Reduce(&maxvz,&node_maxvz,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1490         ISSM_MPI_Bcast(&node_maxvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1490        ISSM_MPI_Bcast(&node_maxvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    14911491        maxvz=node_maxvz;
    14921492
    14931493        /*Assign output pointers:*/
     
    15111511
    15121512        /*Figure out minimum across the cluster: */
    15131513        ISSM_MPI_Reduce(&minvel,&node_minvel,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1514         ISSM_MPI_Bcast(&node_minvel,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1514        ISSM_MPI_Bcast(&node_minvel,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    15151515        minvel=node_minvel;
    15161516
    15171517        /*Assign output pointers:*/
     
    15351535
    15361536        /*Figure out minimum across the cluster: */
    15371537        ISSM_MPI_Reduce(&minvx,&node_minvx,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1538         ISSM_MPI_Bcast(&node_minvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1538        ISSM_MPI_Bcast(&node_minvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    15391539        minvx=node_minvx;
    15401540
    15411541        /*Assign output pointers:*/
     
    15591559
    15601560        /*Figure out minimum across the cluster: */
    15611561        ISSM_MPI_Reduce(&minvy,&node_minvy,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1562         ISSM_MPI_Bcast(&node_minvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1562        ISSM_MPI_Bcast(&node_minvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    15631563        minvy=node_minvy;
    15641564
    15651565        /*Assign output pointers:*/
     
    15831583
    15841584        /*Figure out minimum across the cluster: */
    15851585        ISSM_MPI_Reduce(&minvz,&node_minvz,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1586         ISSM_MPI_Bcast(&node_minvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1586        ISSM_MPI_Bcast(&node_minvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    15871587        minvz=node_minvz;
    15881588
    15891589        /*Assign output pointers:*/
     
    16281628                        weights_input->GetInputValue(&weight,gauss,OmegaAbsGradientEnum);
    16291629                        omega_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
    16301630
    1631                         /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */ 
     1631                        /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
    16321632                        //J+=weight*1/2*(dp[0]*dp[0]+dp[1]*dp[1])*Jdet*gauss->weight;
    16331633                        J+=weight*1/2*pow(dp[0]*dp[0]+dp[1]*dp[1],2)*Jdet*gauss->weight;
    16341634                }
     
    19641964                                                        else{
    19651965                                                                IssmDouble* values    = xNewZeroInit<IssmDouble>(nlines*ncols);
    19661966                                                                IssmDouble* allvalues = xNew<IssmDouble>(nlines*ncols);
    1967                                                                
     1967
    19681968                                                                /*Fill-in matrix*/
    19691969                                                                for(int j=0;j<elements->Size();j++){
    19701970                                                                        Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(j));
     
    19731973                                                                /*Gather from all cpus*/
    19741974                                                                ISSM_MPI_Allreduce((void*)values,(void*)allvalues,ncols*nlines,ISSM_MPI_PDOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    19751975                                                                xDelete<IssmDouble>(values);
    1976                                                                
     1976
    19771977                                                                if(save_results)results->AddResult(new GenericExternalResult<IssmDouble*>(results->Size()+1,output_enum,allvalues,nlines,ncols,step,time));
    19781978                                                                xDelete<IssmDouble>(allvalues);
    19791979                                                        }
     
    20742074                case MaterialsRheologyBbarEnum:          this->ElementResponsex(responses,MaterialsRheologyBbarEnum); break;
    20752075                case VelEnum:                            this->ElementResponsex(responses,VelEnum); break;
    20762076                case FrictionCoefficientEnum:            NodalValuex(responses, FrictionCoefficientEnum,elements,nodes, vertices, loads, materials, parameters); break;
    2077                 default: 
     2077                default:
    20782078                        if(response_descriptor_enum>=Outputdefinition1Enum && response_descriptor_enum <=Outputdefinition100Enum){
    20792079                                IssmDouble double_result = OutputDefinitionsResponsex(this,response_descriptor_enum);
    20802080                                *responses=double_result;
    20812081                        }
    2082                         else _error_("response descriptor \"" << EnumToStringx(response_descriptor_enum) << "\" not supported yet!"); 
    2083                         break; 
     2082                        else _error_("response descriptor \"" << EnumToStringx(response_descriptor_enum) << "\" not supported yet!");
     2083                        break;
    20842084        }
    20852085
    20862086}
     
    22112211                        weights_input->GetInputValue(&weight,gauss,ThicknessAbsGradientEnum);
    22122212                        thickness_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
    22132213
    2214                         /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */ 
     2214                        /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
    22152215                        J+=weight*1/2*(dp[0]*dp[0]+dp[1]*dp[1])*Jdet*gauss->weight;
    22162216                }
    22172217
     
    24022402        Analysis* analysis= EnumToAnalysis(analysis_type);
    24032403        analysis->UpdateConstraints(this);
    24042404        delete analysis;
    2405        
     2405
    24062406        /*Second, constraints might be time dependent: */
    2407         SpcNodesx(nodes,constraints,parameters,analysis_type); 
     2407        SpcNodesx(nodes,constraints,parameters,analysis_type);
    24082408
    24092409        /*Now, update degrees of freedoms: */
    24102410        NodesDofx(nodes,parameters,analysis_type);
     
    24152415
    24162416        IssmDouble         *surface = NULL;
    24172417        IssmDouble         *bed     = NULL;
    2418                        
     2418
    24192419        if(VerboseSolution()) _printf0_("   updating vertices positions\n");
    24202420
    24212421        /*get vertex vectors for bed and thickness: */
     
    24542454/*}}}*/
    24552455
    24562456/*AMR*/
    2457 #if !defined(_HAVE_ADOLC_) 
     2457#if !defined(_HAVE_ADOLC_)
    24582458void FemModel::ReMesh(void){/*{{{*/
    24592459
    24602460        /*Intermediaries*/
     
    24642464        int *newelementslist            = NULL;
    24652465        int newnumberofvertices = -1;
    24662466        int newnumberofelements = -1;
    2467         bool* my_elements                       = NULL; 
     2467        bool* my_elements                       = NULL;
    24682468        int* my_vertices                        = NULL;
    24692469        int elementswidth       = this->GetElementsWidth();//just tria elements in this version
    24702470        int amrtype,basalforcing_model;
    24712471        bool isgroundingline;
    24722472
    2473         /*Branch to specific amr depending on requested method*/       
     2473        /*Branch to specific amr depending on requested method*/
    24742474        this->parameters->FindParam(&amrtype,AmrTypeEnum);
    24752475        switch(amrtype){
    24762476                #if defined(_HAVE_NEOPZ_) && !defined(_HAVE_ADOLC_)
     
    24832483
    24842484                default: _error_("not implemented yet");
    24852485        }
    2486        
     2486
    24872487        /*Partitioning the new mesh. Maybe ElementsAndVerticesPartitioning.cpp could be modified to set this without iomodel.*/
    24882488        this->ElementsAndVerticesPartitioning(newnumberofvertices,newnumberofelements,elementswidth,newelementslist,&my_elements,&my_vertices);
    24892489
     
    25142514                int analysis_enum = this->analysis_type_list[i];
    25152515
    25162516                /*As the domain is 2D, it is not necessary to create nodes for this analysis*/
    2517                 if(analysis_enum==StressbalanceVerticalAnalysisEnum) continue;   
     2517                if(analysis_enum==StressbalanceVerticalAnalysisEnum) continue;
    25182518
    25192519                this->CreateNodes(newnumberofvertices,my_vertices,nodecounter,analysis_enum,new_nodes);
    25202520                this->CreateConstraints(new_vertices,nodecounter,constraintcounter,analysis_enum,new_constraints);
     
    25442544                analysis_type=this->analysis_type_list[i];
    25452545                //SetCurrentConfiguration(analysis_type);
    25462546
    2547                 this->analysis_counter=i;       
     2547                this->analysis_counter=i;
    25482548                /*Now, plug analysis_counter and analysis_type inside the parameters: */
    25492549                this->parameters->SetParam(this->analysis_counter,AnalysisCounterEnum);
    25502550                this->parameters->SetParam(analysis_type,AnalysisTypeEnum);
     
    25612561                }
    25622562
    25632563                ConfigureObjectsx(new_elements,this->loads,new_nodes,new_vertices,new_materials,this->parameters);
    2564                 if(i==0){ 
     2564                if(i==0){
    25652565                        VerticesDofx(new_vertices,this->parameters); //only call once, we only have one set of vertices
    25662566                }
    25672567                SpcNodesx(new_nodes,new_constraints,this->parameters,analysis_type);
     
    26052605
    26062606        /*Insert bedrock from mismip+ setup*/
    26072607        /*This was used to Misomip project/simulations*/
    2608        
     2608
    26092609        if(VerboseSolution())_printf0_("        call Mismip bedrock adjust module\n");
    26102610
    26112611        IssmDouble x,y,bx,by;
     
    26222622                        bx              = -150.-728.8*pow(x/300000.,2)+343.91*pow(x/300000.,4)-50.57*pow(x/300000.,6);
    26232623                        by              = 500./(1.+exp((-2./4000.)*(y-80000./2.-24000.)))+500./(1.+exp((2./4000.)*(y-80000./2.+24000.)));
    26242624                        r[i]    = max(bx+by,-720.);
    2625                 }       
     2625                }
    26262626                /*insert new bedrock*/
    26272627                element->AddInput(BedEnum,&r[0],P1Enum);
    26282628                /*Cleanup*/
     
    26352635void FemModel::AdjustBaseThicknessAndMask(void){/*{{{*/
    26362636
    26372637        if(VerboseSolution())_printf0_("        call adjust base and thickness module\n");
    2638        
     2638
    26392639        int     numvertices = this->GetElementsWidth();
    26402640   IssmDouble rho_water,rho_ice,density,base_float;
    26412641   IssmDouble* phi     = xNew<IssmDouble>(numvertices);
     
    26472647
    26482648        for(int el=0;el<this->elements->Size();el++){
    26492649                Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(el));
    2650        
     2650
    26512651                element->GetInputListOnVertices(&s[0],SurfaceEnum);
    26522652                element->GetInputListOnVertices(&r[0],BedEnum);
    26532653                element->GetInputListOnVertices(&sl[0],SealevelEnum);
     
    26592659                        /*calculate base floatation (which supports given surface*/
    26602660                        base_float = rho_ice*s[i]/(rho_ice-rho_water);
    26612661                        if(r[i]>base_float){
    2662                                 b[i] = r[i];                   
    2663                         } 
     2662                                b[i] = r[i];
     2663                        }
    26642664                        else {
    2665                                 b[i] = base_float;     
    2666                         } 
     2665                                b[i] = base_float;
     2666                        }
    26672667
    26682668                        if(fabs(sl[i])>0) _error_("Sea level value "<<sl[i]<<" not supported!");
    26692669                        /*update thickness and mask grounded ice level set*/
    26702670                        h[i]      = s[i]-b[i];
    2671                         phi[i]  = h[i]+r[i]/density;   
     2671                        phi[i]  = h[i]+r[i]/density;
    26722672                }
    26732673
    26742674                /*Update inputs*/
     
    26762676                element->AddInput(ThicknessEnum,&h[0],P1Enum);
    26772677                element->AddInput(BaseEnum,&b[0],P1Enum);
    26782678        }
    2679        
     2679
    26802680   /*Delete*/
    26812681   xDelete<IssmDouble>(phi);
    26822682   xDelete<IssmDouble>(h);
     
    27042704        int* P1input_interp                                                             = NULL;
    27052705        Vector<IssmDouble>* input_interpolations        = NULL;
    27062706        IssmDouble* input_interpolations_serial = NULL;
    2707    int* pos                                                                                             = NULL; 
     2707   int* pos                                                                                             = NULL;
    27082708        IssmDouble value                                                                        = 0;
    27092709
    27102710        /*Figure out how many inputs we have and their respective interpolation*/
     
    27242724                        P0input_enums  = xNew<int>(numP0inputs);
    27252725                        P0input_interp = xNew<int>(numP0inputs);
    27262726                        P1input_enums  = xNew<int>(numP1inputs);
    2727                         P1input_interp = xNew<int>(numP1inputs);       
     2727                        P1input_interp = xNew<int>(numP1inputs);
    27282728                }
    27292729                numP0inputs = 0;
    27302730                numP1inputs = 0;
     
    27562756                        }
    27572757                }
    27582758        }
    2759        
    2760         /*Get P0 and P1 inputs over the elements*/     
     2759
     2760        /*Get P0 and P1 inputs over the elements*/
    27612761        pos             = xNew<int>(elementswidth);
    27622762        vP0inputs= new Vector<IssmDouble>(numberofelements*numP0inputs);
    27632763        vP1inputs= new Vector<IssmDouble>(numberofvertices*numP1inputs);
    27642764        for(int i=0;i<this->elements->Size();i++){
    27652765                Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
    2766                
     2766
    27672767                /*Get P0 inputs*/
    27682768                for(int j=0;j<numP0inputs;j++){
    2769                         TriaInput* input=xDynamicCast<TriaInput*>(element->GetInput(P0input_enums[j]));         
     2769                        TriaInput* input=xDynamicCast<TriaInput*>(element->GetInput(P0input_enums[j]));
    27702770                        input->GetInputAverage(&value);
    27712771                        pos[0]=element->Sid()*numP0inputs+j;
    2772                         /*Insert input in the vector*/ 
     2772                        /*Insert input in the vector*/
    27732773                        vP0inputs->SetValues(1,pos,&value,INS_VAL);
    27742774                }
    2775                
     2775
    27762776                /*Get P1 inputs*/
    27772777                for(int j=0;j<numP1inputs;j++){
    27782778                        TriaInput* input=xDynamicCast<TriaInput*>(element->GetInput(P1input_enums[j]));
     
    27792779                        pos[0]=element->vertices[0]->Sid()*numP1inputs+j;
    27802780                        pos[1]=element->vertices[1]->Sid()*numP1inputs+j;
    27812781                        pos[2]=element->vertices[2]->Sid()*numP1inputs+j;
    2782                         /*Insert input in the vector*/ 
    2783                         vP1inputs->SetValues(elementswidth,pos,input->values,INS_VAL); 
     2782                        /*Insert input in the vector*/
     2783                        vP1inputs->SetValues(elementswidth,pos,input->values,INS_VAL);
    27842784                }
    27852785        }
    27862786
     
    27892789        vP1inputs->Assemble();
    27902790        P0inputs=vP0inputs->ToMPISerial();
    27912791        P1inputs=vP1inputs->ToMPISerial();
    2792        
     2792
    27932793        /*Assign pointers*/
    2794         *pnumP0inputs           = numP0inputs; 
    2795         *pP0inputs                      = P0inputs; 
     2794        *pnumP0inputs           = numP0inputs;
     2795        *pP0inputs                      = P0inputs;
    27962796        *pP0input_enums = P0input_enums;
    27972797        *pP0input_interp        = P0input_interp;
    2798         *pnumP1inputs           = numP1inputs; 
    2799         *pP1inputs                      = P1inputs; 
     2798        *pnumP1inputs           = numP1inputs;
     2799        *pP1inputs                      = P1inputs;
    28002800        *pP1input_enums = P1input_enums;
    2801         *pP1input_interp        = P1input_interp;       
     2801        *pP1input_interp        = P1input_interp;
    28022802
    28032803        /*Cleanup*/
    28042804        delete input_interpolations;
     
    28092809}
    28102810/*}}}*/
    28112811void FemModel::InterpolateInputs(Vertices* newfemmodel_vertices,Elements* newfemmodel_elements){/*{{{*/
    2812        
     2812
    28132813        int numberofelements                    = this->elements->NumberOfElements();   //global, entire old mesh
    28142814        int newnumberofelements         = newfemmodel_elements->Size();                 //just on the new partition
    28152815        int numberofvertices                    = this->vertices->NumberOfVertices();   //global, entire old mesh
     
    28252825        IssmDouble* newP1inputs         = NULL; //just on the new partition
    28262826        int* P1input_enums                      = NULL;
    28272827        int* P1input_interp                     = NULL;
    2828         IssmDouble* values                      = NULL; 
     2828        IssmDouble* values                      = NULL;
    28292829   IssmDouble* vector           = NULL;
    28302830        IssmDouble* x                                   = NULL;//global, entire old mesh
    28312831        IssmDouble* y                                   = NULL;//global, entire old mesh
     
    28372837        IssmDouble* newxc                               = NULL;//just on the new partition
    28382838        IssmDouble* newyc                               = NULL;//just on the new partition
    28392839        int* newelementslist                    = NULL;//just on the new partition
    2840         int* sidtoindex                         = NULL;//global vertices sid to partition index 
     2840        int* sidtoindex                         = NULL;//global vertices sid to partition index
    28412841
    28422842        /*Get old P0 and P1  inputs (entire mesh)*/
    28432843        this->GetInputs(&numP0inputs,&P0inputs,&P0input_enums,&P0input_interp,&numP1inputs,&P1inputs,&P1input_enums,&P1input_interp);
     
    28702870                                newx,newy,newnumberofvertices,NULL);
    28712871
    28722872        /*Insert P0 and P1 inputs into the new elements (just on the new partition)*/
    2873         values=xNew<IssmDouble>(elementswidth); 
     2873        values=xNew<IssmDouble>(elementswidth);
    28742874        for(int i=0;i<newfemmodel_elements->Size();i++){//just on the new partition
    28752875                Element* element=xDynamicCast<Element*>(newfemmodel_elements->GetObjectByOffset(i));
    28762876                /*newP0inputs is just on the new partition*/
    28772877                for(int j=0;j<numP0inputs;j++){
    2878                         switch(P0input_interp[j]){     
     2878                        switch(P0input_interp[j]){
    28792879                                case P0Enum:
    28802880                                case DoubleInputEnum:
    28812881                                        element->AddInput(new DoubleInput(P0input_enums[j],newP0inputs[i*numP0inputs+j]));
    28822882                                        break;
    2883                                 case IntInputEnum: 
     2883                                case IntInputEnum:
    28842884                                        element->AddInput(new IntInput(P0input_enums[j],reCast<int>(newP0inputs[i*numP0inputs+j])));
    28852885                                        break;
    28862886                                case BoolInputEnum:
     
    28982898                        element->inputs->AddInput(new TriaInput(P1input_enums[j],values,P1Enum));
    28992899                }
    29002900        }
    2901        
     2901
    29022902        /*Cleanup*/
    29032903        xDelete<IssmDouble>(P0inputs);
    29042904        xDelete<IssmDouble>(newP0inputs);
     
    29372937        int* elementslist               = NULL;
    29382938
    29392939        if(!this->elements || !this->vertices || !this->results || !this->parameters) return;
    2940          
     2940
    29412941        parameters->FindParam(&step,StepEnum);
    29422942        parameters->FindParam(&time,TimeEnum);
    29432943        numberofelements=this->elements->NumberOfElements();
     
    29552955
    29562956        this->results->AddResult(new GenericExternalResult<IssmDouble*>(this->results->Size()+1,MeshYEnum,
    29572957                                        y,numberofvertices,1,step,time));
    2958        
     2958
    29592959        /*Cleanup*/
    29602960        xDelete<IssmDouble>(x);
    29612961        xDelete<IssmDouble>(y);
     
    30163016
    30173017   /*Assemble*/
    30183018        vmasklevelset->Assemble();
    3019        
     3019
    30203020        /*Serialize and set output*/
    30213021        (*pmasklevelset)=vmasklevelset->ToMPISerial();
    30223022
     
    30303030void FemModel::CreateVertices(int newnumberofvertices,int newnumberofelements,int elementswidth,int* newelementslist,int* my_vertices,IssmDouble* newx,IssmDouble* newy,IssmDouble* newz,Vertices* vertices){/*{{{*/
    30313031
    30323032        /*newelementslist is in Matlab indexing*/
    3033        
     3033
    30343034        /*Creating connectivity table*/
    30353035        int* connectivity=NULL;
    30363036        connectivity=xNewZeroInit<int>(newnumberofvertices);
     
    30413041                        _assert_(vertexid>0 && vertexid-1<newnumberofvertices);//Matlab indexing
    30423042                        connectivity[vertexid-1]+=1;//Matlab to C indexing
    30433043                }
    3044         }       
     3044        }
    30453045
    30463046        /*Create vertex and insert in vertices*/
    30473047        for(int i=0;i<newnumberofvertices;i++){
    30483048                if(my_vertices[i]){
    3049                         Vertex *newvertex=new Vertex(); 
     3049                        Vertex *newvertex=new Vertex();
    30503050                        newvertex->id=i+1;
    30513051                        newvertex->sid=i;
    30523052                        newvertex->pid=UNDEF;
     
    30573057                        newvertex->sigma=0.;
    30583058                        newvertex->connectivity=connectivity[i];
    30593059                        newvertex->clone=false;//itapopo check this
    3060                         vertices->AddObject(newvertex); 
    3061                 } 
     3060                        vertices->AddObject(newvertex);
     3061                }
    30623062        }
    30633063
    30643064        xDelete<int>(connectivity);
     
    30853085                                for(int j=0;j<nummodels;j++) newtria->element_type_list[j]=0;
    30863086                        }
    30873087                        else newtria->element_type_list=NULL;
    3088                        
     3088
    30893089                        /*Element hook*/
    30903090                        int matpar_id=newnumberofelements+1; //retrieve material parameter id (last pointer in femodel->materials)
    30913091                        int material_id=i+1; // retrieve material_id = i+1;
    30923092                        /*retrieve vertices ids*/
    30933093                        int* vertex_ids=xNew<int>(elementswidth);
    3094                         for(int j=0;j<elementswidth;j++)        vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j]);//this Hook wants Matlab indexing 
     3094                        for(int j=0;j<elementswidth;j++)        vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j]);//this Hook wants Matlab indexing
    30953095                        /*Setting the hooks*/
    30963096                        newtria->numanalyses =this->nummodels;
    30973097                        newtria->hnodes         =new Hook*[this->nummodels];
     
    31033103                        for(int j=0;j<this->nummodels;j++) newtria->hnodes[j]=NULL;
    31043104                        /*Clean up*/
    31053105                        xDelete<int>(vertex_ids);
    3106                         elements->AddObject(newtria);   
    3107                 } 
     3106                        elements->AddObject(newtria);
     3107                }
    31083108        }
    31093109
    31103110}
     
    31143114        /*Just Matice in this version*/
    31153115        for(int i=0;i<newnumberofelements;i++){
    31163116                if(my_elements[i]){
    3117                         materials->AddObject(new Matice(i+1,i,MaticeEnum));     
    3118                 } 
     3117                        materials->AddObject(new Matice(i+1,i,MaticeEnum));
     3118                }
    31193119        }
    3120        
     3120
    31213121        /*Add new constant material property to materials, at the end: */
    31223122        Matpar *newmatpar=static_cast<Matpar*>(this->materials->GetObjectByOffset(this->materials->Size()-1)->copy());
    31233123        newmatpar->SetMid(newnumberofelements+1);
    3124         materials->AddObject(newmatpar);//put it at the end of the materials       
     3124        materials->AddObject(newmatpar);//put it at the end of the materials
    31253125}
    31263126/*}}}*/
    31273127void FemModel::CreateNodes(int newnumberofvertices,int* my_vertices,int nodecounter,int analysis_enum,Nodes* nodes){/*{{{*/
     
    31283128
    31293129        int lid=0;
    31303130        for(int j=0;j<newnumberofvertices;j++){
    3131                 if(my_vertices[j]){                             
    3132                        
    3133                         Node* newnode=new Node();       
    3134                        
     3131                if(my_vertices[j]){
     3132
     3133                        Node* newnode=new Node();
     3134
    31353135                        /*id: */
    31363136                        newnode->id=nodecounter+j+1;
    31373137                        newnode->sid=j;
    31383138                        newnode->lid=lid++;
    31393139                        newnode->analysis_enum=analysis_enum;
    3140                        
     3140
    31413141                        /*Initialize coord_system: Identity matrix by default*/
    31423142                        for(int k=0;k<3;k++) for(int l=0;l<3;l++) newnode->coord_system[k][l]=0.0;
    31433143                        for(int k=0;k<3;k++) newnode->coord_system[k][k]=1.0;
    3144                        
     3144
    31453145                        /*indexing:*/
    31463146                        newnode->indexingupdate=true;
    3147                        
     3147
    31483148                        Analysis* analysis=EnumToAnalysis(analysis_enum);
    31493149                        int *doftypes=NULL;
    31503150                        int numdofs=analysis->DofsPerNode(&doftypes,Domain2DhorizontalEnum,SSAApproximationEnum);
     
    31583158
    31593159                        /*Stressbalance Horiz*/
    31603160                        if(analysis_enum==StressbalanceAnalysisEnum){
    3161                                 // itapopo this code is rarely used. 
     3161                                // itapopo this code is rarely used.
    31623162                                /*Coordinate system provided, convert to coord_system matrix*/
    31633163                                //XZvectorsToCoordinateSystem(&this->coord_system[0][0],&iomodel->Data(StressbalanceReferentialEnum)[j*6]);
    31643164                                //_assert_(sqrt( coord_system[0][0]*coord_system[0][0] + coord_system[1][0]*coord_system[1][0]) >1.e-4);
     
    31733173
    31743174        if(!femmodel_vertices) _error_("GetMesh: vertices are NULL.");
    31753175        if(!femmodel_elements) _error_("GetMesh: elements are NULL.");
    3176        
     3176
    31773177        int numberofvertices = femmodel_vertices->NumberOfVertices();
    31783178        int numberofelements = femmodel_elements->NumberOfElements();
    31793179        int elementswidth               = this->GetElementsWidth(); // just 2D mesh in this version (just tria elements)
    31803180        IssmDouble* x                   = NULL;
    31813181        IssmDouble* y                   = NULL;
    3182         IssmDouble* z                   = NULL; 
     3182        IssmDouble* z                   = NULL;
    31833183        int* elementslist       = NULL;
    31843184        int* elem_vertices      = NULL;
    31853185        IssmDouble *id1         = NULL;
     
    31883188
    31893189        /*Get vertices coordinates*/
    31903190        VertexCoordinatesx(&x,&y,&z,femmodel_vertices,false) ;
    3191        
     3191
    31923192        /*Get element vertices*/
    31933193        elem_vertices                           = xNew<int>(elementswidth);
    31943194        Vector<IssmDouble>* vid1= new Vector<IssmDouble>(numberofelements);
     
    32033203        vid2->SetValue(element->sid,elem_vertices[1],INS_VAL);
    32043204        vid3->SetValue(element->sid,elem_vertices[2],INS_VAL);
    32053205   }
    3206                
     3206
    32073207        /*Assemble*/
    32083208   vid1->Assemble();
    32093209   vid2->Assemble();
     
    32133213        id1 = vid1->ToMPISerial();
    32143214   id2 = vid2->ToMPISerial();
    32153215        id3 = vid3->ToMPISerial();
    3216        
     3216
    32173217        /*Construct elements list*/
    32183218        elementslist=xNew<int>(numberofelements*elementswidth);
    32193219        if(numberofelements*elementswidth<0) _error_("numberofelements negative.");
     
    32223222                elementslist[elementswidth*i+1] = reCast<int>(id2[i])+1; //InterpMesh wants Matlab indexing
    32233223                elementslist[elementswidth*i+2] = reCast<int>(id3[i])+1; //InterpMesh wants Matlab indexing
    32243224        }
    3225        
     3225
    32263226        /*Assign pointers*/
    32273227        *px                             = x;
    32283228        *py                             = y;
     
    32433243
    32443244        if(!femmodel_vertices) _error_("GetMesh: vertices are NULL.");
    32453245        if(!femmodel_elements) _error_("GetMesh: elements are NULL.");
    3246        
     3246
    32473247        int numberofvertices                    = femmodel_vertices->Size();    //number of vertices of this partition
    32483248        int numbertotalofvertices       = femmodel_vertices->NumberOfVertices();        //number total of vertices (entire mesh)
    32493249        int numberofelements                    = femmodel_elements->Size();  //number of elements of this partition
     
    32503250        int elementswidth                               = this->GetElementsWidth();     //just 2D mesh in this version (just tria elements)
    32513251        IssmDouble* x                                   = NULL;
    32523252        IssmDouble* y                                   = NULL;
    3253         IssmDouble* z                                   = NULL; 
     3253        IssmDouble* z                                   = NULL;
    32543254        int* elementslist                               = NULL;
    32553255        int* sidtoindex                         = NULL;
    32563256        int* elem_vertices                      = NULL;
    3257        
     3257
    32583258        /*Get vertices coordinates of this partition*/
    32593259        sidtoindex      = xNewZeroInit<int>(numbertotalofvertices);//entire mesh, all vertices
    32603260        x                               = xNew<IssmDouble>(numberofvertices);//just this partition
    32613261        y                               = xNew<IssmDouble>(numberofvertices);//just this partitio;
    32623262        z                               = xNew<IssmDouble>(numberofvertices);//just this partitio;
    3263        
     3263
    32643264        /*Go through in this partition (vertices)*/
    32653265        for(int i=0;i<numberofvertices;i++){//just this partition
    3266                 Vertex* vertex=(Vertex*)femmodel_vertices->GetObjectByOffset(i);       
     3266                Vertex* vertex=(Vertex*)femmodel_vertices->GetObjectByOffset(i);
    32673267                /*Attention: no spherical coordinates*/
    32683268                x[i]=vertex->GetX();
    32693269                y[i]=vertex->GetY();
     
    32763276        elem_vertices= xNew<int>(elementswidth);
    32773277        elementslist = xNew<int>(numberofelements*elementswidth);
    32783278        if(numberofelements*elementswidth<0) _error_("numberofelements negative.");
    3279        
     3279
    32803280        for(int i=0;i<numberofelements;i++){//just this partition
    32813281        Element* element=xDynamicCast<Element*>(femmodel_elements->GetObjectByOffset(i));
    32823282        element->GetVerticesSidList(elem_vertices);
     
    32833283                elementslist[elementswidth*i+0] = sidtoindex[elem_vertices[0]]+1; //InterpMesh wants Matlab indexing
    32843284                elementslist[elementswidth*i+1] = sidtoindex[elem_vertices[1]]+1; //InterpMesh wants Matlab indexing
    32853285                elementslist[elementswidth*i+2] = sidtoindex[elem_vertices[2]]+1; //InterpMesh wants Matlab indexing
    3286         }       
    3287                
     3286        }
     3287
    32883288        /*Assign pointers*/
    32893289        *px                             = x;
    32903290        *py                             = y;
    32913291        *pz                             = z;
    32923292        *pelementslist = elementslist; //Matlab indexing. InterMesh uses this type.
    3293         *psidtoindex    = sidtoindex;  //it is ncessary to insert inputs 
     3293        *psidtoindex    = sidtoindex;  //it is ncessary to insert inputs
    32943294
    32953295        /*Cleanup*/
    32963296        xDelete<int>(elem_vertices);
     
    33013301        /*ATTENTION: JUST SPCVX AND SPCVY*/
    33023302        /*OTHERS CONSTRAINTS MUST BE IMPLEMENTED*/
    33033303        if(analysis_enum!=StressbalanceAnalysisEnum) return;
    3304        
     3304
    33053305        int numberofnodes_analysistype= this->nodes->NumberOfNodes(analysis_enum);
    3306         int dofpernode                                          = 2;                                                                                                            //vx and vy 
     3306        int dofpernode                                          = 2;                                                                                                            //vx and vy
    33073307        int numberofcols                                        = dofpernode*2;                                                                         //to keep dofs and flags in the vspc vector
    33083308        int numberofvertices                            = this->vertices->NumberOfVertices();                   //global, entire old mesh
    33093309        int numberofelements                            = this->elements->NumberOfElements();                   //global, entire old mesh
     
    33273327        newx=xNew<IssmDouble>(newnumberofvertices);//just the new partition
    33283328        newy=xNew<IssmDouble>(newnumberofvertices);//just the new partition
    33293329        for(int i=0;i<newnumberofvertices;i++){//just the new partition
    3330                 Vertex* vertex=(Vertex*)newfemmodel_vertices->GetObjectByOffset(i);     
     3330                Vertex* vertex=(Vertex*)newfemmodel_vertices->GetObjectByOffset(i);
    33313331                /*Attention: no spherical coordinates*/
    33323332                newx[i]=vertex->GetX();
    33333333                newy[i]=vertex->GetY();
     
    33353335
    33363336        /*Get spcvx and spcvy of old mesh*/
    33373337        for(int i=0;i<this->constraints->Size();i++){
    3338                
     3338
    33393339                Constraint* constraint=(Constraint*)constraints->GetObjectByOffset(i);
    33403340                if(!constraint->InAnalysis(analysis_enum)) _error_("AMR create constraints for "<<EnumToStringx(analysis_enum)<<" not supported yet!\n");
    33413341
     
    33423342                SpcStatic* spcstatic = xDynamicCast<SpcStatic*>(constraint);
    33433343                int dof                                 = spcstatic->GetDof();
    33443344                int node                                        = spcstatic->GetNodeId();
    3345                 IssmDouble spcvalue     = spcstatic->GetValue(); 
     3345                IssmDouble spcvalue     = spcstatic->GetValue();
    33463346                int nodeindex                   = node-1;
    3347                
     3347
    33483348                /*vx and vx flag insertion*/
    33493349                if(dof==0) {//vx
    33503350                        vspc->SetValue(nodeindex*numberofcols,spcvalue,INS_VAL);    //vx
    33513351                        vspc->SetValue(nodeindex*numberofcols+dofpernode,1,INS_VAL);//vxflag
    3352                 } 
     3352                }
    33533353                /*vy and vy flag insertion*/
    33543354                if(dof==1){//vy
    33553355                        vspc->SetValue(nodeindex*numberofcols+1,spcvalue,INS_VAL);      //vy
     
    33653365        InterpFromMeshToMesh2dx(&newspc,elementslist,x,y,numberofvertices,numberofelements,
    33663366                                                                spc,numberofvertices,numberofcols,
    33673367                                                                newx,newy,newnumberofvertices,NULL);
    3368        
     3368
    33693369        /*Now, insert the interpolated constraints in the data set (constraints)*/
    33703370        count=0;
    33713371        for(int i=0;i<newnumberofvertices;i++){//just in the new partition
     
    33823382                Vertex* vertex=(Vertex*)newfemmodel_vertices->GetObjectByOffset(i);
    33833383                /*spcvy*/
    33843384                if(!xIsNan<IssmDouble>(newspc[i*numberofcols+1]) && newspc[i*numberofcols+dofpernode+1]>(1-eps) ){
    3385                         newfemmodel_constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+vertex->Sid()+1,1,newspc[i*numberofcols+1],analysis_enum)); 
     3385                        newfemmodel_constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+vertex->Sid()+1,1,newspc[i*numberofcols+1],analysis_enum));
    33863386                        //add count'th spc, on node i+1, setting dof 1 to vx.
    33873387                        count++;
    33883388                }
     
    34393439        int numprocs            = IssmComm::GetSize();
    34403440        bool *my_elements = NULL;
    34413441        int *my_vertices  = NULL;
    3442        
    3443         _assert_(newnumberofvertices>0); 
    3444         _assert_(newnumberofelements>0); 
     3442
     3443        _assert_(newnumberofvertices>0);
     3444        _assert_(newnumberofelements>0);
    34453445        epart=xNew<int>(newnumberofelements);
    34463446        npart=xNew<int>(newnumberofvertices);
    34473447   index=xNew<int>(elementswidth*newnumberofelements);
    3448    
     3448
    34493449        for (int i=0;i<newnumberofelements;i++){
    34503450        for (int j=0;j<elementswidth;j++){
    34513451        *(index+elementswidth*i+j)=(*(newelementslist+elementswidth*i+j))-1; //-1 for C indexing in Metis
     
    34653465                for (int i=0;i<newnumberofelements;i++) epart[i]=0;
    34663466                for (int i=0;i<newnumberofvertices;i++) npart[i]=0;
    34673467        }
    3468         else _error_("At least one processor is required");         
     3468        else _error_("At least one processor is required");
    34693469
    34703470        my_vertices=xNew<int>(newnumberofvertices);
    34713471        my_elements=xNew<bool>(newnumberofelements);
     
    34753475        /*Start figuring out, out of the partition, which elements belong to this cpu: */
    34763476        for(int i=0;i<newnumberofelements;i++){
    34773477                /*!All elements have been partitioned above, only deal with elements for this cpu: */
    3478                 if(my_rank==epart[i]){ 
     3478                if(my_rank==epart[i]){
    34793479                        my_elements[i]=true;
    3480                         /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use 
    3481                          *the  element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing) 
    3482                          into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices 
     3480                        /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use
     3481                         *the  element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
     3482                         into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
    34833483                         will hold which vertices belong to this partition*/
    34843484                        for(int j=0;j<elementswidth;j++){
    3485                                 _assert_(newelementslist[elementswidth*i+j]-1<newnumberofvertices);//newelementslist is in Matlab indexing 
     3485                                _assert_(newelementslist[elementswidth*i+j]-1<newnumberofvertices);//newelementslist is in Matlab indexing
    34863486                                my_vertices[newelementslist[elementswidth*i+j]-1]=1;//newelementslist is in Matlab indexing
    34873487                        }
    34883488                }
     
    34943494
    34953495        /*Free ressources:*/
    34963496        xDelete<int>(epart);
    3497         xDelete<int>(npart);       
     3497        xDelete<int>(npart);
    34983498        xDelete<int>(index);
    34993499}
    35003500/*}}}*/
    35013501void FemModel::SmoothedDeviatoricStressTensor(IssmDouble** ptauxx,IssmDouble** ptauyy,IssmDouble** ptauxy){/*{{{*/
    3502        
     3502
    35033503        int elementswidth                                                       = this->GetElementsWidth();//just 2D mesh, tria elements
    35043504   int numberofvertices                                         = this->vertices->NumberOfVertices();
    35053505   IssmDouble weight                                            = 0.;
    3506         IssmDouble*     tauxx                                                   = NULL; 
    3507         IssmDouble*     tauyy                                                   = NULL; 
    3508         IssmDouble*     tauxy                                                   = NULL; 
     3506        IssmDouble*     tauxx                                                   = NULL;
     3507        IssmDouble*     tauyy                                                   = NULL;
     3508        IssmDouble*     tauxy                                                   = NULL;
    35093509   IssmDouble* totalweight                              = NULL;
    35103510        IssmDouble* deviatoricstressxx          = xNew<IssmDouble>(elementswidth);
    35113511   IssmDouble* deviatoricstressyy               = xNew<IssmDouble>(elementswidth);
     
    35153515   Vector<IssmDouble>* vectauyy                 = new Vector<IssmDouble>(numberofvertices);
    35163516   Vector<IssmDouble>* vectauxy                 = new Vector<IssmDouble>(numberofvertices);
    35173517   Vector<IssmDouble>* vectotalweight   = new Vector<IssmDouble>(numberofvertices);
    3518        
     3518
    35193519        /*Update the Deviatoric Stress tensor over the elements*/
    35203520        this->DeviatoricStressx();
    3521        
     3521
    35223522   /*Calculate the Smoothed Deviatoric Stress tensor*/
    35233523        for(int i=0;i<this->elements->Size();i++){
    35243524      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     
    35633563
    35643564        /*Divide for the total weight*/
    35653565        for(int i=0;i<numberofvertices;i++){
    3566                 _assert_(totalweight[i]>0);     
     3566                _assert_(totalweight[i]>0);
    35673567                tauxx[i] = tauxx[i]/totalweight[i];
    35683568                tauyy[i] = tauyy[i]/totalweight[i];
    35693569                tauxy[i] = tauxy[i]/totalweight[i];
     
    35883588/*}}}*/
    35893589void FemModel::ZZErrorEstimator(IssmDouble** pelementerror){/*{{{*/
    35903590
    3591         /*Compute the Zienkiewicz and Zhu (ZZ) error estimator for the deviatoric stress tensor. 
     3591        /*Compute the Zienkiewicz and Zhu (ZZ) error estimator for the deviatoric stress tensor.
    35923592         * Ref.: Zienkiewicz and Zhu, A Simple Error Estimator and Adaptive Procedure for Practical Engineering Analysis, Int. J. Numer. Meth. Eng, 1987*/
    35933593
    35943594        IssmDouble Jdet,error,ftxx,ftyy,ftxy;
     
    36083608
    36093609        /*Get smoothed deviatoric stress tensor*/
    36103610        this->SmoothedDeviatoricStressTensor(&smoothedtauxx,&smoothedtauyy,&smoothedtauxy);
    3611        
     3611
    36123612        /*Integrate the error over elements*/
    36133613   for(int i=0;i<this->elements->Size();i++){
    36143614      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     
    36163616      element->GetInputListOnVertices(tauyy,DeviatoricStressyyEnum);
    36173617      element->GetInputListOnVertices(tauxy,DeviatoricStressxyEnum);
    36183618      element->GetVerticesSidList(elem_vertices);
    3619                
     3619
    36203620                /*Integrate*/
    36213621                element->GetVerticesCoordinates(&xyz_list);
    36223622                Gauss* gauss=element->NewGauss(2);
     
    36313631                                ftyy+=(tauyy[n]-smoothedtauyy[elem_vertices[n]])*basis[n];
    36323632                                ftxy+=(tauxy[n]-smoothedtauxy[elem_vertices[n]])*basis[n];
    36333633                        }
    3634                         error+=Jdet*gauss->weight*( pow(ftxx,2)+pow(ftyy,2)+pow(ftxy,2) ); //e^2 
     3634                        error+=Jdet*gauss->weight*( pow(ftxx,2)+pow(ftyy,2)+pow(ftxy,2) ); //e^2
    36353635                }
    3636                 /*Set the error in the global vector*/ 
     3636                /*Set the error in the global vector*/
    36373637      sid=element->Sid();
    36383638                error = sqrt(error);//sqrt(e^2)
    36393639                velementerror->SetValue(sid,error,INS_VAL);
     
    36473647
    36483648   /*Serialize and set output*/
    36493649   (*pelementerror)=velementerror->ToMPISerial();
    3650        
     3650
    36513651        /*Cleanup*/
    36523652        xDelete<IssmDouble>(smoothedtauxx);
    36533653        xDelete<IssmDouble>(smoothedtauyy);
     
    36913691      /*weight to calculate the smoothed grad H*/
    36923692      Tria* triaelement = xDynamicCast<Tria*>(element);
    36933693      weight            = triaelement->GetArea();//the tria area is a choice for the weight
    3694      
     3694
    36953695                /*dH/dx*/
    36963696      vecdHdx->SetValue(elem_vertices[0],weight*GradH[0],ADD_VAL);
    36973697      vecdHdx->SetValue(elem_vertices[1],weight*GradH[0],ADD_VAL);
     
    37593759
    37603760   /*Get smoothed deviatoric stress tensor*/
    37613761   this->SmoothedGradThickness(&smoothed_dHdx,&smoothed_dHdy);
    3762    
     3762
    37633763        /*Integrate the error over elements*/
    37643764   for(int i=0;i<this->elements->Size();i++){
    37653765      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     
    38453845   Vector<IssmDouble>* vyc              = new Vector<IssmDouble>(numberofelements);
    38463846        IssmDouble* x                                   = NULL;
    38473847        IssmDouble* y                                   = NULL;
    3848         IssmDouble* z                                   = NULL; 
     3848        IssmDouble* z                                   = NULL;
    38493849        IssmDouble* xyz_list                    = NULL;
    38503850        IssmDouble x1,y1,x2,y2,x3,y3;
    38513851
     
    38543854      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
    38553855      //element->GetVerticesSidList(elem_vertices);
    38563856      int sid = element->Sid();
    3857                 element->GetVerticesCoordinates(&xyz_list); 
     3857                element->GetVerticesCoordinates(&xyz_list);
    38583858                x1 = xyz_list[3*0+0];y1 = xyz_list[3*0+1];
    38593859                x2 = xyz_list[3*1+0];y2 = xyz_list[3*1+1];
    38603860                x3 = xyz_list[3*2+0];y3 = xyz_list[3*2+1];
     
    38873887        if(levelset_type!=MaskGroundediceLevelsetEnum && levelset_type!=MaskIceLevelsetEnum){
    38883888                _error_("level set type not implemented yet!");
    38893889        }
    3890        
     3890
    38913891        /*Outputs*/
    38923892        IssmDouble* zerolevelset_points                 = NULL;
    38933893        int npoints                                                                             = 0;
    3894        
     3894
    38953895        /*Intermediaries*/
    38963896        int elementswidth                       = this->GetElementsWidth();
    38973897   int numberofelements                 = this->elements->NumberOfElements();
     
    39043904        IssmDouble* y_zerolevelset                                      = NULL;
    39053905        int count,sid;
    39063906        IssmDouble xc,yc,x1,y1,x2,y2,x3,y3;
    3907        
     3907
    39083908        /*Use the element center coordinate if level set is zero (grounding line or ice front), otherwise set NAN*/
    39093909   for(int i=0;i<this->elements->Size();i++){
    39103910      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     
    39113911      element->GetInputListOnVertices(levelset,levelset_type);
    39123912                element->GetVerticesSidList(elem_vertices);
    39133913                sid= element->Sid();
    3914                 element->GetVerticesCoordinates(&xyz_list); 
     3914                element->GetVerticesCoordinates(&xyz_list);
    39153915                x1 = xyz_list[3*0+0];y1 = xyz_list[3*0+1];
    39163916                x2 = xyz_list[3*1+0];y2 = xyz_list[3*1+1];
    39173917                x3 = xyz_list[3*2+0];y3 = xyz_list[3*2+1];
    39183918                xc      = NAN;
    3919                 yc      = NAN; 
     3919                yc      = NAN;
    39203920        Tria* tria      = xDynamicCast<Tria*>(element);
    39213921                if(tria->IsIceInElement()){/*verify if there is ice in the element*/
    3922                         if(levelset[0]*levelset[1]<0. || levelset[0]*levelset[2]<0. || 
     3922                        if(levelset[0]*levelset[1]<0. || levelset[0]*levelset[2]<0. ||
    39233923                                abs(levelset[0]*levelset[1])<DBL_EPSILON || abs(levelset[0]*levelset[2])<DBL_EPSILON) {
    39243924                                xc=(x1+x2+x3)/3.;
    39253925                                yc=(y1+y2+y3)/3.;
     
    39493949                        count++;
    39503950                }
    39513951        }
    3952        
     3952
    39533953        /*Assign outputs*/
    39543954        numberofpoints                          = npoints;
    39553955        (*pzerolevelset_points) = zerolevelset_points;
     
    39893989        /*save the d_responses pointer: */
    39903990        responses_pointer=d_responses;
    39913991
    3992         //watch out, we have more d_numresponses than numresponsedescriptors, because the responses have been expanded if they were scaled. 
     3992        //watch out, we have more d_numresponses than numresponsedescriptors, because the responses have been expanded if they were scaled.
    39933993        //because we don't know the d_responses descriptors (the scaled ones) we can't key off them, so we will key off the responses_descriptors: */
    39943994
    39953995        for(i=0;i<numresponsedescriptors;i++){
     
    40824082void FemModel::EsaGeodetic2D(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pX, Vector<IssmDouble>* pY, IssmDouble* xx, IssmDouble* yy){/*{{{*/
    40834083
    40844084        int         ns,nsmax;
    4085        
     4085
    40864086        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    40874087        ns = elements->Size();
    4088        
     4088
    40894089        /*Figure out max of ns: */
    40904090        ISSM_MPI_Reduce(&ns,&nsmax,1,ISSM_MPI_INT,ISSM_MPI_MAX,0,IssmComm::GetComm());
    40914091        ISSM_MPI_Bcast(&nsmax,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     
    41044104                        pY->Assemble();
    41054105                }
    41064106        }
    4107        
     4107
    41084108        /*One last time: */
    41094109        pUp->Assemble();
    41104110        pNorth->Assemble();
     
    41234123        IssmDouble  eartharea_cpu=0;
    41244124
    41254125        int         ns,nsmax;
    4126        
     4126
    41274127        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    41284128        ns = elements->Size();
    4129        
    4130         /*First, figure out the surface area of Earth: */ 
     4129
     4130        /*First, figure out the surface area of Earth: */
    41314131        for(int i=0;i<ns;i++){
    41324132                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    41334133                eartharea_cpu += element->GetAreaSpherical();
     
    41514151                        pEast->Assemble();
    41524152                }
    41534153        }
    4154        
     4154
    41554155        /*One last time: */
    41564156        pUp->Assemble();
    41574157        pNorth->Assemble();
     
    42134213                if(i%loop==0)pRSLgi->Assemble();
    42144214        }
    42154215        if(VerboseConvergence())_printf0_("\n");
    4216                
     4216
    42174217        /*One last time: */
    42184218        pRSLgi->Assemble();
    42194219
     
    42314231
    42324232        /*serialized vectors:*/
    42334233        IssmDouble* RSLg_old=NULL;
    4234        
     4234
    42354235        IssmDouble  eartharea=0;
    42364236        IssmDouble  eartharea_cpu=0;
    42374237
    42384238        int         ns,nsmax;
    4239        
     4239
    42404240        /*Serialize vectors from previous iteration:*/
    42414241        RSLg_old=pRSLg_old->ToMPISerial();
    42424242
     
    42484248                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    42494249                eartharea_cpu += element->GetAreaSpherical();
    42504250        }
    4251        
     4251
    42524252        ISSM_MPI_Reduce (&eartharea_cpu,&eartharea,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    42534253        ISSM_MPI_Bcast(&eartharea,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    42544254
     
    42664266                if(i%loop==0)pRSLgo->Assemble();
    42674267        }
    42684268        if(verboseconvolution)if(VerboseConvergence())_printf0_("\n");
    4269        
     4269
    42704270        /*Free ressources:*/
    42714271        xDelete<IssmDouble>(RSLg_old);
    42724272}
     
    43544354
    43554355        /*Free ressources:*/
    43564356        xDelete<IssmDouble>(RSLg_old);
    4357        
    4358        
     4357
     4358
    43594359}
    43604360/*}}}*/
    43614361void FemModel::SealevelriseElastic(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pRSLg, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, IssmDouble* xx, IssmDouble* yy, IssmDouble* zz,int loop,int horiz){/*{{{*/
     
    43624362
    43634363        /*serialized vectors:*/
    43644364        IssmDouble* RSLg=NULL;
    4365        
     4365
    43664366        IssmDouble  eartharea=0;
    43674367        IssmDouble  eartharea_cpu=0;
    43684368
    43694369        int         ns,nsmax;
    4370        
     4370
    43714371        /*Serialize vectors from previous iteration:*/
    43724372        RSLg=pRSLg->ToMPISerial();
    43734373
    43744374        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    43754375        ns = elements->Size();
    4376        
     4376
    43774377        /*First, figure out the area of the ocean, which is needed to compute the eustatic component: */
    43784378        for(int i=0;i<ns;i++){
    43794379                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     
    44014401                        }
    44024402                }
    44034403        }
    4404        
     4404
    44054405        /*One last time: */
    44064406        pUp->Assemble();
    44074407        if(horiz){
     
    44354435        }
    44364436        ISSM_MPI_Reduce (&oceanarea_cpu,&oceanarea,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    44374437        ISSM_MPI_Bcast(&oceanarea,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4438        
     4438
    44394439        ISSM_MPI_Reduce (&oceanvalue_cpu,&oceanvalue,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    44404440        ISSM_MPI_Bcast(&oceanvalue,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    44414441
    44424442        /*Free ressources:*/
    44434443        xDelete<IssmDouble>(RSLg_serial);
    4444        
     4444
    44454445        return oceanvalue/oceanarea;
    44464446}
    44474447/*}}}*/
     
    44574457        IssmDouble*         old_active        = NULL;
    44584458        int*                eplzigzag_counter = NULL;
    44594459        int                 eplflip_lock;
    4460        
     4460
    44614461        HydrologyDCEfficientAnalysis* effanalysis =  new HydrologyDCEfficientAnalysis();
    44624462        HydrologyDCInefficientAnalysis* inefanalysis =  new HydrologyDCInefficientAnalysis();
    44634463
     
    44644464        /*Step 1: update mask, the mask might be extended by residual and/or using downstream sediment head*/
    44654465        mask=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
    44664466        recurence=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
    4467         this->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum); 
    4468         this->parameters->FindParam(&eplflip_lock,HydrologydcEplflipLockEnum); 
     4467        this->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum);
     4468        this->parameters->FindParam(&eplflip_lock,HydrologydcEplflipLockEnum);
    44694469        GetVectorFromInputsx(&old_active,this,HydrologydcMaskEplactiveNodeEnum,NodeSIdEnum);
    4470        
     4470
    44714471        for (int i=0;i<elements->Size();i++){
    44724472                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    44734473                effanalysis->HydrologyEPLGetMask(mask,recurence,eplzigzag_counter,element);
     
    44854485        this->parameters->SetParam(eplzigzag_counter,this->nodes->Size(),EplZigZagCounterEnum);
    44864486        /*Assemble and serialize*/
    44874487        mask->Assemble();
    4488         serial_mask=mask->ToMPISerial();       
    4489        
     4488        serial_mask=mask->ToMPISerial();
     4489
    44904490        xDelete<int>(eplzigzag_counter);
    44914491        xDelete<IssmDouble>(serial_rec);
    44924492        xDelete<IssmDouble>(old_active);
     
    45284528        delete inefanalysis;
    45294529        int sum_counter;
    45304530        ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    4531         ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());               
     4531        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    45324532        counter=sum_counter;
    45334533        *pEplcount = counter;
    45344534        if(VerboseSolution()) _printf0_("   Number of active nodes in EPL layer: "<< counter <<"\n");
     
    46494649        xDelete<IssmDouble>(serial_active);
    46504650        int sum_counter;
    46514651        ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    4652         ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());               
     4652        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    46534653        counter=sum_counter;
    46544654        *pL2count = counter;
    46554655        if(VerboseSolution()) _printf0_("   Number of active nodes L2 Projection: "<< counter <<"\n");
     
    47344734        }
    47354735}
    47364736/*}}}*/
    4737 #ifdef _HAVE_JAVASCRIPT_ 
     4737#ifdef _HAVE_JAVASCRIPT_
    47384738FemModel::FemModel(IssmDouble* buffer, int buffersize, char* toolkits, char* solution, char* modelname,ISSM_MPI_Comm incomm, bool trace){ /*{{{*/
    47394739        /*configuration: */
    47404740        int  solution_type;
     
    47494749
    47504750        /*From command line arguments, retrieve different filenames needed to create the FemModel: */
    47514751        solution_type=StringToEnumx(solution);
    4752        
     4752
    47534753        /*Create femmodel from input files: */
    47544754        profiler->Start(MPROCESSOR);
    47554755        this->InitFromBuffers((char*)buffer,buffersize,toolkits, solution_type,trace,NULL);
    47564756        profiler->Stop(MPROCESSOR);
    4757        
     4757
    47584758        /*Save communicator in the parameters dataset: */
    47594759        this->parameters->AddObject(new GenericParam<ISSM_MPI_Comm>(incomm,FemModelCommEnum));
    47604760
     
    47694769        char** poutputbuffer;
    47704770        size_t* poutputbuffersize;
    47714771
    4772        
     4772
    47734773        /*Before we delete the profiler, report statistics for this run: */
    47744774        profiler->Stop(TOTAL);  //final tagging
    47754775        _printf0_("\n");
     
    47824782                                <<profiler->TotalTimeModSec(TOTAL)<<" sec"
    47834783                                );
    47844784        _printf0_("\n");
    4785        
     4785
    47864786        /*Before we close the output file, recover the buffer and size:*/
    47874787        outputbufferparam = xDynamicCast<GenericParam<char**>*>(this->parameters->FindParamObject(OutputBufferPointerEnum));
    47884788        poutputbuffer=outputbufferparam->GetParameterValue();
     
    48224822        fclose(toolkitsoptionsfid);
    48234823
    48244824        /*Open output file once for all and add output file descriptor to parameters*/
    4825         output_fid=open_memstream(&outputbuffer,&outputsize); 
    4826         if(output_fid==NULL||output_fid==0)_error_("could not initialize output stream");
     4825        output_fid=open_memstream(&outputbuffer,&outputsize);
     4826        if(output_fid==NULL)_error_("could not initialize output stream");
    48274827        this->parameters->SetParam(output_fid,OutputFilePointerEnum);
    48284828        this->parameters->AddObject(new GenericParam<char**>(&outputbuffer,OutputBufferPointerEnum));
    48294829        this->parameters->AddObject(new GenericParam<size_t*>(&outputsize,OutputBufferSizePointerEnum));
     
    48644864                this->amrbamg->thicknesserror_threshold>0||this->amrbamg->deviatoricerror_threshold>0){
    48654865                /*Initialize hmaxvertices with NAN*/
    48664866                hmaxvertices_serial=xNew<IssmDouble>(numberofvertices);
    4867                 for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN; 
     4867                for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN;
    48684868                /*Fill hmaxvertices*/
    48694869                if(this->amrbamg->groundingline_distance>0)             this->GethmaxVerticesFromZeroLevelSetDistance(hmaxvertices_serial,MaskGroundediceLevelsetEnum);
    48704870                if(this->amrbamg->icefront_distance>0)                          this->GethmaxVerticesFromZeroLevelSetDistance(hmaxvertices_serial,MaskIceLevelsetEnum);
     
    48714871                if(this->amrbamg->thicknesserror_threshold>0)   this->GethmaxVerticesFromEstimators(hmaxvertices_serial,ThicknessErrorEstimatorEnum);
    48724872                if(this->amrbamg->deviatoricerror_threshold>0)  this->GethmaxVerticesFromEstimators(hmaxvertices_serial,DeviatoricStressErrorEstimatorEnum);
    48734873        }
    4874        
     4874
    48754875        if(my_rank==0){
    48764876                this->amrbamg->ExecuteRefinementBamg(vector_serial,hmaxvertices_serial,&newnumberofvertices,&newnumberofelements,&newx,&newy,&newz,&newelementslist);
    48774877                if(newnumberofvertices<=0 || newnumberofelements<=0) _error_("Error in the refinement process.");
     
    48914891                newz=xNew<IssmDouble>(newnumberofvertices);
    48924892                newelementslist=xNew<int>(newnumberofelements*this->GetElementsWidth());
    48934893        }
    4894         ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    4895         ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    4896         ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    4897         ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());       
     4894        ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     4895        ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     4896        ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     4897        ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());
    48984898
    48994899        /*Assign output pointers*/
    49004900        *pnewnumberofvertices = newnumberofvertices;
     
    49274927
    49284928        /*Create bamg data structures for bamg*/
    49294929        this->amrbamg = new AmrBamg();
    4930        
     4930
    49314931        /*Get amr parameters*/
    49324932        this->parameters->FindParam(&hmin,AmrHminEnum);
    49334933        this->parameters->FindParam(&hmax,AmrHmaxEnum);
     
    49514951        this->amrbamg->SetBamgOpts(hmin,hmax,err,gradation);
    49524952
    49534953        /*Re-create original mesh and put it in bamg structure (only cpu 0)*/
    4954         if(my_rank==0){ 
     4954        if(my_rank==0){
    49554955                this->amrbamg->Initialize(elements,x,y,numberofvertices,numberofelements);
    49564956        }
    49574957
     
    49654965void FemModel::GethmaxVerticesFromZeroLevelSetDistance(IssmDouble* hmaxvertices,int levelset_type){/*{{{*/
    49664966
    49674967        if(!hmaxvertices) _error_("hmaxvertices is NULL!\n");
    4968        
     4968
    49694969        /*Intermediaries*/
    49704970        int numberofvertices                     = this->vertices->NumberOfVertices();
    49714971        IssmDouble* verticedistance = NULL;
     
    49724972        IssmDouble threshold,resolution;
    49734973
    49744974        switch(levelset_type){
    4975                 case MaskGroundediceLevelsetEnum: 
     4975                case MaskGroundediceLevelsetEnum:
    49764976                        threshold       = this->amrbamg->groundingline_distance;
    49774977                        resolution      = this->amrbamg->groundingline_resolution;
    49784978                        break;
     
    49864986        /*Get vertice distance to zero level set points*/
    49874987        this->GetVerticeDistanceToZeroLevelSet(&verticedistance,levelset_type);
    49884988        if(!verticedistance) _error_("verticedistance is NULL!\n");
    4989        
     4989
    49904990        /*Fill hmaxVertices*/
    49914991        for(int i=0;i<numberofvertices;i++){
    49924992                if(verticedistance[i]<threshold){
     
    50005000}
    50015001/*}}}*/
    50025002void FemModel::GethmaxVerticesFromEstimators(IssmDouble* hmaxvertices,int errorestimator_type){/*{{{*/
    5003    
     5003
    50045004        if(!hmaxvertices) _error_("hmaxvertices is NULL!\n");
    50055005
    50065006        /*Intermediaries*/
     
    50085008        int numberofelements                                            = this->elements->NumberOfElements();
    50095009        int numberofvertices                                            = this->vertices->NumberOfVertices();
    50105010        IssmDouble* maxlength                                   = xNew<IssmDouble>(numberofelements);
    5011         IssmDouble* error_vertices                              = xNewZeroInit<IssmDouble>(numberofvertices);   
     5011        IssmDouble* error_vertices                              = xNewZeroInit<IssmDouble>(numberofvertices);
    50125012        IssmDouble* error_elements                              = NULL;
    50135013        IssmDouble* x                                                           = NULL;
    50145014        IssmDouble* y                                                           = NULL;
     
    50215021
    50225022        /*Fill variables*/
    50235023        switch(errorestimator_type){
    5024                 case ThicknessErrorEstimatorEnum: 
     5024                case ThicknessErrorEstimatorEnum:
    50255025                        threshold               = this->amrbamg->thicknesserror_threshold;
    50265026                        groupthreshold  = this->amrbamg->thicknesserror_groupthreshold;
    50275027                        resolution              = this->amrbamg->thicknesserror_resolution;
     
    50465046                switch(errorestimator_type){
    50475047        case ThicknessErrorEstimatorEnum:                       this->amrbamg->thicknesserror_maximum   = maxerror;break;
    50485048        case DeviatoricStressErrorEstimatorEnum:        this->amrbamg->deviatoricerror_maximum = maxerror;break;
    5049         }       
     5049        }
    50505050        }
    50515051
    50525052        /*Get mesh*/
    50535053        this->GetMesh(this->vertices,this->elements,&x,&y,&z,&index);
    5054        
     5054
    50555055        /*Fill error_vertices (this is the sum of all elements connected to the vertex)*/
    50565056        for(int i=0;i<numberofelements;i++){
    50575057                v1=index[i*elementswidth+0]-1;//Matlab to C indexing
     
    50655065                error_vertices[v1]+=error_elements[i];
    50665066                error_vertices[v2]+=error_elements[i];
    50675067                error_vertices[v3]+=error_elements[i];
    5068         }       
     5068        }
    50695069
    50705070        /*Fill hmaxvertices with the criteria*/
    50715071        for(int i=0;i<numberofelements;i++){
     
    50795079                                if(error_vertices[vid]>groupthreshold*maxerror) refine=true;
    50805080                        }
    50815081                }
    5082                 /*Now, fill the hmaxvertices if requested*/       
     5082                /*Now, fill the hmaxvertices if requested*/
    50835083                if(refine){
    50845084                        for(int j=0;j<elementswidth;j++){
    50855085                                vid=index[i*elementswidth+j]-1;//Matlab to C indexing
     
    51095109
    51105110        /*Output*/
    51115111        IssmDouble* verticedistance;
    5112        
     5112
    51135113        /*Intermediaries*/
    51145114   int numberofvertices       = this->vertices->NumberOfVertices();
    51155115   IssmDouble* levelset_points= NULL;
     
    51215121
    51225122        /*Get vertices coordinates*/
    51235123        VertexCoordinatesx(&x,&y,&z,this->vertices,false) ;
    5124        
    5125         /*Get points which level set is zero (center of elements with zero level set)*/ 
     5124
     5125        /*Get points which level set is zero (center of elements with zero level set)*/
    51265126        this->GetZeroLevelSetPoints(&levelset_points,numberofpoints,levelset_type);
    51275127
    51285128        /*Find the minimal vertice distance to the zero levelset (grounding line or ice front)*/
     
    51315131                verticedistance[i]=INFINITY;
    51325132                for(int j=0;j<numberofpoints;j++){
    51335133                        distance=sqrt((x[i]-levelset_points[2*j])*(x[i]-levelset_points[2*j])+(y[i]-levelset_points[2*j+1])*(y[i]-levelset_points[2*j+1]));
    5134                         verticedistance[i]=min(distance,verticedistance[i]);           
     5134                        verticedistance[i]=min(distance,verticedistance[i]);
    51355135                }
    5136         }       
     5136        }
    51375137
    51385138        /*Assign the pointer*/
    51395139        (*pverticedistance)=verticedistance;
     
    51675167        /*Get fields, if requested*/
    51685168        if(this->amr->groundingline_distance>0)         this->GetElementDistanceToZeroLevelSet(&gl_distance,MaskGroundediceLevelsetEnum);
    51695169   if(this->amr->icefront_distance>0)                           this->GetElementDistanceToZeroLevelSet(&if_distance,MaskIceLevelsetEnum);
    5170    if(this->amr->thicknesserror_threshold>0)            this->ThicknessZZErrorEstimator(&thicknesserror);       
    5171         if(this->amr->deviatoricerror_threshold>0)      this->ZZErrorEstimator(&deviatoricerror);       
    5172        
     5170   if(this->amr->thicknesserror_threshold>0)            this->ThicknessZZErrorEstimator(&thicknesserror);
     5171        if(this->amr->deviatoricerror_threshold>0)      this->ZZErrorEstimator(&deviatoricerror);
     5172
    51735173        if(my_rank==0){
    51745174                this->amr->ExecuteRefinement(gl_distance,if_distance,deviatoricerror,thicknesserror,
    5175                                                                                                 &newnumberofvertices,&newnumberofelements,&newx,&newy,&newelementslist); 
     5175                                                                                                &newnumberofvertices,&newnumberofelements,&newx,&newy,&newelementslist);
    51765176                newz=xNewZeroInit<IssmDouble>(newnumberofvertices);
    51775177                if(newnumberofvertices<=0 || newnumberofelements<=0) _error_("Error in the ReMeshNeopz.");
    51785178        }
     
    51865186                newz=xNew<IssmDouble>(newnumberofvertices);
    51875187                newelementslist=xNew<int>(newnumberofelements*this->GetElementsWidth());
    51885188        }
    5189         ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    5190         ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    5191         ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    5192         ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());       
     5189        ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     5190        ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     5191        ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     5192        ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());
    51935193
    5194         /*Assign the pointers*/ 
     5194        /*Assign the pointers*/
    51955195        (*pnewelementslist)     = newelementslist; //Matlab indexing
    51965196        (*pnewx)                                        = newx;
    51975197        (*pnewy)                                        = newy;
     
    52075207}
    52085208/*}}}*/
    52095209void FemModel::InitializeAdaptiveRefinementNeopz(void){/*{{{*/
    5210        
     5210
    52115211        /*Define variables*/
    52125212        int my_rank                                                                             = IssmComm::GetRank();
    52135213        int numberofvertices                                                    = this->vertices->NumberOfVertices();
     
    52165216        IssmDouble* y                                                                   = NULL;
    52175217        IssmDouble* z                                                                   = NULL;
    52185218        int* elements                                                                   = NULL;
    5219        
     5219
    52205220        /*Initialize field as NULL for now*/
    52215221        this->amr = NULL;
    52225222
     
    52245224        /*elements comes in Matlab indexing*/
    52255225        this->GetMesh(this->vertices,this->elements,&x,&y,&z,&elements);
    52265226
    5227         /*Create initial mesh (coarse mesh) in neopz data structure*/ 
     5227        /*Create initial mesh (coarse mesh) in neopz data structure*/
    52285228        /*Just CPU #0 should keep AMR object*/
    52295229   /*Initialize refinement pattern*/
    52305230        this->SetRefPatterns();
    52315231        this->amr = new AdaptiveMeshRefinement();
    5232         this->amr->refinement_type=1;//1 is refpattern; 0 is uniform (faster) 
     5232        this->amr->refinement_type=1;//1 is refpattern; 0 is uniform (faster)
    52335233        /*Get amr parameters*/
    52345234        this->parameters->FindParam(&this->amr->level_max,AmrLevelMaxEnum);
    52355235        this->parameters->FindParam(&this->amr->gradation,AmrGradationEnum);
     
    52425242        this->parameters->FindParam(&this->amr->deviatoricerror_threshold,AmrDeviatoricErrorThresholdEnum);
    52435243        this->parameters->FindParam(&this->amr->deviatoricerror_groupthreshold,AmrDeviatoricErrorGroupThresholdEnum);
    52445244        this->parameters->FindParam(&this->amr->deviatoricerror_maximum,AmrDeviatoricErrorMaximumEnum);
    5245         if(my_rank==0){ 
     5245        if(my_rank==0){
    52465246                this->amr->CreateInitialMesh(numberofvertices,numberofelements,x,y,elements);
    52475247        }
    52485248
     
    52635263
    52645264        /*Output*/
    52655265        IssmDouble* elementdistance;
    5266        
     5266
    52675267        /*Intermediaries*/
    52685268   int numberofelements                                                 = this->elements->NumberOfElements();
    52695269   Vector<IssmDouble>* velementdistance = new Vector<IssmDouble>(numberofelements);
     
    52725272        IssmDouble mindistance,distance;
    52735273        IssmDouble xc,yc,x1,y1,x2,y2,x3,y3;
    52745274        int numberofpoints;
    5275        
    5276         /*Get points which level set is zero (center of elements with zero level set, levelset_points is serial)*/     
     5275
     5276        /*Get points which level set is zero (center of elements with zero level set, levelset_points is serial)*/
    52775277        this->GetZeroLevelSetPoints(&levelset_points,numberofpoints,levelset_type);
    52785278
    52795279        for(int i=0;i<this->elements->Size();i++){//parallel
    52805280      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
    52815281      int sid = element->Sid();
    5282                 element->GetVerticesCoordinates(&xyz_list); 
     5282                element->GetVerticesCoordinates(&xyz_list);
    52835283                x1 = xyz_list[3*0+0];y1 = xyz_list[3*0+1];
    52845284                x2 = xyz_list[3*1+0];y2 = xyz_list[3*1+1];
    52855285                x3 = xyz_list[3*2+0];y3 = xyz_list[3*2+1];
     
    52895289                /*Loop over each point (where level set is zero)*/
    52905290                for(int j=0;j<numberofpoints;j++){
    52915291                        distance =sqrt((xc-levelset_points[2*j])*(xc-levelset_points[2*j])+(yc-levelset_points[2*j+1])*(yc-levelset_points[2*j+1]));
    5292                         mindistance=min(distance,mindistance);         
     5292                        mindistance=min(distance,mindistance);
    52935293                }
    52945294                velementdistance->SetValue(sid,mindistance,INS_VAL);
    52955295                xDelete<IssmDouble>(xyz_list);
    5296         }       
     5296        }
    52975297
    52985298   /*Assemble*/
    52995299   velementdistance->Assemble();
Note: See TracBrowser for help on using the repository browser.