Changeset 18659


Ignore:
Timestamp:
10/20/14 09:14:10 (10 years ago)
Author:
seroussi
Message:

BUG: fixed spc of basal conditions using a vector

Location:
issm/trunk-jpl/src/c/analyses
Files:
2 edited

Legend:

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

    r18656 r18659  
    11891189}/*}}}*/
    11901190void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
     1191
    11911192        /*Update basal dirichlet BCs for enthalpy: */
     1193        Vector<IssmDouble>* spc           = NULL;
     1194        IssmDouble*         serial_spc    = NULL;
     1195
     1196        spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes(EnthalpyAnalysisEnum));
     1197        /*First create a vector to figure out what elements should be constrained*/
    11921198        for(int i=0;i<femmodel->elements->Size();i++){
    11931199                Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
    1194                 UpdateBasalConstraints(element);
    1195         }
     1200                GetBasalConstraints(spc,element);
     1201        }
     1202
     1203        /*Assemble and serialize*/
     1204        spc->Assemble();
     1205        serial_spc=spc->ToMPISerial();
     1206        delete spc;
     1207
     1208        /*Then update basal constraints nodes accordingly*/
     1209        for(int i=0;i<femmodel->elements->Size();i++){
     1210                Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
     1211                ApplyBasalConstraints(serial_spc,element);
     1212        }
     1213
    11961214        femmodel->UpdateConstraintsx();
    1197 }/*}}}*/
    1198 void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
     1215
     1216        /*Delete*/
     1217        xDelete<IssmDouble>(serial_spc);
     1218}/*}}}*/
     1219void EnthalpyAnalysis::ApplyBasalConstraints(IssmDouble* serial_spc,Element* element){/*{{{*/
     1220
     1221        /* Check if ice in element */
     1222        if(!element->IsIceInElement()) return;
     1223
     1224        /* Only update Constraints at the base of grounded ice*/
     1225        if(!(element->IsOnBase()) || element->IsFloating()) return;
     1226
     1227        /*Intermediary*/
     1228        bool        isdynamicbasalspc;
     1229        int         numindices;
     1230        int        *indices = NULL;
     1231        Node*       node = NULL;
     1232        IssmDouble      pressure;
     1233
     1234        /*Check wether dynamic basal boundary conditions are activated */
     1235        element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
     1236        if(!isdynamicbasalspc) return;
     1237
     1238        /*Get parameters and inputs: */
     1239        Input* pressure_input            = element->GetInput(PressureEnum);                                                      _assert_(pressure_input);
     1240
     1241        /*Fetch indices of basal & surface nodes for this finite element*/
     1242        Penta *penta =  (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
     1243        penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
     1244
     1245        GaussPenta* gauss=new GaussPenta();
     1246        for(int i=0;i<numindices;i++){
     1247                gauss->GaussNode(element->GetElementType(),indices[i]);
     1248
     1249                pressure_input->GetInputValue(&pressure,gauss);
     1250
     1251                /*apply or release spc*/
     1252                node=element->GetNode(indices[i]);
     1253                if(serial_spc[node->Sid()]==1.){
     1254                        pressure_input->GetInputValue(&pressure, gauss);
     1255                        node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
     1256                }
     1257                else                   
     1258                        node->DofInFSet(0);
     1259        }
     1260
     1261        /*Free ressources:*/
     1262        xDelete<int>(indices);
     1263        delete gauss;
     1264}/*}}}*/
     1265void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
    11991266
    12001267        /* Check if ice in element */
     
    12141281        element->FindParam(&dt,TimesteppingTimeStepEnum);
    12151282        if(dt==0.){
    1216                 UpdateBasalConstraintsSteadystate(element);
     1283                GetBasalConstraintsSteadystate(vec_spc,element);
    12171284        }
    12181285        else{
    1219                 UpdateBasalConstraintsTransient(element);
    1220         }
    1221 }/*}}}*/
    1222 void EnthalpyAnalysis::UpdateBasalConstraintsTransient(Element* element){/*{{{*/
     1286                GetBasalConstraintsTransient(vec_spc,element);
     1287        }
     1288}/*}}}*/
     1289void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
    12231290
    12241291        /* Check if ice in element */
     
    12291296
    12301297        /*Intermediary*/
    1231         bool        isdynamicbasalspc,setspc;
    12321298        int         numindices, numindicesup, state;
    12331299        int        *indices = NULL, *indicesup = NULL;
    1234         Node*       node = NULL;
    12351300        IssmDouble      enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
    1236 
    1237         /*Check wether dynamic basal boundary conditions are activated */
    1238         element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
    1239         if(!isdynamicbasalspc) return;
    12401301
    12411302        /*Get parameters and inputs: */
     
    12661327                state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
    12671328
    1268                 setspc=false;
    12691329                switch (state) {
    12701330                        case 0:
    12711331                                // cold, dry base: apply basal surface forcing
     1332                                vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
    12721333                                break;
    12731334                        case 1:
    12741335                                // cold, wet base: keep at pressure melting point
    1275                                 setspc=true;
     1336                                vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
    12761337                                break;
    12771338                        case 2:
    12781339                                // temperate, thin refreezing base: release spc
     1340                                vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
    12791341                                break;
    12801342                        case 3:
    12811343                                // temperate, thin melting base: set spc
    1282                                 setspc=true;
     1344                                vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
    12831345                                break;
    12841346                        case 4:
    12851347                                // temperate, thick melting base: set grad H*n=0
     1348                                vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
    12861349                                break;
    12871350                        default:
     
    12891352                }
    12901353
    1291                 /*apply or release spc*/
    1292                 node=element->GetNode(indices[i]);
    1293                 if(setspc){
    1294                         pressure_input->GetInputValue(&pressure, gauss);
    1295                         node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
    1296                 }
    1297                 else                   
    1298                         node->DofInFSet(0);
    12991354        }
    13001355
     
    13051360        delete gaussup;
    13061361}/*}}}*/
    1307 void EnthalpyAnalysis::UpdateBasalConstraintsSteadystate(Element* element){/*{{{*/
     1362void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
    13081363
    13091364        /* Check if ice in element */
     
    13141369
    13151370        /*Intermediary*/
    1316         bool        isdynamicbasalspc,setspc;
    13171371        int         numindices, numindicesup, state;
    13181372        int        *indices = NULL, *indicesup = NULL;
    1319         Node*       node = NULL;
    13201373        IssmDouble      enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
    1321 
    1322         /*Check wether dynamic basal boundary conditions are activated */
    1323         element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
    1324         if(!isdynamicbasalspc) return;
    13251374
    13261375        /*Get parameters and inputs: */
     
    13491398
    13501399                state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
    1351                 setspc=false;
    13521400                switch (state) {
    13531401                        case 0:
    13541402                                // cold, dry base: apply basal surface forcing
     1403                                vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
    13551404                                break;
    13561405                        case 1:
    13571406                                // cold, wet base: keep at pressure melting point
    1358                                 setspc=true;
     1407                                vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
    13591408                                break;
    13601409                        case 2:
    13611410                                // temperate, thin refreezing base: release spc
     1411                                vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
    13621412                                break;
    13631413                        case 3:
    13641414                                // temperate, thin melting base: set spc
    1365                                 setspc=true;
     1415                                vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
    13661416                                break;
    13671417                        case 4:
    13681418                                // temperate, thick melting base: s
    1369                                 setspc=true;
     1419                                vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
    13701420                                break;
    13711421                        default:
    13721422                                _printf0_("     unknown thermal basal state found!");
    13731423                }
    1374 
    1375                 /*apply or release spc*/
    1376                 node=element->GetNode(indices[i]);
    1377                 if(setspc){
    1378                         pressure_input->GetInputValue(&pressure, gauss);
    1379                         node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
    1380                 }
    1381                 else                   
    1382                         node->DofInFSet(0);
    13831424        }
    13841425
  • TabularUnified issm/trunk-jpl/src/c/analyses/EnthalpyAnalysis.h

    r18620 r18659  
    4848                static void DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element);
    4949                static void UpdateBasalConstraints(FemModel* femmodel);
    50                 static void UpdateBasalConstraints(Element* element);
    51                 static void UpdateBasalConstraintsTransient(Element* element);
    52                 static void UpdateBasalConstraintsSteadystate(Element* element);
     50                static void ApplyBasalConstraints(IssmDouble* serial_spc,Element* element);
     51                static void GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element);
     52                static void GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element);
     53                static void GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element);
    5354                static int GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpy_up, IssmDouble pressure, IssmDouble pressure_up, IssmDouble watercolumn, IssmDouble meltingrate);
    5455                static IssmDouble GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure);
Note: See TracChangeset for help on using the changeset viewer.