Ignore:
Timestamp:
07/16/18 15:39:26 (7 years ago)
Author:
Eric.Larour
Message:

CHG: new reorganization of the slr capabilities.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r22902 r22955  
    14541454        /*Figure out maximum across the cluster: */
    14551455        ISSM_MPI_Reduce(&maxvy,&node_maxvy,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1456         ISSM_MPI_Bcast(&node_maxvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     1456        ISSM_MPI_Bcast(&node_maxvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
    14571457        maxvy=node_maxvy;
    14581458
     
    14781478        /*Figure out maximum across the cluster: */
    14791479        ISSM_MPI_Reduce(&maxvz,&node_maxvz,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1480         ISSM_MPI_Bcast(&node_maxvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     1480        ISSM_MPI_Bcast(&node_maxvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
    14811481        maxvz=node_maxvz;
    14821482
     
    15021502        /*Figure out minimum across the cluster: */
    15031503        ISSM_MPI_Reduce(&minvel,&node_minvel,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1504         ISSM_MPI_Bcast(&node_minvel,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     1504        ISSM_MPI_Bcast(&node_minvel,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
    15051505        minvel=node_minvel;
    15061506
     
    15261526        /*Figure out minimum across the cluster: */
    15271527        ISSM_MPI_Reduce(&minvx,&node_minvx,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1528         ISSM_MPI_Bcast(&node_minvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     1528        ISSM_MPI_Bcast(&node_minvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
    15291529        minvx=node_minvx;
    15301530
     
    15501550        /*Figure out minimum across the cluster: */
    15511551        ISSM_MPI_Reduce(&minvy,&node_minvy,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1552         ISSM_MPI_Bcast(&node_minvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     1552        ISSM_MPI_Bcast(&node_minvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
    15531553        minvy=node_minvy;
    15541554
     
    15741574        /*Figure out minimum across the cluster: */
    15751575        ISSM_MPI_Reduce(&minvz,&node_minvz,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1576         ISSM_MPI_Bcast(&node_minvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     1576        ISSM_MPI_Bcast(&node_minvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
    15771577        minvz=node_minvz;
    15781578
     
    16191619                        omega_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
    16201620
    1621                         /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
     1621                        /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */ 
    16221622                        //J+=weight*1/2*(dp[0]*dp[0]+dp[1]*dp[1])*Jdet*gauss->weight;
    16231623                        J+=weight*1/2*pow(dp[0]*dp[0]+dp[1]*dp[1],2)*Jdet*gauss->weight;
     
    19551955                                                                IssmDouble* values    = xNewZeroInit<IssmDouble>(nlines*ncols);
    19561956                                                                IssmDouble* allvalues = xNew<IssmDouble>(nlines*ncols);
    1957 
     1957                                                               
    19581958                                                                /*Fill-in matrix*/
    19591959                                                                for(int j=0;j<elements->Size();j++){
     
    19641964                                                                ISSM_MPI_Allreduce((void*)values,(void*)allvalues,ncols*nlines,ISSM_MPI_PDOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    19651965                                                                xDelete<IssmDouble>(values);
    1966 
     1966                                                               
    19671967                                                                if(save_results)results->AddResult(new GenericExternalResult<IssmDouble*>(results->Size()+1,output_enum,allvalues,nlines,ncols,step,time));
    19681968                                                                xDelete<IssmDouble>(allvalues);
     
    20122012        int domaintype;
    20132013        this->parameters->FindParam(&domaintype,DomainTypeEnum);
    2014 
     2014       
    20152015        /*1: go throug all elements of this partition and figure out how many
    20162016         * segments we have (corresopnding to levelset = 0)*/
     
    21322132                case VelEnum:                            this->ElementResponsex(responses,VelEnum); break;
    21332133                case FrictionCoefficientEnum:            NodalValuex(responses, FrictionCoefficientEnum,elements,nodes, vertices, loads, materials, parameters); break;
    2134                 default:
     2134                default: 
    21352135                        if(response_descriptor_enum>=Outputdefinition1Enum && response_descriptor_enum <=Outputdefinition100Enum){
    21362136                                IssmDouble double_result = OutputDefinitionsResponsex(this,response_descriptor_enum);
    21372137                                *responses=double_result;
    21382138                        }
    2139                         else _error_("response descriptor \"" << EnumToStringx(response_descriptor_enum) << "\" not supported yet!");
    2140                         break;
     2139                        else _error_("response descriptor \"" << EnumToStringx(response_descriptor_enum) << "\" not supported yet!"); 
     2140                        break; 
    21412141        }
    21422142
     
    22692269                        thickness_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
    22702270
    2271                         /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
     2271                        /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */ 
    22722272                        J+=weight*1/2*(dp[0]*dp[0]+dp[1]*dp[1])*Jdet*gauss->weight;
    22732273                }
     
    24602460        analysis->UpdateConstraints(this);
    24612461        delete analysis;
    2462 
     2462       
    24632463        /*Second, constraints might be time dependent: */
    2464         SpcNodesx(nodes,constraints,parameters,analysis_type);
     2464        SpcNodesx(nodes,constraints,parameters,analysis_type); 
    24652465
    24662466        /*Now, update degrees of freedoms: */
     
    24732473        IssmDouble         *surface = NULL;
    24742474        IssmDouble         *bed     = NULL;
    2475 
     2475                       
    24762476        if(VerboseSolution()) _printf0_("   updating vertices positions\n");
    24772477
     
    25122512
    25132513/*AMR*/
    2514 #if !defined(_HAVE_ADOLC_)
     2514#if !defined(_HAVE_ADOLC_) 
    25152515void FemModel::ReMesh(void){/*{{{*/
    25162516
     
    25222522        int newnumberofvertices = -1;
    25232523        int newnumberofelements = -1;
    2524         bool* my_elements                       = NULL;
     2524        bool* my_elements                       = NULL; 
    25252525        int* my_vertices                        = NULL;
    25262526        int elementswidth       = this->GetElementsWidth();//just tria elements in this version
     
    25282528        bool isgroundingline;
    25292529
    2530         /*Branch to specific amr depending on requested method*/
     2530        /*Branch to specific amr depending on requested method*/       
    25312531        this->parameters->FindParam(&amrtype,AmrTypeEnum);
    25322532        switch(amrtype){
     
    25412541                default: _error_("not implemented yet");
    25422542        }
    2543 
     2543       
    25442544        /*Partitioning the new mesh. Maybe ElementsAndVerticesPartitioning.cpp could be modified to set this without iomodel.*/
    25452545        this->ElementsAndVerticesPartitioning(newnumberofvertices,newnumberofelements,elementswidth,newelementslist,&my_elements,&my_vertices);
     
    25722572
    25732573                /*As the domain is 2D, it is not necessary to create nodes for this analysis*/
    2574                 if(analysis_enum==StressbalanceVerticalAnalysisEnum) continue;
     2574                if(analysis_enum==StressbalanceVerticalAnalysisEnum) continue;   
    25752575
    25762576                this->CreateNodes(newnumberofvertices,my_vertices,nodecounter,analysis_enum,new_nodes);
     
    26022602                //SetCurrentConfiguration(analysis_type);
    26032603
    2604                 this->analysis_counter=i;
     2604                this->analysis_counter=i;       
    26052605                /*Now, plug analysis_counter and analysis_type inside the parameters: */
    26062606                this->parameters->SetParam(this->analysis_counter,AnalysisCounterEnum);
     
    26192619
    26202620                ConfigureObjectsx(new_elements,this->loads,new_nodes,new_vertices,new_materials,this->parameters);
    2621                 if(i==0){
     2621                if(i==0){ 
    26222622                        VerticesDofx(new_vertices,this->parameters); //only call once, we only have one set of vertices
    26232623                }
     
    26632663        /*Insert bedrock from mismip+ setup*/
    26642664        /*This was used to Misomip project/simulations*/
    2665 
     2665       
    26662666        if(VerboseSolution())_printf0_("        call Mismip bedrock adjust module\n");
    26672667
     
    26802680                        by              = 500./(1.+exp((-2./4000.)*(y-80000./2.-24000.)))+500./(1.+exp((2./4000.)*(y-80000./2.+24000.)));
    26812681                        r[i]    = max(bx+by,-720.);
    2682                 }
     2682                }       
    26832683                /*insert new bedrock*/
    26842684                element->AddInput(BedEnum,&r[0],P1Enum);
     
    26932693
    26942694        if(VerboseSolution())_printf0_("        call adjust base and thickness module\n");
    2695 
     2695       
    26962696        int     numvertices = this->GetElementsWidth();
    26972697   IssmDouble rho_water,rho_ice,density,base_float;
     
    27052705        for(int el=0;el<this->elements->Size();el++){
    27062706                Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(el));
    2707 
     2707       
    27082708                element->GetInputListOnVertices(&s[0],SurfaceEnum);
    27092709                element->GetInputListOnVertices(&r[0],BedEnum);
     
    27172717                        base_float = rho_ice*s[i]/(rho_ice-rho_water);
    27182718                        if(r[i]>base_float){
    2719                                 b[i] = r[i];
    2720                         }
     2719                                b[i] = r[i];                   
     2720                        } 
    27212721                        else {
    2722                                 b[i] = base_float;
    2723                         }
     2722                                b[i] = base_float;     
     2723                        } 
    27242724
    27252725                        if(fabs(sl[i])>0) _error_("Sea level value "<<sl[i]<<" not supported!");
    27262726                        /*update thickness and mask grounded ice level set*/
    27272727                        h[i]      = s[i]-b[i];
    2728                         phi[i]  = h[i]+r[i]/density;
     2728                        phi[i]  = h[i]+r[i]/density;   
    27292729                }
    27302730
     
    27342734                element->AddInput(BaseEnum,&b[0],P1Enum);
    27352735        }
    2736 
     2736       
    27372737   /*Delete*/
    27382738   xDelete<IssmDouble>(phi);
     
    27622762        Vector<IssmDouble>* input_interpolations        = NULL;
    27632763        IssmDouble* input_interpolations_serial = NULL;
    2764    int* pos                                                                                             = NULL;
     2764   int* pos                                                                                             = NULL; 
    27652765        IssmDouble value                                                                        = 0;
    27662766
     
    27822782                        P0input_interp = xNew<int>(numP0inputs);
    27832783                        P1input_enums  = xNew<int>(numP1inputs);
    2784                         P1input_interp = xNew<int>(numP1inputs);
     2784                        P1input_interp = xNew<int>(numP1inputs);       
    27852785                }
    27862786                numP0inputs = 0;
     
    28142814                }
    28152815        }
    2816 
    2817         /*Get P0 and P1 inputs over the elements*/
     2816       
     2817        /*Get P0 and P1 inputs over the elements*/     
    28182818        pos             = xNew<int>(elementswidth);
    28192819        vP0inputs= new Vector<IssmDouble>(numberofelements*numP0inputs);
     
    28212821        for(int i=0;i<this->elements->Size();i++){
    28222822                Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
    2823 
     2823               
    28242824                /*Get P0 inputs*/
    28252825                for(int j=0;j<numP0inputs;j++){
    2826                         TriaInput* input=xDynamicCast<TriaInput*>(element->GetInput(P0input_enums[j]));
     2826                        TriaInput* input=xDynamicCast<TriaInput*>(element->GetInput(P0input_enums[j]));         
    28272827                        input->GetInputAverage(&value);
    28282828                        pos[0]=element->Sid()*numP0inputs+j;
    2829                         /*Insert input in the vector*/
     2829                        /*Insert input in the vector*/ 
    28302830                        vP0inputs->SetValues(1,pos,&value,INS_VAL);
    28312831                }
    2832 
     2832               
    28332833                /*Get P1 inputs*/
    28342834                for(int j=0;j<numP1inputs;j++){
     
    28372837                        pos[1]=element->vertices[1]->Sid()*numP1inputs+j;
    28382838                        pos[2]=element->vertices[2]->Sid()*numP1inputs+j;
    2839                         /*Insert input in the vector*/
    2840                         vP1inputs->SetValues(elementswidth,pos,input->values,INS_VAL);
     2839                        /*Insert input in the vector*/ 
     2840                        vP1inputs->SetValues(elementswidth,pos,input->values,INS_VAL); 
    28412841                }
    28422842        }
     
    28472847        P0inputs=vP0inputs->ToMPISerial();
    28482848        P1inputs=vP1inputs->ToMPISerial();
    2849 
     2849       
    28502850        /*Assign pointers*/
    2851         *pnumP0inputs           = numP0inputs;
    2852         *pP0inputs                      = P0inputs;
     2851        *pnumP0inputs           = numP0inputs; 
     2852        *pP0inputs                      = P0inputs; 
    28532853        *pP0input_enums = P0input_enums;
    28542854        *pP0input_interp        = P0input_interp;
    2855         *pnumP1inputs           = numP1inputs;
    2856         *pP1inputs                      = P1inputs;
     2855        *pnumP1inputs           = numP1inputs; 
     2856        *pP1inputs                      = P1inputs; 
    28572857        *pP1input_enums = P1input_enums;
    2858         *pP1input_interp        = P1input_interp;
     2858        *pP1input_interp        = P1input_interp;       
    28592859
    28602860        /*Cleanup*/
     
    28672867/*}}}*/
    28682868void FemModel::InterpolateInputs(Vertices* newfemmodel_vertices,Elements* newfemmodel_elements){/*{{{*/
    2869 
     2869       
    28702870        int numberofelements                    = this->elements->NumberOfElements();   //global, entire old mesh
    28712871        int newnumberofelements         = newfemmodel_elements->Size();                 //just on the new partition
     
    28832883        int* P1input_enums                      = NULL;
    28842884        int* P1input_interp                     = NULL;
    2885         IssmDouble* values                      = NULL;
     2885        IssmDouble* values                      = NULL; 
    28862886   IssmDouble* vector           = NULL;
    28872887        IssmDouble* x                                   = NULL;//global, entire old mesh
     
    28952895        IssmDouble* newyc                               = NULL;//just on the new partition
    28962896        int* newelementslist                    = NULL;//just on the new partition
    2897         int* sidtoindex                         = NULL;//global vertices sid to partition index
     2897        int* sidtoindex                         = NULL;//global vertices sid to partition index 
    28982898
    28992899        /*Get old P0 and P1  inputs (entire mesh)*/
     
    29282928
    29292929        /*Insert P0 and P1 inputs into the new elements (just on the new partition)*/
    2930         values=xNew<IssmDouble>(elementswidth);
     2930        values=xNew<IssmDouble>(elementswidth); 
    29312931        for(int i=0;i<newfemmodel_elements->Size();i++){//just on the new partition
    29322932                Element* element=xDynamicCast<Element*>(newfemmodel_elements->GetObjectByOffset(i));
    29332933                /*newP0inputs is just on the new partition*/
    29342934                for(int j=0;j<numP0inputs;j++){
    2935                         switch(P0input_interp[j]){
     2935                        switch(P0input_interp[j]){     
    29362936                                case P0Enum:
    29372937                                case DoubleInputEnum:
    29382938                                        element->AddInput(new DoubleInput(P0input_enums[j],newP0inputs[i*numP0inputs+j]));
    29392939                                        break;
    2940                                 case IntInputEnum:
     2940                                case IntInputEnum: 
    29412941                                        element->AddInput(new IntInput(P0input_enums[j],reCast<int>(newP0inputs[i*numP0inputs+j])));
    29422942                                        break;
     
    29562956                }
    29572957        }
    2958 
     2958       
    29592959        /*Cleanup*/
    29602960        xDelete<IssmDouble>(P0inputs);
     
    29952995
    29962996        if(!this->elements || !this->vertices || !this->results || !this->parameters) return;
    2997 
     2997         
    29982998        parameters->FindParam(&step,StepEnum);
    29992999        parameters->FindParam(&time,TimeEnum);
     
    30133013        this->results->AddResult(new GenericExternalResult<IssmDouble*>(this->results->Size()+1,MeshYEnum,
    30143014                                        y,numberofvertices,1,step,time));
    3015 
     3015       
    30163016        /*Cleanup*/
    30173017        xDelete<IssmDouble>(x);
     
    30743074   /*Assemble*/
    30753075        vmasklevelset->Assemble();
    3076 
     3076       
    30773077        /*Serialize and set output*/
    30783078        (*pmasklevelset)=vmasklevelset->ToMPISerial();
     
    30883088
    30893089        /*newelementslist is in Matlab indexing*/
    3090 
     3090       
    30913091        /*Creating connectivity table*/
    30923092        int* connectivity=NULL;
     
    30993099                        connectivity[vertexid-1]+=1;//Matlab to C indexing
    31003100                }
    3101         }
     3101        }       
    31023102
    31033103        /*Create vertex and insert in vertices*/
    31043104        for(int i=0;i<newnumberofvertices;i++){
    31053105                if(my_vertices[i]){
    3106                         Vertex *newvertex=new Vertex();
     3106                        Vertex *newvertex=new Vertex(); 
    31073107                        newvertex->id=i+1;
    31083108                        newvertex->sid=i;
     
    31153115                        newvertex->connectivity=connectivity[i];
    31163116                        newvertex->clone=false;//itapopo check this
    3117                         vertices->AddObject(newvertex);
    3118                 }
     3117                        vertices->AddObject(newvertex); 
     3118                } 
    31193119        }
    31203120
     
    31433143                        }
    31443144                        else newtria->element_type_list=NULL;
    3145 
     3145                       
    31463146                        /*Element hook*/
    31473147                        int matpar_id=newnumberofelements+1; //retrieve material parameter id (last pointer in femodel->materials)
     
    31493149                        /*retrieve vertices ids*/
    31503150                        int* vertex_ids=xNew<int>(elementswidth);
    3151                         for(int j=0;j<elementswidth;j++)        vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j]);//this Hook wants Matlab indexing
     3151                        for(int j=0;j<elementswidth;j++)        vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j]);//this Hook wants Matlab indexing 
    31523152                        /*Setting the hooks*/
    31533153                        newtria->numanalyses =this->nummodels;
     
    31613161                        /*Clean up*/
    31623162                        xDelete<int>(vertex_ids);
    3163                         elements->AddObject(newtria);
    3164                 }
     3163                        elements->AddObject(newtria);   
     3164                } 
    31653165        }
    31663166
     
    31723172        for(int i=0;i<newnumberofelements;i++){
    31733173                if(my_elements[i]){
    3174                         materials->AddObject(new Matice(i+1,i,MaticeEnum));
    3175                 }
    3176         }
    3177 
     3174                        materials->AddObject(new Matice(i+1,i,MaticeEnum));     
     3175                } 
     3176        }
     3177       
    31783178        /*Add new constant material property to materials, at the end: */
    31793179        Matpar *newmatpar=static_cast<Matpar*>(this->materials->GetObjectByOffset(this->materials->Size()-1)->copy());
    31803180        newmatpar->SetMid(newnumberofelements+1);
    3181         materials->AddObject(newmatpar);//put it at the end of the materials
     3181        materials->AddObject(newmatpar);//put it at the end of the materials       
    31823182}
    31833183/*}}}*/
     
    31863186        int lid=0;
    31873187        for(int j=0;j<newnumberofvertices;j++){
    3188                 if(my_vertices[j]){
    3189 
    3190                         Node* newnode=new Node();
    3191 
     3188                if(my_vertices[j]){                             
     3189                       
     3190                        Node* newnode=new Node();       
     3191                       
    31923192                        /*id: */
    31933193                        newnode->id=nodecounter+j+1;
     
    31953195                        newnode->lid=lid++;
    31963196                        newnode->analysis_enum=analysis_enum;
    3197 
     3197                       
    31983198                        /*Initialize coord_system: Identity matrix by default*/
    31993199                        for(int k=0;k<3;k++) for(int l=0;l<3;l++) newnode->coord_system[k][l]=0.0;
    32003200                        for(int k=0;k<3;k++) newnode->coord_system[k][k]=1.0;
    3201 
     3201                       
    32023202                        /*indexing:*/
    32033203                        newnode->indexingupdate=true;
    3204 
     3204                       
    32053205                        Analysis* analysis=EnumToAnalysis(analysis_enum);
    32063206                        int *doftypes=NULL;
     
    32163216                        /*Stressbalance Horiz*/
    32173217                        if(analysis_enum==StressbalanceAnalysisEnum){
    3218                                 // itapopo this code is rarely used.
     3218                                // itapopo this code is rarely used. 
    32193219                                /*Coordinate system provided, convert to coord_system matrix*/
    32203220                                //XZvectorsToCoordinateSystem(&this->coord_system[0][0],&iomodel->Data(StressbalanceReferentialEnum)[j*6]);
     
    32313231        if(!femmodel_vertices) _error_("GetMesh: vertices are NULL.");
    32323232        if(!femmodel_elements) _error_("GetMesh: elements are NULL.");
    3233 
     3233       
    32343234        int numberofvertices = femmodel_vertices->NumberOfVertices();
    32353235        int numberofelements = femmodel_elements->NumberOfElements();
     
    32373237        IssmDouble* x                   = NULL;
    32383238        IssmDouble* y                   = NULL;
    3239         IssmDouble* z                   = NULL;
     3239        IssmDouble* z                   = NULL; 
    32403240        int* elementslist       = NULL;
    32413241        int* elem_vertices      = NULL;
     
    32463246        /*Get vertices coordinates*/
    32473247        VertexCoordinatesx(&x,&y,&z,femmodel_vertices,false) ;
    3248 
     3248       
    32493249        /*Get element vertices*/
    32503250        elem_vertices                           = xNew<int>(elementswidth);
     
    32613261        vid3->SetValue(element->sid,elem_vertices[2],INS_VAL);
    32623262   }
    3263 
     3263               
    32643264        /*Assemble*/
    32653265   vid1->Assemble();
     
    32713271   id2 = vid2->ToMPISerial();
    32723272        id3 = vid3->ToMPISerial();
    3273 
     3273       
    32743274        /*Construct elements list*/
    32753275        elementslist=xNew<int>(numberofelements*elementswidth);
     
    32803280                elementslist[elementswidth*i+2] = reCast<int>(id3[i])+1; //InterpMesh wants Matlab indexing
    32813281        }
    3282 
     3282       
    32833283        /*Assign pointers*/
    32843284        *px                             = x;
     
    33013301        if(!femmodel_vertices) _error_("GetMesh: vertices are NULL.");
    33023302        if(!femmodel_elements) _error_("GetMesh: elements are NULL.");
    3303 
     3303       
    33043304        int numberofvertices                    = femmodel_vertices->Size();    //number of vertices of this partition
    33053305        int numbertotalofvertices       = femmodel_vertices->NumberOfVertices();        //number total of vertices (entire mesh)
     
    33083308        IssmDouble* x                                   = NULL;
    33093309        IssmDouble* y                                   = NULL;
    3310         IssmDouble* z                                   = NULL;
     3310        IssmDouble* z                                   = NULL; 
    33113311        int* elementslist                               = NULL;
    33123312        int* sidtoindex                         = NULL;
    33133313        int* elem_vertices                      = NULL;
    3314 
     3314       
    33153315        /*Get vertices coordinates of this partition*/
    33163316        sidtoindex      = xNewZeroInit<int>(numbertotalofvertices);//entire mesh, all vertices
     
    33183318        y                               = xNew<IssmDouble>(numberofvertices);//just this partitio;
    33193319        z                               = xNew<IssmDouble>(numberofvertices);//just this partitio;
    3320 
     3320       
    33213321        /*Go through in this partition (vertices)*/
    33223322        for(int i=0;i<numberofvertices;i++){//just this partition
    3323                 Vertex* vertex=(Vertex*)femmodel_vertices->GetObjectByOffset(i);
     3323                Vertex* vertex=(Vertex*)femmodel_vertices->GetObjectByOffset(i);       
    33243324                /*Attention: no spherical coordinates*/
    33253325                x[i]=vertex->GetX();
     
    33343334        elementslist = xNew<int>(numberofelements*elementswidth);
    33353335        if(numberofelements*elementswidth<0) _error_("numberofelements negative.");
    3336 
     3336       
    33373337        for(int i=0;i<numberofelements;i++){//just this partition
    33383338        Element* element=xDynamicCast<Element*>(femmodel_elements->GetObjectByOffset(i));
     
    33413341                elementslist[elementswidth*i+1] = sidtoindex[elem_vertices[1]]+1; //InterpMesh wants Matlab indexing
    33423342                elementslist[elementswidth*i+2] = sidtoindex[elem_vertices[2]]+1; //InterpMesh wants Matlab indexing
    3343         }
    3344 
     3343        }       
     3344               
    33453345        /*Assign pointers*/
    33463346        *px                             = x;
     
    33483348        *pz                             = z;
    33493349        *pelementslist = elementslist; //Matlab indexing. InterMesh uses this type.
    3350         *psidtoindex    = sidtoindex;  //it is ncessary to insert inputs
     3350        *psidtoindex    = sidtoindex;  //it is ncessary to insert inputs 
    33513351
    33523352        /*Cleanup*/
     
    33593359        /*OTHERS CONSTRAINTS MUST BE IMPLEMENTED*/
    33603360        if(analysis_enum!=StressbalanceAnalysisEnum) return;
    3361 
     3361       
    33623362        int numberofnodes_analysistype= this->nodes->NumberOfNodes(analysis_enum);
    3363         int dofpernode                                          = 2;                                                                                                            //vx and vy
     3363        int dofpernode                                          = 2;                                                                                                            //vx and vy 
    33643364        int numberofcols                                        = dofpernode*2;                                                                         //to keep dofs and flags in the vspc vector
    33653365        int numberofvertices                            = this->vertices->NumberOfVertices();                   //global, entire old mesh
     
    33853385        newy=xNew<IssmDouble>(newnumberofvertices);//just the new partition
    33863386        for(int i=0;i<newnumberofvertices;i++){//just the new partition
    3387                 Vertex* vertex=(Vertex*)newfemmodel_vertices->GetObjectByOffset(i);
     3387                Vertex* vertex=(Vertex*)newfemmodel_vertices->GetObjectByOffset(i);     
    33883388                /*Attention: no spherical coordinates*/
    33893389                newx[i]=vertex->GetX();
     
    33933393        /*Get spcvx and spcvy of old mesh*/
    33943394        for(int i=0;i<this->constraints->Size();i++){
    3395 
     3395               
    33963396                Constraint* constraint=(Constraint*)constraints->GetObjectByOffset(i);
    33973397                if(!constraint->InAnalysis(analysis_enum)) _error_("AMR create constraints for "<<EnumToStringx(analysis_enum)<<" not supported yet!\n");
     
    34003400                int dof                                 = spcstatic->GetDof();
    34013401                int node                                        = spcstatic->GetNodeId();
    3402                 IssmDouble spcvalue     = spcstatic->GetValue();
     3402                IssmDouble spcvalue     = spcstatic->GetValue(); 
    34033403                int nodeindex                   = node-1;
    3404 
     3404               
    34053405                /*vx and vx flag insertion*/
    34063406                if(dof==0) {//vx
    34073407                        vspc->SetValue(nodeindex*numberofcols,spcvalue,INS_VAL);    //vx
    34083408                        vspc->SetValue(nodeindex*numberofcols+dofpernode,1,INS_VAL);//vxflag
    3409                 }
     3409                } 
    34103410                /*vy and vy flag insertion*/
    34113411                if(dof==1){//vy
     
    34233423                                                                spc,numberofvertices,numberofcols,
    34243424                                                                newx,newy,newnumberofvertices,NULL);
    3425 
     3425       
    34263426        /*Now, insert the interpolated constraints in the data set (constraints)*/
    34273427        count=0;
     
    34403440                /*spcvy*/
    34413441                if(!xIsNan<IssmDouble>(newspc[i*numberofcols+1]) && newspc[i*numberofcols+dofpernode+1]>(1-eps) ){
    3442                         newfemmodel_constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+vertex->Sid()+1,1,newspc[i*numberofcols+1],analysis_enum));
     3442                        newfemmodel_constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+vertex->Sid()+1,1,newspc[i*numberofcols+1],analysis_enum)); 
    34433443                        //add count'th spc, on node i+1, setting dof 1 to vx.
    34443444                        count++;
     
    34973497        bool *my_elements = NULL;
    34983498        int *my_vertices  = NULL;
    3499 
    3500         _assert_(newnumberofvertices>0);
    3501         _assert_(newnumberofelements>0);
     3499       
     3500        _assert_(newnumberofvertices>0); 
     3501        _assert_(newnumberofelements>0); 
    35023502        epart=xNew<int>(newnumberofelements);
    35033503        npart=xNew<int>(newnumberofvertices);
    35043504   index=xNew<int>(elementswidth*newnumberofelements);
    3505 
     3505   
    35063506        for (int i=0;i<newnumberofelements;i++){
    35073507        for (int j=0;j<elementswidth;j++){
     
    35233523                for (int i=0;i<newnumberofvertices;i++) npart[i]=0;
    35243524        }
    3525         else _error_("At least one processor is required");
     3525        else _error_("At least one processor is required");         
    35263526
    35273527        my_vertices=xNew<int>(newnumberofvertices);
     
    35333533        for(int i=0;i<newnumberofelements;i++){
    35343534                /*!All elements have been partitioned above, only deal with elements for this cpu: */
    3535                 if(my_rank==epart[i]){
     3535                if(my_rank==epart[i]){ 
    35363536                        my_elements[i]=true;
    3537                         /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use
    3538                          *the  element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
    3539                          into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
     3537                        /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use 
     3538                         *the  element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing) 
     3539                         into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices 
    35403540                         will hold which vertices belong to this partition*/
    35413541                        for(int j=0;j<elementswidth;j++){
    3542                                 _assert_(newelementslist[elementswidth*i+j]-1<newnumberofvertices);//newelementslist is in Matlab indexing
     3542                                _assert_(newelementslist[elementswidth*i+j]-1<newnumberofvertices);//newelementslist is in Matlab indexing 
    35433543                                my_vertices[newelementslist[elementswidth*i+j]-1]=1;//newelementslist is in Matlab indexing
    35443544                        }
     
    35523552        /*Free ressources:*/
    35533553        xDelete<int>(epart);
    3554         xDelete<int>(npart);
     3554        xDelete<int>(npart);       
    35553555        xDelete<int>(index);
    35563556}
    35573557/*}}}*/
    35583558void FemModel::SmoothedDeviatoricStressTensor(IssmDouble** ptauxx,IssmDouble** ptauyy,IssmDouble** ptauxy){/*{{{*/
    3559 
     3559       
    35603560        int elementswidth                                                       = this->GetElementsWidth();//just 2D mesh, tria elements
    35613561   int numberofvertices                                         = this->vertices->NumberOfVertices();
    35623562   IssmDouble weight                                            = 0.;
    3563         IssmDouble*     tauxx                                                   = NULL;
    3564         IssmDouble*     tauyy                                                   = NULL;
    3565         IssmDouble*     tauxy                                                   = NULL;
     3563        IssmDouble*     tauxx                                                   = NULL; 
     3564        IssmDouble*     tauyy                                                   = NULL; 
     3565        IssmDouble*     tauxy                                                   = NULL; 
    35663566   IssmDouble* totalweight                              = NULL;
    35673567        IssmDouble* deviatoricstressxx          = xNew<IssmDouble>(elementswidth);
     
    35733573   Vector<IssmDouble>* vectauxy                 = new Vector<IssmDouble>(numberofvertices);
    35743574   Vector<IssmDouble>* vectotalweight   = new Vector<IssmDouble>(numberofvertices);
    3575 
     3575       
    35763576        /*Update the Deviatoric Stress tensor over the elements*/
    35773577        this->DeviatoricStressx();
    3578 
     3578       
    35793579   /*Calculate the Smoothed Deviatoric Stress tensor*/
    35803580        for(int i=0;i<this->elements->Size();i++){
     
    36213621        /*Divide for the total weight*/
    36223622        for(int i=0;i<numberofvertices;i++){
    3623                 _assert_(totalweight[i]>0);
     3623                _assert_(totalweight[i]>0);     
    36243624                tauxx[i] = tauxx[i]/totalweight[i];
    36253625                tauyy[i] = tauyy[i]/totalweight[i];
     
    36463646void FemModel::ZZErrorEstimator(IssmDouble** pelementerror){/*{{{*/
    36473647
    3648         /*Compute the Zienkiewicz and Zhu (ZZ) error estimator for the deviatoric stress tensor.
     3648        /*Compute the Zienkiewicz and Zhu (ZZ) error estimator for the deviatoric stress tensor. 
    36493649         * Ref.: Zienkiewicz and Zhu, A Simple Error Estimator and Adaptive Procedure for Practical Engineering Analysis, Int. J. Numer. Meth. Eng, 1987*/
    36503650
     
    36663666        /*Get smoothed deviatoric stress tensor*/
    36673667        this->SmoothedDeviatoricStressTensor(&smoothedtauxx,&smoothedtauyy,&smoothedtauxy);
    3668 
     3668       
    36693669        /*Integrate the error over elements*/
    36703670   for(int i=0;i<this->elements->Size();i++){
     
    36743674      element->GetInputListOnVertices(tauxy,DeviatoricStressxyEnum);
    36753675      element->GetVerticesSidList(elem_vertices);
    3676 
     3676               
    36773677                /*Integrate*/
    36783678                element->GetVerticesCoordinates(&xyz_list);
     
    36893689                                ftxy+=(tauxy[n]-smoothedtauxy[elem_vertices[n]])*basis[n];
    36903690                        }
    3691                         error+=Jdet*gauss->weight*( pow(ftxx,2)+pow(ftyy,2)+pow(ftxy,2) ); //e^2
    3692                 }
    3693                 /*Set the error in the global vector*/
     3691                        error+=Jdet*gauss->weight*( pow(ftxx,2)+pow(ftyy,2)+pow(ftxy,2) ); //e^2 
     3692                }
     3693                /*Set the error in the global vector*/ 
    36943694      sid=element->Sid();
    36953695                error = sqrt(error);//sqrt(e^2)
     
    37053705   /*Serialize and set output*/
    37063706   (*pelementerror)=velementerror->ToMPISerial();
    3707 
     3707       
    37083708        /*Cleanup*/
    37093709        xDelete<IssmDouble>(smoothedtauxx);
     
    37493749      Tria* triaelement = xDynamicCast<Tria*>(element);
    37503750      weight            = triaelement->GetArea();//the tria area is a choice for the weight
    3751 
     3751     
    37523752                /*dH/dx*/
    37533753      vecdHdx->SetValue(elem_vertices[0],weight*GradH[0],ADD_VAL);
     
    38173817   /*Get smoothed deviatoric stress tensor*/
    38183818   this->SmoothedGradThickness(&smoothed_dHdx,&smoothed_dHdy);
    3819 
     3819   
    38203820        /*Integrate the error over elements*/
    38213821   for(int i=0;i<this->elements->Size();i++){
     
    39033903        IssmDouble* x                                   = NULL;
    39043904        IssmDouble* y                                   = NULL;
    3905         IssmDouble* z                                   = NULL;
     3905        IssmDouble* z                                   = NULL; 
    39063906        IssmDouble* xyz_list                    = NULL;
    39073907        IssmDouble x1,y1,x2,y2,x3,y3;
     
    39123912      //element->GetVerticesSidList(elem_vertices);
    39133913      int 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];
     
    39453945                _error_("level set type not implemented yet!");
    39463946        }
    3947 
     3947       
    39483948        /*Outputs*/
    39493949        IssmDouble* zerolevelset_points                 = NULL;
    39503950        int npoints                                                                             = 0;
    3951 
     3951       
    39523952        /*Intermediaries*/
    39533953        int elementswidth                       = this->GetElementsWidth();
     
    39623962        int count,sid;
    39633963        IssmDouble xc,yc,x1,y1,x2,y2,x3,y3;
    3964 
     3964       
    39653965        /*Use the element center coordinate if level set is zero (grounding line or ice front), otherwise set NAN*/
    39663966   for(int i=0;i<this->elements->Size();i++){
     
    39693969                element->GetVerticesSidList(elem_vertices);
    39703970                sid= element->Sid();
    3971                 element->GetVerticesCoordinates(&xyz_list);
     3971                element->GetVerticesCoordinates(&xyz_list); 
    39723972                x1 = xyz_list[3*0+0];y1 = xyz_list[3*0+1];
    39733973                x2 = xyz_list[3*1+0];y2 = xyz_list[3*1+1];
    39743974                x3 = xyz_list[3*2+0];y3 = xyz_list[3*2+1];
    39753975                xc      = NAN;
    3976                 yc      = NAN;
     3976                yc      = NAN; 
    39773977        Tria* tria      = xDynamicCast<Tria*>(element);
    39783978                if(tria->IsIceInElement()){/*verify if there is ice in the element*/
    3979                         if(levelset[0]*levelset[1]<0. || levelset[0]*levelset[2]<0. ||
     3979                        if(levelset[0]*levelset[1]<0. || levelset[0]*levelset[2]<0. || 
    39803980                                abs(levelset[0]*levelset[1])<DBL_EPSILON || abs(levelset[0]*levelset[2])<DBL_EPSILON) {
    39813981                                xc=(x1+x2+x3)/3.;
     
    40074007                }
    40084008        }
    4009 
     4009       
    40104010        /*Assign outputs*/
    40114011        numberofpoints                          = npoints;
     
    40474047        responses_pointer=d_responses;
    40484048
    4049         //watch out, we have more d_numresponses than numresponsedescriptors, because the responses have been expanded if they were scaled.
     4049        //watch out, we have more d_numresponses than numresponsedescriptors, because the responses have been expanded if they were scaled. 
    40504050        //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: */
    40514051
     
    41404140
    41414141        int         ns,nsmax;
    4142 
     4142       
    41434143        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    41444144        ns = elements->Size();
    4145 
     4145       
    41464146        /*Figure out max of ns: */
    41474147        ISSM_MPI_Reduce(&ns,&nsmax,1,ISSM_MPI_INT,ISSM_MPI_MAX,0,IssmComm::GetComm());
     
    41624162                }
    41634163        }
    4164 
     4164       
    41654165        /*One last time: */
    41664166        pUp->Assemble();
     
    41814181
    41824182        int         ns,nsmax;
    4183 
     4183       
    41844184        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    41854185        ns = elements->Size();
    4186 
    4187         /*First, figure out the surface area of Earth: */
     4186       
     4187        /*First, figure out the surface area of Earth: */ 
    41884188        for(int i=0;i<ns;i++){
    41894189                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     
    42094209                }
    42104210        }
    4211 
     4211       
    42124212        /*One last time: */
    42134213        pUp->Assemble();
     
    42264226#endif
    42274227#ifdef _HAVE_SEALEVELRISE_
    4228 void FemModel::SealevelriseEustatic(Vector<IssmDouble>* pSgi, IssmDouble* peustatic, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius) { /*{{{*/
     4228void FemModel::SealevelriseEustatic(Vector<IssmDouble>* pRSLgi, IssmDouble* peustatic, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius,int loop) { /*{{{*/
    42294229
    42304230        /*serialized vectors:*/
     
    42624262                if(i<ns){
    42634263
    4264                         if(VerboseConvergence())if(i%100==0)_printf0_("\r" << "      convolution progress: " << (double)i/(double)ns*100 << "%  ");
     4264                        if(VerboseConvergence())if(i%100==0)_printf0_("\r" << "              convolution progress: " << (double)i/(double)ns*100 << "%  ");
    42654265
    42664266                        Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    4267                         element->SealevelriseEustatic(pSgi,&eustatic_cpu_e,latitude,longitude,radius,oceanarea,eartharea);
     4267                        element->SealevelriseEustatic(pRSLgi,&eustatic_cpu_e,latitude,longitude,radius,oceanarea,eartharea);
    42684268                        eustatic_cpu+=eustatic_cpu_e;
    42694269                }
    4270                 if(i%100==0)pSgi->Assemble();
     4270                if(i%loop==0)pRSLgi->Assemble();
    42714271        }
    42724272        if(VerboseConvergence())_printf0_("\n");
    4273 
     4273               
    42744274        /*One last time: */
    4275         pSgi->Assemble();
     4275        pRSLgi->Assemble();
    42764276
    42774277        /*Sum all eustatic components from all cpus:*/
     
    42854285}
    42864286/*}}}*/
    4287 void FemModel::SealevelriseNonEustatic(Vector<IssmDouble>* pSgo, Vector<IssmDouble>* pSg_old, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, bool verboseconvolution){/*{{{*/
     4287void FemModel::SealevelriseNonEustatic(Vector<IssmDouble>* pRSLgo, Vector<IssmDouble>* pRSLg_old, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, bool verboseconvolution,int loop){/*{{{*/
    42884288
    42894289        /*serialized vectors:*/
    4290         IssmDouble* Sg_old=NULL;
    4291 
     4290        IssmDouble* RSLg_old=NULL;
     4291       
    42924292        IssmDouble  eartharea=0;
    42934293        IssmDouble  eartharea_cpu=0;
    42944294
    42954295        int         ns,nsmax;
    4296 
     4296       
    42974297        /*Serialize vectors from previous iteration:*/
    4298         Sg_old=pSg_old->ToMPISerial();
     4298        RSLg_old=pRSLg_old->ToMPISerial();
    42994299
    43004300        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
     
    43064306                eartharea_cpu += element->GetAreaSpherical();
    43074307        }
    4308 
     4308       
    43094309        ISSM_MPI_Reduce (&eartharea_cpu,&eartharea,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    43104310        ISSM_MPI_Bcast(&eartharea,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     
    43174317        for(int i=0;i<nsmax;i++){
    43184318                if(i<ns){
    4319                         if(verboseconvolution)if(VerboseConvergence())if(i%100==0)_printf_("\r" << "      convolution progress: " << (double)i/(double)ns*100 << "%   ");
     4319                        if(verboseconvolution)if(VerboseConvergence())if(i%100==0)_printf0_("\r" << "              convolution progress: " << (double)i/(double)ns*100 << "%   ");
    43204320                        Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    4321                         element->SealevelriseNonEustatic(pSgo,Sg_old,latitude,longitude,radius,eartharea);
    4322                 }
    4323                 if(i%100==0)pSgo->Assemble();
    4324         }
    4325         if(verboseconvolution)if(VerboseConvergence())_printf_("\n");
    4326 
     4321                        element->SealevelriseNonEustatic(pRSLgo,RSLg_old,latitude,longitude,radius,eartharea);
     4322                }
     4323                if(i%loop==0)pRSLgo->Assemble();
     4324        }
     4325        if(verboseconvolution)if(VerboseConvergence())_printf0_("\n");
     4326       
    43274327        /*Free ressources:*/
    4328         xDelete<IssmDouble>(Sg_old);
    4329 }
    4330 /*}}}*/
    4331 void FemModel::SealevelriseRotationalFeedback(Vector<IssmDouble>* pSgo_rot, Vector<IssmDouble>* pSg_old, IssmDouble* pIxz, IssmDouble* pIyz, IssmDouble* pIzz, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius){/*{{{*/
     4328        xDelete<IssmDouble>(RSLg_old);
     4329}
     4330/*}}}*/
     4331void FemModel::SealevelriseRotationalFeedback(Vector<IssmDouble>* pRSLgo_rot, Vector<IssmDouble>* pRSLg_old, IssmDouble* pIxz, IssmDouble* pIyz, IssmDouble* pIzz, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius){/*{{{*/
    43324332
    43334333        /*serialized vectors:*/
    4334         IssmDouble* Sg_old=NULL;
     4334        IssmDouble* RSLg_old=NULL;
    43354335        IssmDouble  eartharea=0;
    43364336        IssmDouble  eartharea_cpu=0;
     
    43414341
    43424342        /*Serialize vectors from previous iteration:*/
    4343         Sg_old=pSg_old->ToMPISerial();
     4343        RSLg_old=pRSLg_old->ToMPISerial();
    43444344
    43454345        /*First, figure out the area of the ocean, which is needed to compute the eustatic component: */
     
    43554355        for(int i=0;i<elements->Size();i++){
    43564356                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    4357                 element->SealevelriseMomentOfInertia(&moi_list[0],Sg_old,eartharea);
     4357                element->SealevelriseMomentOfInertia(&moi_list[0],RSLg_old,eartharea);
    43584358                moi_list_cpu[0] += moi_list[0];
    43594359                moi_list_cpu[1] += moi_list[1];
     
    43994399                                                (-m3/6.0 + 0.5*m3*cos(2.0*lati) - 0.5*sin(2.*lati)*(m1*cos(longi)+m2*sin(longi)));
    44004400
    4401                 pSgo_rot->SetValue(sid,value,INS_VAL); //INS_VAL ensures that you don't add several times
     4401                pRSLgo_rot->SetValue(sid,value,INS_VAL); //INS_VAL ensures that you don't add several times
    44024402        }
    44034403
    44044404        /*Assemble mesh velocity*/
    4405         pSgo_rot->Assemble();
     4405        pRSLgo_rot->Assemble();
    44064406
    44074407        /*Assign output pointers:*/
    4408         *pIxz=moi_list[0];
    4409         *pIyz=moi_list[1];
    4410         *pIzz=moi_list[2];
     4408        if(pIxz)*pIxz=moi_list[0];
     4409        if(pIyz)*pIyz=moi_list[1];
     4410        if(pIzz)*pIzz=moi_list[2];
    44114411
    44124412        /*Free ressources:*/
    4413         xDelete<IssmDouble>(Sg_old);
    4414 
    4415 }
    4416 /*}}}*/
    4417 void FemModel::SealevelriseGeodetic(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pSg, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, IssmDouble* xx, IssmDouble* yy, IssmDouble* zz){/*{{{*/
     4413        xDelete<IssmDouble>(RSLg_old);
     4414       
     4415       
     4416}
     4417/*}}}*/
     4418void 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){/*{{{*/
    44184419
    44194420        /*serialized vectors:*/
    4420         IssmDouble* Sg=NULL;
    4421 
     4421        IssmDouble* RSLg=NULL;
     4422       
    44224423        IssmDouble  eartharea=0;
    44234424        IssmDouble  eartharea_cpu=0;
    44244425
    44254426        int         ns,nsmax;
    4426 
     4427       
    44274428        /*Serialize vectors from previous iteration:*/
    4428         Sg=pSg->ToMPISerial();
     4429        RSLg=pRSLg->ToMPISerial();
    44294430
    44304431        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    44314432        ns = elements->Size();
    4432 
     4433       
    44334434        /*First, figure out the area of the ocean, which is needed to compute the eustatic component: */
    44344435        for(int i=0;i<ns;i++){
     
    44464447        for(int i=0;i<nsmax;i++){
    44474448                if(i<ns){
     4449                        if(VerboseConvergence())if(i%100==0)_printf0_("\r" << "              convolution progress: " << (double)i/(double)ns*100 << "%  ");
    44484450                        Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    4449                         element->SealevelriseGeodetic(pUp,pNorth,pEast,Sg,latitude,longitude,radius,xx,yy,zz,eartharea);
    4450                 }
    4451                 if(i%100==0){
     4451                        element->SealevelriseGeodetic(pUp,pNorth,pEast,RSLg,latitude,longitude,radius,xx,yy,zz,eartharea,horiz);
     4452                }
     4453                if(i%loop==0){
    44524454                        pUp->Assemble();
    4453                         pNorth->Assemble();
    4454                         pEast->Assemble();
    4455                 }
    4456         }
    4457 
     4455                        if (horiz){
     4456                                pNorth->Assemble();
     4457                                pEast->Assemble();
     4458                        }
     4459                }
     4460        }
     4461       
    44584462        /*One last time: */
    44594463        pUp->Assemble();
    4460         pNorth->Assemble();
    4461         pEast->Assemble();
     4464        if(horiz){
     4465                pNorth->Assemble();
     4466                pEast->Assemble();
     4467        }
     4468        if(VerboseConvergence())_printf0_("\n");
    44624469
    44634470        /*Free ressources:*/
    4464         xDelete<IssmDouble>(Sg);
    4465         xDelete<IssmDouble>(latitude);
    4466         xDelete<IssmDouble>(longitude);
    4467         xDelete<IssmDouble>(radius);
    4468         xDelete<IssmDouble>(xx);
    4469         xDelete<IssmDouble>(yy);
    4470         xDelete<IssmDouble>(zz);
    4471 }
    4472 /*}}}*/
    4473 IssmDouble FemModel::SealevelriseOceanAverage(Vector<IssmDouble>* Sg) { /*{{{*/
    4474 
    4475         IssmDouble* Sg_serial=NULL;
     4471        xDelete<IssmDouble>(RSLg);
     4472}
     4473/*}}}*/
     4474IssmDouble FemModel::SealevelriseOceanAverage(Vector<IssmDouble>* RSLg) { /*{{{*/
     4475
     4476        IssmDouble* RSLg_serial=NULL;
    44764477        IssmDouble  oceanvalue,oceanvalue_cpu;
    44774478        IssmDouble  oceanarea,oceanarea_cpu;
    44784479
    44794480        /*Serialize vectors from previous iteration:*/
    4480         Sg_serial=Sg->ToMPISerial();
     4481        RSLg_serial=RSLg->ToMPISerial();
    44814482
    44824483        /*Initialize:*/
     
    44884489                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    44894490                oceanarea_cpu += element->OceanArea();
    4490                 oceanvalue_cpu += element->OceanAverage(Sg_serial);
     4491                oceanvalue_cpu += element->OceanAverage(RSLg_serial);
    44914492        }
    44924493        ISSM_MPI_Reduce (&oceanarea_cpu,&oceanarea,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    44934494        ISSM_MPI_Bcast(&oceanarea,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4494 
     4495       
    44954496        ISSM_MPI_Reduce (&oceanvalue_cpu,&oceanvalue,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    44964497        ISSM_MPI_Bcast(&oceanvalue,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    44974498
    44984499        /*Free ressources:*/
    4499         xDelete<IssmDouble>(Sg_serial);
    4500 
     4500        xDelete<IssmDouble>(RSLg_serial);
     4501       
    45014502        return oceanvalue/oceanarea;
    45024503}
     
    45144515        int*                eplzigzag_counter = NULL;
    45154516        int                 eplflip_lock;
    4516 
     4517       
    45174518        HydrologyDCEfficientAnalysis* effanalysis =  new HydrologyDCEfficientAnalysis();
    45184519        HydrologyDCInefficientAnalysis* inefanalysis =  new HydrologyDCInefficientAnalysis();
     
    45214522        mask=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
    45224523        recurence=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
    4523         this->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum);
    4524         this->parameters->FindParam(&eplflip_lock,HydrologydcEplflipLockEnum);
     4524        this->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum); 
     4525        this->parameters->FindParam(&eplflip_lock,HydrologydcEplflipLockEnum); 
    45254526        GetVectorFromInputsx(&old_active,this,HydrologydcMaskEplactiveNodeEnum,NodeSIdEnum);
    4526 
     4527       
    45274528        for (int i=0;i<elements->Size();i++){
    45284529                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     
    45424543        /*Assemble and serialize*/
    45434544        mask->Assemble();
    4544         serial_mask=mask->ToMPISerial();
    4545 
     4545        serial_mask=mask->ToMPISerial();       
     4546       
    45464547        xDelete<int>(eplzigzag_counter);
    45474548        xDelete<IssmDouble>(serial_rec);
     
    45854586        int sum_counter;
    45864587        ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    4587         ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     4588        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());               
    45884589        counter=sum_counter;
    45894590        *pEplcount = counter;
    45904591        if(VerboseSolution()) _printf0_("   Number of active nodes in EPL layer: "<< counter <<"\n");
    4591 
    4592         /*Update dof indexings*/
    4593         this->UpdateConstraintsx();
    4594 
    4595 }
    4596 /*}}}*/
    4597 void FemModel::HydrologyIDSupdateDomainx(IssmDouble* pIDScount){ /*{{{*/
    4598 
    4599         bool                isthermal;
    4600         Vector<IssmDouble>* mask                                = NULL;
    4601         Vector<IssmDouble>* active                              = NULL;
    4602         IssmDouble*         serial_mask = NULL;
    4603         IssmDouble*         serial_active       = NULL;
    4604 
    4605         HydrologyDCInefficientAnalysis* inefanalysis =  new HydrologyDCInefficientAnalysis();
    4606         parameters->FindParam(&isthermal,TransientIsthermalEnum);
    4607 
    4608         /*When solving a thermal model we update the thawed nodes*/
    4609         if(isthermal){
    4610                 /*Step 1: update mask, the mask correspond to thawed nodes (that have a meltingrate)*/
    4611                 mask=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCInefficientAnalysisEnum));
    4612 
    4613                 for (int i=0;i<elements->Size();i++){
    4614                         Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    4615                         inefanalysis->HydrologyIDSGetMask(mask,element);
    4616                 }
    4617                 /*Assemble and serialize*/
    4618                 mask->Assemble();
    4619                 serial_mask=mask->ToMPISerial();
    4620                 delete mask;
    4621         }
    4622         /*for other cases we just grab the mask from the initialisation value*/
    4623         else{
    4624                 GetVectorFromInputsx(&serial_mask,this,HydrologydcMaskThawedNodeEnum,NodeSIdEnum);
    4625         }
    4626         /*Update Mask and elementize*/
    4627         InputUpdateFromVectorx(this,serial_mask,HydrologydcMaskThawedNodeEnum,NodeSIdEnum);
    4628         xDelete<IssmDouble>(serial_mask);
    4629         inefanalysis->ElementizeIdsMask(this);
    4630 
    4631         /*get node mask coherent with element mask*/
    4632         active=new Vector<IssmDouble>(nodes->NumberOfNodes(HydrologyDCInefficientAnalysisEnum));
    4633         for (int i=0;i<elements->Size();i++){
    4634                 Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    4635                 inefanalysis->HydrologyIdsGetActive(active,element);
    4636         }
    4637 
    4638         /*Assemble and serialize*/
    4639         active->Assemble();
    4640         serial_active=active->ToMPISerial();
    4641         delete active;
    4642 
    4643         /*Update node activation accordingly*/
    4644         int counter =0;
    4645         for (int i=0;i<nodes->Size();i++){
    4646                 Node* node=xDynamicCast<Node*>(nodes->GetObjectByOffset(i));
    4647                 if(node->InAnalysis(HydrologyDCInefficientAnalysisEnum)){
    4648                         if(serial_active[node->Sid()]==1.){
    4649                                 node->Activate();
    4650                                 if(!node->IsClone()) counter++;
    4651                         }
    4652                         else{
    4653                                 node->Deactivate();
    4654                         }
    4655                 }
    4656         }
    4657 
    4658         xDelete<IssmDouble>(serial_active);
    4659         delete inefanalysis;
    4660         int sum_counter;
    4661         ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    4662         ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    4663         counter=sum_counter;
    4664         *pIDScount = counter;
    4665         if(VerboseSolution()) _printf0_("   Number of active nodes in IDS layer: "<< counter <<"\n");
    46664592
    46674593        /*Update dof indexings*/
     
    47064632        int sum_counter;
    47074633        ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    4708         ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     4634        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());               
    47094635        counter=sum_counter;
    47104636        *pL2count = counter;
     
    47914717}
    47924718/*}}}*/
    4793 #ifdef _HAVE_JAVASCRIPT_
     4719#ifdef _HAVE_JAVASCRIPT_ 
    47944720FemModel::FemModel(IssmDouble* buffer, int buffersize, char* toolkits, char* solution, char* modelname,ISSM_MPI_Comm incomm, bool trace){ /*{{{*/
    47954721        /*configuration: */
     
    48064732        /*From command line arguments, retrieve different filenames needed to create the FemModel: */
    48074733        solution_type=StringToEnumx(solution);
    4808 
     4734       
    48094735        /*Create femmodel from input files: */
    48104736        profiler->Start(MPROCESSOR);
    48114737        this->InitFromBuffers((char*)buffer,buffersize,toolkits, solution_type,trace,NULL);
    48124738        profiler->Stop(MPROCESSOR);
    4813 
     4739       
    48144740        /*Save communicator in the parameters dataset: */
    48154741        this->parameters->AddObject(new GenericParam<ISSM_MPI_Comm>(incomm,FemModelCommEnum));
     
    48264752        size_t* poutputbuffersize;
    48274753
    4828 
     4754       
    48294755        /*Before we delete the profiler, report statistics for this run: */
    48304756        profiler->Stop(TOTAL);  //final tagging
     
    48394765                                );
    48404766        _printf0_("\n");
    4841 
     4767       
    48424768        /*Before we close the output file, recover the buffer and size:*/
    48434769        outputbufferparam = xDynamicCast<GenericParam<char**>*>(this->parameters->FindParamObject(OutputBufferPointerEnum));
     
    48794805
    48804806        /*Open output file once for all and add output file descriptor to parameters*/
    4881         output_fid=open_memstream(&outputbuffer,&outputsize);
     4807        output_fid=open_memstream(&outputbuffer,&outputsize); 
    48824808        if(output_fid==NULL)_error_("could not initialize output stream");
    48834809        this->parameters->SetParam(output_fid,OutputFilePointerEnum);
     
    48874813}/*}}}*/
    48884814#endif
     4815
    48894816
    48904817#if defined(_HAVE_BAMG_) && !defined(_HAVE_ADOLC_)
     
    49204847                /*Initialize hmaxvertices with NAN*/
    49214848                hmaxvertices_serial=xNew<IssmDouble>(numberofvertices);
    4922                 for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN;
     4849                for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN; 
    49234850                /*Fill hmaxvertices*/
    49244851                if(this->amrbamg->groundingline_distance>0)             this->GethmaxVerticesFromZeroLevelSetDistance(hmaxvertices_serial,MaskGroundediceLevelsetEnum);
     
    49274854                if(this->amrbamg->deviatoricerror_threshold>0)  this->GethmaxVerticesFromEstimators(hmaxvertices_serial,DeviatoricStressErrorEstimatorEnum);
    49284855        }
    4929 
     4856       
    49304857        if(my_rank==0){
    49314858                this->amrbamg->ExecuteRefinementBamg(vector_serial,hmaxvertices_serial,&newnumberofvertices,&newnumberofelements,&newx,&newy,&newz,&newelementslist);
     
    49474874                newelementslist=xNew<int>(newnumberofelements*this->GetElementsWidth());
    49484875        }
    4949         ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4950         ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4951         ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4952         ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());
     4876        ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     4877        ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     4878        ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     4879        ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());       
    49534880
    49544881        /*Assign output pointers*/
     
    49834910        /*Create bamg data structures for bamg*/
    49844911        this->amrbamg = new AmrBamg();
    4985 
     4912       
    49864913        /*Get amr parameters*/
    49874914        this->parameters->FindParam(&hmin,AmrHminEnum);
     
    50074934
    50084935        /*Re-create original mesh and put it in bamg structure (only cpu 0)*/
    5009         if(my_rank==0){
     4936        if(my_rank==0){ 
    50104937                this->amrbamg->Initialize(elements,x,y,numberofvertices,numberofelements);
    50114938        }
     
    50214948
    50224949        if(!hmaxvertices) _error_("hmaxvertices is NULL!\n");
    5023 
     4950       
    50244951        /*Intermediaries*/
    50254952        int numberofvertices                     = this->vertices->NumberOfVertices();
     
    50284955
    50294956        switch(levelset_type){
    5030                 case MaskGroundediceLevelsetEnum:
     4957                case MaskGroundediceLevelsetEnum: 
    50314958                        threshold       = this->amrbamg->groundingline_distance;
    50324959                        resolution      = this->amrbamg->groundingline_resolution;
     
    50424969        this->GetVerticeDistanceToZeroLevelSet(&verticedistance,levelset_type);
    50434970        if(!verticedistance) _error_("verticedistance is NULL!\n");
    5044 
     4971       
    50454972        /*Fill hmaxVertices*/
    50464973        for(int i=0;i<numberofvertices;i++){
     
    50564983/*}}}*/
    50574984void FemModel::GethmaxVerticesFromEstimators(IssmDouble* hmaxvertices,int errorestimator_type){/*{{{*/
    5058 
     4985   
    50594986        if(!hmaxvertices) _error_("hmaxvertices is NULL!\n");
    50604987
     
    50644991        int numberofvertices                                            = this->vertices->NumberOfVertices();
    50654992        IssmDouble* maxlength                                   = xNew<IssmDouble>(numberofelements);
    5066         IssmDouble* error_vertices                              = xNewZeroInit<IssmDouble>(numberofvertices);
     4993        IssmDouble* error_vertices                              = xNewZeroInit<IssmDouble>(numberofvertices);   
    50674994        IssmDouble* error_elements                              = NULL;
    50684995        IssmDouble* x                                                           = NULL;
     
    50775004        /*Fill variables*/
    50785005        switch(errorestimator_type){
    5079                 case ThicknessErrorEstimatorEnum:
     5006                case ThicknessErrorEstimatorEnum: 
    50805007                        threshold               = this->amrbamg->thicknesserror_threshold;
    50815008                        groupthreshold  = this->amrbamg->thicknesserror_groupthreshold;
     
    51025029        case ThicknessErrorEstimatorEnum:                       this->amrbamg->thicknesserror_maximum   = maxerror;break;
    51035030        case DeviatoricStressErrorEstimatorEnum:        this->amrbamg->deviatoricerror_maximum = maxerror;break;
    5104         }
     5031        }       
    51055032        }
    51065033
    51075034        /*Get mesh*/
    51085035        this->GetMesh(this->vertices,this->elements,&x,&y,&z,&index);
    5109 
     5036       
    51105037        /*Fill error_vertices (this is the sum of all elements connected to the vertex)*/
    51115038        for(int i=0;i<numberofelements;i++){
     
    51215048                error_vertices[v2]+=error_elements[i];
    51225049                error_vertices[v3]+=error_elements[i];
    5123         }
     5050        }       
    51245051
    51255052        /*Fill hmaxvertices with the criteria*/
     
    51355062                        }
    51365063                }
    5137                 /*Now, fill the hmaxvertices if requested*/
     5064                /*Now, fill the hmaxvertices if requested*/       
    51385065                if(refine){
    51395066                        for(int j=0;j<elementswidth;j++){
     
    51655092        /*Output*/
    51665093        IssmDouble* verticedistance;
    5167 
     5094       
    51685095        /*Intermediaries*/
    51695096   int numberofvertices       = this->vertices->NumberOfVertices();
     
    51775104        /*Get vertices coordinates*/
    51785105        VertexCoordinatesx(&x,&y,&z,this->vertices,false) ;
    5179 
    5180         /*Get points which level set is zero (center of elements with zero level set)*/
     5106       
     5107        /*Get points which level set is zero (center of elements with zero level set)*/ 
    51815108        this->GetZeroLevelSetPoints(&levelset_points,numberofpoints,levelset_type);
    51825109
     
    51875114                for(int j=0;j<numberofpoints;j++){
    51885115                        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]));
    5189                         verticedistance[i]=min(distance,verticedistance[i]);
    5190                 }
    5191         }
     5116                        verticedistance[i]=min(distance,verticedistance[i]);           
     5117                }
     5118        }       
    51925119
    51935120        /*Assign the pointer*/
     
    52235150        if(this->amr->groundingline_distance>0)         this->GetElementDistanceToZeroLevelSet(&gl_distance,MaskGroundediceLevelsetEnum);
    52245151   if(this->amr->icefront_distance>0)                           this->GetElementDistanceToZeroLevelSet(&if_distance,MaskIceLevelsetEnum);
    5225    if(this->amr->thicknesserror_threshold>0)            this->ThicknessZZErrorEstimator(&thicknesserror);
    5226         if(this->amr->deviatoricerror_threshold>0)      this->ZZErrorEstimator(&deviatoricerror);
    5227 
     5152   if(this->amr->thicknesserror_threshold>0)            this->ThicknessZZErrorEstimator(&thicknesserror);       
     5153        if(this->amr->deviatoricerror_threshold>0)      this->ZZErrorEstimator(&deviatoricerror);       
     5154       
    52285155        if(my_rank==0){
    52295156                this->amr->ExecuteRefinement(gl_distance,if_distance,deviatoricerror,thicknesserror,
    5230                                                                                                 &newnumberofvertices,&newnumberofelements,&newx,&newy,&newelementslist);
     5157                                                                                                &newnumberofvertices,&newnumberofelements,&newx,&newy,&newelementslist); 
    52315158                newz=xNewZeroInit<IssmDouble>(newnumberofvertices);
    52325159                if(newnumberofvertices<=0 || newnumberofelements<=0) _error_("Error in the ReMeshNeopz.");
     
    52425169                newelementslist=xNew<int>(newnumberofelements*this->GetElementsWidth());
    52435170        }
    5244         ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    5245         ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    5246         ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    5247         ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());
    5248 
    5249         /*Assign the pointers*/
     5171        ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     5172        ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     5173        ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     5174        ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());       
     5175
     5176        /*Assign the pointers*/ 
    52505177        (*pnewelementslist)     = newelementslist; //Matlab indexing
    52515178        (*pnewx)                                        = newx;
     
    52635190/*}}}*/
    52645191void FemModel::InitializeAdaptiveRefinementNeopz(void){/*{{{*/
    5265 
     5192       
    52665193        /*Define variables*/
    52675194        int my_rank                                                                             = IssmComm::GetRank();
     
    52725199        IssmDouble* z                                                                   = NULL;
    52735200        int* elements                                                                   = NULL;
    5274 
     5201       
    52755202        /*Initialize field as NULL for now*/
    52765203        this->amr = NULL;
     
    52805207        this->GetMesh(this->vertices,this->elements,&x,&y,&z,&elements);
    52815208
    5282         /*Create initial mesh (coarse mesh) in neopz data structure*/
     5209        /*Create initial mesh (coarse mesh) in neopz data structure*/ 
    52835210        /*Just CPU #0 should keep AMR object*/
    52845211   /*Initialize refinement pattern*/
    52855212        this->SetRefPatterns();
    52865213        this->amr = new AdaptiveMeshRefinement();
    5287         this->amr->refinement_type=1;//1 is refpattern; 0 is uniform (faster)
     5214        this->amr->refinement_type=1;//1 is refpattern; 0 is uniform (faster) 
    52885215        /*Get amr parameters*/
    52895216        this->parameters->FindParam(&this->amr->level_max,AmrLevelMaxEnum);
     
    52985225        this->parameters->FindParam(&this->amr->deviatoricerror_groupthreshold,AmrDeviatoricErrorGroupThresholdEnum);
    52995226        this->parameters->FindParam(&this->amr->deviatoricerror_maximum,AmrDeviatoricErrorMaximumEnum);
    5300         if(my_rank==0){
     5227        if(my_rank==0){ 
    53015228                this->amr->CreateInitialMesh(numberofvertices,numberofelements,x,y,elements);
    53025229        }
     
    53195246        /*Output*/
    53205247        IssmDouble* elementdistance;
    5321 
     5248       
    53225249        /*Intermediaries*/
    53235250   int numberofelements                                                 = this->elements->NumberOfElements();
     
    53285255        IssmDouble xc,yc,x1,y1,x2,y2,x3,y3;
    53295256        int numberofpoints;
    5330 
    5331         /*Get points which level set is zero (center of elements with zero level set, levelset_points is serial)*/
     5257       
     5258        /*Get points which level set is zero (center of elements with zero level set, levelset_points is serial)*/     
    53325259        this->GetZeroLevelSetPoints(&levelset_points,numberofpoints,levelset_type);
    53335260
     
    53355262      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
    53365263      int sid = element->Sid();
    5337                 element->GetVerticesCoordinates(&xyz_list);
     5264                element->GetVerticesCoordinates(&xyz_list); 
    53385265                x1 = xyz_list[3*0+0];y1 = xyz_list[3*0+1];
    53395266                x2 = xyz_list[3*1+0];y2 = xyz_list[3*1+1];
     
    53455272                for(int j=0;j<numberofpoints;j++){
    53465273                        distance =sqrt((xc-levelset_points[2*j])*(xc-levelset_points[2*j])+(yc-levelset_points[2*j+1])*(yc-levelset_points[2*j+1]));
    5347                         mindistance=min(distance,mindistance);
     5274                        mindistance=min(distance,mindistance);         
    53485275                }
    53495276                velementdistance->SetValue(sid,mindistance,INS_VAL);
    53505277                xDelete<IssmDouble>(xyz_list);
    5351         }
     5278        }       
    53525279
    53535280   /*Assemble*/
Note: See TracChangeset for help on using the changeset viewer.