Ignore:
Timestamp:
06/07/17 10:50:54 (8 years ago)
Author:
Eric.Larour
Message:

CHG: merged branch back to trunk-jpl 21754.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-NatGeoScience2016/src/c/analyses/HydrologyDCEfficientAnalysis.cpp

    r21233 r21759  
    99        return 1;
    1010}/*}}}*/
     11
    1112void HydrologyDCEfficientAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
    1213
     
    3334        iomodel->FetchData(&eplthickcomp,"md.hydrology.epl_thick_comp");
    3435        parameters->AddObject(new IntParam(HydrologydcEplThickCompEnum,eplthickcomp));
    35 
    36        
    37 }/*}}}*/
     36}/*}}}*/
     37
    3838void HydrologyDCEfficientAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
    3939
     
    8383        if(!isefficientlayer) return;
    8484
    85         if(iomodel->domaintype!=Domain2DhorizontalEnum) iomodel->FetchData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
     85        if(iomodel->domaintype!=Domain2DhorizontalEnum){
     86                iomodel->FetchData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
     87        }
    8688        ::CreateNodes(nodes,iomodel,HydrologyDCEfficientAnalysisEnum,P1Enum);
    8789        iomodel->DeleteData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
     
    104106
    105107void HydrologyDCEfficientAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
    106         /*Nothing for now*/
    107 
    108         /*Fetch parameters: */
     108
     109        /*Do we really want DC?*/
    109110        int hydrology_model;
    110111        iomodel->FindConstant(&hydrology_model,"md.hydrology.model");
    111112        if(hydrology_model!=HydrologydcEnum) return;
    112113
    113         if(iomodel->domaintype==Domain3DEnum) iomodel->FetchData(1,"md.mesh.vertexonbase");
    114 
    115         //create penalties for nodes: no node can have water above the max
     114        /*Do we want an efficient layer*/
     115        bool isefficientlayer;
     116        iomodel->FindConstant(&isefficientlayer,"md.hydrology.isefficientlayer");
     117        if(!isefficientlayer) return;
     118
     119        /*Fetch parameters: */
     120        if(iomodel->domaintype==Domain3DEnum){
     121                iomodel->FetchData(1,"md.mesh.vertexonbase");
     122        }
     123
     124        //Add moulin inputs as loads
    116125        CreateSingleNodeToElementConnectivity(iomodel);
    117126        for(int i=0;i<iomodel->numberofvertices;i++){
     
    132141
    133142void HydrologyDCEfficientAnalysis::InitZigZagCounter(FemModel* femmodel){/*{{{*/
     143
    134144        int*   eplzigzag_counter =NULL;
    135        
    136145        eplzigzag_counter=xNewZeroInit<int>(femmodel->nodes->Size());
    137146        femmodel->parameters->AddObject(new IntVecParam(EplZigZagCounterEnum,eplzigzag_counter,femmodel->nodes->Size()));
     
    142151
    143152        int*     eplzigzag_counter=NULL;
    144         Element* element=NULL;
    145 
    146153        femmodel->parameters->FindParam(&eplzigzag_counter,NULL,EplZigZagCounterEnum);
    147154        for(int i=0;i<femmodel->nodes->Size();i++){
    148 
    149155                eplzigzag_counter[i]=0;
    150156        }
     
    201207        /* Intermediaries */
    202208        IssmDouble  D_scalar,Jdet,dt;
    203         IssmDouble  epl_thickness;
    204209        IssmDouble  transfer;
     210        IssmDouble  epl_transmitivity;
     211        IssmDouble  epl_storing;
    205212        IssmDouble *xyz_list = NULL;
    206213
     
    219226
    220227        Input* epl_thick_input = basalelement->GetInput(HydrologydcEplThicknessEnum); _assert_(epl_thick_input);
    221         Input* sed_head_input  = basalelement->GetInput(SedimentHeadEnum);
    222         Input* epl_head_input  = basalelement->GetInput(EplHeadEnum);
    223         Input* thick_input     = basalelement->GetInput(ThicknessEnum);
    224         Input* base_input      = basalelement->GetInput(BaseEnum);
    225 
    226         IssmDouble epl_specificstoring   = EplSpecificStoring(basalelement);
    227         IssmDouble epl_conductivity      = basalelement->GetMaterialParameter(HydrologydcEplConductivityEnum);
     228        Input* epl_head_input   = basalelement->GetInput(EplHeadEnum);  _assert_(epl_head_input);
     229        Input* base_input                       = basalelement->GetInput(BaseEnum); _assert_(base_input);
    228230
    229231        /* Start  looping on the number of gaussian points: */
    230         Gauss* gauss=basalelement->NewGauss(2);
     232        Gauss* gauss                                    = basalelement->NewGauss(2);
    231233        for(int ig=gauss->begin();ig<gauss->end();ig++){
    232234                gauss           ->GaussPoint(ig);
    233235                basalelement    ->JacobianDeterminant(&Jdet,xyz_list,gauss);
    234                 epl_thick_input ->GetInputValue(&epl_thickness,gauss);
     236               
     237                epl_transmitivity = EplTransmitivity(basalelement,gauss,epl_thick_input,epl_head_input,base_input);
     238                epl_storing                             = EplStoring(basalelement,gauss,epl_thick_input,epl_head_input,base_input);
    235239
    236240                /*Diffusivity*/
    237                 D_scalar=epl_conductivity*epl_thickness*gauss->weight*Jdet;
     241                D_scalar=epl_transmitivity*gauss->weight*Jdet;
    238242                if(dt!=0.) D_scalar=D_scalar*dt;
    239243                D[0][0]=D_scalar;
     
    248252                if(dt!=0.){
    249253                        basalelement->NodalFunctions(&basis[0],gauss);
    250                         D_scalar=epl_specificstoring*epl_thickness*gauss->weight*Jdet;
     254                        D_scalar=epl_storing*gauss->weight*Jdet;
    251255                        TripleMultiply(basis,numnodes,1,0,
    252256                                                &D_scalar,1,1,0,
     
    256260                       
    257261                        /*Transfer EPL part*/
    258                         transfer=GetHydrologyKMatrixTransfer(basalelement,gauss,sed_head_input,epl_head_input,thick_input,base_input);
     262                        transfer=GetHydrologyKMatrixTransfer(basalelement);
    259263                        D_scalar=dt*transfer*gauss->weight*Jdet;
    260264                        TripleMultiply(basis,numnodes,1,0,
     
    299303        /*Check that all nodes are active, else return empty matrix*/
    300304        if(!active_element) {
    301         if(domaintype!=Domain2DhorizontalEnum){
     305                if(domaintype!=Domain2DhorizontalEnum){
    302306                        basalelement->DeleteMaterials();
    303307                        delete basalelement;
     
    308312        IssmDouble dt,scalar,water_head;
    309313        IssmDouble water_load,transfer;
    310         IssmDouble epl_thickness;
     314        IssmDouble epl_storing;
    311315        IssmDouble Jdet;
    312316        IssmDouble residual,connectivity;
     
    328332
    329333        Input* epl_thick_input = basalelement->GetInput(HydrologydcEplThicknessEnum); _assert_(epl_thick_input);
    330         Input* sed_head_input  = basalelement->GetInput(SedimentHeadEnum);
    331         Input* epl_head_input  = basalelement->GetInput(EplHeadEnum);
    332         Input* thick_input     = basalelement->GetInput(ThicknessEnum);
    333         Input* base_input      = basalelement->GetInput(BaseEnum);
     334        Input* sed_head_input  = basalelement->GetInput(SedimentHeadEnum); _assert_(sed_head_input);
     335        Input* epl_head_input    = basalelement->GetInput(EplHeadEnum); _assert_(epl_head_input);
    334336        Input* water_input               = basalelement->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(water_input);
    335         Input* residual_input  = basalelement->GetInput(SedimentHeadResidualEnum);    _assert_(residual_input);
    336         if(dt!= 0.){old_wh_input = basalelement->GetInput(EplHeadOldEnum);            _assert_(old_wh_input);}
    337 
    338         IssmDouble epl_specificstoring = EplSpecificStoring(basalelement);
    339 
     337        Input* residual_input  = basalelement->GetInput(SedimentHeadResidualEnum); _assert_(residual_input);
     338        Input* base_input                        = basalelement->GetInput(BaseEnum); _assert_(base_input);
     339
     340        if(dt!= 0.){
     341                old_wh_input = basalelement->GetInput(EplHeadOldEnum);            _assert_(old_wh_input);
     342        }
    340343        /* Start  looping on the number of gaussian points: */
    341         Gauss* gauss=basalelement->NewGauss(2);
     344        Gauss* gauss           = basalelement->NewGauss(2);
    342345        for(int ig=gauss->begin();ig<gauss->end();ig++){
    343346                gauss->GaussPoint(ig);
    344 
    345347                basalelement ->JacobianDeterminant(&Jdet,xyz_list,gauss);
    346348                basalelement ->NodalFunctions(basis,gauss);
    347 
     349                epl_storing     = EplStoring(basalelement,gauss,epl_thick_input,epl_head_input,base_input);
    348350                /*Loading term*/
    349351                water_input->GetInputValue(&water_load,gauss);
    350352                scalar = Jdet*gauss->weight*(water_load);
    351353                if(dt!=0.) scalar = scalar*dt;
    352                 for(int i=0;i<numnodes;i++){
    353                         pe->values[i]+=scalar*basis[i];
    354                 }
     354                for(int i=0;i<numnodes;i++)pe->values[i]+=scalar*basis[i];
    355355               
    356356                /*Transient and transfer terms*/
    357357                if(dt!=0.){
    358                         old_wh_input    ->GetInputValue(&water_head,gauss);
    359                         epl_thick_input ->GetInputValue(&epl_thickness,gauss);
    360                        
     358                        old_wh_input->GetInputValue(&water_head,gauss);
    361359                        /*Dealing with the epl part of the transfer term*/
    362                         transfer=GetHydrologyPVectorTransfer(basalelement,gauss,sed_head_input,epl_head_input,thick_input,base_input);
    363                         scalar = Jdet*gauss->weight*((water_head*epl_specificstoring*epl_thickness)+(dt*transfer));
     360                        transfer=GetHydrologyPVectorTransfer(basalelement,gauss,sed_head_input);
     361                        scalar = Jdet*gauss->weight*((water_head*epl_storing)+(dt*transfer));
    364362                        for(int i=0;i<numnodes;i++)pe->values[i]+=scalar*basis[i];
    365363                }
     
    371369        for(int iv=0;iv<numvertices;iv++){
    372370                gauss->GaussVertex(iv);
    373 
    374371                connectivity = IssmDouble(basalelement->VertexConnectivity(iv));
    375372                residual_input->GetInputValue(&residual,gauss);
    376373                pe->values[iv]+=residual/connectivity;
    377 
    378         }
    379 
     374        }
    380375        /*Clean up and return*/
    381376        xDelete<IssmDouble>(xyz_list);
     
    395390
    396391void HydrologyDCEfficientAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
    397 
    398         bool active_element;
    399         int domaintype,i;
    400         Element*   basalelement=NULL;
    401 
     392        /*Intermediaries*/
     393        bool     active_element;
     394        int      domaintype;
     395        Element* basalelement=NULL;
     396
     397        /*Get basal element*/
    402398        element->FindParam(&domaintype,DomainTypeEnum);
    403 
    404         if(domaintype!=Domain2DhorizontalEnum){
    405                 if(!element->IsOnBase()) return;
    406                 basalelement=element->SpawnBasalElement();
    407         }
    408         else{
    409                 basalelement = element;
    410         }
    411        
     399        switch(domaintype){
     400                case Domain2DhorizontalEnum:
     401                        basalelement = element;
     402                        break;
     403                case Domain3DEnum:
     404                        if(!element->IsOnBase()) return;
     405                        basalelement = element->SpawnBasalElement();
     406                        break;
     407                default: _error_("mesh "<<EnumToStringx(domaintype)<<" not supported yet");
     408        }
    412409        /*Intermediary*/
    413410        int* doflist = NULL;
     
    417414
    418415        /*Fetch dof list and allocate solution vector*/
    419         IssmDouble* sedhead     = xNew<IssmDouble>(numnodes);
    420416        IssmDouble* eplHeads    = xNew<IssmDouble>(numnodes);
    421 
    422417        basalelement->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
    423         basalelement->GetInputListOnVertices(&sedhead[0],SedimentHeadEnum);
    424418
    425419        Input* active_element_input=basalelement->GetInput(HydrologydcMaskEplactiveEltEnum); _assert_(active_element_input);
     
    427421
    428422        /*Use the dof list to index into the solution vector: */
    429         for(i=0;i<numnodes;i++){
    430                 eplHeads[i]=solution[doflist[i]];
    431                 if(xIsNan<IssmDouble>(eplHeads[i])) _error_("NaN found in solution vector");
    432                 if(xIsInf<IssmDouble>(eplHeads[i])) _error_("Inf found in solution vector");
     423        /*If the EPL is not active we revert to the bedrock elevation*/
     424        if(active_element){
     425                for(int i=0;i<numnodes;i++){
     426                        eplHeads[i]=solution[doflist[i]];
     427                        if(xIsNan<IssmDouble>(eplHeads[i])) _error_("NaN found in solution vector");
     428                        if(xIsInf<IssmDouble>(eplHeads[i])) _error_("Inf found in solution vector");
     429                }
     430        }
     431        else{
     432                basalelement->GetInputListOnVertices(&eplHeads[0],BaseEnum);
     433                for(int i=0;i<numnodes;i++){
     434                        if(xIsNan<IssmDouble>(eplHeads[i])) _error_("NaN found in solution vector");
     435                        if(xIsInf<IssmDouble>(eplHeads[i])) _error_("Inf found in solution vector");
     436                }
    433437        }
    434438        /*Add input to the element: */
    435439        element->AddBasalInput(EplHeadEnum,eplHeads,P1Enum);
    436 
    437440        /*Free ressources:*/
    438441        xDelete<IssmDouble>(eplHeads);
    439         xDelete<IssmDouble>(sedhead);
    440442        xDelete<int>(doflist);
    441443        if(domaintype!=Domain2DhorizontalEnum){basalelement->DeleteMaterials(); delete basalelement;};
     
    448450
    449451/*Intermediaries*/
    450 IssmDouble HydrologyDCEfficientAnalysis::EplSpecificStoring(Element* element){/*{{{*/
    451         IssmDouble rho_freshwater        = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
    452         IssmDouble g                     = element->GetMaterialParameter(ConstantsGEnum);
    453         IssmDouble epl_porosity          = element->GetMaterialParameter(HydrologydcEplPorosityEnum);
    454         IssmDouble epl_compressibility   = element->GetMaterialParameter(HydrologydcEplCompressibilityEnum);
    455         IssmDouble water_compressibility = element->GetMaterialParameter(HydrologydcWaterCompressibilityEnum);
    456         return rho_freshwater*g*epl_porosity*(water_compressibility+(epl_compressibility/epl_porosity));                 
    457 }/*}}}*/
    458 
    459 IssmDouble HydrologyDCEfficientAnalysis::SedimentStoring(Element* element){/*{{{*/
    460         IssmDouble rho_freshwater           = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
    461         IssmDouble g                        = element->GetMaterialParameter(ConstantsGEnum);
    462         IssmDouble sediment_porosity        = element->GetMaterialParameter(HydrologydcSedimentPorosityEnum);
    463         IssmDouble sediment_thickness       = element->GetMaterialParameter(HydrologydcSedimentThicknessEnum);
    464         IssmDouble sediment_compressibility = element->GetMaterialParameter(HydrologydcSedimentCompressibilityEnum);
    465         IssmDouble water_compressibility    = element->GetMaterialParameter(HydrologydcWaterCompressibilityEnum);
    466         return rho_freshwater*g*sediment_porosity*sediment_thickness*(water_compressibility+(sediment_compressibility/sediment_porosity));               
    467 }/*}}}*/
    468 
    469 IssmDouble HydrologyDCEfficientAnalysis::GetHydrologyKMatrixTransfer(Element* element, Gauss* gauss, Input* sed_head_input, Input* epl_head_input, Input* thick_input, Input* base_input){/*{{{*/
     452IssmDouble HydrologyDCEfficientAnalysis::GetHydrologyKMatrixTransfer(Element* element){/*{{{*/
    470453
    471454        int transfermethod;
    472         IssmDouble hmax;
    473         IssmDouble epl_head,sediment_head;
    474455        IssmDouble leakage,transfer;
    475         IssmDouble continuum, factor;
    476         HydrologyDCInefficientAnalysis* inefanalysis = NULL;
    477456
    478457        element->FindParam(&transfermethod,HydrologydcTransferFlagEnum);
    479 
     458        /*Switch between the different transfer methods cases*/
     459        switch(transfermethod){
     460        case 0:
     461                /*Just keepping the transfer to zero*/
     462                transfer=0.0;
     463                break;
     464        case 1:
     465                element->FindParam(&leakage,HydrologydcLeakageFactorEnum);
     466                transfer=leakage;
     467                break;
     468        default:
     469                _error_("no case higher than 1 for the Transfer method");
     470        }
     471        return transfer;
     472}/*}}}*/
     473
     474IssmDouble HydrologyDCEfficientAnalysis::GetHydrologyPVectorTransfer(Element* element, Gauss* gauss, Input* sed_head_input){/*{{{*/
     475
     476        int transfermethod;
     477        IssmDouble sediment_head;
     478        IssmDouble leakage,transfer;
     479
     480        element->FindParam(&transfermethod,HydrologydcTransferFlagEnum);
    480481        /*Switch between the different transfer methods cases*/
    481482        switch(transfermethod){
     
    486487        case 1:
    487488                _assert_(sed_head_input);
    488                 _assert_(epl_head_input);
    489                
    490                 inefanalysis = new HydrologyDCInefficientAnalysis();
    491                 hmax = inefanalysis->GetHydrologyDCInefficientHmax(element,gauss,thick_input,base_input);
    492                 delete inefanalysis;
    493 
    494489                sed_head_input->GetInputValue(&sediment_head,gauss);
    495                 epl_head_input->GetInputValue(&epl_head,gauss);
    496490                element->FindParam(&leakage,HydrologydcLeakageFactorEnum);
    497                
    498                 //Computing continuum function to apply to transfer term, transfer is null only if
    499                 // epl_head>sediment_head AND sediment_head>h_max
    500                 continuum=((1.0/(1.0+exp(-20.0*(sediment_head-epl_head)))))+(1.0/(1.0+exp(-20.0*(hmax-sediment_head))));
    501                 factor=min(continuum,1.0);
    502                 transfer=leakage*factor;
    503                 break;
    504         default:
    505                 _error_("no case higher than 1 for the Transfer method");
    506         }
    507         return transfer;
    508 }/*}}}*/
    509 
    510 IssmDouble HydrologyDCEfficientAnalysis::GetHydrologyPVectorTransfer(Element* element, Gauss* gauss, Input* sed_head_input, Input* epl_head_input, Input* thick_input, Input* base_input){/*{{{*/
    511 
    512         int transfermethod;
    513         IssmDouble hmax;
    514         IssmDouble epl_head,sediment_head;
    515         IssmDouble leakage,transfer;
    516         IssmDouble continuum, factor;
    517 
    518         HydrologyDCInefficientAnalysis* inefanalysis = NULL;
    519 
    520         element->FindParam(&transfermethod,HydrologydcTransferFlagEnum);
    521 
    522         /*Switch between the different transfer methods cases*/
    523         switch(transfermethod){
    524         case 0:
    525                 /*Just keepping the transfer to zero*/
    526                 transfer=0.0;
    527                 break;
    528         case 1:
    529                 _assert_(sed_head_input);
    530                 _assert_(epl_head_input);
    531 
    532                 inefanalysis = new HydrologyDCInefficientAnalysis();
    533                 hmax = inefanalysis->GetHydrologyDCInefficientHmax(element,gauss,thick_input,base_input);
    534                 delete inefanalysis;
    535                
    536                 sed_head_input->GetInputValue(&sediment_head,gauss);
    537                 epl_head_input->GetInputValue(&epl_head,gauss);
    538                 element->FindParam(&leakage,HydrologydcLeakageFactorEnum);
    539 
    540                 //Computing continuum function to apply to transfer term, transfer is null only if
    541                 // epl_head>sediment_head AND sediment_head>h_max
    542                 continuum=((1.0/(1.0+exp(-20.0*(sediment_head-epl_head)))))+(1.0/(1.0+exp(-20.0*(hmax-sediment_head))));
    543                 factor=min(continuum,1.0);
    544                 transfer=sediment_head*leakage*factor;
    545 
     491                transfer=sediment_head*leakage;
    546492                break;
    547493        default:
     
    560506        IssmDouble  EPLgrad2;
    561507        IssmDouble  EPL_N;
    562 
    563508       
    564509        femmodel->parameters->FindParam(&domaintype,DomainTypeEnum);
     510        femmodel->parameters->FindParam(&iseplthickcomp,HydrologydcEplThickCompEnum);
     511        if(iseplthickcomp==0) return;
    565512
    566513        for(int j=0;j<femmodel->elements->Size();j++){
    567514               
    568515                Element* element=(Element*)femmodel->elements->GetObjectByOffset(j);
    569                 element->parameters->FindParam(&iseplthickcomp,HydrologydcEplThickCompEnum);
    570                 if(iseplthickcomp==0) return;
    571516               
    572517                switch(domaintype){
     
    615560               
    616561                if(!active_element){
    617                        
    618562                        /*Keeping thickness to initial value if EPL is not active*/
    619563                        for(int i=0;i<numnodes;i++){
     
    623567                else{
    624568                        for(int i=0;i<numnodes;i++){
    625                                
    626569                                /*Compute first the effective pressure in the EPL*/
    627                                 EPL_N=gravity*((rho_ice*ice_thickness[i])-(rho_water*max(0.0,(eplhead[i]-bed[i]))));
     570                                EPL_N=gravity*((rho_ice*ice_thickness[i])-(rho_water*(eplhead[i]-bed[i])));
    628571                                if(EPL_N<0.0)EPL_N=0.0;
    629572                                /*Get then the square of the gradient of EPL heads*/
    630573                                EPLgrad2 = (epl_slopeX[i]*epl_slopeX[i])+(epl_slopeY[i]*epl_slopeY[i]);
    631                                
    632574                                /*And proceed to the real thing*/
    633                                 thickness[i] = old_thickness[i]*(1.0+((rho_water*gravity*dt)/(rho_ice*latentheat))*epl_conductivity*EPLgrad2-
    634                                                                                                                                                                  (2.0*(A*dt/(pow(n,n)))*(pow(EPL_N,n))));
    635                                
     575                                thickness[i] = old_thickness[i]/(1.0
     576                                                                                                                                                                 -((rho_water*gravity*epl_conductivity*EPLgrad2*dt)/(rho_ice*latentheat))
     577                                                                                                                                                                 +((2.0*A*dt*pow(EPL_N,n))/(pow(n,n))));
    636578                                /*Take care of otherthikening*/
    637579                                if(thickness[i]>max_thick){
     
    682624
    683625        bool        active_element;
    684         int         i,j;
    685626        int         domaintype;
    686627        IssmDouble  h_max;
     
    707648        IssmDouble* eplhead       =xNew<IssmDouble>(numnodes);
    708649        IssmDouble* residual      =xNew<IssmDouble>(numnodes);
     650        IssmDouble* base          =xNew<IssmDouble>(numnodes);
    709651       
    710652        IssmDouble init_thick    =basalelement->GetMaterialParameter(HydrologydcEplInitialThicknessEnum);
     
    719661        basalelement-> GetInputListOnVertices(&eplhead[0],EplHeadEnum);
    720662        basalelement-> GetInputListOnVertices(&residual[0],SedimentHeadResidualEnum);
     663        basalelement-> GetInputListOnVertices(&base[0],BaseEnum);
    721664
    722665        /*Get minimum sediment head of the element*/
    723666        sedheadmin=sedhead[0];
    724         for(i=1;i<numnodes;i++) if(sedhead[i]<=sedheadmin)sedheadmin=sedhead[i];
    725         for(i=0;i<numnodes;i++){
    726                 /*If node is now closed bring its thickness back to initial*/
    727                 if (old_active[i]==0.){
    728                         epl_thickness[i]=init_thick;
    729                 }
    730 
    731                 /*Now starting to look at the activations*/
    732                 if(residual[i]>0.){
     667        for(int i=1;i<numnodes;i++) if(sedhead[i]<=sedheadmin)sedheadmin=sedhead[i];
     668        for(int i=0;i<numnodes;i++){
     669                GetHydrologyDCInefficientHmax(&h_max,basalelement,basalelement->nodes[i]);
     670                /*If mask was already one, keep one or colapse*/
     671                if(old_active[i]>0.){
    733672                        vec_mask->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
    734                         if(old_active[i]==0.)   recurence->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
    735                 }
    736                 /*If mask was already one, keep one or colapse*/
    737                 else if(old_active[i]>0.){
    738                         vec_mask->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
    739                         /*If epl thickness gets under colapse thickness, close the layer*/
     673                        /* If epl thickness gets under colapse thickness, close the layer */
    740674                        if(epl_thickness[i]<colapse_thick){
    741675                                vec_mask->SetValue(basalelement->nodes[i]->Sid(),0.,INS_VAL);
    742676                                recurence->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
    743677                        }
     678                        /* //If epl head gets under base elevation, close the layer */
     679                        /* else if(eplhead[i]<(base[i]-1.0e-8)){ */
     680                        /*      vec_mask->SetValue(basalelement->nodes[i]->Sid(),0.,INS_VAL); */
     681                        /*      recurence->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL); */
     682                        /* } */
     683                }
     684                /*If node is now closed bring its thickness back to initial*/
     685                if (old_active[i]==0.){
     686                        epl_thickness[i]=init_thick;
     687                        /*Activate if we have a residual from sediment*/
     688                        if(residual[i]>0.){
     689                                vec_mask->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
     690                                if(old_active[i]==0.){
     691                                        recurence->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
     692                                }
     693                        }
    744694                }
    745695                /*Increase of the efficient system is needed if the epl head reach the maximum value (sediment max value for now)*/
    746                 GetHydrologyDCInefficientHmax(&h_max,basalelement,basalelement->nodes[i]);
    747696                if(eplhead[i]>=h_max && active_element){
    748                         for(j=0;j<numnodes;j++){
     697                        for(int j=0;j<numnodes;j++){
    749698                                /*Increase of the domain is on the downstream node in term of sediment head*/
    750                                 if(sedhead[j] == sedheadmin){
     699                                if((sedhead[j] == sedheadmin) && (i!=j)){
    751700                                        vec_mask->SetValue(basalelement->nodes[j]->Sid(),1.,INS_VAL);
    752                                         if(old_active[i]==0.)   recurence->SetValue(basalelement->nodes[i]->Sid(),1.,INS_VAL);
     701                                        if(old_active[j]==0.){
     702                                                recurence->SetValue(basalelement->nodes[j]->Sid(),1.,INS_VAL);
     703                                        }
    753704                                }
    754705                        }
     
    763714        xDelete<IssmDouble>(eplhead);
    764715        xDelete<IssmDouble>(residual);
     716        xDelete<IssmDouble>(base);
    765717}
    766718/*}}}*/
    767 
    768 void HydrologyDCEfficientAnalysis::HydrologyEPLGetActive(Vector<IssmDouble>* active_vec, Element* element){
     719IssmDouble HydrologyDCEfficientAnalysis::EplStoring(Element* element,Gauss* gauss, Input* epl_thick_input, Input* epl_head_input, Input* base_input){/*{{{*/
     720        IssmDouble epl_storing;
     721        IssmDouble water_sheet,storing;
     722        IssmDouble epl_thickness,prestep_head,base_elev;
     723        IssmDouble rho_freshwater        = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
     724        IssmDouble g                     = element->GetMaterialParameter(ConstantsGEnum);
     725        IssmDouble epl_porosity                                  = element->GetMaterialParameter(HydrologydcEplPorosityEnum);
     726        IssmDouble epl_compressibility   = element->GetMaterialParameter(HydrologydcEplCompressibilityEnum);
     727        IssmDouble water_compressibility = element->GetMaterialParameter(HydrologydcWaterCompressibilityEnum);
     728
     729        epl_thick_input->GetInputValue(&epl_thickness,gauss);
     730        epl_head_input->GetInputValue(&prestep_head,gauss);
     731        base_input->GetInputValue(&base_elev,gauss);
     732        water_sheet=max(0.0,(prestep_head-base_elev));
     733
     734        storing=rho_freshwater*g*epl_porosity*epl_thickness*(water_compressibility+(epl_compressibility/epl_porosity));
     735
     736        /* //porosity for unconfined region */
     737        /* if (water_sheet<=0.9*epl_thickness){ */
     738        /*      epl_storing=epl_porosity; */
     739        /* } */
     740        /* //continuity ramp */
     741        /* else if((water_sheet<epl_thickness) && (water_sheet>0.9*epl_thickness)){ */
     742        /*      epl_storing=(epl_thickness-water_sheet)*(epl_porosity-storing)/(0.1*epl_thickness)+storing; */
     743        /* } */
     744        /* //storing coefficient for confined */
     745        /* else{ */
     746        /*      epl_storing=storing; */
     747        /* } */
     748        /* return epl_storing; */
     749        return storing;
     750}/*}}}*/
     751
     752IssmDouble HydrologyDCEfficientAnalysis::EplTransmitivity(Element* element,Gauss* gauss, Input* epl_thick_input, Input* epl_head_input, Input* base_input){/*{{{*/
     753        IssmDouble epl_transmitivity;
     754        IssmDouble water_sheet;
     755        IssmDouble epl_thickness,base_elev,prestep_head;
     756        IssmDouble epl_conductivity      = element->GetMaterialParameter(HydrologydcEplConductivityEnum);
     757        epl_thick_input->GetInputValue(&epl_thickness,gauss);
     758        epl_head_input->GetInputValue(&prestep_head,gauss);
     759        base_input->GetInputValue(&base_elev,gauss);
     760
     761        water_sheet=max(0.0,(prestep_head-base_elev));
     762       
     763        epl_transmitivity=epl_conductivity*epl_thickness;
     764        //epl_transmitivity=max(1.0e-6,(epl_conductivity*min(water_sheet,epl_thickness)));
     765        return epl_transmitivity;
     766}/*}}}*/
     767
     768void HydrologyDCEfficientAnalysis::HydrologyEPLGetActive(Vector<IssmDouble>* active_vec, Element* element){/*{{{*/
    769769        /*Constants*/
    770770        int      domaintype;
     
    787787        IssmDouble  flag     = 0.;
    788788        IssmDouble* active   = xNew<IssmDouble>(numnodes);
     789        bool active_element;
    789790
    790791        /*Pass the activity mask from elements to nodes*/
    791792        basalelement->GetInputListOnVertices(&active[0],HydrologydcMaskEplactiveNodeEnum);
    792         bool active_element;
    793793        Input*  active_element_input=basalelement->GetInput(HydrologydcMaskEplactiveEltEnum); _assert_(active_element_input);           
    794794        active_element_input->GetInputValue(&active_element);
     
    814814        xDelete<IssmDouble>(active);
    815815}
     816/*}}}*/
    816817
    817818void HydrologyDCEfficientAnalysis::GetHydrologyDCInefficientHmax(IssmDouble* ph_max,Element* element, Node* innode){/*{{{*/
Note: See TracChangeset for help on using the changeset viewer.