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

Last change on this file since 21546 was 21546, checked in by Mathieu Morlighem, 8 years ago

CHG: use IoModelToConstrain to create spcs

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