Changeset 22898


Ignore:
Timestamp:
07/04/18 07:48:56 (7 years ago)
Author:
bdef
Message:

NEW:deactivation of hydrologydc for frozen elements

Location:
issm/trunk-jpl/src/c
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/analyses/HydrologyDCInefficientAnalysis.cpp

    r22860 r22898  
    100100        iomodel->FetchDataToInput(elements,"md.initialization.sediment_head",SedimentHeadHydrostepEnum);
    101101        iomodel->FetchDataToInput(elements,"md.hydrology.sediment_transmitivity",HydrologydcSedimentTransmitivityEnum);
     102        iomodel->FetchDataToInput(elements,"md.hydrology.mask_thawed_node",HydrologydcMaskThawedNodeEnum);
    102103        if(iomodel->domaintype!=Domain2DhorizontalEnum){
    103104                iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum);
     
    184185
    185186        /*Intermediaries*/
     187        bool     thawed_element;
    186188        int      domaintype;
    187189        Element* basalelement;
     
    199201                default: _error_("mesh "<<EnumToStringx(domaintype)<<" not supported yet");
    200202        }
     203
     204        Input* thawed_element_input = basalelement->GetInput(HydrologydcMaskThawedEltEnum); _assert_(thawed_element_input);
     205        thawed_element_input->GetInputValue(&thawed_element);
     206
     207        /*Check that all nodes are active, else return empty matrix*/
     208        if(!thawed_element) {
     209        if(domaintype!=Domain2DhorizontalEnum){
     210                        basalelement->DeleteMaterials();
     211                        delete basalelement;
     212                }
     213                return NULL;
     214        }
     215
    201216
    202217        /*Intermediaries */
     
    297312
    298313        /*Intermediaries*/
    299         int      domaintype;
     314        bool             thawed_element;
     315        int                      domaintype;
    300316        Element* basalelement;
    301317
     
    311327                        break;
    312328                default: _error_("mesh "<<EnumToStringx(domaintype)<<" not supported yet");
     329        }
     330
     331        Input* thawed_element_input = basalelement->GetInput(HydrologydcMaskThawedEltEnum); _assert_(thawed_element_input);
     332        thawed_element_input->GetInputValue(&thawed_element);
     333
     334        /*Check that all nodes are active, else return empty matrix*/
     335        if(!thawed_element) {
     336        if(domaintype!=Domain2DhorizontalEnum){
     337                        basalelement->DeleteMaterials();
     338                        delete basalelement;
     339                }
     340                return NULL;
    313341        }
    314342
     
    626654                _error_("UnconfinedFlag is 0 or 1");
    627655        }
    628 
    629         /*Let's deal with the frozen parts for which transmitivity is zero*/
    630         if (isthermal){
    631                 element->GetInputValue(&meltingrate,gauss,BasalforcingsGroundediceMeltingRateEnum);
    632                 element->GetInputValue(&groundedice,gauss,MaskGroundediceLevelsetEnum);
    633                 if ((meltingrate<=0.0) && (groundedice>0)) sediment_transmitivity=0.;
    634         }
    635 
    636656        return sediment_transmitivity;
    637657}/*}}}*/
     
    738758        }
    739759}/*}}}*/
     760
     761void  HydrologyDCInefficientAnalysis::HydrologyIDSGetMask(Vector<IssmDouble>* vec_mask, Element* element){
     762        bool        active_element;
     763        int         domaintype;
     764        Element*    basalelement=NULL;
     765
     766        /*Get basal element*/
     767        element->FindParam(&domaintype,DomainTypeEnum);
     768        switch(domaintype){
     769                case Domain2DhorizontalEnum:
     770                        basalelement = element;
     771                        break;
     772                case Domain3DEnum:
     773                        if(!element->IsOnBase()) return;
     774                        basalelement = element->SpawnBasalElement();
     775                        break;
     776                default: _error_("mesh "<<EnumToStringx(domaintype)<<" not supported yet");
     777        }
     778        /*Intermediaries*/
     779        int                                             numnodes    =   basalelement->GetNumberOfNodes();
     780        IssmDouble*             meltingrate =   xNew<IssmDouble>(numnodes);
     781        IssmDouble*             groundedice =   xNew<IssmDouble>(numnodes);
     782
     783        basalelement->GetInputListOnVertices(&meltingrate[0],BasalforcingsGroundediceMeltingRateEnum);
     784        basalelement->GetInputListOnVertices(&groundedice[0],MaskGroundediceLevelsetEnum);
     785
     786        /*if melting rate is not positive and node is not floating, deactivate*/
     787        for(int i=0;i<numnodes;i++){
     788                if ((meltingrate[i]<=0.0) && (groundedice[i]>0)){
     789                        vec_mask->SetValue(basalelement->nodes[i]->Sid(),0.,INS_VAL);
     790                }
     791                else{
     792                        vec_mask->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
     793                }
     794        }
     795
     796        if(domaintype!=Domain2DhorizontalEnum){
     797                basalelement->DeleteMaterials();
     798                delete basalelement;
     799        }
     800        xDelete<IssmDouble>(meltingrate);
     801        xDelete<IssmDouble>(groundedice);
     802}
     803void HydrologyDCInefficientAnalysis::ElementizeIdsMask(FemModel* femmodel){/*{{{*/
     804
     805        bool     element_active;
     806        Element* element=NULL;
     807
     808        for(int i=0;i<femmodel->elements->Size();i++){
     809                element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
     810                        Input* node_mask_input = element->GetInput(HydrologydcMaskThawedNodeEnum); _assert_(node_mask_input);
     811
     812                if(node_mask_input->Max()>0.){
     813                        element_active = true;
     814                }
     815                else{
     816                        element_active = false;
     817                }
     818                element->AddInput(new BoolInput(HydrologydcMaskThawedEltEnum,element_active));
     819        }
     820}/*}}}*/
  • issm/trunk-jpl/src/c/analyses/HydrologyDCInefficientAnalysis.h

    r21436 r22898  
    1 /*! \file HydrologyDCInefficientAnalysis.h 
     1/*! \file HydrologyDCInefficientAnalysis.h
    22 *  \brief: header file for generic external result object
    33 */
     
    88/*Headers*/
    99#include "./Analysis.h"
    10 class Node; 
     10class Node;
    1111class Input;
    1212class HydrologyDCInefficientAnalysis: public Analysis{
     
    4040                IssmDouble GetHydrologyPVectorTransfer(Element* element, Gauss* gauss, Input* epl_head_input);
    4141                void ElementizeEplMask(FemModel* femmodel);
     42                void HydrologyIDSGetMask(Vector<IssmDouble>* vec_mask, Element* element);
     43                void ElementizeIdsMask(FemModel* femmodel);
    4244};
    4345#endif
  • issm/trunk-jpl/src/c/classes/Elements/Element.cpp

    r22873 r22898  
    20692069                                name==HydrologydcEplThicknessHydrostepEnum ||
    20702070                                name==HydrologydcMaskEplactiveNodeEnum ||
     2071                                name==HydrologydcMaskThawedNodeEnum ||
    20712072                                name==HydrologyHeadEnum ||
    20722073                                name==HydrologyHeadOldEnum ||
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r22704 r22898  
    136136        bool traceon=true;
    137137        this->profiler=NULL; /*avoid leak, as we are not using the profiler ever in ad control run. */
    138        
    139         /*Store the communicator, but do not set it as a global variable, as this has already 
     138
     139        /*Store the communicator, but do not set it as a global variable, as this has already
    140140         * been done by the FemModel that called this copy constructor: */
    141141        IssmComm::SetComm(incomm);
     
    152152        this->amrbamg = NULL;
    153153        #endif
    154        
     154
    155155        /*Save communicator in the parameters dataset: */
    156156        this->parameters->AddObject(new GenericParam<ISSM_MPI_Comm>(incomm,FemModelCommEnum));
     
    182182        if(parameters)delete parameters;
    183183        if(results)delete results;
    184        
     184
    185185        #if defined(_HAVE_NEOPZ_) && !defined(_HAVE_ADOLC_)
    186186        if(amr)delete amr;
     
    206206        /*First, recover the name of the restart file: */
    207207        parameters->FindParam(&restartfilename,RestartFileNameEnum);
    208        
     208
    209209        /*Open file for writing: */
    210210        restartfid=pfopen(restartfilename,"wb");
     
    215215        /*Create buffer to hold marshalled femmodel: */
    216216        this->Marshall(NULL,&femmodel_size,MARSHALLING_SIZE);
    217         femmodel_buffer=xNew<char>(femmodel_size); 
     217        femmodel_buffer=xNew<char>(femmodel_size);
    218218        /*Keep track of initial position of femmodel_buffer: */
    219219        femmodel_buffer_ini=femmodel_buffer;
    220        
     220
    221221        /*Marshall:*/
    222222        this->Marshall(&femmodel_buffer,NULL,MARSHALLING_FORWARD);
     
    376376}/*}}}*/
    377377void FemModel::InitFromFids(char* rootpath, FILE* IOMODEL, FILE* toolkitsoptionsfid, int in_solution_type, bool trace, IssmPDouble* X){/*{{{*/
    378        
     378
    379379        /*Initialize internal data: */
    380380        this->solution_type    = in_solution_type;
    381381        this->analysis_counter = nummodels-1;   //point to last analysis_type carried out.
    382382        this->results          = new Results(); //not initialized by CreateDataSets
    383        
     383
    384384        /*create IoModel */
    385385        IoModel* iomodel = new IoModel(IOMODEL,in_solution_type,trace,X);
     
    399399                if(VerboseMProcessor()) _printf0_("      configuring element and loads\n");
    400400                ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
    401                
     401
    402402                if(i==0){
    403403                        if(VerboseMProcessor()) _printf0_("      creating vertex PIDs\n");
    404                         VerticesDofx(vertices,parameters); 
     404                        VerticesDofx(vertices,parameters);
    405405
    406406                        if(VerboseMProcessor()) _printf0_("      detecting active vertices\n");
     
    409409
    410410                if(VerboseMProcessor()) _printf0_("      resolving node constraints\n");
    411                 SpcNodesx(nodes,constraints,parameters,analysis_type_list[i]); 
     411                SpcNodesx(nodes,constraints,parameters,analysis_type_list[i]);
    412412
    413413                if(VerboseMProcessor()) _printf0_("      creating nodal degrees of freedom\n");
     
    487487        FILE* restartfid=NULL;
    488488        char* restartfilename = NULL;
    489         int   femmodel_size=0; 
    490         int   fread_return=0; 
     489        int   femmodel_size=0;
     490        int   fread_return=0;
    491491        char* femmodel_buffer=NULL;
    492492        char* femmodel_buffer_ini=NULL;
     
    513513
    514514        /*Figure out size of buffer to be read: */
    515         fseek(restartfid, 0L, SEEK_END); 
     515        fseek(restartfid, 0L, SEEK_END);
    516516        femmodel_size = ftell(restartfid);
    517517        fseek(restartfid, 0L, SEEK_SET);
    518518
    519519        /*Allocate buffer: */
    520         femmodel_buffer=xNew<char>(femmodel_size); 
     520        femmodel_buffer=xNew<char>(femmodel_size);
    521521
    522522        /*Read buffer from file: */
     
    539539void FemModel::SetCurrentConfiguration(int configuration_type,int analysis_type){/*{{{*/
    540540
    541         /*Use configuration_type to setup the analysis counter, the configurations of objects etc ... but use 
    542          * analysis_type to drive the element numerics. This allows for use of 1 configuration_type for several 
    543          * analyses. For example: do a SurfaceSlopeX, SurfaceSlopeY, BedSlopeX and BedSlopeY analysis using the 
     541        /*Use configuration_type to setup the analysis counter, the configurations of objects etc ... but use
     542         * analysis_type to drive the element numerics. This allows for use of 1 configuration_type for several
     543         * analyses. For example: do a SurfaceSlopeX, SurfaceSlopeY, BedSlopeX and BedSlopeY analysis using the
    544544         * Slope configuration.*/
    545545        int found=-1;
     
    700700                        analyses_temp[numanalyses++]=EsaAnalysisEnum;
    701701                        break;
    702                
     702
    703703                case SealevelriseSolutionEnum:
    704704                        analyses_temp[numanalyses++]=SealevelriseAnalysisEnum;
     
    825825
    826826        /*run solution core: */
    827         profiler->Start(CORE);   
    828         solutioncore(this); 
     827        profiler->Start(CORE);
     828        solutioncore(this);
    829829        profiler->Stop(CORE);
    830830
    831831        /*run AD core if needed: */
    832         profiler->Start(ADCORE); 
    833         ad_core(this);     
     832        profiler->Start(ADCORE);
     833        ad_core(this);
    834834        profiler->Stop(ADCORE);
    835835
     
    11211121        /*Broadcast and plug into response: */
    11221122        ISSM_MPI_Allreduce ( &cpu_found,&cpu_found,1,ISSM_MPI_INT,ISSM_MPI_MAX,IssmComm::GetComm());
    1123         ISSM_MPI_Bcast(&response,1,ISSM_MPI_DOUBLE,cpu_found,IssmComm::GetComm()); 
     1123        ISSM_MPI_Bcast(&response,1,ISSM_MPI_DOUBLE,cpu_found,IssmComm::GetComm());
    11241124
    11251125        /*Assign output pointers: */
     
    12681268        num_segments = mdims_array[counter-1];
    12691269
    1270         /*Go through segments, and then elements, and figure out which elements belong to a segment. 
     1270        /*Go through segments, and then elements, and figure out which elements belong to a segment.
    12711271         * When we find one, use the element to compute the mass flux on the segment: */
    12721272        for(i=0;i<num_segments;i++){
     
    13151315        /*Figure out maximum across the cluster: */
    13161316        ISSM_MPI_Reduce(&maxabsvx,&node_maxabsvx,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1317         ISSM_MPI_Bcast(&node_maxabsvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1317        ISSM_MPI_Bcast(&node_maxabsvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    13181318        maxabsvx=node_maxabsvx;
    13191319
     
    13391339        /*Figure out maximum across the cluster: */
    13401340        ISSM_MPI_Reduce(&maxabsvy,&node_maxabsvy,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1341         ISSM_MPI_Bcast(&node_maxabsvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1341        ISSM_MPI_Bcast(&node_maxabsvy,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    13421342        maxabsvy=node_maxabsvy;
    13431343
     
    13631363        /*Figure out maximum across the cluster: */
    13641364        ISSM_MPI_Reduce(&maxabsvz,&node_maxabsvz,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1365         ISSM_MPI_Bcast(&node_maxabsvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1365        ISSM_MPI_Bcast(&node_maxabsvz,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    13661366        maxabsvz=node_maxabsvz;
    13671367
     
    14061406        /*Figure out maximum across the cluster: */
    14071407        ISSM_MPI_Reduce(&maxvel,&node_maxvel,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1408         ISSM_MPI_Bcast(&node_maxvel,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1408        ISSM_MPI_Bcast(&node_maxvel,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    14091409        maxvel=node_maxvel;
    14101410
     
    14301430        /*Figure out maximum across the cluster: */
    14311431        ISSM_MPI_Reduce(&maxvx,&node_maxvx,1,ISSM_MPI_DOUBLE,ISSM_MPI_MAX,0,IssmComm::GetComm() );
    1432         ISSM_MPI_Bcast(&node_maxvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());   
     1432        ISSM_MPI_Bcast(&node_maxvx,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    14331433        maxvx=node_maxvx;
    14341434
     
    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;
     
    16781678                        omega0_input->GetInputValue(&p0,gauss);
    16791679
    1680                         /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */ 
     1680                        /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
    16811681                        //J+=weight*1/2*(dp[0]*dp[0]+dp[1]*dp[1])*Jdet*gauss->weight;
    16821682                        J+=weight*1/2*pow(p - p0,2)*Jdet*gauss->weight;
     
    19021902                                                ISSM_MPI_Bcast(&nodesperelement,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    19031903                                                ISSM_MPI_Bcast(&array_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    1904                                                
     1904
    19051905                                                if(results_on_nodes){
    19061906
     
    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();
     
    42374237        IssmDouble  eartharea_cpu  = 0.;
    42384238        int         ns,nsmax;
    4239        
     4239
    42404240        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    42414241        ns = elements->Size();
     
    42614261        for(int i=0;i<nsmax;i++){
    42624262                if(i<ns){
    4263                
     4263
    42644264                        if(VerboseConvergence())if(i%100==0)_printf0_("\r" << "      convolution progress: " << (double)i/(double)ns*100 << "%  ");
    4265                
     4265
    42664266                        Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    42674267                        element->SealevelriseEustatic(pSgi,&eustatic_cpu_e,latitude,longitude,radius,oceanarea,eartharea);
     
    42714271        }
    42724272        if(VerboseConvergence())_printf0_("\n");
    4273                
     4273
    42744274        /*One last time: */
    42754275        pSgi->Assemble();
     
    42894289        /*serialized vectors:*/
    42904290        IssmDouble* Sg_old=NULL;
    4291        
     4291
    42924292        IssmDouble  eartharea=0;
    42934293        IssmDouble  eartharea_cpu=0;
    42944294
    42954295        int         ns,nsmax;
    4296        
     4296
    42974297        /*Serialize vectors from previous iteration:*/
    42984298        Sg_old=pSg_old->ToMPISerial();
     
    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());
     
    43244324        }
    43254325        if(verboseconvolution)if(VerboseConvergence())_printf_("\n");
    4326        
     4326
    43274327        /*Free ressources:*/
    43284328        xDelete<IssmDouble>(Sg_old);
     
    43364336        IssmDouble  eartharea_cpu=0;
    43374337        IssmDouble      tide_love_h, tide_love_k, fluid_love, moi_e, moi_p, omega, g;
    4338         IssmDouble      load_love_k2 = -0.30922675; //degree 2 load Love number 
    4339         IssmDouble      m1, m2, m3; 
    4340         IssmDouble      lati, longi, radi, value; 
     4338        IssmDouble      load_love_k2 = -0.30922675; //degree 2 load Love number
     4339        IssmDouble      m1, m2, m3;
     4340        IssmDouble      lati, longi, radi, value;
    43414341
    43424342        /*Serialize vectors from previous iteration:*/
     
    43514351        ISSM_MPI_Bcast(&eartharea,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    43524352
    4353         IssmDouble moi_list[3]={0,0,0}; 
    4354         IssmDouble moi_list_cpu[3]={0,0,0}; 
     4353        IssmDouble moi_list[3]={0,0,0};
     4354        IssmDouble moi_list_cpu[3]={0,0,0};
    43554355        for(int i=0;i<elements->Size();i++){
    43564356                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    43574357                element->SealevelriseMomentOfInertia(&moi_list[0],Sg_old,eartharea);
    4358                 moi_list_cpu[0] += moi_list[0]; 
    4359                 moi_list_cpu[1] += moi_list[1]; 
    4360                 moi_list_cpu[2] += moi_list[2]; 
     4358                moi_list_cpu[0] += moi_list[0];
     4359                moi_list_cpu[1] += moi_list[1];
     4360                moi_list_cpu[2] += moi_list[2];
    43614361        }
    43624362        ISSM_MPI_Reduce (&moi_list_cpu[0],&moi_list[0],1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    43634363        ISSM_MPI_Bcast(&moi_list[0],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4364         //     
     4364        //
    43654365        ISSM_MPI_Reduce (&moi_list_cpu[1],&moi_list[1],1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    43664366        ISSM_MPI_Bcast(&moi_list[1],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4367         //     
     4367        //
    43684368        ISSM_MPI_Reduce (&moi_list_cpu[2],&moi_list[2],1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    43694369        ISSM_MPI_Bcast(&moi_list[2],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4370        
     4370
    43714371        /*pull out some useful parameters: */
    43724372        parameters->FindParam(&tide_love_h,SealevelriseTidalLoveHEnum);
     
    43784378
    43794379        /*compute perturbation terms for angular velocity vector: */
    4380         m1 = 1/(1-tide_love_k/fluid_love) * (1+load_love_k2)/(moi_p-moi_e) * moi_list[0]; 
    4381         m2 = 1/(1-tide_love_k/fluid_love) * (1+load_love_k2)/(moi_p-moi_e) * moi_list[1]; 
    4382         m3 = -(1+load_love_k2)/moi_p * moi_list[2];     // term associated with fluid number (3-order-of-magnitude smaller) is negelected 
     4380        m1 = 1/(1-tide_love_k/fluid_love) * (1+load_love_k2)/(moi_p-moi_e) * moi_list[0];
     4381        m2 = 1/(1-tide_love_k/fluid_love) * (1+load_love_k2)/(moi_p-moi_e) * moi_list[1];
     4382        m3 = -(1+load_love_k2)/moi_p * moi_list[2];     // term associated with fluid number (3-order-of-magnitude smaller) is negelected
    43834383
    43844384        /* Green's function (1+k_2-h_2/g): checked against Glenn Milne's thesis Chapter 3 (eqs: 3.3-4, 3.10-11)
    4385          * Perturbation terms for angular velocity vector (m1, m2, m3): checked against Mitrovica (2005 Appendix) & Jensen et al (2013 Appendix A3) 
    4386          * Sea level rotational feedback: checked against GMD eqs 8-9 (only first order terms, i.e., degree 2 order 0 & 1 considered) 
    4387          * all DONE in Geographic coordinates: theta \in [-90,90], lambda \in [-180 180] 
     4385         * Perturbation terms for angular velocity vector (m1, m2, m3): checked against Mitrovica (2005 Appendix) & Jensen et al (2013 Appendix A3)
     4386         * Sea level rotational feedback: checked against GMD eqs 8-9 (only first order terms, i.e., degree 2 order 0 & 1 considered)
     4387         * all DONE in Geographic coordinates: theta \in [-90,90], lambda \in [-180 180]
    43884388         */
    43894389        for(int i=0;i<vertices->Size();i++){
     
    43954395                lati=latitude[sid]/180*PI;      longi=longitude[sid]/180*PI; radi=radius[sid];
    43964396
    4397                 /*only first order terms are considered now: */ 
     4397                /*only first order terms are considered now: */
    43984398                value=((1.0+tide_love_k-tide_love_h)/9.81)*pow(omega*radi,2.0)*
    4399                                                 (-m3/6.0 + 0.5*m3*cos(2.0*lati) - 0.5*sin(2.*lati)*(m1*cos(longi)+m2*sin(longi))); 
    4400        
     4399                                                (-m3/6.0 + 0.5*m3*cos(2.0*lati) - 0.5*sin(2.*lati)*(m1*cos(longi)+m2*sin(longi)));
     4400
    44014401                pSgo_rot->SetValue(sid,value,INS_VAL); //INS_VAL ensures that you don't add several times
    44024402        }
     
    44044404        /*Assemble mesh velocity*/
    44054405        pSgo_rot->Assemble();
    4406        
     4406
    44074407        /*Assign output pointers:*/
    44084408        *pIxz=moi_list[0];
     
    44124412        /*Free ressources:*/
    44134413        xDelete<IssmDouble>(Sg_old);
    4414        
     4414
    44154415}
    44164416/*}}}*/
     
    44194419        /*serialized vectors:*/
    44204420        IssmDouble* Sg=NULL;
    4421        
     4421
    44224422        IssmDouble  eartharea=0;
    44234423        IssmDouble  eartharea_cpu=0;
    44244424
    44254425        int         ns,nsmax;
    4426        
     4426
    44274427        /*Serialize vectors from previous iteration:*/
    44284428        Sg=pSg->ToMPISerial();
     
    44304430        /*Go through elements, and add contribution from each element to the deflection vector wg:*/
    44314431        ns = elements->Size();
    4432        
     4432
    44334433        /*First, figure out the area of the ocean, which is needed to compute the eustatic component: */
    44344434        for(int i=0;i<ns;i++){
     
    44554455                }
    44564456        }
    4457        
     4457
    44584458        /*One last time: */
    44594459        pUp->Assemble();
     
    44924492        ISSM_MPI_Reduce (&oceanarea_cpu,&oceanarea,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    44934493        ISSM_MPI_Bcast(&oceanarea,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    4494        
     4494
    44954495        ISSM_MPI_Reduce (&oceanvalue_cpu,&oceanvalue,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    44964496        ISSM_MPI_Bcast(&oceanvalue,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     
    44984498        /*Free ressources:*/
    44994499        xDelete<IssmDouble>(Sg_serial);
    4500        
     4500
    45014501        return oceanvalue/oceanarea;
    45024502}
     
    45144514        int*                eplzigzag_counter = NULL;
    45154515        int                 eplflip_lock;
    4516        
     4516
    45174517        HydrologyDCEfficientAnalysis* effanalysis =  new HydrologyDCEfficientAnalysis();
    45184518        HydrologyDCInefficientAnalysis* inefanalysis =  new HydrologyDCInefficientAnalysis();
     
    45214521        mask=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
    45224522        recurence=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
    4523         this->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum); 
    4524         this->parameters->FindParam(&eplflip_lock,HydrologydcEplflipLockEnum); 
     4523        this->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum);
     4524        this->parameters->FindParam(&eplflip_lock,HydrologydcEplflipLockEnum);
    45254525        GetVectorFromInputsx(&old_active,this,HydrologydcMaskEplactiveNodeEnum,NodeSIdEnum);
    4526        
     4526
    45274527        for (int i=0;i<elements->Size();i++){
    45284528                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     
    45424542        /*Assemble and serialize*/
    45434543        mask->Assemble();
    4544         serial_mask=mask->ToMPISerial();       
    4545        
     4544        serial_mask=mask->ToMPISerial();
     4545
    45464546        xDelete<int>(eplzigzag_counter);
    45474547        xDelete<IssmDouble>(serial_rec);
     
    45854585        int sum_counter;
    45864586        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());               
     4587        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    45884588        counter=sum_counter;
    45894589        *pEplcount = counter;
    45904590        if(VerboseSolution()) _printf0_("   Number of active nodes in EPL layer: "<< counter <<"\n");
     4591
     4592        /*Update dof indexings*/
     4593        this->UpdateConstraintsx();
     4594
     4595}
     4596/*}}}*/
     4597void FemModel::HydrologyIDSupdateDomainx(IssmDouble* pIDScount){ /*{{{*/
     4598
     4599        bool                isthermal;
     4600        Vector<IssmDouble>* mask                                = NULL;
     4601        IssmDouble*         serial_mask = NULL;
     4602
     4603        HydrologyDCInefficientAnalysis* inefanalysis =  new HydrologyDCInefficientAnalysis();
     4604        parameters->FindParam(&isthermal,TransientIsthermalEnum);
     4605
     4606        /*When solving a thermal model we update the thawed nodes*/
     4607        if(isthermal){
     4608                /*Step 1: update mask, the mask correspond to thawed nodes (that have a meltingrate)*/
     4609                mask=new Vector<IssmDouble>(this->nodes->NumberOfNodes(HydrologyDCInefficientAnalysisEnum));
     4610
     4611                for (int i=0;i<elements->Size();i++){
     4612                        Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     4613                        inefanalysis->HydrologyIDSGetMask(mask,element);
     4614                }
     4615                /*Assemble and serialize*/
     4616                mask->Assemble();
     4617                serial_mask=mask->ToMPISerial();
     4618                delete mask;
     4619        }
     4620        /*for other cases we just grab the mask from the initialisation value*/
     4621        else{
     4622        GetVectorFromInputsx(&serial_mask,this,HydrologydcMaskThawedNodeEnum,NodeSIdEnum);
     4623        }
     4624        /*Update node activation accordingly*/
     4625        int counter =0;
     4626        for (int i=0;i<nodes->Size();i++){
     4627                Node* node=xDynamicCast<Node*>(nodes->GetObjectByOffset(i));
     4628                if(node->InAnalysis(HydrologyDCInefficientAnalysisEnum)){
     4629                        if(serial_mask[node->Sid()]==1.){
     4630                                node->Activate();
     4631                                if(!node->IsClone()) counter++;
     4632                        }
     4633                        else{
     4634                                node->Deactivate();
     4635                        }
     4636                }
     4637        }
     4638
     4639        /*Update Mask*/
     4640        InputUpdateFromVectorx(this,serial_mask,HydrologydcMaskThawedNodeEnum,NodeSIdEnum);
     4641        xDelete<IssmDouble>(serial_mask);
     4642        inefanalysis->ElementizeIdsMask(this);
     4643
     4644        int sum_counter;
     4645        ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
     4646        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     4647        counter=sum_counter;
     4648        *pIDScount = counter;
     4649        if(VerboseSolution()) _printf0_("   Number of active nodes in IDS layer: "<< counter <<"\n");
    45914650
    45924651        /*Update dof indexings*/
     
    46314690        int sum_counter;
    46324691        ISSM_MPI_Reduce(&counter,&sum_counter,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,IssmComm::GetComm() );
    4633         ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());               
     4692        ISSM_MPI_Bcast(&sum_counter,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    46344693        counter=sum_counter;
    46354694        *pL2count = counter;
     
    47164775}
    47174776/*}}}*/
    4718 #ifdef _HAVE_JAVASCRIPT_ 
     4777#ifdef _HAVE_JAVASCRIPT_
    47194778FemModel::FemModel(IssmDouble* buffer, int buffersize, char* toolkits, char* solution, char* modelname,ISSM_MPI_Comm incomm, bool trace){ /*{{{*/
    47204779        /*configuration: */
     
    47314790        /*From command line arguments, retrieve different filenames needed to create the FemModel: */
    47324791        solution_type=StringToEnumx(solution);
    4733        
     4792
    47344793        /*Create femmodel from input files: */
    47354794        profiler->Start(MPROCESSOR);
    47364795        this->InitFromBuffers((char*)buffer,buffersize,toolkits, solution_type,trace,NULL);
    47374796        profiler->Stop(MPROCESSOR);
    4738        
     4797
    47394798        /*Save communicator in the parameters dataset: */
    47404799        this->parameters->AddObject(new GenericParam<ISSM_MPI_Comm>(incomm,FemModelCommEnum));
     
    47514810        size_t* poutputbuffersize;
    47524811
    4753        
     4812
    47544813        /*Before we delete the profiler, report statistics for this run: */
    47554814        profiler->Stop(TOTAL);  //final tagging
     
    47644823                                );
    47654824        _printf0_("\n");
    4766        
     4825
    47674826        /*Before we close the output file, recover the buffer and size:*/
    47684827        outputbufferparam = xDynamicCast<GenericParam<char**>*>(this->parameters->FindParamObject(OutputBufferPointerEnum));
     
    48044863
    48054864        /*Open output file once for all and add output file descriptor to parameters*/
    4806         output_fid=open_memstream(&outputbuffer,&outputsize); 
     4865        output_fid=open_memstream(&outputbuffer,&outputsize);
    48074866        if(output_fid==NULL)_error_("could not initialize output stream");
    48084867        this->parameters->SetParam(output_fid,OutputFilePointerEnum);
     
    48454904                /*Initialize hmaxvertices with NAN*/
    48464905                hmaxvertices_serial=xNew<IssmDouble>(numberofvertices);
    4847                 for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN; 
     4906                for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN;
    48484907                /*Fill hmaxvertices*/
    48494908                if(this->amrbamg->groundingline_distance>0)             this->GethmaxVerticesFromZeroLevelSetDistance(hmaxvertices_serial,MaskGroundediceLevelsetEnum);
     
    48524911                if(this->amrbamg->deviatoricerror_threshold>0)  this->GethmaxVerticesFromEstimators(hmaxvertices_serial,DeviatoricStressErrorEstimatorEnum);
    48534912        }
    4854        
     4913
    48554914        if(my_rank==0){
    48564915                this->amrbamg->ExecuteRefinementBamg(vector_serial,hmaxvertices_serial,&newnumberofvertices,&newnumberofelements,&newx,&newy,&newz,&newelementslist);
     
    48724931                newelementslist=xNew<int>(newnumberofelements*this->GetElementsWidth());
    48734932        }
    4874         ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    4875         ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    4876         ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    4877         ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());       
     4933        ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     4934        ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     4935        ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     4936        ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());
    48784937
    48794938        /*Assign output pointers*/
     
    49084967        /*Create bamg data structures for bamg*/
    49094968        this->amrbamg = new AmrBamg();
    4910        
     4969
    49114970        /*Get amr parameters*/
    49124971        this->parameters->FindParam(&hmin,AmrHminEnum);
     
    49324991
    49334992        /*Re-create original mesh and put it in bamg structure (only cpu 0)*/
    4934         if(my_rank==0){ 
     4993        if(my_rank==0){
    49354994                this->amrbamg->Initialize(elements,x,y,numberofvertices,numberofelements);
    49364995        }
     
    49465005
    49475006        if(!hmaxvertices) _error_("hmaxvertices is NULL!\n");
    4948        
     5007
    49495008        /*Intermediaries*/
    49505009        int numberofvertices                     = this->vertices->NumberOfVertices();
     
    49535012
    49545013        switch(levelset_type){
    4955                 case MaskGroundediceLevelsetEnum: 
     5014                case MaskGroundediceLevelsetEnum:
    49565015                        threshold       = this->amrbamg->groundingline_distance;
    49575016                        resolution      = this->amrbamg->groundingline_resolution;
     
    49675026        this->GetVerticeDistanceToZeroLevelSet(&verticedistance,levelset_type);
    49685027        if(!verticedistance) _error_("verticedistance is NULL!\n");
    4969        
     5028
    49705029        /*Fill hmaxVertices*/
    49715030        for(int i=0;i<numberofvertices;i++){
     
    49815040/*}}}*/
    49825041void FemModel::GethmaxVerticesFromEstimators(IssmDouble* hmaxvertices,int errorestimator_type){/*{{{*/
    4983    
     5042
    49845043        if(!hmaxvertices) _error_("hmaxvertices is NULL!\n");
    49855044
     
    49895048        int numberofvertices                                            = this->vertices->NumberOfVertices();
    49905049        IssmDouble* maxlength                                   = xNew<IssmDouble>(numberofelements);
    4991         IssmDouble* error_vertices                              = xNewZeroInit<IssmDouble>(numberofvertices);   
     5050        IssmDouble* error_vertices                              = xNewZeroInit<IssmDouble>(numberofvertices);
    49925051        IssmDouble* error_elements                              = NULL;
    49935052        IssmDouble* x                                                           = NULL;
     
    50025061        /*Fill variables*/
    50035062        switch(errorestimator_type){
    5004                 case ThicknessErrorEstimatorEnum: 
     5063                case ThicknessErrorEstimatorEnum:
    50055064                        threshold               = this->amrbamg->thicknesserror_threshold;
    50065065                        groupthreshold  = this->amrbamg->thicknesserror_groupthreshold;
     
    50275086        case ThicknessErrorEstimatorEnum:                       this->amrbamg->thicknesserror_maximum   = maxerror;break;
    50285087        case DeviatoricStressErrorEstimatorEnum:        this->amrbamg->deviatoricerror_maximum = maxerror;break;
    5029         }       
     5088        }
    50305089        }
    50315090
    50325091        /*Get mesh*/
    50335092        this->GetMesh(this->vertices,this->elements,&x,&y,&z,&index);
    5034        
     5093
    50355094        /*Fill error_vertices (this is the sum of all elements connected to the vertex)*/
    50365095        for(int i=0;i<numberofelements;i++){
     
    50465105                error_vertices[v2]+=error_elements[i];
    50475106                error_vertices[v3]+=error_elements[i];
    5048         }       
     5107        }
    50495108
    50505109        /*Fill hmaxvertices with the criteria*/
     
    50605119                        }
    50615120                }
    5062                 /*Now, fill the hmaxvertices if requested*/       
     5121                /*Now, fill the hmaxvertices if requested*/
    50635122                if(refine){
    50645123                        for(int j=0;j<elementswidth;j++){
     
    50905149        /*Output*/
    50915150        IssmDouble* verticedistance;
    5092        
     5151
    50935152        /*Intermediaries*/
    50945153   int numberofvertices       = this->vertices->NumberOfVertices();
     
    51025161        /*Get vertices coordinates*/
    51035162        VertexCoordinatesx(&x,&y,&z,this->vertices,false) ;
    5104        
    5105         /*Get points which level set is zero (center of elements with zero level set)*/ 
     5163
     5164        /*Get points which level set is zero (center of elements with zero level set)*/
    51065165        this->GetZeroLevelSetPoints(&levelset_points,numberofpoints,levelset_type);
    51075166
     
    51125171                for(int j=0;j<numberofpoints;j++){
    51135172                        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]));
    5114                         verticedistance[i]=min(distance,verticedistance[i]);           
    5115                 }
    5116         }       
     5173                        verticedistance[i]=min(distance,verticedistance[i]);
     5174                }
     5175        }
    51175176
    51185177        /*Assign the pointer*/
     
    51485207        if(this->amr->groundingline_distance>0)         this->GetElementDistanceToZeroLevelSet(&gl_distance,MaskGroundediceLevelsetEnum);
    51495208   if(this->amr->icefront_distance>0)                           this->GetElementDistanceToZeroLevelSet(&if_distance,MaskIceLevelsetEnum);
    5150    if(this->amr->thicknesserror_threshold>0)            this->ThicknessZZErrorEstimator(&thicknesserror);       
    5151         if(this->amr->deviatoricerror_threshold>0)      this->ZZErrorEstimator(&deviatoricerror);       
    5152        
     5209   if(this->amr->thicknesserror_threshold>0)            this->ThicknessZZErrorEstimator(&thicknesserror);
     5210        if(this->amr->deviatoricerror_threshold>0)      this->ZZErrorEstimator(&deviatoricerror);
     5211
    51535212        if(my_rank==0){
    51545213                this->amr->ExecuteRefinement(gl_distance,if_distance,deviatoricerror,thicknesserror,
    5155                                                                                                 &newnumberofvertices,&newnumberofelements,&newx,&newy,&newelementslist); 
     5214                                                                                                &newnumberofvertices,&newnumberofelements,&newx,&newy,&newelementslist);
    51565215                newz=xNewZeroInit<IssmDouble>(newnumberofvertices);
    51575216                if(newnumberofvertices<=0 || newnumberofelements<=0) _error_("Error in the ReMeshNeopz.");
     
    51675226                newelementslist=xNew<int>(newnumberofelements*this->GetElementsWidth());
    51685227        }
    5169         ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    5170         ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    5171         ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
    5172         ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());       
    5173 
    5174         /*Assign the pointers*/ 
     5228        ISSM_MPI_Bcast(newx,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     5229        ISSM_MPI_Bcast(newy,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     5230        ISSM_MPI_Bcast(newz,newnumberofvertices,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     5231        ISSM_MPI_Bcast(newelementslist,newnumberofelements*this->GetElementsWidth(),ISSM_MPI_INT,0,IssmComm::GetComm());
     5232
     5233        /*Assign the pointers*/
    51755234        (*pnewelementslist)     = newelementslist; //Matlab indexing
    51765235        (*pnewx)                                        = newx;
     
    51885247/*}}}*/
    51895248void FemModel::InitializeAdaptiveRefinementNeopz(void){/*{{{*/
    5190        
     5249
    51915250        /*Define variables*/
    51925251        int my_rank                                                                             = IssmComm::GetRank();
     
    51975256        IssmDouble* z                                                                   = NULL;
    51985257        int* elements                                                                   = NULL;
    5199        
     5258
    52005259        /*Initialize field as NULL for now*/
    52015260        this->amr = NULL;
     
    52055264        this->GetMesh(this->vertices,this->elements,&x,&y,&z,&elements);
    52065265
    5207         /*Create initial mesh (coarse mesh) in neopz data structure*/ 
     5266        /*Create initial mesh (coarse mesh) in neopz data structure*/
    52085267        /*Just CPU #0 should keep AMR object*/
    52095268   /*Initialize refinement pattern*/
    52105269        this->SetRefPatterns();
    52115270        this->amr = new AdaptiveMeshRefinement();
    5212         this->amr->refinement_type=1;//1 is refpattern; 0 is uniform (faster) 
     5271        this->amr->refinement_type=1;//1 is refpattern; 0 is uniform (faster)
    52135272        /*Get amr parameters*/
    52145273        this->parameters->FindParam(&this->amr->level_max,AmrLevelMaxEnum);
     
    52235282        this->parameters->FindParam(&this->amr->deviatoricerror_groupthreshold,AmrDeviatoricErrorGroupThresholdEnum);
    52245283        this->parameters->FindParam(&this->amr->deviatoricerror_maximum,AmrDeviatoricErrorMaximumEnum);
    5225         if(my_rank==0){ 
     5284        if(my_rank==0){
    52265285                this->amr->CreateInitialMesh(numberofvertices,numberofelements,x,y,elements);
    52275286        }
     
    52445303        /*Output*/
    52455304        IssmDouble* elementdistance;
    5246        
     5305
    52475306        /*Intermediaries*/
    52485307   int numberofelements                                                 = this->elements->NumberOfElements();
     
    52535312        IssmDouble xc,yc,x1,y1,x2,y2,x3,y3;
    52545313        int numberofpoints;
    5255        
    5256         /*Get points which level set is zero (center of elements with zero level set, levelset_points is serial)*/     
     5314
     5315        /*Get points which level set is zero (center of elements with zero level set, levelset_points is serial)*/
    52575316        this->GetZeroLevelSetPoints(&levelset_points,numberofpoints,levelset_type);
    52585317
     
    52605319      Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
    52615320      int sid = element->Sid();
    5262                 element->GetVerticesCoordinates(&xyz_list); 
     5321                element->GetVerticesCoordinates(&xyz_list);
    52635322                x1 = xyz_list[3*0+0];y1 = xyz_list[3*0+1];
    52645323                x2 = xyz_list[3*1+0];y2 = xyz_list[3*1+1];
     
    52705329                for(int j=0;j<numberofpoints;j++){
    52715330                        distance =sqrt((xc-levelset_points[2*j])*(xc-levelset_points[2*j])+(yc-levelset_points[2*j+1])*(yc-levelset_points[2*j+1]));
    5272                         mindistance=min(distance,mindistance);         
     5331                        mindistance=min(distance,mindistance);
    52735332                }
    52745333                velementdistance->SetValue(sid,mindistance,INS_VAL);
    52755334                xDelete<IssmDouble>(xyz_list);
    5276         }       
     5335        }
    52775336
    52785337   /*Assemble*/
  • issm/trunk-jpl/src/c/classes/FemModel.h

    r22418 r22898  
    11/*
    2  * FemModel.h: 
     2 * FemModel.h:
    33 */
    44
     
    4747                Nodes       *nodes;                //one set of nodes
    4848                Parameters  *parameters;           //one set of parameters, independent of the analysis_type
    49                 Results     *results;              //results that cannot be fit into the elements 
     49                Results     *results;              //results that cannot be fit into the elements
    5050                Vertices    *vertices;             //one set of vertices
    5151
     
    8080                void Solve(void);
    8181
    82                 /*Modules*/ 
     82                /*Modules*/
    8383                void BalancethicknessMisfitx(IssmDouble* pV);
    8484                void CalvingRateVonmisesx();
     
    135135                #endif
    136136                #ifdef _HAVE_ESA_
    137                 void EsaGeodetic2D(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pX, Vector<IssmDouble>* pY, IssmDouble* xx, IssmDouble* yy); 
    138                 void EsaGeodetic3D(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, IssmDouble* xx, IssmDouble* yy, IssmDouble* zz); 
     137                void EsaGeodetic2D(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pX, Vector<IssmDouble>* pY, IssmDouble* xx, IssmDouble* yy);
     138                void EsaGeodetic3D(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, IssmDouble* xx, IssmDouble* yy, IssmDouble* zz);
    139139                #endif
    140140                #ifdef _HAVE_SEALEVELRISE_
     
    142142                void SealevelriseNonEustatic(Vector<IssmDouble>* pSgo, Vector<IssmDouble>* pSg_old, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius,bool verboseconvolution);
    143143                void SealevelriseRotationalFeedback(Vector<IssmDouble>* pSgo_rot, Vector<IssmDouble>* pSg_old, IssmDouble* pIxz, IssmDouble* pIyz, IssmDouble* pIzz, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius);
    144                 void SealevelriseGeodetic(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pSg_old, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, IssmDouble* xx, IssmDouble* yy, IssmDouble* zz); 
     144                void SealevelriseGeodetic(Vector<IssmDouble>* pUp, Vector<IssmDouble>* pNorth, Vector<IssmDouble>* pEast, Vector<IssmDouble>* pSg_old, IssmDouble* latitude, IssmDouble* longitude, IssmDouble* radius, IssmDouble* xx, IssmDouble* yy, IssmDouble* zz);
    145145                IssmDouble SealevelriseOceanAverage(Vector<IssmDouble>* Sg);
    146146                #endif
    147147                void HydrologyEPLupdateDomainx(IssmDouble* pEplcount);
     148                void HydrologyIDSupdateDomainx(IssmDouble* pIDScount);
    148149                void TimeAdaptx(IssmDouble* pdt);
    149150                void UpdateConstraintsExtrudeFromBasex();
  • issm/trunk-jpl/src/c/cores/hydrology_core.cpp

    r22856 r22898  
    1313
    1414        /*intermediary*/
    15         int  hydrology_model;
    16         int  solution_type;
    17         int  numoutputs=0;
    18         bool save_results;
    19         bool modify_loads=true;
    20         char **requested_outputs = NULL;
     15        int                                                     hydrology_model;
     16        int                                                     solution_type;
     17        int                                                     numoutputs                              =       0;
     18        bool                                            save_results;
     19        bool                                            modify_loads                    =       true;
     20        char                                    **requested_outputs = NULL;
     21        IssmDouble                      ThawedNodes;
    2122
    2223        /*first recover parameters common to all solutions*/
     
    4546        else if (hydrology_model==HydrologydcEnum){
    4647                /*intermediary: */
    47                 bool       isefficientlayer;
    48                 int        step,hydroslices;
    49                 IssmDouble time,init_time,hydrotime,yts;
    50                 IssmDouble dt,hydrodt;
     48                bool                            isefficientlayer;
     49                bool                            isthermal;
     50                int                                     step,hydroslices;
     51                IssmDouble      time,init_time,hydrotime,yts;
     52                IssmDouble      dt,hydrodt;
    5153
    5254                femmodel->parameters->FindParam(&isefficientlayer,HydrologydcIsefficientlayerEnum);
     
    5759                femmodel->parameters->FindParam(&yts,ConstantsYtsEnum);
    5860
    59                 init_time = time-dt; //getting the time back to the start of the timestep
    60                 hydrotime=init_time;
    61                 hydrodt=dt/hydroslices; //computing hydro dt from dt and a divider
    62                 femmodel->parameters->AddObject(new DoubleParam(HydrologydtEnum,hydrodt));
    63                 if(hydroslices>1){
    64                         /*define which variable needs to be averaged on the sub-timestep and initialize as needed*/
    65                         if (isefficientlayer){
    66                                 int inputtostack[4]={EffectivePressureHydrostepEnum,SedimentHeadHydrostepEnum,EplHeadHydrostepEnum,HydrologydcEplThicknessHydrostepEnum};
    67                                 int stackedinput[4]={EffectivePressureStackedEnum,SedimentHeadStackedEnum,EplHeadStackedEnum,HydrologydcEplThicknessStackedEnum};
    68                                 int averagedinput[4]={EffectivePressureEnum,SedimentHeadEnum,EplHeadEnum,HydrologydcEplThicknessEnum};
    69                                 femmodel->InitTransientOutputx(&stackedinput[0],4);
    70                                 while(hydrotime<time-(yts*DBL_EPSILON)){ //loop on hydro dts
    71                                         hydrotime+=hydrodt;
    72                                         /*save preceding timestep*/
    73                                         InputDuplicatex(femmodel,SedimentHeadHydrostepEnum,SedimentHeadOldEnum);
     61                femmodel->parameters->FindParam(&isthermal,TransientIsthermalEnum);
     62                /*first we exclude frozen nodes of the solved nodes*/
     63                femmodel->SetCurrentConfiguration(HydrologyDCInefficientAnalysisEnum);
     64                femmodel->HydrologyIDSupdateDomainx(&ThawedNodes);
     65                if(ThawedNodes>0){
     66                        init_time = time-dt; //getting the time back to the start of the timestep
     67                        hydrotime=init_time;
     68                        hydrodt=dt/hydroslices; //computing hydro dt from dt and a divider
     69                        femmodel->parameters->AddObject(new DoubleParam(HydrologydtEnum,hydrodt));
     70                        if(hydroslices>1){
     71                                /*define which variable needs to be averaged on the sub-timestep and initialize as needed*/
     72                                if (isefficientlayer){
     73                                        int inputtostack[4]={EffectivePressureHydrostepEnum,SedimentHeadHydrostepEnum,EplHeadHydrostepEnum,HydrologydcEplThicknessHydrostepEnum};
     74                                        int stackedinput[4]={EffectivePressureStackedEnum,SedimentHeadStackedEnum,EplHeadStackedEnum,HydrologydcEplThicknessStackedEnum};
     75                                        int averagedinput[4]={EffectivePressureEnum,SedimentHeadEnum,EplHeadEnum,HydrologydcEplThicknessEnum};
     76                                        femmodel->InitTransientOutputx(&stackedinput[0],4);
     77                                        while(hydrotime<time-(yts*DBL_EPSILON)){ //loop on hydro dts
     78                                                hydrotime+=hydrodt;
     79                                                /*save preceding timestep*/
     80                                                InputDuplicatex(femmodel,SedimentHeadHydrostepEnum,SedimentHeadOldEnum);
     81                                                InputDuplicatex(femmodel,EplHeadHydrostepEnum,EplHeadOldEnum);
     82                                                InputDuplicatex(femmodel,HydrologydcEplThicknessHydrostepEnum,HydrologydcEplThicknessOldEnum);
     83                                                /*Proceed now to heads computations*/
     84                                                solutionsequence_hydro_nonlinear(femmodel);
     85                                                /*If we have a sub-timestep we stack the variables here*/
     86                                                femmodel->StackTransientOutputx(&inputtostack[0],&stackedinput[0],hydrotime,4);
     87                                        }
     88                                        femmodel->AverageTransientOutputx(&stackedinput[0],&averagedinput[0],init_time,4);
     89                                }
     90                                else{
     91                                        int inputtostack[2]={EffectivePressureHydrostepEnum,SedimentHeadHydrostepEnum};
     92                                        int stackedinput[2]={EffectivePressureStackedEnum,SedimentHeadStackedEnum};
     93                                        int averagedinput[2]={EffectivePressureEnum,SedimentHeadEnum};
     94                                        femmodel->InitTransientOutputx(&stackedinput[0],2);
     95                                        while(hydrotime<time-(yts*DBL_EPSILON)){ //loop on hydro dts
     96                                                hydrotime+=hydrodt;
     97                                                /*save preceding timestep*/
     98                                                InputDuplicatex(femmodel,SedimentHeadHydrostepEnum,SedimentHeadOldEnum);
     99                                                /*Proceed now to heads computations*/
     100                                                solutionsequence_hydro_nonlinear(femmodel);
     101                                                /*If we have a sub-timestep we stack the variables here*/
     102                                                femmodel->StackTransientOutputx(&inputtostack[0],&stackedinput[0],hydrotime,2);
     103                                        }
     104                                        femmodel->AverageTransientOutputx(&stackedinput[0],&averagedinput[0],init_time,2);
     105                                }
     106                        }
     107                        else{
     108                                InputDuplicatex(femmodel,SedimentHeadHydrostepEnum,SedimentHeadOldEnum);
     109                                if (isefficientlayer){
    74110                                        InputDuplicatex(femmodel,EplHeadHydrostepEnum,EplHeadOldEnum);
    75111                                        InputDuplicatex(femmodel,HydrologydcEplThicknessHydrostepEnum,HydrologydcEplThicknessOldEnum);
    76                                         /*Proceed now to heads computations*/
    77                                         solutionsequence_hydro_nonlinear(femmodel);
    78                                         /*If we have a sub-timestep we stack the variables here*/
    79                                         femmodel->StackTransientOutputx(&inputtostack[0],&stackedinput[0],hydrotime,4);
    80112                                }
    81                                 femmodel->AverageTransientOutputx(&stackedinput[0],&averagedinput[0],init_time,4);
     113                                /*Proceed now to heads computations*/
     114                                solutionsequence_hydro_nonlinear(femmodel);
    82115                        }
    83                         else{
    84                                 int inputtostack[2]={EffectivePressureHydrostepEnum,SedimentHeadHydrostepEnum};
    85                                 int stackedinput[2]={EffectivePressureStackedEnum,SedimentHeadStackedEnum};
    86                                 int averagedinput[2]={EffectivePressureEnum,SedimentHeadEnum};
    87                                 femmodel->InitTransientOutputx(&stackedinput[0],2);
    88                                 while(hydrotime<time-(yts*DBL_EPSILON)){ //loop on hydro dts
    89                                         hydrotime+=hydrodt;
    90                                         /*save preceding timestep*/
    91                                         InputDuplicatex(femmodel,SedimentHeadHydrostepEnum,SedimentHeadOldEnum);
    92                                         /*Proceed now to heads computations*/
    93                                         solutionsequence_hydro_nonlinear(femmodel);
    94                                         /*If we have a sub-timestep we stack the variables here*/
    95                                         femmodel->StackTransientOutputx(&inputtostack[0],&stackedinput[0],hydrotime,2);
    96                                 }
    97                                 femmodel->AverageTransientOutputx(&stackedinput[0],&averagedinput[0],init_time,2);
    98                         }
    99                 }
    100                 else{
    101                         InputDuplicatex(femmodel,SedimentHeadHydrostepEnum,SedimentHeadOldEnum);
    102                         if (isefficientlayer){
    103                                 InputDuplicatex(femmodel,EplHeadHydrostepEnum,EplHeadOldEnum);
    104                                 InputDuplicatex(femmodel,HydrologydcEplThicknessHydrostepEnum,HydrologydcEplThicknessOldEnum);
    105                         }
    106                         /*Proceed now to heads computations*/
    107                         solutionsequence_hydro_nonlinear(femmodel);
    108116                }
    109117        }
    110118        else if (hydrology_model==HydrologysommersEnum){
    111119                femmodel->SetCurrentConfiguration(HydrologySommersAnalysisEnum);
    112       InputDuplicatex(femmodel,HydrologyHeadEnum,HydrologyHeadOldEnum);
     120                InputDuplicatex(femmodel,HydrologyHeadEnum,HydrologyHeadOldEnum);
    113121                solutionsequence_shakti_nonlinear(femmodel);
    114122                if(VerboseSolution()) _printf0_("   updating gap height\n");
     
    122130        if(save_results){
    123131                if(VerboseSolution()) _printf0_("   saving results \n");
    124                 femmodel->RequestedOutputsx(&femmodel->results,requested_outputs,numoutputs);
     132                if(hydrology_model==HydrologydcEnum && ThawedNodes==0){
     133                        if(VerboseSolution()) _printf0_("   No thawed node hydro is skiped \n");}
     134                else{
     135                        femmodel->RequestedOutputsx(&femmodel->results,requested_outputs,numoutputs);
     136                }
    125137        }
    126138        /*Free ressources:*/
  • issm/trunk-jpl/src/c/cores/transient_core.cpp

    r22848 r22898  
    11/*!\file: transient_3d_core.cpp
    2  * \brief: core of the transient_3d solution 
    3  */ 
     2 * \brief: core of the transient_3d solution
     3 */
    44
    55#ifdef HAVE_CONFIG_H
     
    142142                        InterpFromMeshToMesh2dx(&base_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice,
    143143                                                        icebase,ngrids_ice,1,
    144                                                         oceangridx,oceangridy,ngrids_ocean,options);   
     144                                                        oceangridx,oceangridy,ngrids_ocean,options);
    145145                        delete options;
    146146
     
    239239                                int         ngrids_ice=femmodel->vertices->NumberOfVertices();
    240240                                int         nels_ice=femmodel->elements->NumberOfElements();
    241                                
     241
    242242                                /*Recover mesh and inputs needed*/
    243243                                femmodel->parameters->FindParam(&rho_ice,MaterialsRhoIceEnum);
     
    253253                                InterpFromMeshToMesh2dx(&base_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice,
    254254                                                        icebase,ngrids_ice,1,
    255                                                         oceangridx,oceangridy,ngrids_ocean,NULL);   
    256                                
     255                                                        oceangridx,oceangridy,ngrids_ocean,NULL);
     256
    257257                                /*Send and receive data*/
    258258                                ISSM_MPI_Send(&time,1,ISSM_MPI_DOUBLE,0,10001001,tomitgcmcomm);
     
    267267                                InterpFromMeshToMesh2dx(&melt_mesh,index_ocean,oceangridx,oceangridy,ngrids_ocean,nels_ocean,
    268268                                                        oceanmelt,ngrids_ocean,1,
    269                                                         lon_ice,lat_ice,ngrids_ice,NULL);   
     269                                                        lon_ice,lat_ice,ngrids_ice,NULL);
    270270
    271271                                for(int i=0;i<ngrids_ice;i++) melt_mesh[i]=-melt_mesh[i]/rho_ice; //heat flux provided by ocean is in kg/m^2/s
     
    293293                /*}}}*/
    294294
    295                 if(isthermal && domaintype==Domain3DEnum){ 
     295                if(isthermal && domaintype==Domain3DEnum){
    296296                        if(issmb){
    297297                                bool isenthalpy;
     
    327327                        femmodel->UpdateVertexPositionsx();
    328328                }
    329                
     329
    330330                if(isgroundingline){
    331331                        if(VerboseSolution()) _printf0_("   computing new grounding line position\n");
     
    338338                        femmodel->parameters->SetParam(SurfaceEnum,InputToExtrudeEnum);
    339339                        extrudefrombase_core(femmodel);
    340                                
     340
    341341                        if(save_results){
    342342                                int outputs[3] = {SurfaceEnum,BaseEnum,MaskGroundediceLevelsetEnum};
     
    356356                /*esa: */
    357357                if(isesa) esa_core(femmodel);
    358                
     358
    359359                /*Sea level rise: */
    360360                if(isslr || iscoupler) sealevelrise_core(femmodel);
     
    367367                        femmodel->RequestedOutputsx(&femmodel->results,&outputs[0],1,save_results);
    368368                }
    369                
     369
    370370                if(save_results){
    371371                        if(VerboseSolution()) _printf0_("   saving temporary results\n");
     
    402402                        }
    403403        }
    404        
     404
    405405        if(!iscontrol || !isautodiff) femmodel->RequestedDependentsx();
    406406        if(iscontrol && isautodiff) femmodel->parameters->SetParam(dependent_objects,AutodiffDependentObjectsEnum);
    407407
    408         /*Free ressources:*/   
     408        /*Free ressources:*/
    409409        if(numoutputs){for(int i=0;i<numoutputs;i++){xDelete<char>(requested_outputs[i]);} xDelete<char*>(requested_outputs);}
    410410}
  • issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h

    r22856 r22898  
    441441        HydrologydcMaskEplactiveEltEnum,
    442442        HydrologydcMaskEplactiveNodeEnum,
     443        HydrologydcMaskThawedEltEnum,
     444        HydrologydcMaskThawedNodeEnum,
    443445        HydrologydcSedimentTransmitivityEnum,
    444446        HydrologyEnglacialInputEnum,
  • issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp

    r22856 r22898  
    447447                case HydrologydcMaskEplactiveEltEnum : return "HydrologydcMaskEplactiveElt";
    448448                case HydrologydcMaskEplactiveNodeEnum : return "HydrologydcMaskEplactiveNode";
     449                case HydrologydcMaskThawedEltEnum : return "HydrologydcMaskThawedElt";
     450                case HydrologydcMaskThawedNodeEnum : return "HydrologydcMaskThawedNode";
    449451                case HydrologydcSedimentTransmitivityEnum : return "HydrologydcSedimentTransmitivity";
    450452                case HydrologyEnglacialInputEnum : return "HydrologyEnglacialInput";
  • issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp

    r22856 r22898  
    456456              else if (strcmp(name,"HydrologydcMaskEplactiveElt")==0) return HydrologydcMaskEplactiveEltEnum;
    457457              else if (strcmp(name,"HydrologydcMaskEplactiveNode")==0) return HydrologydcMaskEplactiveNodeEnum;
     458              else if (strcmp(name,"HydrologydcMaskThawedElt")==0) return HydrologydcMaskThawedEltEnum;
     459              else if (strcmp(name,"HydrologydcMaskThawedNode")==0) return HydrologydcMaskThawedNodeEnum;
    458460              else if (strcmp(name,"HydrologydcSedimentTransmitivity")==0) return HydrologydcSedimentTransmitivityEnum;
    459461              else if (strcmp(name,"HydrologyEnglacialInput")==0) return HydrologyEnglacialInputEnum;
     
    504506              else if (strcmp(name,"Pressure")==0) return PressureEnum;
    505507              else if (strcmp(name,"RheologyBAbsGradient")==0) return RheologyBAbsGradientEnum;
    506               else if (strcmp(name,"RheologyBbarAbsGradient")==0) return RheologyBbarAbsGradientEnum;
    507               else if (strcmp(name,"Sealevel")==0) return SealevelEnum;
    508508         else stage=5;
    509509   }
    510510   if(stage==5){
    511               if (strcmp(name,"SealevelriseDeltathickness")==0) return SealevelriseDeltathicknessEnum;
     511              if (strcmp(name,"RheologyBbarAbsGradient")==0) return RheologyBbarAbsGradientEnum;
     512              else if (strcmp(name,"Sealevel")==0) return SealevelEnum;
     513              else if (strcmp(name,"SealevelriseDeltathickness")==0) return SealevelriseDeltathicknessEnum;
    512514              else if (strcmp(name,"SedimentHeadHydrostep")==0) return SedimentHeadHydrostepEnum;
    513515              else if (strcmp(name,"SedimentHeadOld")==0) return SedimentHeadOldEnum;
     
    627629              else if (strcmp(name,"VzMesh")==0) return VzMeshEnum;
    628630              else if (strcmp(name,"VzSSA")==0) return VzSSAEnum;
    629               else if (strcmp(name,"Watercolumn")==0) return WatercolumnEnum;
    630               else if (strcmp(name,"WaterColumnOld")==0) return WaterColumnOldEnum;
    631631         else stage=6;
    632632   }
    633633   if(stage==6){
    634               if (strcmp(name,"WaterfractionDrainage")==0) return WaterfractionDrainageEnum;
     634              if (strcmp(name,"Watercolumn")==0) return WatercolumnEnum;
     635              else if (strcmp(name,"WaterColumnOld")==0) return WaterColumnOldEnum;
     636              else if (strcmp(name,"WaterfractionDrainage")==0) return WaterfractionDrainageEnum;
    635637              else if (strcmp(name,"WaterfractionDrainageIntegrated")==0) return WaterfractionDrainageIntegratedEnum;
    636638              else if (strcmp(name,"Waterfraction")==0) return WaterfractionEnum;
     
    750752              else if (strcmp(name,"FSpressure")==0) return FSpressureEnum;
    751753              else if (strcmp(name,"FSSolver")==0) return FSSolverEnum;
    752               else if (strcmp(name,"FSvelocity")==0) return FSvelocityEnum;
    753               else if (strcmp(name,"GaussPenta")==0) return GaussPentaEnum;
    754754         else stage=7;
    755755   }
    756756   if(stage==7){
    757               if (strcmp(name,"GaussSeg")==0) return GaussSegEnum;
     757              if (strcmp(name,"FSvelocity")==0) return FSvelocityEnum;
     758              else if (strcmp(name,"GaussPenta")==0) return GaussPentaEnum;
     759              else if (strcmp(name,"GaussSeg")==0) return GaussSegEnum;
    758760              else if (strcmp(name,"GaussTetra")==0) return GaussTetraEnum;
    759761              else if (strcmp(name,"GaussTria")==0) return GaussTriaEnum;
     
    873875              else if (strcmp(name,"MaxAbsVz")==0) return MaxAbsVzEnum;
    874876              else if (strcmp(name,"MaxDivergence")==0) return MaxDivergenceEnum;
    875               else if (strcmp(name,"MaxVel")==0) return MaxVelEnum;
    876               else if (strcmp(name,"MaxVx")==0) return MaxVxEnum;
    877877         else stage=8;
    878878   }
    879879   if(stage==8){
    880               if (strcmp(name,"MaxVy")==0) return MaxVyEnum;
     880              if (strcmp(name,"MaxVel")==0) return MaxVelEnum;
     881              else if (strcmp(name,"MaxVx")==0) return MaxVxEnum;
     882              else if (strcmp(name,"MaxVy")==0) return MaxVyEnum;
    881883              else if (strcmp(name,"MaxVz")==0) return MaxVzEnum;
    882884              else if (strcmp(name,"Melange")==0) return MelangeEnum;
     
    996998              else if (strcmp(name,"Outputdefinition88")==0) return Outputdefinition88Enum;
    997999              else if (strcmp(name,"Outputdefinition89")==0) return Outputdefinition89Enum;
    998               else if (strcmp(name,"Outputdefinition8")==0) return Outputdefinition8Enum;
    999               else if (strcmp(name,"Outputdefinition90")==0) return Outputdefinition90Enum;
    10001000         else stage=9;
    10011001   }
    10021002   if(stage==9){
    1003               if (strcmp(name,"Outputdefinition91")==0) return Outputdefinition91Enum;
     1003              if (strcmp(name,"Outputdefinition8")==0) return Outputdefinition8Enum;
     1004              else if (strcmp(name,"Outputdefinition90")==0) return Outputdefinition90Enum;
     1005              else if (strcmp(name,"Outputdefinition91")==0) return Outputdefinition91Enum;
    10041006              else if (strcmp(name,"Outputdefinition92")==0) return Outputdefinition92Enum;
    10051007              else if (strcmp(name,"Outputdefinition93")==0) return Outputdefinition93Enum;
     
    11191121              else if (strcmp(name,"TotalSmbScaled")==0) return TotalSmbScaledEnum;
    11201122              else if (strcmp(name,"TransientArrayParam")==0) return TransientArrayParamEnum;
    1121               else if (strcmp(name,"TransientInput")==0) return TransientInputEnum;
    1122               else if (strcmp(name,"TransientParam")==0) return TransientParamEnum;
    11231123         else stage=10;
    11241124   }
    11251125   if(stage==10){
    1126               if (strcmp(name,"TransientSolution")==0) return TransientSolutionEnum;
     1126              if (strcmp(name,"TransientInput")==0) return TransientInputEnum;
     1127              else if (strcmp(name,"TransientParam")==0) return TransientParamEnum;
     1128              else if (strcmp(name,"TransientSolution")==0) return TransientSolutionEnum;
    11271129              else if (strcmp(name,"Tria")==0) return TriaEnum;
    11281130              else if (strcmp(name,"TriaInput")==0) return TriaInputEnum;
  • issm/trunk-jpl/src/c/solutionsequences/solutionsequence_hydro_nonlinear.cpp

    r22551 r22898  
    11/*!\file: solutionsequence_hydro_nonlinear.cpp
    2  * \brief: core of the hydro solution 
    3  */ 
     2 * \brief: core of the hydro solution
     3 */
    44
    55#include "../toolkits/toolkits.h"
     
    1212void solutionsequence_hydro_nonlinear(FemModel* femmodel){
    1313        /*solution : */
    14         Vector<IssmDouble>* ug_sed=NULL; 
    15         Vector<IssmDouble>* uf_sed=NULL; 
    16         Vector<IssmDouble>* uf_sed_sub_iter=NULL; 
     14        Vector<IssmDouble>* ug_sed=NULL;
     15        Vector<IssmDouble>* uf_sed=NULL;
     16        Vector<IssmDouble>* uf_sed_sub_iter=NULL;
    1717        Vector<IssmDouble>* ug_sed_main_iter=NULL;
    1818
    19         Vector<IssmDouble>* ug_epl=NULL; 
     19        Vector<IssmDouble>* ug_epl=NULL;
    2020        Vector<IssmDouble>* uf_epl=NULL;
    21         Vector<IssmDouble>* uf_epl_sub_iter=NULL; 
     21        Vector<IssmDouble>* uf_epl_sub_iter=NULL;
    2222        Vector<IssmDouble>* ug_epl_sub_iter=NULL;
    2323        Vector<IssmDouble>* ug_epl_main_iter=NULL;
    2424
    25         Vector<IssmDouble>* ys=NULL; 
     25        Vector<IssmDouble>* ys=NULL;
    2626        Vector<IssmDouble>* dug=NULL;
    2727        Vector<IssmDouble>* duf=NULL;
     
    3535        HydrologyDCInefficientAnalysis* inefanalysis = NULL;
    3636        HydrologyDCEfficientAnalysis* effanalysis = NULL;
    37        
     37
    3838        bool       sedconverged,eplconverged,hydroconverged;
    3939        bool       isefficientlayer;
     
    5858
    5959        /*Retrieve inputs as the initial state for the non linear iteration*/
    60         GetSolutionFromInputsx(&ug_sed,femmodel);       
     60        GetSolutionFromInputsx(&ug_sed,femmodel);
    6161        Reducevectorgtofx(&uf_sed, ug_sed, femmodel->nodes,femmodel->parameters);
     62        /*Initialize the thawed element mask*/
    6263        if(isefficientlayer) {
    6364                inefanalysis = new HydrologyDCInefficientAnalysis();
     
    8788                InputUpdateFromConstantx(femmodel,false,ConvergedEnum);
    8889                femmodel->UpdateConstraintsx();
    89                
     90
    9091                /*Reset constraint on the ZigZag Lock*/
    9192                ResetConstraintsx(femmodel);
     
    126127                                if(sedconverged)break;
    127128                        }
    128                
     129
    129130                        /*}}}*//*End of the sediment penalization loop*/
    130131                        sedconverged=false;
    131                        
     132
    132133                        /*Checking convegence on the value of the sediment head*/
    133134                        duf=uf_sed_sub_iter->Duplicate();_assert_(duf);
     
    184185                                inefanalysis->ElementizeEplMask(femmodel);
    185186                                /*}}}*/
    186                                        
     187
    187188                                if(VerboseSolution()) _printf0_("Building EPL Matrix...\n");
    188189                                SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
     
    197198                                uf_epl_sub_iter=uf_epl->Duplicate();
    198199                                uf_epl->Copy(uf_epl_sub_iter);
    199                                 delete ug_epl; 
     200                                delete ug_epl;
    200201                                Mergesolutionfromftogx(&ug_epl,uf_epl,ys,femmodel->nodes,femmodel->parameters); delete ys;
    201202                                InputUpdateFromSolutionx(femmodel,ug_epl);
    202203                                ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
    203                                                
     204
    204205                                dug=ug_epl_sub_iter->Duplicate();_assert_(dug);
    205206                                ug_epl_sub_iter->Copy(dug);
     
    218219                                /* if(ThickCount<L2Count)eplconverged=true; */
    219220                                eplcount++;
    220                                
     221
    221222                                delete ug_epl_sub_iter;
    222223                                if(eplconverged){
     
    235236                        //compute norm(du)/norm(u)
    236237                        dug=ug_sed_main_iter->Duplicate(); _assert_(dug);
    237                         ug_sed_main_iter->Copy(dug);   
     238                        ug_sed_main_iter->Copy(dug);
    238239                        dug->AYPX(ug_sed,-1.0);
    239                         ndu_sed=dug->Norm(NORM_TWO); 
     240                        ndu_sed=dug->Norm(NORM_TWO);
    240241                        delete dug;
    241242                        nu_sed=ug_sed_main_iter->Norm(NORM_TWO);
     
    243244                        if (xIsNan<IssmDouble>(ndu_sed) || xIsNan<IssmDouble>(nu_sed)) _error_("Sed convergence criterion is NaN!");
    244245                        if (ndu_sed==0.0 && nu_sed==0.0) nu_sed=1.0e-6; /*Hacking the case where the Sediment is used but empty*/
    245                         dug=ug_epl_main_iter->Duplicate();_assert_(dug); 
    246                         ug_epl_main_iter->Copy(dug); 
     246                        dug=ug_epl_main_iter->Duplicate();_assert_(dug);
     247                        ug_epl_main_iter->Copy(dug);
    247248                        dug->AYPX(ug_epl,-1.0);
    248                         ndu_epl=dug->Norm(NORM_TWO); 
     249                        ndu_epl=dug->Norm(NORM_TWO);
    249250                        delete dug;
    250251                        nu_epl=ug_epl_main_iter->Norm(NORM_TWO);
     
    257258                                        hydroconverged=true;
    258259                                }
    259                                 else{ 
     260                                else{
    260261                                        if(VerboseConvergence()) _printf0_(setw(50) << left << "   Sediment Convergence criterion:" << ndu_sed/nu_sed*100 << "%, aiming lower than " << eps_hyd*100 << " %\n");
    261262                                        if(VerboseConvergence()) _printf0_(setw(50) << left << "   EPL Convergence criterion:" << ndu_epl/nu_epl*100 << "%, aiming lower than " << eps_hyd*100 << " %\n");
Note: See TracChangeset for help on using the changeset viewer.