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

Last change on this file since 18612 was 18612, checked in by jbondzio, 10 years ago

CHG: new unified decision chart for basal thermal condition

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