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
Line 
1#include "./EnthalpyAnalysis.h"
2#include "../toolkits/toolkits.h"
3#include "../classes/classes.h"
4#include "../shared/shared.h"
5#include "../modules/modules.h"
6#include "../solutionsequences/solutionsequences.h"
7#include "../cores/cores.h"
8
9/*Model processing*/
10void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
11
12 /*Intermediary*/
13 int count;
14 int M,N;
15 bool spcpresent = false;
16 int finiteelement;
17 IssmDouble heatcapacity;
18 IssmDouble referencetemperature;
19
20 /*Output*/
21 IssmDouble *spcvector = NULL;
22 IssmDouble *spcvectorstatic = NULL;
23 IssmDouble* times=NULL;
24 IssmDouble* values=NULL;
25 IssmDouble* issurface = NULL;
26
27 /*Fetch parameters: */
28 iomodel->FindConstant(&heatcapacity,"md.materials.heatcapacity");
29 iomodel->FindConstant(&referencetemperature,"md.constants.referencetemperature");
30 iomodel->FindConstant(&finiteelement,"md.thermal.fe");
31
32 /*return if 2d mesh*/
33 if(iomodel->domaintype==Domain2DhorizontalEnum) return;
34
35 /*Fetch data: */
36 iomodel->FetchData(&issurface,&M,&N,"md.mesh.vertexonsurface"); _assert_(N>0); _assert_(M==iomodel->numberofvertices);
37 iomodel->FetchData(&spcvector,&M,&N,"md.thermal.spctemperature");
38 iomodel->FetchData(&spcvectorstatic,&M,&N,"md.thermal.spctemperature");
39
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");
45 if(smb_model==SMBpddEnum) isdynamic=true;
46 if(smb_model==SMBd18opddEnum) isdynamic=true;
47 if(smb_model==SMBpddSicopolisEnum) isdynamic=true;
48 }
49
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);
57 spcvectorstatic[i*N+j] = NAN;
58 }
59 else{
60 spcvector[i*N+j] = NAN;
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
70 if(isdynamic){
71 IoModelToDynamicConstraintsx(constraints,iomodel,spcvector,iomodel->numberofvertices,1,EnthalpyAnalysisEnum,finiteelement);
72 IoModelToConstraintsx(constraints,iomodel,spcvectorstatic,M,N,EnthalpyAnalysisEnum,finiteelement);
73 }
74 else{
75 IoModelToConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement);
76 }
77
78 /*Free ressources:*/
79 iomodel->DeleteData(spcvector,"md.thermal.spctemperature");
80 iomodel->DeleteData(spcvectorstatic,"md.thermal.spctemperature");
81 iomodel->DeleteData(issurface,"md.mesh.vertexonsurface");
82 xDelete<IssmDouble>(times);
83 xDelete<IssmDouble>(values);
84}/*}}}*/
85void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
86
87 /*No loads */
88}/*}}}*/
89void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
90
91 int finiteelement;
92 iomodel->FindConstant(&finiteelement,"md.thermal.fe");
93
94 if(iomodel->domaintype==Domain3DEnum) iomodel->FetchData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
95 ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,finiteelement);
96 iomodel->DeleteData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
97}/*}}}*/
98int EnthalpyAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
99 return 1;
100}/*}}}*/
101void EnthalpyAnalysis::UpdateElements(Elements* elements,Inputs2* inputs2,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
102
103 bool dakota_analysis,ismovingfront,isenthalpy;
104 int frictionlaw,basalforcing_model,materialstype;
105 int FrictionCoupling;
106
107 /*Now, is the model 3d? otherwise, do nothing: */
108 if(iomodel->domaintype==Domain2DhorizontalEnum)return;
109
110 /*Is enthalpy requested?*/
111 iomodel->FindConstant(&isenthalpy,"md.thermal.isenthalpy");
112 if(!isenthalpy) return;
113
114 /*Fetch data needed: */
115 iomodel->FetchData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
116
117 /*Finite element type*/
118 int finiteelement;
119 iomodel->FindConstant(&finiteelement,"md.thermal.fe");
120
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);
126 element->Update(inputs2,i,iomodel,analysis_counter,analysis_type,finiteelement);
127 counter++;
128 }
129 }
130
131 iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
132 iomodel->FindConstant(&ismovingfront,"md.transient.ismovingfront");
133 iomodel->FindConstant(&frictionlaw,"md.friction.law");
134 iomodel->FindConstant(&materialstype,"md.materials.type");
135
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);
142 if(iomodel->domaintype!=Domain2DhorizontalEnum){
143 iomodel->FetchDataToInput(inputs2,elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum);
144 iomodel->FetchDataToInput(inputs2,elements,"md.mesh.vertexonsurface",MeshVertexonsurfaceEnum);
145 }
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);
158 if(ismovingfront){
159 iomodel->FetchDataToInput(inputs2,elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum); // required for updating active nodes
160 }
161
162 /*Basal forcings variables*/
163 iomodel->FindConstant(&basalforcing_model,"md.basalforcings.model");
164 switch(basalforcing_model){
165 case MantlePlumeGeothermalFluxEnum:
166 break;
167 default:
168 iomodel->FetchDataToInput(inputs2,elements,"md.basalforcings.geothermalflux",BasalforcingsGeothermalfluxEnum);
169 break;
170 }
171
172 /*Rheology type*/
173 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_B",MaterialsRheologyBEnum);
174 switch(materialstype){
175 case MatenhancediceEnum:
176 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
177 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_E",MaterialsRheologyEEnum);
178 break;
179 case MatdamageiceEnum:
180 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
181 break;
182 case MatestarEnum:
183 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_Ec",MaterialsRheologyEcEnum);
184 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_Es",MaterialsRheologyEsEnum);
185 break;
186 case MaticeEnum:
187 iomodel->FetchDataToInput(inputs2,elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
188 break;
189 default:
190 _error_("not supported");
191 }
192
193 /*Friction law variables*/
194 switch(frictionlaw){
195 case 1:
196 iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
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);
200 if (FrictionCoupling==3){
201 iomodel->FetchDataToInput(inputs2,elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);}
202 else if(FrictionCoupling==4){
203 iomodel->FetchDataToInput(inputs2,elements,"md.friction.effective_pressure",EffectivePressureEnum);
204 }
205 break;
206 case 2:
207 iomodel->FetchDataToInput(inputs2,elements,"md.friction.C",FrictionCEnum);
208 iomodel->FetchDataToInput(inputs2,elements,"md.friction.m",FrictionMEnum);
209 break;
210 case 3:
211 iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
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);
215 if (FrictionCoupling==3){
216 iomodel->FetchDataToInput(inputs2,elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);}
217 else if(FrictionCoupling==4){
218 iomodel->FetchDataToInput(inputs2,elements,"md.friction.effective_pressure",EffectivePressureEnum);
219 }
220 break;
221 case 4:
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);
227 iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
228 break;
229 case 5:
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);
234 break;
235 case 6:
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);
240 break;
241 case 7:
242 iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
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);
247 if (FrictionCoupling==3){
248 iomodel->FetchDataToInput(inputs2,elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);}
249 else if(FrictionCoupling==4){
250 iomodel->FetchDataToInput(inputs2,elements,"md.friction.effective_pressure",EffectivePressureEnum);
251 }
252 break;
253 case 9:
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);
258 break;
259 default:
260 _error_("friction law not supported");
261 }
262
263 /*Free data: */
264 iomodel->DeleteData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
265
266}/*}}}*/
267void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
268
269 int numoutputs;
270 char** requestedoutputs = NULL;
271
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));
277 parameters->AddObject(iomodel->CopyConstantObject("md.thermal.isdrainicecolumn",ThermalIsdrainicecolumnEnum));
278 parameters->AddObject(iomodel->CopyConstantObject("md.thermal.watercolumn_upperlimit",ThermalWatercolumnUpperlimitEnum));
279 parameters->AddObject(iomodel->CopyConstantObject("md.friction.law",FrictionLawEnum));
280
281 iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.thermal.requested_outputs");
282 parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
283 if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
284 iomodel->DeleteData(&requestedoutputs,numoutputs,"md.thermal.requested_outputs");
285
286 /*Deal with friction parameters*/
287 int frictionlaw;
288 iomodel->FindConstant(&frictionlaw,"md.friction.law");
289 if(frictionlaw==4 || frictionlaw==6){
290 parameters->AddObject(iomodel->CopyConstantObject("md.friction.gamma",FrictionGammaEnum));
291 }
292 if(frictionlaw==3 || frictionlaw==1 || frictionlaw==7){
293 parameters->AddObject(iomodel->CopyConstantObject("md.friction.coupling",FrictionCouplingEnum));
294 }
295 if(frictionlaw==9){
296 parameters->AddObject(iomodel->CopyConstantObject("md.friction.gamma",FrictionGammaEnum));
297 parameters->AddObject(new IntParam(FrictionCouplingEnum,0));
298 }
299}/*}}}*/
300
301/*Finite Element Analysis*/
302void EnthalpyAnalysis::ApplyBasalConstraints(IssmDouble* serial_spc,Element* element){/*{{{*/
303
304 /* Do not check if ice in element, this may lead to inconsistencies between cpu partitions */
305 /* Only update constraints at the base. */
306 if(!(element->IsOnBase())) return;
307
308 /*Intermediary*/
309 bool isdynamicbasalspc;
310 int numindices;
311 int *indices = NULL;
312 Node* node = NULL;
313 IssmDouble pressure;
314
315 /*Check wether dynamic basal boundary conditions are activated */
316 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
317 if(!isdynamicbasalspc) return;
318
319 /*Get parameters and inputs: */
320 Input2* pressure_input = element->GetInput2(PressureEnum); _assert_(pressure_input);
321
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());
325
326 GaussPenta* gauss=new GaussPenta();
327 for(int i=0;i<numindices;i++){
328 gauss->GaussNode(element->GetElementType(),indices[i]);
329
330 pressure_input->GetInputValue(&pressure,gauss);
331
332 /*apply or release spc*/
333 node=element->GetNode(indices[i]);
334 if(!node->IsActive()) continue;
335 if(serial_spc[node->Sid()]==1.){
336 pressure_input->GetInputValue(&pressure, gauss);
337 node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
338 }
339 else {
340 node->DofInFSet(0);
341 }
342 }
343
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 }
354
355 /*extrude inputs*/
356 femmodel->parameters->SetParam(BasalforcingsGroundediceMeltingRateEnum,InputToExtrudeEnum);
357 extrudefrombase_core(femmodel);
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*/
362
363 /* Check if ice in element */
364 if(!element->IsIceInElement()) return;
365
366 /* Only compute melt rates at the base of grounded ice*/
367 if(!element->IsOnBase() || element->IsFloating()) return;
368
369 /* Intermediaries */
370 bool converged;
371 const int dim=3;
372 int i,is,state;
373 int nodedown,nodeup,numnodes,numsegments;
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;
383
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
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);
398 IssmDouble kappa = EnthalpyDiffusionParameterVolume(element,enthalpy_enum); _assert_(kappa>=0.);
399 IssmDouble kappa_mix;
400
401 /*retrieve inputs*/
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);
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);
414 element->VerticalSegmentIndicesBase(&pairindices,&numsegments);
415 IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
416 IssmDouble* heating = xNew<IssmDouble>(numsegments);
417
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);
427
428 IssmDouble watercolumnupperlimit = element->FindParam(ThermalWatercolumnUpperlimitEnum);
429
430 Gauss* gauss=element->NewGauss();
431 for(is=0;is<numsegments;is++){
432 nodedown = pairindices[is*2+0];
433 nodeup = pairindices[is*2+1];
434 gauss->GaussNode(element->GetElementType(),nodedown);
435
436 state=GetThermalBasalCondition(element, enthalpies[nodedown], enthalpies[nodeup], pressures[nodedown], pressures[nodeup], watercolumns[nodedown], basalmeltingrates[nodedown]);
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;
442 case 1: case 2: case 3:
443 // case 1 : cold, wet base: keep at pressure melting point
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
451 kappa_mix=GetWetIceConductivity(element, enthalpies[nodedown], pressures[nodedown]);
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++){
477 nodedown = pairindices[is*2+0];
478 nodeup = pairindices[is*2+1];
479 if(dt!=0.){
480 if(watercolumns[nodedown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
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
485 }
486 else{
487 basalmeltingrates[nodedown]=meltingrate_enthalpy[is];
488 watercolumns[nodedown]+=dt*meltingrate_enthalpy[is];
489 }
490 if(watercolumns[nodedown]>watercolumnupperlimit) watercolumns[nodedown]=watercolumnupperlimit;
491 }
492 else{
493 basalmeltingrates[nodedown]=meltingrate_enthalpy[is];
494 if(watercolumns[nodedown]+meltingrate_enthalpy[is]<0.)
495 watercolumns[nodedown]=0.;
496 else
497 watercolumns[nodedown]+=meltingrate_enthalpy[is];
498 }
499 basalmeltingrates[nodedown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
500 _assert_(watercolumns[nodedown]>=0.);
501 }/*}}}*/
502
503 /*feed updated variables back into model*/
504 int finite_element = element->GetElementType(); if(finite_element==P1Enum) finite_element = P1DGEnum;
505 if(dt!=0.){
506 element->AddInput2(enthalpy_enum,enthalpies,finite_element);
507 element->AddInput2(WatercolumnEnum,watercolumns,finite_element);
508 }
509 element->AddInput2(BasalforcingsGroundediceMeltingRateEnum,basalmeltingrates,finite_element);
510
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);
523}/*}}}*/
524void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
525
526 IssmDouble dt;
527 bool isdynamicbasalspc;
528
529 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
530 femmodel->parameters->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
531
532 if(VerboseSolution()) _printf0_(" computing enthalpy\n");
533 femmodel->SetCurrentConfiguration(EnthalpyAnalysisEnum);
534 if((dt>0.) && isdynamicbasalspc) UpdateBasalConstraints(femmodel);
535 solutionsequence_thermal_nonlinear(femmodel);
536
537 /*transfer enthalpy to enthalpy picard for the next step: */
538 InputDuplicatex(femmodel,EnthalpyEnum,EnthalpyPicardEnum);
539
540 PostProcessing(femmodel);
541
542}/*}}}*/
543ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
544 /*Default, return NULL*/
545 return NULL;
546}/*}}}*/
547ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
548_error_("Not implemented");
549}/*}}}*/
550ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
551
552 /* Check if ice in element */
553 if(!element->IsIceInElement()) return NULL;
554
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;
564}/*}}}*/
565ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
566
567 /* Check if ice in element */
568 if(!element->IsIceInElement()) return NULL;
569
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;
575 IssmDouble tau_parameter_anisotropic[2],tau_parameter_hor,tau_parameter_ver;
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);
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);
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);
604
605 /*Enthalpy diffusion parameter*/
606 IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
607
608 /* Start looping on the number of gaussian points: */
609 Gauss* gauss=element->NewGauss(4);
610 for(int ig=gauss->begin();ig<gauss->end();ig++){
611 gauss->GaussPoint(ig);
612
613 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
614 element->NodalFunctions(basis,gauss);
615 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
616
617 D_scalar=gauss->weight*Jdet;
618 if(dt!=0.) D_scalar=D_scalar*dt;
619
620 /*Conduction: */
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 }
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;
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 }
640
641 /*Transient: */
642 if(dt!=0.){
643 D_scalar=gauss->weight*Jdet;
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 }
649 D_scalar=D_scalar*dt;
650 }
651
652 /*Artificial diffusivity*/
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));
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);
660 for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
661
662 GetBAdvecprime(Bprime,element,xyz_list,gauss);
663 TripleMultiply(Bprime,3,numnodes,1,
664 &K[0][0],3,3,0,
665 Bprime,3,numnodes,0,
666 &Ke->values[0],1);
667 }
668 /*SUPG*/
669 else if(stabilization==2){
670 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
671 diameter=element->MinEdgeLength(xyz_list);
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*
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]);
678 }
679 }
680 if(dt!=0.){
681 D_scalar=gauss->weight*Jdet;
682 for(int i=0;i<numnodes;i++){
683 for(int j=0;j<numnodes;j++){
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]);
685 }
686 }
687 }
688 }
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 }
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
716 /* Check if ice in element */
717 if(!element->IsIceInElement()) return NULL;
718
719 /*Initialize Element matrix and return if necessary*/
720 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
721
722 /*Intermediaries*/
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);
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);
742
743 /* Start looping on the number of gaussian points: */
744 Gauss* gauss=element->NewGaussBase(4);
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}/*}}}*/
766ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
767
768 /* Check if ice in element */
769 if(!element->IsIceInElement()) return NULL;
770
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;
782}/*}}}*/
783ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
784
785 /* Check if ice in element */
786 if(!element->IsIceInElement()) return NULL;
787
788 /*Intermediaries*/
789 int i, stabilization;
790 IssmDouble Jdet,phi,dt;
791 IssmDouble enthalpy, Hpmp;
792 IssmDouble enthalpypicard, d1enthalpypicard[3];
793 IssmDouble pressure, d1pressure[3], d2pressure;
794 IssmDouble waterfractionpicard;
795 IssmDouble kappa,tau_parameter,diameter,hx,hy,hz,kappa_w;
796 IssmDouble tau_parameter_anisotropic[2],tau_parameter_hor,tau_parameter_ver;
797 IssmDouble u,v,w;
798 IssmDouble scalar_def, scalar_sens ,scalar_transient;
799 IssmDouble* xyz_list = NULL;
800 IssmDouble d1H_d1P, d1P2;
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);
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);
819 element->FindParam(&dt,TimesteppingTimeStepEnum);
820 element->FindParam(&stabilization,ThermalStabilizationEnum);
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);}
828
829 /* Start looping on the number of gaussian points: */
830 Gauss* gauss=element->NewGauss(4);
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);
836
837 /*viscous dissipation*/
838 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
839
840 scalar_def=phi/rho_ice*Jdet*gauss->weight;
841 if(dt!=0.) scalar_def=scalar_def*dt;
842
843 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
844
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
854
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];
863 }
864
865 /* Build transient now */
866 if(reCast<bool,IssmDouble>(dt)){
867 enthalpy_input->GetInputValue(&enthalpy, gauss);
868 scalar_transient=enthalpy*Jdet*gauss->weight;
869 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
870 }
871
872 /* SUPG */
873 if(stabilization==2){
874 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
875 diameter=element->MinEdgeLength(xyz_list);
876 kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
877 vx_input->GetInputValue(&u,gauss);
878 vy_input->GetInputValue(&v,gauss);
879 vz_input->GetInputValue(&w,gauss);
880 tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
881
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]);
883
884 if(dt!=0.){
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]);
886 }
887 }
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 }
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){/*{{{*/
913
914 /* Check if ice in element */
915 if(!element->IsIceInElement()) return NULL;
916
917 /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
918 if(!element->IsOnBase() || element->IsFloating()) return NULL;
919
920 bool converged, isdynamicbasalspc;
921 int i, state;
922 int enthalpy_enum;
923 IssmDouble dt,Jdet,scalar;
924 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
925 IssmDouble vx,vy,vz;
926 IssmDouble alpha2,basalfriction,geothermalflux,heatflux;
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);
939 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
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
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);
951 IssmDouble rho_ice = element->FindParam(MaterialsRhoIceEnum);
952
953 /*Build friction element, needed later: */
954 Friction* friction=new Friction(element,3);
955
956 /* Start looping on the number of gaussian points: */
957 Gauss* gauss=element->NewGaussBase(4);
958 Gauss* gaussup=element->NewGaussTop(4);
959 for(int ig=gauss->begin();ig<gauss->end();ig++){
960 gauss->GaussPoint(ig);
961 gaussup->GaussPoint(ig);
962
963 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
964 element->NodalFunctions(basis,gauss);
965
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;
977
978 switch (state) {
979 case 0: case 1: case 2: case 3:
980 // cold, dry base; cold, wet base; refreezing temperate base; thin temperate base:
981 // Apply basal surface forcing.
982 // Interpolated values of enthalpy on gauss nodes may indicate cold base,
983 // although one node might have become temperate. So keep heat flux switched on.
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;
993 for(i=0;i<numnodes;i++)
994 pe->values[i]+=scalar*basis[i];
995 break;
996 case 4:
997 // temperate, thick melting base: set grad H*n=0
998 for(i=0;i<numnodes;i++)
999 pe->values[i]+=0.;
1000 break;
1001 default:
1002 _printf0_(" unknown thermal basal state found!");
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
1014}/*}}}*/
1015ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
1016
1017 /* Check if ice in element */
1018 if(!element->IsIceInElement()) return NULL;
1019
1020 /*Get basal element*/
1021 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
1022
1023 IssmDouble Hpmp,dt,Jdet,scalar_ocean,pressure;
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);
1036 Input2* pressure_input=element->GetInput2(PressureEnum); _assert_(pressure_input);
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);
1043
1044 /* Start looping on the number of gaussian points: */
1045 Gauss* gauss=element->NewGaussBase(4);
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);
1053 Hpmp=element->PureIceEnthalpy(pressure);
1054
1055 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*Hpmp/(heatcapacity*rho_ice);
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}/*}}}*/
1067void EnthalpyAnalysis::DrainWaterfraction(FemModel* femmodel){/*{{{*/
1068 /*Drain excess water fraction in ice column: */
1069 ComputeWaterfractionDrainage(femmodel);
1070 DrainageUpdateWatercolumn(femmodel);
1071 DrainageUpdateEnthalpy(femmodel);
1072}/*}}}*/
1073void EnthalpyAnalysis::ComputeWaterfractionDrainage(FemModel* femmodel){/*{{{*/
1074
1075 int i,k,numnodes;
1076 IssmDouble dt;
1077 Element* element= NULL;
1078
1079 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1080
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);
1086
1087 element->GetInputListOnNodes(waterfractions,WaterfractionEnum);
1088 for(k=0; k<numnodes;k++){
1089 drainage[k]=DrainageFunctionWaterfraction(waterfractions[k], dt);
1090 }
1091 int finite_element = element->GetElementType(); if(finite_element==P1Enum) finite_element = P1DGEnum;
1092 element->AddInput2(WaterfractionDrainageEnum,drainage,finite_element);
1093
1094 xDelete<IssmDouble>(waterfractions);
1095 xDelete<IssmDouble>(drainage);
1096 }
1097}/*}}}*/
1098void EnthalpyAnalysis::DrainageUpdateWatercolumn(FemModel* femmodel){/*{{{*/
1099
1100 int i,k,numnodes, numbasalnodes;
1101 IssmDouble dt;
1102 int* basalnodeindices=NULL;
1103 Element* element= NULL;
1104
1105 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1106
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);
1119
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 }
1125 int finite_element = element->GetElementType(); if(finite_element==P1Enum) finite_element = P1DGEnum;
1126 element->AddInput2(WaterfractionDrainageIntegratedEnum, drainage_int,finite_element);
1127
1128 xDelete<IssmDouble>(drainage_int);
1129 xDelete<IssmDouble>(thicknesses);
1130 }
1131
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;
1137 if(!element->IsOnBase()) continue;
1138
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);
1144
1145 element->BasalNodeIndices(&numbasalnodes,&basalnodeindices,element->GetElementType());
1146 for(k=0;k<numbasalnodes;k++){
1147 watercolumn[basalnodeindices[k]]+=dt*drainage_int[basalnodeindices[k]];
1148 }
1149 int finite_element = element->GetElementType(); if(finite_element==P1Enum) finite_element = P1DGEnum;
1150 element->AddInput2(WatercolumnEnum, watercolumn,finite_element);
1151
1152 xDelete<IssmDouble>(watercolumn);
1153 xDelete<IssmDouble>(drainage_int);
1154 xDelete<int>(basalnodeindices);
1155 }
1156}/*}}}*/
1157void EnthalpyAnalysis::DrainageUpdateEnthalpy(FemModel* femmodel){/*{{{*/
1158
1159 int i,k,numnodes;
1160 IssmDouble dt;
1161 Element* element= NULL;
1162 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1163
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);
1172
1173 element->GetInputListOnNodes(pressures,PressureEnum);
1174 element->GetInputListOnNodes(temperatures,TemperatureEnum);
1175 element->GetInputListOnNodes(waterfractions,WaterfractionEnum);
1176 element->GetInputListOnNodes(drainage,WaterfractionDrainageEnum);
1177
1178 for(k=0;k<numnodes;k++){
1179 if(dt==0.)
1180 waterfractions[k]-=drainage[k];
1181 else
1182 waterfractions[k]-=dt*drainage[k];
1183
1184 element->ThermalToEnthalpy(&enthalpies[k], temperatures[k], waterfractions[k], pressures[k]);
1185 }
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);
1189
1190 xDelete<IssmDouble>(enthalpies);
1191 xDelete<IssmDouble>(pressures);
1192 xDelete<IssmDouble>(temperatures);
1193 xDelete<IssmDouble>(waterfractions);
1194 xDelete<IssmDouble>(drainage);
1195 }
1196}/*}}}*/
1197IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
1198
1199 IssmDouble heatcapacity = element->FindParam(MaterialsHeatcapacityEnum);
1200 IssmDouble temperateiceconductivity = element->FindParam(MaterialsTemperateiceconductivityEnum);
1201 IssmDouble thermalconductivity = element->FindParam(MaterialsThermalconductivityEnum);
1202
1203 if(enthalpy < PureIceEnthalpy(element,pressure))
1204 return thermalconductivity/heatcapacity;
1205 else
1206 return temperateiceconductivity/heatcapacity;
1207}/*}}}*/
1208IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
1209
1210 int iv;
1211 IssmDouble lambda; /* fraction of cold ice */
1212 IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
1213 IssmDouble Hc,Ht;
1214
1215 /*Get pressures and enthalpies on vertices*/
1216 int numvertices = element->GetNumberOfVertices();
1217 int effectiveconductivity_averaging;
1218 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1219 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1220 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
1221 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
1222 element->GetInputListOnVertices(pressures,PressureEnum);
1223 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
1224 element->FindParam(&effectiveconductivity_averaging,MaterialsEffectiveconductivityAveragingEnum);
1225
1226 for(iv=0;iv<numvertices;iv++){
1227 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
1228 dHpmp[iv] = enthalpies[iv]-PIE[iv];
1229 }
1230
1231 bool allequalsign = true;
1232 if(dHpmp[0]<0.){
1233 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
1234 }
1235 else{
1236 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
1237 }
1238
1239 if(allequalsign){
1240 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
1241 }
1242 else{
1243 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
1244 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
1245
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);
1255 _assert_(lambda>=0.);
1256 _assert_(lambda<=1.);
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 */
1264 kappa=kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c);
1265 }
1266 else if(effectiveconductivity_averaging==2){
1267 /* return geometric mean (power law) of thermal conductivities, weighted by fraction of cold/temperate ice */
1268 kappa=pow(kappa_c,lambda)*pow(kappa_t,1.-lambda);
1269 }
1270 else{
1271 _error_("effectiveconductivity_averaging not supported yet");
1272 }
1273 }
1274
1275 /*Clean up and return*/
1276 xDelete<IssmDouble>(PIE);
1277 xDelete<IssmDouble>(dHpmp);
1278 xDelete<IssmDouble>(pressures);
1279 xDelete<IssmDouble>(enthalpies);
1280 return kappa;
1281}/*}}}*/
1282void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1283 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1284 * For node i, Bi' can be expressed in the actual coordinate system
1285 * by:
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 */
1293
1294 /*Fetch number of nodes for this finite element*/
1295 int numnodes = element->GetNumberOfNodes();
1296
1297 /*Get nodal functions*/
1298 IssmDouble* basis=xNew<IssmDouble>(numnodes);
1299 element->NodalFunctions(basis,gauss);
1300
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];
1306 }
1307
1308 /*Clean-up*/
1309 xDelete<IssmDouble>(basis);
1310}/*}}}*/
1311void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1312 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1313 * For node i, Bi' can be expressed in the actual coordinate system
1314 * by:
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 */
1322
1323 /*Fetch number of nodes for this finite element*/
1324 int numnodes = element->GetNumberOfNodes();
1325
1326 /*Get nodal functions derivatives*/
1327 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
1328 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
1329
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];
1335 }
1336
1337 /*Clean-up*/
1338 xDelete<IssmDouble>(dbasis);
1339}/*}}}*/
1340void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1341
1342 /*Intermediary*/
1343 bool isdynamicbasalspc;
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.){
1352 GetBasalConstraintsSteadystate(vec_spc,element);
1353 }
1354 else{
1355 GetBasalConstraintsTransient(vec_spc,element);
1356 }
1357}/*}}}*/
1358void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1359
1360 /* Check if ice in element */
1361 if(!element->IsIceInElement()) return;
1362
1363 /* Only update constraints at the base.
1364 * Floating ice is not affected by basal BC decision chart. */
1365 if(!(element->IsOnBase()) || element->IsFloating()) return;
1366
1367 /*Intermediary*/
1368 int numindices, numindicesup, state;
1369 int *indices = NULL, *indicesup = NULL;
1370 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1371
1372 /*Get parameters and inputs: */
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);
1377
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());
1381 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1382
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]);
1388
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
1400 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1401 break;
1402 case 1:
1403 // cold, wet base: keep at pressure melting point
1404 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1405 break;
1406 case 2:
1407 // temperate, thin refreezing base:
1408 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1409 break;
1410 case 3:
1411 // temperate, thin melting base: set spc
1412 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1413 break;
1414 case 4:
1415 // temperate, thick melting base:
1416 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
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}/*}}}*/
1429void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1430
1431 /* Check if ice in element */
1432 if(!element->IsIceInElement()) return;
1433
1434 /* Only update constraints at the base.
1435 * Floating ice is not affected by basal BC decision chart.*/
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
1443 /*Get parameters and inputs: */
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);
1448
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
1454 GaussPenta* gauss=new GaussPenta();
1455 GaussPenta* gaussup=new GaussPenta();
1456
1457 for(int i=0;i<numindices;i++){
1458 gauss->GaussNode(element->GetElementType(),indices[i]);
1459 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1460
1461 enthalpy_input->GetInputValue(&enthalpy,gauss);
1462 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1463 pressure_input->GetInputValue(&pressure,gauss);
1464 pressure_input->GetInputValue(&pressureup,gaussup);
1465 watercolumn_input->GetInputValue(&watercolumn,gauss);
1466 meltingrate_input->GetInputValue(&meltingrate,gauss);
1467
1468 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1469
1470 switch (state) {
1471 case 0:
1472 // cold, dry base: apply basal surface forcing
1473 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1474 break;
1475 case 1:
1476 // cold, wet base: keep at pressure melting point
1477 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1478 break;
1479 case 2:
1480 // temperate, thin refreezing base: release spc
1481 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1482 break;
1483 case 3:
1484 // temperate, thin melting base: set spc
1485 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1486 break;
1487 case 4:
1488 // temperate, thick melting base: set grad H*n=0
1489 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1490 break;
1491 default:
1492 _printf0_(" unknown thermal basal state found!");
1493 }
1494
1495 }
1496
1497 /*Free ressources:*/
1498 xDelete<int>(indices);
1499 xDelete<int>(indicesup);
1500 delete gauss;
1501 delete gaussup;
1502}/*}}}*/
1503void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1504 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1505 * For node i, Bi' can be expressed in the actual coordinate system
1506 * by:
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 */
1514
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
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
1550 if(enthalpy<PureIceEnthalpy(element,pressure)){
1551 if(watercolumn<=0.) state=0; // cold, dry base
1552 else state=1; // cold, wet base (refreezing)
1553 }
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
1558 }
1559 else state=4; // temperate layer with positive thickness
1560 }
1561
1562 _assert_(state>=0);
1563 return state;
1564}/*}}}*/
1565IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
1566
1567 IssmDouble temperature, waterfraction;
1568 IssmDouble kappa_w = 0.6; // thermal conductivity of water (in W/m/K)
1569 IssmDouble kappa_i = element->FindParam(MaterialsThermalconductivityEnum);
1570 element->EnthalpyToThermal(&temperature, &waterfraction, enthalpy, pressure);
1571
1572 return (1.-waterfraction)*kappa_i + waterfraction*kappa_w;
1573}/*}}}*/
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){/*{{{*/
1578
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;
1584
1585 /*Fetch number of nodes and dof for this finite element*/
1586 int numnodes = element->GetNumberOfNodes();
1587
1588 /*Fetch dof list and allocate solution vector*/
1589 element->GetDofListLocal(&doflist,NoneApproximationEnum,GsetEnum);
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);
1596
1597 /*Use the dof list to index into the solution vector: */
1598 for(i=0;i<numnodes;i++){
1599 values[i]=solution[doflist[i]];
1600
1601 /*Check solution*/
1602 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
1603 if(xIsInf<IssmDouble>(values[i])) _error_("Inf found in solution vector");
1604 }
1605
1606 /*Get all inputs and parameters*/
1607 element->GetInputValue(&converged,ConvergedEnum);
1608 element->GetInputListOnNodes(&pressure[0],PressureEnum);
1609 int finite_element = element->GetElementType(); if(finite_element==P1Enum) finite_element = P1DGEnum;
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 }
1616 element->AddInput2(EnthalpyEnum,values,finite_element);
1617 element->AddInput2(WaterfractionEnum,waterfraction,finite_element);
1618 element->AddInput2(TemperatureEnum,temperature,finite_element);
1619
1620 IssmDouble* n = xNew<IssmDouble>(numnodes);
1621 if(element->material->ObjectEnum()==MatestarEnum){
1622 for(i=0;i<numnodes;i++) n[i]=3.;
1623 }
1624 else{
1625 element->GetInputListOnNodes(&n[0],MaterialsRheologyNEnum);
1626 }
1627
1628 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
1629 * otherwise the rheology could be negative*/
1630 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
1631 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
1632 switch(rheology_law){
1633 case NoneEnum:
1634 /*Do nothing: B is not temperature dependent*/
1635 break;
1636 case BuddJackaEnum:
1637 for(i=0;i<numnodes;i++) B[i]=BuddJacka(temperature[i]);
1638 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1639 break;
1640 case CuffeyEnum:
1641 for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
1642 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1643 break;
1644 case CuffeyTemperateEnum:
1645 for(i=0;i<numnodes;i++) B[i]=CuffeyTemperate(temperature[i], waterfraction[i],n[i]);
1646 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1647 break;
1648 case PatersonEnum:
1649 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
1650 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1651 break;
1652 case NyeH2OEnum:
1653 for(i=0;i<numnodes;i++) B[i]=NyeH2O(values[i]);
1654 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1655 break;
1656 case NyeCO2Enum:
1657 for(i=0;i<numnodes;i++) B[i]=NyeCO2(values[i]);
1658 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1659 break;
1660 case ArrheniusEnum:{
1661 element->GetVerticesCoordinates(&xyz_list);
1662 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],n[i]);
1663 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1664 break;
1665 }
1666 case LliboutryDuvalEnum:{
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));
1668 element->AddInput2(MaterialsRheologyBEnum,&B[0],finite_element);
1669 break;
1670 }
1671 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
1672 }
1673 xDelete<IssmDouble>(n);
1674 }
1675 else{
1676 element->AddInput2(EnthalpyPicardEnum,values,finite_element);
1677 }
1678
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){/*{{{*/
1690
1691 /*Intermediaries*/
1692 bool computebasalmeltingrates=true;
1693 bool isdrainicecolumn;
1694 IssmDouble dt;
1695
1696 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1697 femmodel->parameters->FindParam(&isdrainicecolumn,ThermalIsdrainicecolumnEnum);
1698
1699 if(isdrainicecolumn){
1700 DrainWaterfraction(femmodel);
1701 }
1702 if(computebasalmeltingrates){
1703 ComputeBasalMeltingrate(femmodel);
1704 }
1705
1706}/*}}}*/
1707IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
1708
1709 IssmDouble heatcapacity = element->FindParam(MaterialsHeatcapacityEnum);
1710 IssmDouble referencetemperature = element->FindParam(ConstantsReferencetemperatureEnum);
1711
1712 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1713}/*}}}*/
1714IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
1715
1716 IssmDouble meltingpoint = element->FindParam(MaterialsMeltingpointEnum);
1717 IssmDouble beta = element->FindParam(MaterialsBetaEnum);
1718
1719 return meltingpoint-beta*pressure;
1720}/*}}}*/
1721void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
1722
1723 /*Update basal dirichlet BCs for enthalpy: */
1724 Vector<IssmDouble>* spc = NULL;
1725 IssmDouble* serial_spc = NULL;
1726
1727 spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes());
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){/*{{{*/
1751 SetActiveNodesLSMx(femmodel);
1752}/*}}}*/
Note: See TracBrowser for help on using the repository browser.