[16534] | 1 | #include "./EnthalpyAnalysis.h"
|
---|
| 2 | #include "../toolkits/toolkits.h"
|
---|
| 3 | #include "../classes/classes.h"
|
---|
| 4 | #include "../shared/shared.h"
|
---|
| 5 | #include "../modules/modules.h"
|
---|
[18591] | 6 | #include "../solutionsequences/solutionsequences.h"
|
---|
[21721] | 7 | #include "../cores/cores.h"
|
---|
[16534] | 8 |
|
---|
| 9 | /*Model processing*/
|
---|
[18930] | 10 | void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
[16604] | 11 |
|
---|
[18930] | 12 | /*Intermediary*/
|
---|
| 13 | int count;
|
---|
| 14 | int M,N;
|
---|
| 15 | bool spcpresent = false;
|
---|
[21546] | 16 | int finiteelement;
|
---|
[18930] | 17 | IssmDouble heatcapacity;
|
---|
| 18 | IssmDouble referencetemperature;
|
---|
[16604] | 19 |
|
---|
[18930] | 20 | /*Output*/
|
---|
| 21 | IssmDouble *spcvector = NULL;
|
---|
| 22 | IssmDouble* times=NULL;
|
---|
| 23 | IssmDouble* values=NULL;
|
---|
[16604] | 24 |
|
---|
[18930] | 25 | /*Fetch parameters: */
|
---|
[20690] | 26 | iomodel->FindConstant(&heatcapacity,"md.materials.heatcapacity");
|
---|
| 27 | iomodel->FindConstant(&referencetemperature,"md.constants.referencetemperature");
|
---|
[21546] | 28 | iomodel->FindConstant(&finiteelement,"md.thermal.fe");
|
---|
[18732] | 29 |
|
---|
[18930] | 30 | /*return if 2d mesh*/
|
---|
| 31 | if(iomodel->domaintype==Domain2DhorizontalEnum) return;
|
---|
| 32 |
|
---|
| 33 | /*Fetch data: */
|
---|
[20690] | 34 | iomodel->FetchData(&spcvector,&M,&N,"md.thermal.spctemperature");
|
---|
[18930] | 35 |
|
---|
[21546] | 36 | /*Convert spcs from temperatures to enthalpy*/
|
---|
| 37 | _assert_(N>0); _assert_(M>=iomodel->numberofvertices);
|
---|
| 38 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
[21549] | 39 | for(int j=0;j<N;j++){
|
---|
| 40 | spcvector[i*N+j] = heatcapacity*(spcvector[i*N+j]-referencetemperature);
|
---|
[18930] | 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[21548] | 44 | /*Specific case for PDD, we want the constaints to be updated by the PDD scheme itself*/
|
---|
| 45 | bool isdynamic = false;
|
---|
| 46 | if (iomodel->solution_enum==TransientSolutionEnum){
|
---|
| 47 | int smb_model;
|
---|
| 48 | iomodel->FindConstant(&smb_model,"md.smb.model");
|
---|
| 49 | if(smb_model==SMBpddEnum) isdynamic=true;
|
---|
| 50 | if(smb_model==SMBd18opddEnum) isdynamic=true;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | if(isdynamic){
|
---|
[21560] | 54 | IoModelToDynamicConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement);
|
---|
[21548] | 55 | }
|
---|
| 56 | else{
|
---|
| 57 | IoModelToConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[18930] | 60 | /*Free ressources:*/
|
---|
[20690] | 61 | iomodel->DeleteData(spcvector,"md.thermal.spctemperature");
|
---|
[18930] | 62 | xDelete<IssmDouble>(times);
|
---|
| 63 | xDelete<IssmDouble>(values);
|
---|
[16539] | 64 | }/*}}}*/
|
---|
[18930] | 65 | void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
| 66 |
|
---|
| 67 | /*No loads */
|
---|
| 68 | }/*}}}*/
|
---|
| 69 | void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
|
---|
| 70 |
|
---|
[21542] | 71 | int finiteelement;
|
---|
| 72 | iomodel->FindConstant(&finiteelement,"md.thermal.fe");
|
---|
| 73 |
|
---|
[20690] | 74 | if(iomodel->domaintype==Domain3DEnum) iomodel->FetchData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
|
---|
[21542] | 75 | ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,finiteelement);
|
---|
[20690] | 76 | iomodel->DeleteData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
|
---|
[18930] | 77 | }/*}}}*/
|
---|
| 78 | int EnthalpyAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
| 79 | return 1;
|
---|
| 80 | }/*}}}*/
|
---|
[16539] | 81 | void EnthalpyAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
| 82 |
|
---|
[20459] | 83 | bool dakota_analysis,ismovingfront,isenthalpy;
|
---|
[21382] | 84 | int frictionlaw,basalforcing_model,materialstype;
|
---|
[19161] | 85 | int FrictionCoupling;
|
---|
| 86 |
|
---|
[16539] | 87 | /*Now, is the model 3d? otherwise, do nothing: */
|
---|
[17700] | 88 | if(iomodel->domaintype==Domain2DhorizontalEnum)return;
|
---|
[16539] | 89 |
|
---|
| 90 | /*Is enthalpy requested?*/
|
---|
[20690] | 91 | iomodel->FindConstant(&isenthalpy,"md.thermal.isenthalpy");
|
---|
[16539] | 92 | if(!isenthalpy) return;
|
---|
| 93 |
|
---|
| 94 | /*Fetch data needed: */
|
---|
[20690] | 95 | iomodel->FetchData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
|
---|
[16539] | 96 |
|
---|
[21542] | 97 | /*Finite element type*/
|
---|
| 98 | int finiteelement;
|
---|
| 99 | iomodel->FindConstant(&finiteelement,"md.thermal.fe");
|
---|
| 100 |
|
---|
[16539] | 101 | /*Update elements: */
|
---|
| 102 | int counter=0;
|
---|
| 103 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
| 104 | if(iomodel->my_elements[i]){
|
---|
| 105 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
[21542] | 106 | element->Update(i,iomodel,analysis_counter,analysis_type,finiteelement);
|
---|
[16539] | 107 | counter++;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[20690] | 111 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
---|
| 112 | iomodel->FindConstant(&ismovingfront,"md.transient.ismovingfront");
|
---|
| 113 | iomodel->FindConstant(&frictionlaw,"md.friction.law");
|
---|
[21382] | 114 | iomodel->FindConstant(&materialstype,"md.materials.type");
|
---|
[16539] | 115 |
|
---|
[20690] | 116 | iomodel->FetchDataToInput(elements,"md.geometry.thickness",ThicknessEnum);
|
---|
| 117 | iomodel->FetchDataToInput(elements,"md.geometry.surface",SurfaceEnum);
|
---|
| 118 | iomodel->FetchDataToInput(elements,"md.slr.sealevel",SealevelEnum,0);
|
---|
| 119 | iomodel->FetchDataToInput(elements,"md.geometry.base",BaseEnum);
|
---|
| 120 | iomodel->FetchDataToInput(elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
---|
| 121 | iomodel->FetchDataToInput(elements,"md.mask.groundedice_levelset",MaskGroundediceLevelsetEnum);
|
---|
[17886] | 122 | if(iomodel->domaintype!=Domain2DhorizontalEnum){
|
---|
[20690] | 123 | iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum);
|
---|
| 124 | iomodel->FetchDataToInput(elements,"md.mesh.vertexonsurface",MeshVertexonsurfaceEnum);
|
---|
[17886] | 125 | }
|
---|
[20690] | 126 | iomodel->FetchDataToInput(elements,"md.initialization.pressure",PressureEnum);
|
---|
| 127 | iomodel->FetchDataToInput(elements,"md.initialization.temperature",TemperatureEnum);
|
---|
| 128 | iomodel->FetchDataToInput(elements,"md.initialization.waterfraction",WaterfractionEnum);
|
---|
| 129 | iomodel->FetchDataToInput(elements,"md.initialization.enthalpy",EnthalpyEnum);
|
---|
| 130 | iomodel->FetchDataToInput(elements,"md.initialization.watercolumn",WatercolumnEnum);
|
---|
| 131 | iomodel->FetchDataToInput(elements,"md.basalforcings.groundedice_melting_rate",BasalforcingsGroundediceMeltingRateEnum);
|
---|
| 132 | iomodel->FetchDataToInput(elements,"md.initialization.vx",VxEnum);
|
---|
| 133 | iomodel->FetchDataToInput(elements,"md.initialization.vy",VyEnum);
|
---|
| 134 | iomodel->FetchDataToInput(elements,"md.initialization.vz",VzEnum);
|
---|
[16539] | 135 | InputUpdateFromConstantx(elements,0.,VxMeshEnum);
|
---|
| 136 | InputUpdateFromConstantx(elements,0.,VyMeshEnum);
|
---|
| 137 | InputUpdateFromConstantx(elements,0.,VzMeshEnum);
|
---|
[20459] | 138 | if(ismovingfront){
|
---|
[20690] | 139 | iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum); // required for updating active nodes
|
---|
[17434] | 140 | }
|
---|
[20020] | 141 |
|
---|
| 142 | /*Basal forcings variables*/
|
---|
[20690] | 143 | iomodel->FindConstant(&basalforcing_model,"md.basalforcings.model");
|
---|
[20020] | 144 | switch(basalforcing_model){
|
---|
| 145 | case MantlePlumeGeothermalFluxEnum:
|
---|
| 146 | break;
|
---|
| 147 | default:
|
---|
[20690] | 148 | iomodel->FetchDataToInput(elements,"md.basalforcings.geothermalflux",BasalforcingsGeothermalfluxEnum);
|
---|
[20020] | 149 | break;
|
---|
| 150 | }
|
---|
[21382] | 151 |
|
---|
| 152 | /*Rheology type*/
|
---|
| 153 | iomodel->FetchDataToInput(elements,"md.materials.rheology_B",MaterialsRheologyBEnum);
|
---|
| 154 | switch(materialstype){
|
---|
[21389] | 155 | case MatenhancediceEnum:
|
---|
| 156 | iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
|
---|
| 157 | iomodel->FetchDataToInput(elements,"md.materials.rheology_E",MaterialsRheologyEEnum);
|
---|
| 158 | break;
|
---|
[21382] | 159 | case MatdamageiceEnum:
|
---|
| 160 | iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
|
---|
| 161 | break;
|
---|
| 162 | case MatestarEnum:
|
---|
| 163 | iomodel->FetchDataToInput(elements,"md.materials.rheology_Ec",MaterialsRheologyEcEnum);
|
---|
| 164 | iomodel->FetchDataToInput(elements,"md.materials.rheology_Es",MaterialsRheologyEsEnum);
|
---|
| 165 | break;
|
---|
| 166 | case MaticeEnum:
|
---|
| 167 | iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
|
---|
| 168 | break;
|
---|
| 169 | default:
|
---|
| 170 | _error_("not supported");
|
---|
| 171 | }
|
---|
[17952] | 172 |
|
---|
| 173 | /*Friction law variables*/
|
---|
| 174 | switch(frictionlaw){
|
---|
| 175 | case 1:
|
---|
[21740] | 176 | iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
|
---|
[20690] | 177 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
| 178 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
| 179 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
[21740] | 180 | if (FrictionCoupling==1){
|
---|
| 181 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);
|
---|
| 182 | }
|
---|
[17952] | 183 | break;
|
---|
| 184 | case 2:
|
---|
[20690] | 185 | iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
|
---|
| 186 | iomodel->FetchDataToInput(elements,"md.friction.m",FrictionMEnum);
|
---|
[17952] | 187 | break;
|
---|
[18778] | 188 | case 3:
|
---|
[20690] | 189 | iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
|
---|
| 190 | iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
|
---|
| 191 | iomodel->FetchDataToInput(elements,"md.friction.As",FrictionAsEnum);
|
---|
| 192 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
[21740] | 193 | if (FrictionCoupling==1){
|
---|
[20690] | 194 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);
|
---|
[19161] | 195 | }
|
---|
[18778] | 196 | break;
|
---|
[18732] | 197 | case 4:
|
---|
[20690] | 198 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
| 199 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
| 200 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
| 201 | iomodel->FetchDataToInput(elements,"md.initialization.pressure",PressureEnum);
|
---|
| 202 | iomodel->FetchDataToInput(elements,"md.initialization.temperature",TemperatureEnum);
|
---|
[18732] | 203 | break;
|
---|
[18772] | 204 | case 5:
|
---|
[20690] | 205 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
| 206 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
| 207 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
| 208 | iomodel->FetchDataToInput(elements,"md.friction.water_layer",FrictionWaterLayerEnum);
|
---|
[18772] | 209 | break;
|
---|
[18804] | 210 | case 6:
|
---|
[20690] | 211 | iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
|
---|
| 212 | iomodel->FetchDataToInput(elements,"md.friction.m",FrictionMEnum);
|
---|
| 213 | iomodel->FetchDataToInput(elements,"md.initialization.pressure",PressureEnum);
|
---|
| 214 | iomodel->FetchDataToInput(elements,"md.initialization.temperature",TemperatureEnum);
|
---|
[18804] | 215 | break;
|
---|
[21556] | 216 | case 9:
|
---|
| 217 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
| 218 | iomodel->FetchDataToInput(elements,"md.friction.pressure_adjusted_temperature",FrictionPressureAdjustedTemperatureEnum);
|
---|
[21565] | 219 | InputUpdateFromConstantx(elements,1.,FrictionPEnum);
|
---|
| 220 | InputUpdateFromConstantx(elements,1.,FrictionQEnum);
|
---|
[21556] | 221 | break;
|
---|
[17952] | 222 | default:
|
---|
| 223 | _error_("not supported");
|
---|
| 224 | }
|
---|
[20690] | 225 |
|
---|
[16539] | 226 | /*Free data: */
|
---|
[20690] | 227 | iomodel->DeleteData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
|
---|
| 228 |
|
---|
[16539] | 229 | }/*}}}*/
|
---|
[18930] | 230 | void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
[16539] | 231 |
|
---|
[18930] | 232 | int numoutputs;
|
---|
| 233 | char** requestedoutputs = NULL;
|
---|
| 234 |
|
---|
[20690] | 235 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.stabilization",ThermalStabilizationEnum));
|
---|
| 236 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.maxiter",ThermalMaxiterEnum));
|
---|
| 237 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.reltol",ThermalReltolEnum));
|
---|
| 238 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.isenthalpy",ThermalIsenthalpyEnum));
|
---|
| 239 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.isdynamicbasalspc",ThermalIsdynamicbasalspcEnum));
|
---|
| 240 | parameters->AddObject(iomodel->CopyConstantObject("md.friction.law",FrictionLawEnum));
|
---|
[18930] | 241 |
|
---|
[20690] | 242 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.thermal.requested_outputs");
|
---|
[18930] | 243 | parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
|
---|
| 244 | if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
[20690] | 245 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.thermal.requested_outputs");
|
---|
[18930] | 246 |
|
---|
| 247 | /*Deal with friction parameters*/
|
---|
| 248 | int frictionlaw;
|
---|
[20690] | 249 | iomodel->FindConstant(&frictionlaw,"md.friction.law");
|
---|
| 250 | if(frictionlaw==4 || frictionlaw==6) parameters->AddObject(iomodel->CopyConstantObject("md.friction.gamma",FrictionGammaEnum));
|
---|
[21740] | 251 | if(frictionlaw==3 || frictionlaw==1) parameters->AddObject(iomodel->CopyConstantObject("md.friction.coupling",FrictionCouplingEnum));
|
---|
[21600] | 252 | if(frictionlaw==9) parameters->AddObject(iomodel->CopyConstantObject("md.friction.gamma",FrictionGammaEnum));
|
---|
[16539] | 253 | }/*}}}*/
|
---|
| 254 |
|
---|
[18930] | 255 | /*Finite Element Analysis*/
|
---|
| 256 | void EnthalpyAnalysis::ApplyBasalConstraints(IssmDouble* serial_spc,Element* element){/*{{{*/
|
---|
[16539] | 257 |
|
---|
[21481] | 258 | /* Do not check if ice in element, this may lead to inconsistencies between cpu partitions */
|
---|
[20213] | 259 | /* Only update constraints at the base. */
|
---|
| 260 | if(!(element->IsOnBase())) return;
|
---|
[16539] | 261 |
|
---|
[18930] | 262 | /*Intermediary*/
|
---|
| 263 | bool isdynamicbasalspc;
|
---|
| 264 | int numindices;
|
---|
| 265 | int *indices = NULL;
|
---|
| 266 | Node* node = NULL;
|
---|
| 267 | IssmDouble pressure;
|
---|
[16539] | 268 |
|
---|
[18930] | 269 | /*Check wether dynamic basal boundary conditions are activated */
|
---|
| 270 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
| 271 | if(!isdynamicbasalspc) return;
|
---|
[16539] | 272 |
|
---|
[18930] | 273 | /*Get parameters and inputs: */
|
---|
| 274 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
[16539] | 275 |
|
---|
[18930] | 276 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
| 277 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
| 278 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
[16539] | 279 |
|
---|
[18930] | 280 | GaussPenta* gauss=new GaussPenta();
|
---|
| 281 | for(int i=0;i<numindices;i++){
|
---|
| 282 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
[16539] | 283 |
|
---|
[18930] | 284 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
[16539] | 285 |
|
---|
[18930] | 286 | /*apply or release spc*/
|
---|
| 287 | node=element->GetNode(indices[i]);
|
---|
[21481] | 288 | if(!node->IsActive()) continue;
|
---|
[18930] | 289 | if(serial_spc[node->Sid()]==1.){
|
---|
| 290 | pressure_input->GetInputValue(&pressure, gauss);
|
---|
| 291 | node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
|
---|
[16539] | 292 | }
|
---|
[21481] | 293 | else {
|
---|
[18930] | 294 | node->DofInFSet(0);
|
---|
[21481] | 295 | }
|
---|
[16539] | 296 | }
|
---|
| 297 |
|
---|
[18930] | 298 | /*Free ressources:*/
|
---|
| 299 | xDelete<int>(indices);
|
---|
| 300 | delete gauss;
|
---|
| 301 | }/*}}}*/
|
---|
| 302 | void EnthalpyAnalysis::ComputeBasalMeltingrate(FemModel* femmodel){/*{{{*/
|
---|
| 303 | /*Compute basal melting rates: */
|
---|
| 304 | for(int i=0;i<femmodel->elements->Size();i++){
|
---|
| 305 | Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 306 | ComputeBasalMeltingrate(element);
|
---|
| 307 | }
|
---|
| 308 | }/*}}}*/
|
---|
| 309 | void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
|
---|
| 310 | /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
|
---|
| 311 | /* melting rate is positive when melting, negative when refreezing*/
|
---|
[16539] | 312 |
|
---|
[18930] | 313 | /* Check if ice in element */
|
---|
| 314 | if(!element->IsIceInElement()) return;
|
---|
[16539] | 315 |
|
---|
[18930] | 316 | /* Only compute melt rates at the base of grounded ice*/
|
---|
| 317 | if(!element->IsOnBase() || element->IsFloating()) return;
|
---|
[16539] | 318 |
|
---|
[18930] | 319 | /* Intermediaries */
|
---|
| 320 | bool converged;
|
---|
| 321 | const int dim=3;
|
---|
| 322 | int i,is,state;
|
---|
[21718] | 323 | int nodedown,nodeup,numnodes,numsegments;
|
---|
[18930] | 324 | int enthalpy_enum;
|
---|
| 325 | IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim],d1pressure[dim];
|
---|
| 326 | IssmDouble basalfriction,alpha2,geothermalflux,heatflux;
|
---|
| 327 | IssmDouble dt,yts;
|
---|
| 328 | IssmDouble melting_overshoot,lambda;
|
---|
| 329 | IssmDouble vx,vy,vz;
|
---|
| 330 | IssmDouble *xyz_list = NULL;
|
---|
| 331 | IssmDouble *xyz_list_base = NULL;
|
---|
| 332 | int *pairindices = NULL;
|
---|
[16539] | 333 |
|
---|
[18930] | 334 | /*Fetch parameters*/
|
---|
| 335 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 336 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 337 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
| 338 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 339 | element->FindParam(&yts, ConstantsYtsEnum);
|
---|
| 340 |
|
---|
| 341 | if(dt==0. && !converged) enthalpy_enum=EnthalpyPicardEnum;
|
---|
| 342 | else enthalpy_enum=EnthalpyEnum;
|
---|
| 343 |
|
---|
| 344 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
| 345 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 346 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
|
---|
| 347 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
| 348 | IssmDouble kappa = EnthalpyDiffusionParameterVolume(element,enthalpy_enum); _assert_(kappa>=0.);
|
---|
| 349 | IssmDouble kappa_mix;
|
---|
| 350 |
|
---|
| 351 | /*retrieve inputs*/
|
---|
| 352 | Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
|
---|
| 353 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 354 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
| 355 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 356 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 357 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 358 |
|
---|
| 359 | /*Build friction element, needed later: */
|
---|
| 360 | Friction* friction=new Friction(element,dim);
|
---|
| 361 |
|
---|
| 362 | /******** MELTING RATES ************************************//*{{{*/
|
---|
| 363 | element->NormalBase(&normal_base[0],xyz_list_base);
|
---|
[21718] | 364 | element->VerticalSegmentIndicesBase(&pairindices,&numsegments);
|
---|
[18930] | 365 | IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
|
---|
| 366 | IssmDouble* heating = xNew<IssmDouble>(numsegments);
|
---|
| 367 |
|
---|
[21718] | 368 | numnodes=element->GetNumberOfNodes();
|
---|
| 369 | IssmDouble* enthalpies = xNew<IssmDouble>(numnodes);
|
---|
| 370 | IssmDouble* pressures = xNew<IssmDouble>(numnodes);
|
---|
| 371 | IssmDouble* watercolumns = xNew<IssmDouble>(numnodes);
|
---|
| 372 | IssmDouble* basalmeltingrates = xNew<IssmDouble>(numnodes);
|
---|
| 373 | element->GetInputListOnNodes(enthalpies,enthalpy_enum);
|
---|
| 374 | element->GetInputListOnNodes(pressures,PressureEnum);
|
---|
| 375 | element->GetInputListOnNodes(watercolumns,WatercolumnEnum);
|
---|
| 376 | element->GetInputListOnNodes(basalmeltingrates,BasalforcingsGroundediceMeltingRateEnum);
|
---|
[18930] | 377 |
|
---|
| 378 | Gauss* gauss=element->NewGauss();
|
---|
| 379 | for(is=0;is<numsegments;is++){
|
---|
[21718] | 380 | nodedown = pairindices[is*2+0];
|
---|
| 381 | nodeup = pairindices[is*2+1];
|
---|
| 382 | gauss->GaussNode(element->GetElementType(),nodedown);
|
---|
[18930] | 383 |
|
---|
[21718] | 384 | state=GetThermalBasalCondition(element, enthalpies[nodedown], enthalpies[nodeup], pressures[nodedown], pressures[nodeup], watercolumns[nodedown], basalmeltingrates[nodedown]);
|
---|
[18930] | 385 | switch (state) {
|
---|
| 386 | case 0:
|
---|
| 387 | // cold, dry base: apply basal surface forcing
|
---|
| 388 | for(i=0;i<3;i++) vec_heatflux[i]=0.;
|
---|
| 389 | break;
|
---|
| 390 | case 1: case 2: case 3:
|
---|
| 391 | // case 1 : cold, wet base: keep at pressure melting point
|
---|
| 392 | // case 2: temperate, thin refreezing base: release spc
|
---|
| 393 | // case 3: temperate, thin melting base: set spc
|
---|
| 394 | enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
|
---|
| 395 | for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
|
---|
| 396 | break;
|
---|
| 397 | case 4:
|
---|
| 398 | // temperate, thick melting base: set grad H*n=0
|
---|
[21718] | 399 | kappa_mix=GetWetIceConductivity(element, enthalpies[nodedown], pressures[nodedown]);
|
---|
[18930] | 400 | pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
|
---|
| 401 | for(i=0;i<3;i++) vec_heatflux[i]=kappa_mix*beta*d1pressure[i];
|
---|
| 402 | break;
|
---|
| 403 | default:
|
---|
| 404 | _printf0_(" unknown thermal basal state found!");
|
---|
| 405 | }
|
---|
| 406 | if(state==0) meltingrate_enthalpy[is]=0.;
|
---|
| 407 | else{
|
---|
| 408 | /*heat flux along normal*/
|
---|
| 409 | heatflux=0.;
|
---|
| 410 | for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
|
---|
| 411 |
|
---|
| 412 | /*basal friction*/
|
---|
| 413 | friction->GetAlpha2(&alpha2,gauss);
|
---|
| 414 | vx_input->GetInputValue(&vx,gauss); vy_input->GetInputValue(&vy,gauss); vz_input->GetInputValue(&vz,gauss);
|
---|
| 415 | basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
| 416 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
| 417 | /* -Mb= Fb-(q-q_geo)/((1-w)*L*rho), and (1-w)*rho=rho_ice, cf Aschwanden 2012, eqs.1, 2, 66*/
|
---|
| 418 | heating[is]=(heatflux+basalfriction+geothermalflux);
|
---|
| 419 | meltingrate_enthalpy[is]=heating[is]/(latentheat*rho_ice); // m/s water equivalent
|
---|
| 420 | }
|
---|
| 421 | }/*}}}*/
|
---|
| 422 |
|
---|
| 423 | /******** UPDATE MELTINGRATES AND WATERCOLUMN **************//*{{{*/
|
---|
| 424 | for(is=0;is<numsegments;is++){
|
---|
[21718] | 425 | nodedown = pairindices[is*2+0];
|
---|
| 426 | nodeup = pairindices[is*2+1];
|
---|
[18930] | 427 | if(dt!=0.){
|
---|
[21718] | 428 | if(watercolumns[nodedown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
|
---|
| 429 | lambda = -watercolumns[nodedown]/(dt*meltingrate_enthalpy[is]); _assert_(lambda>=0.); _assert_(lambda<1.);
|
---|
| 430 | watercolumns[nodedown]=0.;
|
---|
| 431 | basalmeltingrates[nodedown]=lambda*meltingrate_enthalpy[is]; // restrict freeze on only to size of watercolumn
|
---|
| 432 | enthalpies[nodedown]+=(1.-lambda)*dt/yts*meltingrate_enthalpy[is]*latentheat*rho_ice; // use rest of energy to cool down base: dE=L*m, m=(1-lambda)*meltingrate*rho_ice
|
---|
[16539] | 433 | }
|
---|
[18930] | 434 | else{
|
---|
[21718] | 435 | basalmeltingrates[nodedown]=meltingrate_enthalpy[is];
|
---|
| 436 | watercolumns[nodedown]+=dt*meltingrate_enthalpy[is];
|
---|
[18930] | 437 | }
|
---|
[16539] | 438 | }
|
---|
[18930] | 439 | else{
|
---|
[21718] | 440 | basalmeltingrates[nodedown]=meltingrate_enthalpy[is];
|
---|
| 441 | if(watercolumns[nodedown]+meltingrate_enthalpy[is]<0.)
|
---|
| 442 | watercolumns[nodedown]=0.;
|
---|
[18930] | 443 | else
|
---|
[21718] | 444 | watercolumns[nodedown]+=meltingrate_enthalpy[is];
|
---|
[18930] | 445 | }
|
---|
[21718] | 446 | basalmeltingrates[nodedown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
|
---|
| 447 | _assert_(watercolumns[nodedown]>=0.);
|
---|
[18930] | 448 | }/*}}}*/
|
---|
| 449 |
|
---|
| 450 | /*feed updated variables back into model*/
|
---|
| 451 | if(dt!=0.){
|
---|
[21718] | 452 | element->AddInput(enthalpy_enum,enthalpies,element->GetElementType());
|
---|
| 453 | element->AddInput(WatercolumnEnum,watercolumns,element->GetElementType());
|
---|
[16539] | 454 | }
|
---|
[21718] | 455 | element->AddInput(BasalforcingsGroundediceMeltingRateEnum,basalmeltingrates,element->GetElementType());
|
---|
[16539] | 456 |
|
---|
[18930] | 457 | /*Clean up and return*/
|
---|
| 458 | delete gauss;
|
---|
| 459 | delete friction;
|
---|
| 460 | xDelete<int>(pairindices);
|
---|
| 461 | xDelete<IssmDouble>(enthalpies);
|
---|
| 462 | xDelete<IssmDouble>(pressures);
|
---|
| 463 | xDelete<IssmDouble>(watercolumns);
|
---|
| 464 | xDelete<IssmDouble>(basalmeltingrates);
|
---|
| 465 | xDelete<IssmDouble>(meltingrate_enthalpy);
|
---|
| 466 | xDelete<IssmDouble>(heating);
|
---|
| 467 | xDelete<IssmDouble>(xyz_list);
|
---|
| 468 | xDelete<IssmDouble>(xyz_list_base);
|
---|
[16539] | 469 | }/*}}}*/
|
---|
[18930] | 470 | void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
[21160] | 471 |
|
---|
| 472 | IssmDouble dt;
|
---|
| 473 | bool isdynamicbasalspc;
|
---|
| 474 |
|
---|
| 475 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 476 | femmodel->parameters->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
| 477 |
|
---|
[18591] | 478 | if(VerboseSolution()) _printf0_(" computing enthalpy\n");
|
---|
| 479 | femmodel->SetCurrentConfiguration(EnthalpyAnalysisEnum);
|
---|
[21160] | 480 | if((dt>0.) && isdynamicbasalspc) UpdateBasalConstraints(femmodel);
|
---|
[18591] | 481 | solutionsequence_thermal_nonlinear(femmodel);
|
---|
| 482 |
|
---|
| 483 | /*transfer enthalpy to enthalpy picard for the next step: */
|
---|
| 484 | InputDuplicatex(femmodel,EnthalpyEnum,EnthalpyPicardEnum);
|
---|
| 485 |
|
---|
[21161] | 486 | PostProcessing(femmodel);
|
---|
[18591] | 487 |
|
---|
[17005] | 488 | }/*}}}*/
|
---|
[17000] | 489 | ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
| 490 | /*Default, return NULL*/
|
---|
| 491 | return NULL;
|
---|
| 492 | }/*}}}*/
|
---|
[16992] | 493 | ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
| 494 | _error_("Not implemented");
|
---|
| 495 | }/*}}}*/
|
---|
[16782] | 496 | ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
[16888] | 497 |
|
---|
[17434] | 498 | /* Check if ice in element */
|
---|
| 499 | if(!element->IsIceInElement()) return NULL;
|
---|
| 500 |
|
---|
[16888] | 501 | /*compute all stiffness matrices for this element*/
|
---|
| 502 | ElementMatrix* Ke1=CreateKMatrixVolume(element);
|
---|
| 503 | ElementMatrix* Ke2=CreateKMatrixShelf(element);
|
---|
| 504 | ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
|
---|
| 505 |
|
---|
| 506 | /*clean-up and return*/
|
---|
| 507 | delete Ke1;
|
---|
| 508 | delete Ke2;
|
---|
| 509 | return Ke;
|
---|
[16782] | 510 | }/*}}}*/
|
---|
[16888] | 511 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
|
---|
| 512 |
|
---|
[17434] | 513 | /* Check if ice in element */
|
---|
| 514 | if(!element->IsIceInElement()) return NULL;
|
---|
| 515 |
|
---|
[16888] | 516 | /*Intermediaries */
|
---|
| 517 | int stabilization;
|
---|
| 518 | IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
|
---|
| 519 | IssmDouble h,hx,hy,hz,vx,vy,vz;
|
---|
| 520 | IssmDouble tau_parameter,diameter;
|
---|
| 521 | IssmDouble D_scalar;
|
---|
| 522 | IssmDouble* xyz_list = NULL;
|
---|
| 523 |
|
---|
| 524 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 525 | int numnodes = element->GetNumberOfNodes();
|
---|
| 526 |
|
---|
| 527 | /*Initialize Element vector and other vectors*/
|
---|
| 528 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 529 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 530 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
| 531 | IssmDouble* B = xNew<IssmDouble>(3*numnodes);
|
---|
| 532 | IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
|
---|
| 533 | IssmDouble D[3][3] = {0.};
|
---|
| 534 | IssmDouble K[3][3];
|
---|
| 535 |
|
---|
| 536 | /*Retrieve all inputs and parameters*/
|
---|
| 537 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 538 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 539 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
[17946] | 540 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[16888] | 541 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 542 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
| 543 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 544 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 545 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 546 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 547 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 548 | Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
|
---|
| 549 | Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
|
---|
| 550 | Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
|
---|
| 551 | if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
|
---|
| 552 |
|
---|
| 553 | /*Enthalpy diffusion parameter*/
|
---|
[17027] | 554 | IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
[16888] | 555 |
|
---|
| 556 | /* Start looping on the number of gaussian points: */
|
---|
[19637] | 557 | Gauss* gauss=element->NewGauss(4);
|
---|
[16888] | 558 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 559 | gauss->GaussPoint(ig);
|
---|
| 560 |
|
---|
| 561 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 562 | D_scalar=gauss->weight*Jdet;
|
---|
| 563 | if(dt!=0.) D_scalar=D_scalar*dt;
|
---|
| 564 |
|
---|
| 565 | /*Conduction: */
|
---|
| 566 | GetBConduct(B,element,xyz_list,gauss);
|
---|
| 567 | D[0][0]=D_scalar*kappa/rho_ice;
|
---|
| 568 | D[1][1]=D_scalar*kappa/rho_ice;
|
---|
| 569 | D[2][2]=D_scalar*kappa/rho_ice;
|
---|
| 570 | TripleMultiply(B,3,numnodes,1,
|
---|
| 571 | &D[0][0],3,3,0,
|
---|
| 572 | B,3,numnodes,0,
|
---|
| 573 | &Ke->values[0],1);
|
---|
| 574 |
|
---|
| 575 | /*Advection: */
|
---|
| 576 | GetBAdvec(B,element,xyz_list,gauss);
|
---|
| 577 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
| 578 | vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
|
---|
| 579 | vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
|
---|
| 580 | vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
|
---|
| 581 | D[0][0]=D_scalar*vx;
|
---|
| 582 | D[1][1]=D_scalar*vy;
|
---|
| 583 | D[2][2]=D_scalar*vz;
|
---|
| 584 | TripleMultiply(B,3,numnodes,1,
|
---|
| 585 | &D[0][0],3,3,0,
|
---|
| 586 | Bprime,3,numnodes,0,
|
---|
| 587 | &Ke->values[0],1);
|
---|
| 588 |
|
---|
| 589 | /*Transient: */
|
---|
| 590 | if(dt!=0.){
|
---|
| 591 | D_scalar=gauss->weight*Jdet;
|
---|
| 592 | element->NodalFunctions(basis,gauss);
|
---|
| 593 | TripleMultiply(basis,numnodes,1,0,
|
---|
| 594 | &D_scalar,1,1,0,
|
---|
| 595 | basis,1,numnodes,0,
|
---|
| 596 | &Ke->values[0],1);
|
---|
| 597 | D_scalar=D_scalar*dt;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[21382] | 600 | /*Artificial diffusivity*/
|
---|
[16888] | 601 | if(stabilization==1){
|
---|
| 602 | element->ElementSizes(&hx,&hy,&hz);
|
---|
| 603 | vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
|
---|
| 604 | h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
|
---|
[18484] | 605 | K[0][0]=h/(2.*vel)*fabs(vx*vx); K[0][1]=h/(2.*vel)*fabs(vx*vy); K[0][2]=h/(2.*vel)*fabs(vx*vz);
|
---|
| 606 | K[1][0]=h/(2.*vel)*fabs(vy*vx); K[1][1]=h/(2.*vel)*fabs(vy*vy); K[1][2]=h/(2.*vel)*fabs(vy*vz);
|
---|
| 607 | K[2][0]=h/(2.*vel)*fabs(vz*vx); K[2][1]=h/(2.*vel)*fabs(vz*vy); K[2][2]=h/(2.*vel)*fabs(vz*vz);
|
---|
[16888] | 608 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
|
---|
| 609 |
|
---|
| 610 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
| 611 | TripleMultiply(Bprime,3,numnodes,1,
|
---|
| 612 | &K[0][0],3,3,0,
|
---|
| 613 | Bprime,3,numnodes,0,
|
---|
| 614 | &Ke->values[0],1);
|
---|
| 615 | }
|
---|
| 616 | else if(stabilization==2){
|
---|
| 617 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 618 | tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
|
---|
| 619 | for(int i=0;i<numnodes;i++){
|
---|
| 620 | for(int j=0;j<numnodes;j++){
|
---|
| 621 | Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
|
---|
[16895] | 622 | ((u-um)*dbasis[0*numnodes+i]+(v-vm)*dbasis[1*numnodes+i]+(w-wm)*dbasis[2*numnodes+i])*((u-um)*dbasis[0*numnodes+j]+(v-vm)*dbasis[1*numnodes+j]+(w-wm)*dbasis[2*numnodes+j]);
|
---|
[16888] | 623 | }
|
---|
| 624 | }
|
---|
| 625 | if(dt!=0.){
|
---|
[16896] | 626 | D_scalar=gauss->weight*Jdet;
|
---|
[16888] | 627 | for(int i=0;i<numnodes;i++){
|
---|
| 628 | for(int j=0;j<numnodes;j++){
|
---|
[16895] | 629 | Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*basis[j]*((u-um)*dbasis[0*numnodes+i]+(v-vm)*dbasis[1*numnodes+i]+(w-wm)*dbasis[2*numnodes+i]);
|
---|
[16888] | 630 | }
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
| 633 | }
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | /*Clean up and return*/
|
---|
| 637 | xDelete<IssmDouble>(xyz_list);
|
---|
| 638 | xDelete<IssmDouble>(basis);
|
---|
| 639 | xDelete<IssmDouble>(dbasis);
|
---|
| 640 | xDelete<IssmDouble>(B);
|
---|
| 641 | xDelete<IssmDouble>(Bprime);
|
---|
| 642 | delete gauss;
|
---|
| 643 | return Ke;
|
---|
| 644 | }/*}}}*/
|
---|
| 645 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
|
---|
| 646 |
|
---|
[17434] | 647 | /* Check if ice in element */
|
---|
| 648 | if(!element->IsIceInElement()) return NULL;
|
---|
| 649 |
|
---|
[16888] | 650 | /*Initialize Element matrix and return if necessary*/
|
---|
[17585] | 651 | if(!element->IsOnBase() || !element->IsFloating()) return NULL;
|
---|
[16888] | 652 |
|
---|
[16986] | 653 | /*Intermediaries*/
|
---|
[16888] | 654 | IssmDouble dt,Jdet,D;
|
---|
| 655 | IssmDouble *xyz_list_base = NULL;
|
---|
| 656 |
|
---|
| 657 | /*Fetch number of nodes for this finite element*/
|
---|
| 658 | int numnodes = element->GetNumberOfNodes();
|
---|
| 659 |
|
---|
| 660 | /*Initialize vectors*/
|
---|
| 661 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 662 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 663 |
|
---|
| 664 | /*Retrieve all inputs and parameters*/
|
---|
| 665 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 666 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 667 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
[17946] | 668 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[16888] | 669 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 670 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 671 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
| 672 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
| 673 |
|
---|
| 674 | /* Start looping on the number of gaussian points: */
|
---|
[19637] | 675 | Gauss* gauss=element->NewGaussBase(4);
|
---|
[16888] | 676 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 677 | gauss->GaussPoint(ig);
|
---|
| 678 |
|
---|
| 679 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 680 | element->NodalFunctions(basis,gauss);
|
---|
| 681 |
|
---|
| 682 | D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
|
---|
| 683 | if(reCast<bool,IssmDouble>(dt)) D=dt*D;
|
---|
| 684 | TripleMultiply(basis,numnodes,1,0,
|
---|
| 685 | &D,1,1,0,
|
---|
| 686 | basis,1,numnodes,0,
|
---|
| 687 | &Ke->values[0],1);
|
---|
| 688 |
|
---|
| 689 | }
|
---|
| 690 |
|
---|
| 691 | /*Clean up and return*/
|
---|
| 692 | delete gauss;
|
---|
| 693 | xDelete<IssmDouble>(basis);
|
---|
| 694 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 695 | return Ke;
|
---|
| 696 | }/*}}}*/
|
---|
[16782] | 697 | ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
[16812] | 698 |
|
---|
[17434] | 699 | /* Check if ice in element */
|
---|
| 700 | if(!element->IsIceInElement()) return NULL;
|
---|
| 701 |
|
---|
[16812] | 702 | /*compute all load vectors for this element*/
|
---|
| 703 | ElementVector* pe1=CreatePVectorVolume(element);
|
---|
| 704 | ElementVector* pe2=CreatePVectorSheet(element);
|
---|
| 705 | ElementVector* pe3=CreatePVectorShelf(element);
|
---|
| 706 | ElementVector* pe =new ElementVector(pe1,pe2,pe3);
|
---|
| 707 |
|
---|
| 708 | /*clean-up and return*/
|
---|
| 709 | delete pe1;
|
---|
| 710 | delete pe2;
|
---|
| 711 | delete pe3;
|
---|
| 712 | return pe;
|
---|
[16782] | 713 | }/*}}}*/
|
---|
[16812] | 714 | ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
|
---|
| 715 |
|
---|
[17434] | 716 | /* Check if ice in element */
|
---|
| 717 | if(!element->IsIceInElement()) return NULL;
|
---|
| 718 |
|
---|
[16812] | 719 | /*Intermediaries*/
|
---|
[17014] | 720 | int i, stabilization;
|
---|
[16812] | 721 | IssmDouble Jdet,phi,dt;
|
---|
[17014] | 722 | IssmDouble enthalpy, Hpmp;
|
---|
| 723 | IssmDouble enthalpypicard, d1enthalpypicard[3];
|
---|
| 724 | IssmDouble pressure, d1pressure[3], d2pressure;
|
---|
| 725 | IssmDouble waterfractionpicard;
|
---|
| 726 | IssmDouble kappa,tau_parameter,diameter,kappa_w;
|
---|
[16812] | 727 | IssmDouble u,v,w;
|
---|
[17014] | 728 | IssmDouble scalar_def, scalar_sens ,scalar_transient;
|
---|
[16812] | 729 | IssmDouble* xyz_list = NULL;
|
---|
[17014] | 730 | IssmDouble d1H_d1P, d1P2;
|
---|
[16812] | 731 |
|
---|
| 732 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 733 | int numnodes = element->GetNumberOfNodes();
|
---|
| 734 | int numvertices = element->GetNumberOfVertices();
|
---|
| 735 |
|
---|
| 736 | /*Initialize Element vector*/
|
---|
| 737 | ElementVector* pe = element->NewElementVector();
|
---|
| 738 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 739 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
| 740 |
|
---|
| 741 | /*Retrieve all inputs and parameters*/
|
---|
| 742 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 743 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
[17014] | 744 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
[16812] | 745 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
[17014] | 746 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
| 747 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
| 748 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
[16812] | 749 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 750 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
| 751 | Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 752 | Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 753 | Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
|
---|
[17014] | 754 | Input* enthalpypicard_input=element->GetInput(EnthalpyPicardEnum); _assert_(enthalpypicard_input);
|
---|
| 755 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 756 | Input* enthalpy_input=NULL;
|
---|
[16812] | 757 | if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
|
---|
| 758 | if(stabilization==2){
|
---|
| 759 | diameter=element->MinEdgeLength(xyz_list);
|
---|
[17027] | 760 | kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
[16812] | 761 | }
|
---|
| 762 |
|
---|
| 763 | /* Start looping on the number of gaussian points: */
|
---|
[19637] | 764 | Gauss* gauss=element->NewGauss(4);
|
---|
[16812] | 765 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 766 | gauss->GaussPoint(ig);
|
---|
| 767 |
|
---|
| 768 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 769 | element->NodalFunctions(basis,gauss);
|
---|
[17014] | 770 |
|
---|
| 771 | /*viscous dissipation*/
|
---|
[16812] | 772 | element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
|
---|
| 773 |
|
---|
| 774 | scalar_def=phi/rho_ice*Jdet*gauss->weight;
|
---|
[16895] | 775 | if(dt!=0.) scalar_def=scalar_def*dt;
|
---|
[16812] | 776 |
|
---|
[17014] | 777 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
|
---|
[16812] | 778 |
|
---|
[17014] | 779 | /*sensible heat flux in temperate ice*/
|
---|
| 780 | enthalpypicard_input->GetInputValue(&enthalpypicard,gauss);
|
---|
| 781 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 782 | Hpmp=this->PureIceEnthalpy(element, pressure);
|
---|
| 783 |
|
---|
| 784 | if(enthalpypicard>=Hpmp){
|
---|
| 785 | enthalpypicard_input->GetInputDerivativeValue(&d1enthalpypicard[0],xyz_list,gauss);
|
---|
| 786 | pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
|
---|
| 787 | d2pressure=0.; // for linear elements, 2nd derivative is zero
|
---|
| 788 |
|
---|
| 789 | d1H_d1P=0.;
|
---|
| 790 | for(i=0;i<3;i++) d1H_d1P+=d1enthalpypicard[i]*d1pressure[i];
|
---|
| 791 | d1P2=0.;
|
---|
| 792 | for(i=0;i<3;i++) d1P2+=pow(d1pressure[i],2.);
|
---|
| 793 |
|
---|
| 794 | scalar_sens=-beta*((temperateiceconductivity - thermalconductivity)/latentheat*(d1H_d1P + beta*heatcapacity*d1P2))/rho_ice;
|
---|
| 795 | if(dt!=0.) scalar_sens=scalar_sens*dt;
|
---|
| 796 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_sens*basis[i];
|
---|
| 797 | }
|
---|
| 798 |
|
---|
[16812] | 799 | /* Build transient now */
|
---|
| 800 | if(reCast<bool,IssmDouble>(dt)){
|
---|
| 801 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
| 802 | scalar_transient=enthalpy*Jdet*gauss->weight;
|
---|
[17014] | 803 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
|
---|
[16812] | 804 | }
|
---|
| 805 |
|
---|
| 806 | if(stabilization==2){
|
---|
| 807 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 808 |
|
---|
| 809 | vx_input->GetInputValue(&u,gauss);
|
---|
| 810 | vy_input->GetInputValue(&v,gauss);
|
---|
| 811 | vz_input->GetInputValue(&w,gauss);
|
---|
[16895] | 812 | tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
|
---|
[16812] | 813 |
|
---|
[17014] | 814 | for(i=0;i<numnodes;i++) pe->values[i]+=tau_parameter*scalar_def*(u*dbasis[0*numnodes+i]+v*dbasis[1*numnodes+i]+w*dbasis[2*numnodes+i]);
|
---|
[16895] | 815 |
|
---|
| 816 | if(dt!=0.){
|
---|
[17014] | 817 | for(i=0;i<numnodes;i++) pe->values[i]+=tau_parameter*scalar_transient*(u*dbasis[0*numnodes+i]+v*dbasis[1*numnodes+i]+w*dbasis[2*numnodes+i]);
|
---|
[16812] | 818 | }
|
---|
| 819 | }
|
---|
| 820 | }
|
---|
| 821 |
|
---|
| 822 | /*Clean up and return*/
|
---|
| 823 | xDelete<IssmDouble>(basis);
|
---|
| 824 | xDelete<IssmDouble>(dbasis);
|
---|
| 825 | xDelete<IssmDouble>(xyz_list);
|
---|
| 826 | delete gauss;
|
---|
| 827 | return pe;
|
---|
| 828 |
|
---|
| 829 | }/*}}}*/
|
---|
| 830 | ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
|
---|
[16888] | 831 |
|
---|
[17434] | 832 | /* Check if ice in element */
|
---|
| 833 | if(!element->IsIceInElement()) return NULL;
|
---|
| 834 |
|
---|
[17014] | 835 | /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
|
---|
[17585] | 836 | if(!element->IsOnBase() || element->IsFloating()) return NULL;
|
---|
[16888] | 837 |
|
---|
[20272] | 838 | bool converged, isdynamicbasalspc;
|
---|
[18612] | 839 | int i, state;
|
---|
[20272] | 840 | int enthalpy_enum;
|
---|
[18612] | 841 | IssmDouble dt,Jdet,scalar;
|
---|
| 842 | IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
|
---|
| 843 | IssmDouble vx,vy,vz;
|
---|
| 844 | IssmDouble alpha2,basalfriction,geothermalflux,heatflux;
|
---|
[16888] | 845 | IssmDouble *xyz_list_base = NULL;
|
---|
| 846 |
|
---|
| 847 | /*Fetch number of nodes for this finite element*/
|
---|
| 848 | int numnodes = element->GetNumberOfNodes();
|
---|
| 849 |
|
---|
| 850 | /*Initialize vectors*/
|
---|
| 851 | ElementVector* pe = element->NewElementVector();
|
---|
| 852 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 853 |
|
---|
| 854 | /*Retrieve all inputs and parameters*/
|
---|
| 855 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 856 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
[18622] | 857 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
[20272] | 858 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
| 859 | if(dt==0. && !converged) enthalpy_enum=EnthalpyPicardEnum; // use enthalpy from last iteration
|
---|
| 860 | else enthalpy_enum=EnthalpyEnum; // use enthalpy from last time step
|
---|
[16888] | 861 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 862 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 863 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
[20272] | 864 | Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
|
---|
[18612] | 865 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 866 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
| 867 | Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
|
---|
[16888] | 868 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
[18612] | 869 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
[16888] | 870 |
|
---|
| 871 | /*Build friction element, needed later: */
|
---|
| 872 | Friction* friction=new Friction(element,3);
|
---|
| 873 |
|
---|
| 874 | /* Start looping on the number of gaussian points: */
|
---|
[19637] | 875 | Gauss* gauss=element->NewGaussBase(4);
|
---|
| 876 | Gauss* gaussup=element->NewGaussTop(4);
|
---|
[16888] | 877 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 878 | gauss->GaussPoint(ig);
|
---|
[18665] | 879 | gaussup->GaussPoint(ig);
|
---|
[16888] | 880 |
|
---|
| 881 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 882 | element->NodalFunctions(basis,gauss);
|
---|
| 883 |
|
---|
[18622] | 884 | if(isdynamicbasalspc){
|
---|
| 885 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
| 886 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
| 887 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 888 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
| 889 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
| 890 | meltingrate_input->GetInputValue(&meltingrate,gauss);
|
---|
| 891 | state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
|
---|
| 892 | }
|
---|
| 893 | else
|
---|
| 894 | state=0;
|
---|
[16888] | 895 |
|
---|
[18612] | 896 | switch (state) {
|
---|
[20272] | 897 | case 0: case 1: case 2: case 3:
|
---|
| 898 | // cold, dry base; cold, wet base; refreezing temperate base; thin temperate base:
|
---|
| 899 | // Apply basal surface forcing.
|
---|
| 900 | // Interpolated values of enthalpy on gauss nodes may indicate cold base,
|
---|
| 901 | // although one node might have become temperate. So keep heat flux switched on.
|
---|
[18612] | 902 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
| 903 | friction->GetAlpha2(&alpha2,gauss);
|
---|
| 904 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 905 | vy_input->GetInputValue(&vy,gauss);
|
---|
| 906 | vz_input->GetInputValue(&vz,gauss);
|
---|
| 907 | basalfriction=alpha2*(vx*vx+vy*vy+vz*vz);
|
---|
| 908 | heatflux=(basalfriction+geothermalflux)/(rho_ice);
|
---|
| 909 | scalar=gauss->weight*Jdet*heatflux;
|
---|
| 910 | if(dt!=0.) scalar=dt*scalar;
|
---|
| 911 | for(i=0;i<numnodes;i++)
|
---|
| 912 | pe->values[i]+=scalar*basis[i];
|
---|
| 913 | break;
|
---|
| 914 | case 4:
|
---|
| 915 | // temperate, thick melting base: set grad H*n=0
|
---|
| 916 | for(i=0;i<numnodes;i++)
|
---|
| 917 | pe->values[i]+=0.;
|
---|
| 918 | break;
|
---|
| 919 | default:
|
---|
| 920 | _printf0_(" unknown thermal basal state found!");
|
---|
[16888] | 921 | }
|
---|
| 922 | }
|
---|
| 923 |
|
---|
| 924 | /*Clean up and return*/
|
---|
| 925 | delete gauss;
|
---|
| 926 | delete gaussup;
|
---|
| 927 | delete friction;
|
---|
| 928 | xDelete<IssmDouble>(basis);
|
---|
| 929 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 930 | return pe;
|
---|
| 931 |
|
---|
[16812] | 932 | }/*}}}*/
|
---|
| 933 | ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
|
---|
| 934 |
|
---|
[17434] | 935 | /* Check if ice in element */
|
---|
| 936 | if(!element->IsIceInElement()) return NULL;
|
---|
| 937 |
|
---|
[16888] | 938 | /*Get basal element*/
|
---|
[17585] | 939 | if(!element->IsOnBase() || !element->IsFloating()) return NULL;
|
---|
[16888] | 940 |
|
---|
[18612] | 941 | IssmDouble Hpmp,dt,Jdet,scalar_ocean,pressure;
|
---|
[16812] | 942 | IssmDouble *xyz_list_base = NULL;
|
---|
| 943 |
|
---|
| 944 | /*Fetch number of nodes for this finite element*/
|
---|
| 945 | int numnodes = element->GetNumberOfNodes();
|
---|
| 946 |
|
---|
| 947 | /*Initialize vectors*/
|
---|
| 948 | ElementVector* pe = element->NewElementVector();
|
---|
| 949 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 950 |
|
---|
| 951 | /*Retrieve all inputs and parameters*/
|
---|
| 952 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 953 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 954 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 955 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
[17946] | 956 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[16812] | 957 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 958 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 959 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
| 960 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
| 961 |
|
---|
| 962 | /* Start looping on the number of gaussian points: */
|
---|
[19637] | 963 | Gauss* gauss=element->NewGaussBase(4);
|
---|
[16812] | 964 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 965 | gauss->GaussPoint(ig);
|
---|
| 966 |
|
---|
| 967 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 968 | element->NodalFunctions(basis,gauss);
|
---|
| 969 |
|
---|
| 970 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
[18612] | 971 | Hpmp=element->PureIceEnthalpy(pressure);
|
---|
[16812] | 972 |
|
---|
[18612] | 973 | scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*Hpmp/(heatcapacity*rho_ice);
|
---|
[16812] | 974 | if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
|
---|
| 975 |
|
---|
| 976 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
|
---|
| 977 | }
|
---|
| 978 |
|
---|
| 979 | /*Clean up and return*/
|
---|
| 980 | delete gauss;
|
---|
| 981 | xDelete<IssmDouble>(basis);
|
---|
| 982 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 983 | return pe;
|
---|
| 984 | }/*}}}*/
|
---|
[18930] | 985 | void EnthalpyAnalysis::DrainWaterfraction(FemModel* femmodel){/*{{{*/
|
---|
| 986 | /*Drain excess water fraction in ice column: */
|
---|
[21721] | 987 | ComputeWaterfractionDrainage(femmodel);
|
---|
| 988 | DrainageUpdateWatercolumn(femmodel);
|
---|
| 989 | DrainageUpdateEnthalpy(femmodel);
|
---|
[17002] | 990 | }/*}}}*/
|
---|
[21721] | 991 | void EnthalpyAnalysis::ComputeWaterfractionDrainage(FemModel* femmodel){/*{{{*/
|
---|
[17002] | 992 |
|
---|
[21721] | 993 | int i,k,numnodes;
|
---|
| 994 | IssmDouble dt;
|
---|
| 995 | Element* element= NULL;
|
---|
[17434] | 996 |
|
---|
[21721] | 997 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
[17434] | 998 |
|
---|
[21721] | 999 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
| 1000 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 1001 | numnodes=element->GetNumberOfNodes();
|
---|
| 1002 | IssmDouble* waterfractions= xNew<IssmDouble>(numnodes);
|
---|
| 1003 | IssmDouble* drainage= xNew<IssmDouble>(numnodes);
|
---|
[17014] | 1004 |
|
---|
[21721] | 1005 | element->GetInputListOnNodes(waterfractions,WaterfractionEnum);
|
---|
| 1006 | for(k=0; k<numnodes;k++){
|
---|
| 1007 | drainage[k]=DrainageFunctionWaterfraction(waterfractions[k], dt);
|
---|
| 1008 | }
|
---|
| 1009 | element->AddInput(WaterfractionDrainageEnum,drainage,element->GetElementType());
|
---|
[18930] | 1010 |
|
---|
[21721] | 1011 | xDelete<IssmDouble>(waterfractions);
|
---|
| 1012 | xDelete<IssmDouble>(drainage);
|
---|
[18930] | 1013 | }
|
---|
[21721] | 1014 | }/*}}}*/
|
---|
| 1015 | void EnthalpyAnalysis::DrainageUpdateWatercolumn(FemModel* femmodel){/*{{{*/
|
---|
| 1016 |
|
---|
| 1017 | int i,k,numnodes, numbasalnodes;
|
---|
| 1018 | IssmDouble dt;
|
---|
| 1019 | int* basalnodeindices=NULL;
|
---|
| 1020 | Element* element= NULL;
|
---|
[18930] | 1021 |
|
---|
[21721] | 1022 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
[18667] | 1023 |
|
---|
[21721] | 1024 | /*depth-integrate the drained water fraction */
|
---|
| 1025 | femmodel->parameters->SetParam(WaterfractionDrainageEnum,InputToDepthaverageInEnum);
|
---|
| 1026 | femmodel->parameters->SetParam(WaterfractionDrainageIntegratedEnum,InputToDepthaverageOutEnum);
|
---|
| 1027 | depthaverage_core(femmodel);
|
---|
| 1028 | femmodel->parameters->SetParam(WaterfractionDrainageIntegratedEnum,InputToExtrudeEnum);
|
---|
| 1029 | extrudefrombase_core(femmodel);
|
---|
| 1030 | /*multiply depth-average by ice thickness*/
|
---|
| 1031 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
| 1032 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 1033 | numnodes=element->GetNumberOfNodes();
|
---|
| 1034 | IssmDouble* drainage_int= xNew<IssmDouble>(numnodes);
|
---|
| 1035 | IssmDouble* thicknesses= xNew<IssmDouble>(numnodes);
|
---|
[17014] | 1036 |
|
---|
[21721] | 1037 | element->GetInputListOnNodes(drainage_int,WaterfractionDrainageIntegratedEnum);
|
---|
| 1038 | element->GetInputListOnNodes(thicknesses,ThicknessEnum);
|
---|
| 1039 | for(k=0;k<numnodes;k++){
|
---|
| 1040 | drainage_int[k]*=thicknesses[k];
|
---|
| 1041 | }
|
---|
| 1042 | element->AddInput(WaterfractionDrainageIntegratedEnum, drainage_int, element->GetElementType());
|
---|
[17166] | 1043 |
|
---|
[21721] | 1044 | xDelete<IssmDouble>(drainage_int);
|
---|
| 1045 | xDelete<IssmDouble>(thicknesses);
|
---|
| 1046 | }
|
---|
[17434] | 1047 |
|
---|
[21721] | 1048 | /*update water column*/
|
---|
| 1049 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
| 1050 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 1051 | /* Check if ice in element */
|
---|
| 1052 | if(!element->IsIceInElement()) continue;
|
---|
| 1053 | if(!element->IsOnBase()) continue;
|
---|
[17166] | 1054 |
|
---|
[21721] | 1055 | numnodes=element->GetNumberOfNodes();
|
---|
| 1056 | IssmDouble* watercolumn= xNew<IssmDouble>(numnodes);
|
---|
| 1057 | IssmDouble* drainage_int= xNew<IssmDouble>(numnodes);
|
---|
| 1058 | element->GetInputListOnNodes(watercolumn,WatercolumnEnum);
|
---|
| 1059 | element->GetInputListOnNodes(drainage_int,WaterfractionDrainageIntegratedEnum);
|
---|
[17166] | 1060 |
|
---|
[21721] | 1061 | element->BasalNodeIndices(&numbasalnodes,&basalnodeindices,element->GetElementType());
|
---|
| 1062 | for(k=0;k<numbasalnodes;k++){
|
---|
| 1063 | watercolumn[basalnodeindices[k]]+=dt*drainage_int[basalnodeindices[k]];
|
---|
| 1064 | }
|
---|
| 1065 | element->AddInput(WatercolumnEnum, watercolumn, element->GetElementType());
|
---|
[17166] | 1066 |
|
---|
[21721] | 1067 | xDelete<IssmDouble>(watercolumn);
|
---|
| 1068 | xDelete<IssmDouble>(drainage_int);
|
---|
| 1069 | }
|
---|
| 1070 | xDelete<int>(basalnodeindices);
|
---|
| 1071 | }/*}}}*/
|
---|
| 1072 | void EnthalpyAnalysis::DrainageUpdateEnthalpy(FemModel* femmodel){/*{{{*/
|
---|
[17166] | 1073 |
|
---|
[21721] | 1074 | int i,k,numnodes;
|
---|
| 1075 | IssmDouble dt;
|
---|
| 1076 | Element* element= NULL;
|
---|
| 1077 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
[17166] | 1078 |
|
---|
[21721] | 1079 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
| 1080 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 1081 | numnodes=element->GetNumberOfNodes();
|
---|
| 1082 | IssmDouble* enthalpies= xNew<IssmDouble>(numnodes);
|
---|
| 1083 | IssmDouble* pressures= xNew<IssmDouble>(numnodes);
|
---|
| 1084 | IssmDouble* temperatures= xNew<IssmDouble>(numnodes);
|
---|
| 1085 | IssmDouble* waterfractions= xNew<IssmDouble>(numnodes);
|
---|
| 1086 | IssmDouble* drainage= xNew<IssmDouble>(numnodes);
|
---|
[21653] | 1087 |
|
---|
[21721] | 1088 | element->GetInputListOnNodes(pressures,PressureEnum);
|
---|
| 1089 | element->GetInputListOnNodes(temperatures,TemperatureEnum);
|
---|
| 1090 | element->GetInputListOnNodes(waterfractions,WaterfractionEnum);
|
---|
| 1091 | element->GetInputListOnNodes(drainage,WaterfractionDrainageEnum);
|
---|
[21653] | 1092 |
|
---|
[21721] | 1093 | for(k=0;k<numnodes;k++){
|
---|
| 1094 | waterfractions[k]-=dt*drainage[k];
|
---|
| 1095 | element->ThermalToEnthalpy(&enthalpies[k], temperatures[k], waterfractions[k], pressures[k]);
|
---|
| 1096 | }
|
---|
| 1097 | element->AddInput(WaterfractionEnum,waterfractions,element->GetElementType());
|
---|
| 1098 | element->AddInput(EnthalpyEnum,enthalpies,element->GetElementType());
|
---|
[17166] | 1099 |
|
---|
[21721] | 1100 | xDelete<IssmDouble>(enthalpies);
|
---|
| 1101 | xDelete<IssmDouble>(pressures);
|
---|
| 1102 | xDelete<IssmDouble>(temperatures);
|
---|
| 1103 | xDelete<IssmDouble>(waterfractions);
|
---|
| 1104 | xDelete<IssmDouble>(drainage);
|
---|
| 1105 | }
|
---|
[17002] | 1106 | }/*}}}*/
|
---|
[18930] | 1107 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
|
---|
[17014] | 1108 |
|
---|
[18930] | 1109 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 1110 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
| 1111 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
[17434] | 1112 |
|
---|
[18930] | 1113 | if(enthalpy < PureIceEnthalpy(element,pressure)){
|
---|
| 1114 | return thermalconductivity/heatcapacity;
|
---|
| 1115 | }
|
---|
| 1116 | else{
|
---|
| 1117 | return temperateiceconductivity/heatcapacity;
|
---|
| 1118 | }
|
---|
| 1119 | }/*}}}*/
|
---|
| 1120 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
|
---|
[17014] | 1121 |
|
---|
[18930] | 1122 | int iv;
|
---|
| 1123 | IssmDouble lambda; /* fraction of cold ice */
|
---|
| 1124 | IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
|
---|
| 1125 | IssmDouble Hc,Ht;
|
---|
[17014] | 1126 |
|
---|
[18930] | 1127 | /*Get pressures and enthalpies on vertices*/
|
---|
| 1128 | int numvertices = element->GetNumberOfVertices();
|
---|
| 1129 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
| 1130 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
| 1131 | IssmDouble* PIE = xNew<IssmDouble>(numvertices);
|
---|
| 1132 | IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
|
---|
[17014] | 1133 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
[18930] | 1134 | element->GetInputListOnVertices(enthalpies,enthalpy_enum);
|
---|
| 1135 | for(iv=0;iv<numvertices;iv++){
|
---|
| 1136 | PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
|
---|
| 1137 | dHpmp[iv] = enthalpies[iv]-PIE[iv];
|
---|
| 1138 | }
|
---|
[17014] | 1139 |
|
---|
[18930] | 1140 | bool allequalsign = true;
|
---|
| 1141 | if(dHpmp[0]<0.){
|
---|
| 1142 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
|
---|
[17014] | 1143 | }
|
---|
[18930] | 1144 | else{
|
---|
| 1145 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
|
---|
[17014] | 1146 | }
|
---|
| 1147 |
|
---|
[18930] | 1148 | if(allequalsign){
|
---|
| 1149 | kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
|
---|
[17014] | 1150 | }
|
---|
[18930] | 1151 | else{
|
---|
| 1152 | /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
|
---|
| 1153 | cf Patankar 1980, pp44 */
|
---|
| 1154 | kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
|
---|
| 1155 | kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
|
---|
| 1156 | Hc=0.; Ht=0.;
|
---|
| 1157 | for(iv=0; iv<numvertices;iv++){
|
---|
| 1158 | if(enthalpies[iv]<PIE[iv])
|
---|
| 1159 | Hc+=(PIE[iv]-enthalpies[iv]);
|
---|
| 1160 | else
|
---|
| 1161 | Ht+=(enthalpies[iv]-PIE[iv]);
|
---|
| 1162 | }
|
---|
| 1163 | _assert_((Hc+Ht)>0.);
|
---|
| 1164 | lambda = Hc/(Hc+Ht);
|
---|
| 1165 | kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
|
---|
| 1166 | }
|
---|
[17014] | 1167 |
|
---|
| 1168 | /*Clean up and return*/
|
---|
[18930] | 1169 | xDelete<IssmDouble>(PIE);
|
---|
| 1170 | xDelete<IssmDouble>(dHpmp);
|
---|
| 1171 | xDelete<IssmDouble>(pressures);
|
---|
[17014] | 1172 | xDelete<IssmDouble>(enthalpies);
|
---|
[18930] | 1173 | return kappa;
|
---|
[17002] | 1174 | }/*}}}*/
|
---|
[18930] | 1175 | void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 1176 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 1177 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 1178 | * by:
|
---|
| 1179 | * Bi_advec =[ h ]
|
---|
| 1180 | * [ h ]
|
---|
| 1181 | * [ h ]
|
---|
| 1182 | * where h is the interpolation function for node i.
|
---|
| 1183 | *
|
---|
| 1184 | * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
|
---|
| 1185 | */
|
---|
[18659] | 1186 |
|
---|
[18930] | 1187 | /*Fetch number of nodes for this finite element*/
|
---|
| 1188 | int numnodes = element->GetNumberOfNodes();
|
---|
[18659] | 1189 |
|
---|
[18930] | 1190 | /*Get nodal functions*/
|
---|
| 1191 | IssmDouble* basis=xNew<IssmDouble>(numnodes);
|
---|
| 1192 | element->NodalFunctions(basis,gauss);
|
---|
[18659] | 1193 |
|
---|
[18930] | 1194 | /*Build B: */
|
---|
| 1195 | for(int i=0;i<numnodes;i++){
|
---|
| 1196 | B[numnodes*0+i] = basis[i];
|
---|
| 1197 | B[numnodes*1+i] = basis[i];
|
---|
| 1198 | B[numnodes*2+i] = basis[i];
|
---|
[18659] | 1199 | }
|
---|
| 1200 |
|
---|
[18930] | 1201 | /*Clean-up*/
|
---|
| 1202 | xDelete<IssmDouble>(basis);
|
---|
[18612] | 1203 | }/*}}}*/
|
---|
[18930] | 1204 | void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 1205 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 1206 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 1207 | * by:
|
---|
| 1208 | * Biprime_advec=[ dh/dx ]
|
---|
| 1209 | * [ dh/dy ]
|
---|
| 1210 | * [ dh/dz ]
|
---|
| 1211 | * where h is the interpolation function for node i.
|
---|
| 1212 | *
|
---|
| 1213 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
| 1214 | */
|
---|
[17002] | 1215 |
|
---|
[18930] | 1216 | /*Fetch number of nodes for this finite element*/
|
---|
| 1217 | int numnodes = element->GetNumberOfNodes();
|
---|
[17434] | 1218 |
|
---|
[18930] | 1219 | /*Get nodal functions derivatives*/
|
---|
| 1220 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
| 1221 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
[17434] | 1222 |
|
---|
[18930] | 1223 | /*Build B: */
|
---|
| 1224 | for(int i=0;i<numnodes;i++){
|
---|
| 1225 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
| 1226 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
| 1227 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
[18659] | 1228 | }
|
---|
| 1229 |
|
---|
[18930] | 1230 | /*Clean-up*/
|
---|
| 1231 | xDelete<IssmDouble>(dbasis);
|
---|
[18659] | 1232 | }/*}}}*/
|
---|
[18930] | 1233 | void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
|
---|
[18659] | 1234 |
|
---|
| 1235 | /*Intermediary*/
|
---|
| 1236 | bool isdynamicbasalspc;
|
---|
[18612] | 1237 | IssmDouble dt;
|
---|
| 1238 |
|
---|
| 1239 | /*Check wether dynamic basal boundary conditions are activated */
|
---|
| 1240 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
| 1241 | if(!isdynamicbasalspc) return;
|
---|
| 1242 |
|
---|
| 1243 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 1244 | if(dt==0.){
|
---|
[18659] | 1245 | GetBasalConstraintsSteadystate(vec_spc,element);
|
---|
[18612] | 1246 | }
|
---|
| 1247 | else{
|
---|
[18659] | 1248 | GetBasalConstraintsTransient(vec_spc,element);
|
---|
[18612] | 1249 | }
|
---|
| 1250 | }/*}}}*/
|
---|
[18930] | 1251 | void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
|
---|
[18612] | 1252 |
|
---|
| 1253 | /* Check if ice in element */
|
---|
| 1254 | if(!element->IsIceInElement()) return;
|
---|
| 1255 |
|
---|
[20213] | 1256 | /* Only update constraints at the base.
|
---|
| 1257 | * Floating ice is not affected by basal BC decision chart. */
|
---|
[18612] | 1258 | if(!(element->IsOnBase()) || element->IsFloating()) return;
|
---|
| 1259 |
|
---|
| 1260 | /*Intermediary*/
|
---|
| 1261 | int numindices, numindicesup, state;
|
---|
[17027] | 1262 | int *indices = NULL, *indicesup = NULL;
|
---|
[18612] | 1263 | IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
|
---|
[17014] | 1264 |
|
---|
[18612] | 1265 | /*Get parameters and inputs: */
|
---|
[18930] | 1266 | Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
|
---|
[18612] | 1267 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 1268 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
| 1269 | Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
|
---|
| 1270 |
|
---|
[17027] | 1271 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
| 1272 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
| 1273 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
[18612] | 1274 | penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
|
---|
[17014] | 1275 |
|
---|
[18612] | 1276 | GaussPenta* gauss=new GaussPenta();
|
---|
| 1277 | GaussPenta* gaussup=new GaussPenta();
|
---|
| 1278 | for(int i=0;i<numindices;i++){
|
---|
| 1279 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
| 1280 | gaussup->GaussNode(element->GetElementType(),indicesup[i]);
|
---|
[18930] | 1281 |
|
---|
[18612] | 1282 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
| 1283 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
| 1284 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 1285 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
| 1286 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
| 1287 | meltingrate_input->GetInputValue(&meltingrate,gauss);
|
---|
| 1288 |
|
---|
| 1289 | state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
|
---|
| 1290 | switch (state) {
|
---|
| 1291 | case 0:
|
---|
| 1292 | // cold, dry base: apply basal surface forcing
|
---|
[18659] | 1293 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
[18612] | 1294 | break;
|
---|
| 1295 | case 1:
|
---|
| 1296 | // cold, wet base: keep at pressure melting point
|
---|
[18659] | 1297 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
[18612] | 1298 | break;
|
---|
| 1299 | case 2:
|
---|
[20098] | 1300 | // temperate, thin refreezing base:
|
---|
| 1301 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
[18612] | 1302 | break;
|
---|
| 1303 | case 3:
|
---|
| 1304 | // temperate, thin melting base: set spc
|
---|
[18659] | 1305 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
[18612] | 1306 | break;
|
---|
| 1307 | case 4:
|
---|
[20098] | 1308 | // temperate, thick melting base:
|
---|
[18930] | 1309 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
[18612] | 1310 | break;
|
---|
| 1311 | default:
|
---|
| 1312 | _printf0_(" unknown thermal basal state found!");
|
---|
| 1313 | }
|
---|
| 1314 | }
|
---|
| 1315 |
|
---|
| 1316 | /*Free ressources:*/
|
---|
| 1317 | xDelete<int>(indices);
|
---|
| 1318 | xDelete<int>(indicesup);
|
---|
| 1319 | delete gauss;
|
---|
| 1320 | delete gaussup;
|
---|
| 1321 | }/*}}}*/
|
---|
[18930] | 1322 | void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
|
---|
[18612] | 1323 |
|
---|
| 1324 | /* Check if ice in element */
|
---|
| 1325 | if(!element->IsIceInElement()) return;
|
---|
| 1326 |
|
---|
[20213] | 1327 | /* Only update constraints at the base.
|
---|
| 1328 | * Floating ice is not affected by basal BC decision chart.*/
|
---|
[18612] | 1329 | if(!(element->IsOnBase()) || element->IsFloating()) return;
|
---|
| 1330 |
|
---|
| 1331 | /*Intermediary*/
|
---|
| 1332 | int numindices, numindicesup, state;
|
---|
| 1333 | int *indices = NULL, *indicesup = NULL;
|
---|
| 1334 | IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
|
---|
| 1335 |
|
---|
[17027] | 1336 | /*Get parameters and inputs: */
|
---|
[18930] | 1337 | Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
|
---|
[18612] | 1338 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 1339 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
| 1340 | Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
|
---|
[17014] | 1341 |
|
---|
[18612] | 1342 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
| 1343 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
| 1344 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
| 1345 | penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
|
---|
| 1346 |
|
---|
[17027] | 1347 | GaussPenta* gauss=new GaussPenta();
|
---|
| 1348 | GaussPenta* gaussup=new GaussPenta();
|
---|
[18930] | 1349 |
|
---|
[17027] | 1350 | for(int i=0;i<numindices;i++){
|
---|
| 1351 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
| 1352 | gaussup->GaussNode(element->GetElementType(),indicesup[i]);
|
---|
[18930] | 1353 |
|
---|
[18612] | 1354 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
| 1355 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
| 1356 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 1357 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
[17027] | 1358 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
[18612] | 1359 | meltingrate_input->GetInputValue(&meltingrate,gauss);
|
---|
| 1360 |
|
---|
| 1361 | state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
|
---|
[18930] | 1362 |
|
---|
[18612] | 1363 | switch (state) {
|
---|
| 1364 | case 0:
|
---|
| 1365 | // cold, dry base: apply basal surface forcing
|
---|
[18659] | 1366 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
[18612] | 1367 | break;
|
---|
| 1368 | case 1:
|
---|
| 1369 | // cold, wet base: keep at pressure melting point
|
---|
[18659] | 1370 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
[18612] | 1371 | break;
|
---|
| 1372 | case 2:
|
---|
| 1373 | // temperate, thin refreezing base: release spc
|
---|
[18659] | 1374 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
[18612] | 1375 | break;
|
---|
| 1376 | case 3:
|
---|
| 1377 | // temperate, thin melting base: set spc
|
---|
[18659] | 1378 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
[18612] | 1379 | break;
|
---|
| 1380 | case 4:
|
---|
[18930] | 1381 | // temperate, thick melting base: set grad H*n=0
|
---|
| 1382 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
[18612] | 1383 | break;
|
---|
| 1384 | default:
|
---|
| 1385 | _printf0_(" unknown thermal basal state found!");
|
---|
[17027] | 1386 | }
|
---|
[18930] | 1387 |
|
---|
[17027] | 1388 | }
|
---|
[17014] | 1389 |
|
---|
[17027] | 1390 | /*Free ressources:*/
|
---|
| 1391 | xDelete<int>(indices);
|
---|
| 1392 | xDelete<int>(indicesup);
|
---|
| 1393 | delete gauss;
|
---|
| 1394 | delete gaussup;
|
---|
[17002] | 1395 | }/*}}}*/
|
---|
[18930] | 1396 | void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 1397 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 1398 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 1399 | * by:
|
---|
| 1400 | * Bi_conduct=[ dh/dx ]
|
---|
| 1401 | * [ dh/dy ]
|
---|
| 1402 | * [ dh/dz ]
|
---|
| 1403 | * where h is the interpolation function for node i.
|
---|
| 1404 | *
|
---|
| 1405 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
| 1406 | */
|
---|
[17002] | 1407 |
|
---|
[18930] | 1408 | /*Fetch number of nodes for this finite element*/
|
---|
| 1409 | int numnodes = element->GetNumberOfNodes();
|
---|
| 1410 |
|
---|
| 1411 | /*Get nodal functions derivatives*/
|
---|
| 1412 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
| 1413 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 1414 |
|
---|
| 1415 | /*Build B: */
|
---|
| 1416 | for(int i=0;i<numnodes;i++){
|
---|
| 1417 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
| 1418 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
| 1419 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
| 1420 | }
|
---|
| 1421 |
|
---|
| 1422 | /*Clean-up*/
|
---|
| 1423 | xDelete<IssmDouble>(dbasis);
|
---|
| 1424 | }/*}}}*/
|
---|
| 1425 | void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
| 1426 | element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
|
---|
| 1427 | }/*}}}*/
|
---|
| 1428 | int EnthalpyAnalysis::GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpyup, IssmDouble pressure, IssmDouble pressureup, IssmDouble watercolumn, IssmDouble meltingrate){/*{{{*/
|
---|
| 1429 |
|
---|
[18612] | 1430 | /* Check if ice in element */
|
---|
| 1431 | if(!element->IsIceInElement()) return -1;
|
---|
| 1432 |
|
---|
| 1433 | /* Only update Constraints at the base of grounded ice*/
|
---|
| 1434 | if(!(element->IsOnBase())) return -1;
|
---|
| 1435 |
|
---|
| 1436 | /*Intermediary*/
|
---|
| 1437 | int state=-1;
|
---|
| 1438 | IssmDouble dt;
|
---|
| 1439 |
|
---|
| 1440 | /*Get parameters and inputs: */
|
---|
| 1441 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 1442 |
|
---|
[18620] | 1443 | if(enthalpy<PureIceEnthalpy(element,pressure)){
|
---|
| 1444 | if(watercolumn<=0.) state=0; // cold, dry base
|
---|
| 1445 | else state=1; // cold, wet base (refreezing)
|
---|
[18612] | 1446 | }
|
---|
[18620] | 1447 | else{
|
---|
| 1448 | if(enthalpyup<PureIceEnthalpy(element,pressureup)){
|
---|
| 1449 | if((dt==0.) && (meltingrate<0.)) state=2; // refreezing temperate base (non-physical, only for steadystate solver)
|
---|
| 1450 | else state=3; // temperate base, but no temperate layer
|
---|
[18612] | 1451 | }
|
---|
[18620] | 1452 | else state=4; // temperate layer with positive thickness
|
---|
[18612] | 1453 | }
|
---|
| 1454 |
|
---|
| 1455 | _assert_(state>=0);
|
---|
| 1456 | return state;
|
---|
| 1457 | }/*}}}*/
|
---|
[18930] | 1458 | IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
|
---|
[18612] | 1459 |
|
---|
| 1460 | IssmDouble temperature, waterfraction;
|
---|
| 1461 | IssmDouble kappa_w = 0.6; // thermal conductivity of water (in W/m/K)
|
---|
| 1462 | IssmDouble kappa_i = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 1463 | element->EnthalpyToThermal(&temperature, &waterfraction, enthalpy, pressure);
|
---|
| 1464 |
|
---|
| 1465 | return (1.-waterfraction)*kappa_i + waterfraction*kappa_w;
|
---|
| 1466 | }/*}}}*/
|
---|
[18930] | 1467 | void EnthalpyAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
|
---|
| 1468 | _error_("Not implemented yet");
|
---|
| 1469 | }/*}}}*/
|
---|
| 1470 | void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[18612] | 1471 |
|
---|
[18930] | 1472 | bool converged;
|
---|
| 1473 | int i,rheology_law;
|
---|
| 1474 | IssmDouble B_average,s_average,T_average=0.,P_average=0.;
|
---|
[21382] | 1475 | IssmDouble n=3.0;
|
---|
[18930] | 1476 | int *doflist = NULL;
|
---|
| 1477 | IssmDouble *xyz_list = NULL;
|
---|
[16888] | 1478 |
|
---|
[18930] | 1479 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 1480 | int numnodes = element->GetNumberOfNodes();
|
---|
[16888] | 1481 |
|
---|
[18930] | 1482 | /*Fetch dof list and allocate solution vector*/
|
---|
| 1483 | element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
| 1484 | IssmDouble* values = xNew<IssmDouble>(numnodes);
|
---|
| 1485 | IssmDouble* pressure = xNew<IssmDouble>(numnodes);
|
---|
| 1486 | IssmDouble* surface = xNew<IssmDouble>(numnodes);
|
---|
| 1487 | IssmDouble* B = xNew<IssmDouble>(numnodes);
|
---|
| 1488 | IssmDouble* temperature = xNew<IssmDouble>(numnodes);
|
---|
| 1489 | IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
|
---|
[16888] | 1490 |
|
---|
[18930] | 1491 | /*Use the dof list to index into the solution vector: */
|
---|
| 1492 | for(i=0;i<numnodes;i++){
|
---|
| 1493 | values[i]=solution[doflist[i]];
|
---|
[16888] | 1494 |
|
---|
[18930] | 1495 | /*Check solution*/
|
---|
| 1496 | if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
|
---|
[20669] | 1497 | if(xIsInf<IssmDouble>(values[i])) _error_("Inf found in solution vector");
|
---|
[16888] | 1498 | }
|
---|
| 1499 |
|
---|
[18930] | 1500 | /*Get all inputs and parameters*/
|
---|
[21382] | 1501 | if(element->material->ObjectEnum()!=MatestarEnum) n=element->GetMaterialParameter(MaterialsRheologyNEnum);
|
---|
[18930] | 1502 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
| 1503 | element->GetInputListOnNodes(&pressure[0],PressureEnum);
|
---|
| 1504 | if(converged){
|
---|
| 1505 | for(i=0;i<numnodes;i++){
|
---|
| 1506 | element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
|
---|
| 1507 | if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
|
---|
| 1508 | //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
|
---|
| 1509 | }
|
---|
| 1510 | element->AddInput(EnthalpyEnum,values,element->GetElementType());
|
---|
| 1511 | element->AddInput(WaterfractionEnum,waterfraction,element->GetElementType());
|
---|
| 1512 | element->AddInput(TemperatureEnum,temperature,element->GetElementType());
|
---|
| 1513 |
|
---|
| 1514 | /*Update Rheology only if converged (we must make sure that the temperature is below melting point
|
---|
| 1515 | * otherwise the rheology could be negative*/
|
---|
| 1516 | element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
|
---|
| 1517 | element->GetInputListOnNodes(&surface[0],SurfaceEnum);
|
---|
| 1518 | switch(rheology_law){
|
---|
| 1519 | case NoneEnum:
|
---|
| 1520 | /*Do nothing: B is not temperature dependent*/
|
---|
| 1521 | break;
|
---|
[21377] | 1522 | case BuddJackaEnum:
|
---|
| 1523 | for(i=0;i<numnodes;i++) B[i]=BuddJacka(temperature[i]);
|
---|
| 1524 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
| 1525 | break;
|
---|
[18930] | 1526 | case CuffeyEnum:
|
---|
| 1527 | for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
|
---|
| 1528 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
| 1529 | break;
|
---|
[20625] | 1530 | case CuffeyTemperateEnum:
|
---|
[21382] | 1531 | for(i=0;i<numnodes;i++) B[i]=CuffeyTemperate(temperature[i], waterfraction[i],n);
|
---|
[20625] | 1532 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
| 1533 | break;
|
---|
[18930] | 1534 | case PatersonEnum:
|
---|
| 1535 | for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
|
---|
| 1536 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
| 1537 | break;
|
---|
| 1538 | case ArrheniusEnum:
|
---|
| 1539 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[21382] | 1540 | for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],n);
|
---|
[18930] | 1541 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
| 1542 | break;
|
---|
| 1543 | case LliboutryDuvalEnum:
|
---|
[21382] | 1544 | for(i=0;i<numnodes;i++) B[i]=LliboutryDuval(values[i],pressure[i],n,element->GetMaterialParameter(MaterialsBetaEnum),element->GetMaterialParameter(ConstantsReferencetemperatureEnum),element->GetMaterialParameter(MaterialsHeatcapacityEnum),element->GetMaterialParameter(MaterialsLatentheatEnum));
|
---|
[18930] | 1545 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
| 1546 | break;
|
---|
| 1547 | default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
|
---|
| 1548 | }
|
---|
[16888] | 1549 | }
|
---|
| 1550 | else{
|
---|
[18930] | 1551 | element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
|
---|
[16888] | 1552 | }
|
---|
| 1553 |
|
---|
[18930] | 1554 | /*Free ressources:*/
|
---|
| 1555 | xDelete<IssmDouble>(values);
|
---|
| 1556 | xDelete<IssmDouble>(pressure);
|
---|
| 1557 | xDelete<IssmDouble>(surface);
|
---|
| 1558 | xDelete<IssmDouble>(B);
|
---|
| 1559 | xDelete<IssmDouble>(temperature);
|
---|
| 1560 | xDelete<IssmDouble>(waterfraction);
|
---|
| 1561 | xDelete<IssmDouble>(xyz_list);
|
---|
| 1562 | xDelete<int>(doflist);
|
---|
| 1563 | }/*}}}*/
|
---|
| 1564 | void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
|
---|
[16888] | 1565 |
|
---|
[18930] | 1566 | /*Intermediaries*/
|
---|
| 1567 | bool computebasalmeltingrates=true;
|
---|
| 1568 | bool drainicecolumn=true;
|
---|
| 1569 | IssmDouble dt;
|
---|
| 1570 |
|
---|
| 1571 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 1572 |
|
---|
[21161] | 1573 | if(drainicecolumn && (dt>0.)) DrainWaterfraction(femmodel);
|
---|
[18930] | 1574 | if(computebasalmeltingrates) ComputeBasalMeltingrate(femmodel);
|
---|
| 1575 |
|
---|
[17027] | 1576 | }/*}}}*/
|
---|
[18930] | 1577 | IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
|
---|
[16888] | 1578 |
|
---|
| 1579 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 1580 | IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
|
---|
| 1581 |
|
---|
| 1582 | return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
|
---|
| 1583 | }/*}}}*/
|
---|
[18930] | 1584 | IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
|
---|
[16888] | 1585 |
|
---|
| 1586 | IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
|
---|
| 1587 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
| 1588 |
|
---|
| 1589 | return meltingpoint-beta*pressure;
|
---|
| 1590 | }/*}}}*/
|
---|
[18930] | 1591 | void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
|
---|
| 1592 |
|
---|
| 1593 | /*Update basal dirichlet BCs for enthalpy: */
|
---|
| 1594 | Vector<IssmDouble>* spc = NULL;
|
---|
| 1595 | IssmDouble* serial_spc = NULL;
|
---|
| 1596 |
|
---|
| 1597 | spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes(EnthalpyAnalysisEnum));
|
---|
| 1598 | /*First create a vector to figure out what elements should be constrained*/
|
---|
| 1599 | for(int i=0;i<femmodel->elements->Size();i++){
|
---|
| 1600 | Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 1601 | GetBasalConstraints(spc,element);
|
---|
| 1602 | }
|
---|
| 1603 |
|
---|
| 1604 | /*Assemble and serialize*/
|
---|
| 1605 | spc->Assemble();
|
---|
| 1606 | serial_spc=spc->ToMPISerial();
|
---|
| 1607 | delete spc;
|
---|
| 1608 |
|
---|
| 1609 | /*Then update basal constraints nodes accordingly*/
|
---|
| 1610 | for(int i=0;i<femmodel->elements->Size();i++){
|
---|
| 1611 | Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 1612 | ApplyBasalConstraints(serial_spc,element);
|
---|
| 1613 | }
|
---|
| 1614 |
|
---|
| 1615 | femmodel->UpdateConstraintsx();
|
---|
| 1616 |
|
---|
| 1617 | /*Delete*/
|
---|
| 1618 | xDelete<IssmDouble>(serial_spc);
|
---|
| 1619 | }/*}}}*/
|
---|
| 1620 | void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
[20453] | 1621 | SetActiveNodesLSMx(femmodel);
|
---|
[18930] | 1622 | }/*}}}*/
|
---|