source: issm/trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp@ 24486

Last change on this file since 24486 was 24486, checked in by Mathieu Morlighem, 5 years ago

CHG: making enthalpy work with HO elements

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