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

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

Bug: apply dynamic basal boundary scheme only for isdynamicbasalspc=true

File size: 56.7 KB
Line 
1#include "./EnthalpyAnalysis.h"
2#include "../toolkits/toolkits.h"
3#include "../classes/classes.h"
4#include "../shared/shared.h"
5#include "../modules/modules.h"
6#include "../solutionsequences/solutionsequences.h"
7
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 bool isdynamicbasalspc;
565 int i, state;
566 IssmDouble dt,Jdet,scalar;
567 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
568 IssmDouble vx,vy,vz;
569 IssmDouble alpha2,basalfriction,geothermalflux,heatflux;
570 IssmDouble *xyz_list_base = NULL;
571
572 /*Fetch number of nodes for this finite element*/
573 int numnodes = element->GetNumberOfNodes();
574
575 /*Initialize vectors*/
576 ElementVector* pe = element->NewElementVector();
577 IssmDouble* basis = xNew<IssmDouble>(numnodes);
578
579 /*Retrieve all inputs and parameters*/
580 element->GetVerticesCoordinatesBase(&xyz_list_base);
581 element->FindParam(&dt,TimesteppingTimeStepEnum);
582 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
583 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
584 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
585 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
586 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
587 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
588 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
589 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
590 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
591 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
592
593 /*Build friction element, needed later: */
594 Friction* friction=new Friction(element,3);
595
596 /* Start looping on the number of gaussian points: */
597 GaussPenta* gauss=new GaussPenta(2,2);
598 GaussPenta* gaussup=new GaussPenta(2,2);
599 for(int ig=gauss->begin();ig<gauss->end();ig++){
600 gauss->GaussPoint(ig);
601
602 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
603 element->NodalFunctions(basis,gauss);
604
605 if(isdynamicbasalspc){
606 enthalpy_input->GetInputValue(&enthalpy,gauss);
607 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
608 pressure_input->GetInputValue(&pressure,gauss);
609 pressure_input->GetInputValue(&pressureup,gaussup);
610 watercolumn_input->GetInputValue(&watercolumn,gauss);
611 meltingrate_input->GetInputValue(&meltingrate,gauss);
612 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
613 }
614 else
615 state=0;
616
617 switch (state) {
618 case 0:
619 // cold, dry base: apply basal surface forcing
620 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
621 friction->GetAlpha2(&alpha2,gauss);
622 vx_input->GetInputValue(&vx,gauss);
623 vy_input->GetInputValue(&vy,gauss);
624 vz_input->GetInputValue(&vz,gauss);
625 basalfriction=alpha2*(vx*vx+vy*vy+vz*vz);
626 heatflux=(basalfriction+geothermalflux)/(rho_ice);
627 scalar=gauss->weight*Jdet*heatflux;
628 if(dt!=0.) scalar=dt*scalar;
629 for(i=0;i<numnodes;i++)
630 pe->values[i]+=scalar*basis[i];
631 break;
632 case 1:
633 // cold, wet base: keep at pressure melting point
634 case 2:
635 // temperate, thin refreezing base: release spc
636 case 3:
637 // temperate, thin melting base: set spc
638 case 4:
639 // temperate, thick melting base: set grad H*n=0
640 for(i=0;i<numnodes;i++)
641 pe->values[i]+=0.;
642 break;
643 default:
644 _printf0_(" unknown thermal basal state found!");
645 }
646 }
647
648 /*Clean up and return*/
649 delete gauss;
650 delete gaussup;
651 delete friction;
652 xDelete<IssmDouble>(basis);
653 xDelete<IssmDouble>(xyz_list_base);
654 return pe;
655
656}/*}}}*/
657ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
658
659 /* Check if ice in element */
660 if(!element->IsIceInElement()) return NULL;
661
662 /*Get basal element*/
663 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
664
665 IssmDouble Hpmp,dt,Jdet,scalar_ocean,pressure;
666 IssmDouble *xyz_list_base = NULL;
667
668 /*Fetch number of nodes for this finite element*/
669 int numnodes = element->GetNumberOfNodes();
670
671 /*Initialize vectors*/
672 ElementVector* pe = element->NewElementVector();
673 IssmDouble* basis = xNew<IssmDouble>(numnodes);
674
675 /*Retrieve all inputs and parameters*/
676 element->GetVerticesCoordinatesBase(&xyz_list_base);
677 element->FindParam(&dt,TimesteppingTimeStepEnum);
678 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
679 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
680 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
681 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
682 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
683 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
684 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
685
686 /* Start looping on the number of gaussian points: */
687 Gauss* gauss=element->NewGaussBase(2);
688 for(int ig=gauss->begin();ig<gauss->end();ig++){
689 gauss->GaussPoint(ig);
690
691 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
692 element->NodalFunctions(basis,gauss);
693
694 pressure_input->GetInputValue(&pressure,gauss);
695 Hpmp=element->PureIceEnthalpy(pressure);
696
697 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*Hpmp/(heatcapacity*rho_ice);
698 if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
699
700 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
701 }
702
703 /*Clean up and return*/
704 delete gauss;
705 xDelete<IssmDouble>(basis);
706 xDelete<IssmDouble>(xyz_list_base);
707 return pe;
708}/*}}}*/
709void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
710 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
711 * For node i, Bi' can be expressed in the actual coordinate system
712 * by:
713 * Bi_conduct=[ dh/dx ]
714 * [ dh/dy ]
715 * [ dh/dz ]
716 * where h is the interpolation function for node i.
717 *
718 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
719 */
720
721 /*Fetch number of nodes for this finite element*/
722 int numnodes = element->GetNumberOfNodes();
723
724 /*Get nodal functions derivatives*/
725 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
726 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
727
728 /*Build B: */
729 for(int i=0;i<numnodes;i++){
730 B[numnodes*0+i] = dbasis[0*numnodes+i];
731 B[numnodes*1+i] = dbasis[1*numnodes+i];
732 B[numnodes*2+i] = dbasis[2*numnodes+i];
733 }
734
735 /*Clean-up*/
736 xDelete<IssmDouble>(dbasis);
737}/*}}}*/
738void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
739 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
740 * For node i, Bi' can be expressed in the actual coordinate system
741 * by:
742 * Bi_advec =[ h ]
743 * [ h ]
744 * [ h ]
745 * where h is the interpolation function for node i.
746 *
747 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
748 */
749
750 /*Fetch number of nodes for this finite element*/
751 int numnodes = element->GetNumberOfNodes();
752
753 /*Get nodal functions*/
754 IssmDouble* basis=xNew<IssmDouble>(numnodes);
755 element->NodalFunctions(basis,gauss);
756
757 /*Build B: */
758 for(int i=0;i<numnodes;i++){
759 B[numnodes*0+i] = basis[i];
760 B[numnodes*1+i] = basis[i];
761 B[numnodes*2+i] = basis[i];
762 }
763
764 /*Clean-up*/
765 xDelete<IssmDouble>(basis);
766}/*}}}*/
767void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
768 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
769 * For node i, Bi' can be expressed in the actual coordinate system
770 * by:
771 * Biprime_advec=[ dh/dx ]
772 * [ dh/dy ]
773 * [ dh/dz ]
774 * where h is the interpolation function for node i.
775 *
776 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
777 */
778
779 /*Fetch number of nodes for this finite element*/
780 int numnodes = element->GetNumberOfNodes();
781
782 /*Get nodal functions derivatives*/
783 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
784 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
785
786 /*Build B: */
787 for(int i=0;i<numnodes;i++){
788 B[numnodes*0+i] = dbasis[0*numnodes+i];
789 B[numnodes*1+i] = dbasis[1*numnodes+i];
790 B[numnodes*2+i] = dbasis[2*numnodes+i];
791 }
792
793 /*Clean-up*/
794 xDelete<IssmDouble>(dbasis);
795}/*}}}*/
796void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
797 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
798}/*}}}*/
799void EnthalpyAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
800 _error_("Not implemented yet");
801}/*}}}*/
802void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
803
804 bool converged;
805 int i,rheology_law;
806 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
807 int *doflist = NULL;
808 IssmDouble *xyz_list = NULL;
809
810 /*Fetch number of nodes and dof for this finite element*/
811 int numnodes = element->GetNumberOfNodes();
812
813 /*Fetch dof list and allocate solution vector*/
814 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
815 IssmDouble* values = xNew<IssmDouble>(numnodes);
816 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
817 IssmDouble* surface = xNew<IssmDouble>(numnodes);
818 IssmDouble* B = xNew<IssmDouble>(numnodes);
819 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
820 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
821
822 /*Use the dof list to index into the solution vector: */
823 for(i=0;i<numnodes;i++){
824 values[i]=solution[doflist[i]];
825
826 /*Check solution*/
827 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
828 }
829
830 /*Get all inputs and parameters*/
831 element->GetInputValue(&converged,ConvergedEnum);
832 element->GetInputListOnNodes(&pressure[0],PressureEnum);
833 if(converged){
834 for(i=0;i<numnodes;i++){
835 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
836 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
837 //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
838 }
839 element->AddInput(EnthalpyEnum,values,element->GetElementType());
840 element->AddInput(WaterfractionEnum,waterfraction,element->GetElementType());
841 element->AddInput(TemperatureEnum,temperature,element->GetElementType());
842
843 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
844 * otherwise the rheology could be negative*/
845 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
846 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
847 switch(rheology_law){
848 case NoneEnum:
849 /*Do nothing: B is not temperature dependent*/
850 break;
851 case CuffeyEnum:
852 for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
853 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
854 break;
855 case PatersonEnum:
856 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
857 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
858 break;
859 case ArrheniusEnum:
860 element->GetVerticesCoordinates(&xyz_list);
861 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
862 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
863 break;
864 case LliboutryDuvalEnum:
865 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));
866 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
867 break;
868 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
869 }
870 }
871 else{
872 element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
873 }
874
875 /*Free ressources:*/
876 xDelete<IssmDouble>(values);
877 xDelete<IssmDouble>(pressure);
878 xDelete<IssmDouble>(surface);
879 xDelete<IssmDouble>(B);
880 xDelete<IssmDouble>(temperature);
881 xDelete<IssmDouble>(waterfraction);
882 xDelete<IssmDouble>(xyz_list);
883 xDelete<int>(doflist);
884}/*}}}*/
885void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
886
887 bool islevelset;
888 femmodel->parameters->FindParam(&islevelset,TransientIslevelsetEnum);
889 if(islevelset){
890 SetActiveNodesLSMx(femmodel);
891 }
892 return;
893}/*}}}*/
894
895/*Modules*/
896void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
897
898 /*Intermediaries*/
899 bool computebasalmeltingrates=true;
900 bool drainicecolumn=true;
901 bool isdynamicbasalspc;
902 IssmDouble dt;
903
904 femmodel->parameters->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
905 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
906
907 //TODO: use dt to decide what to do
908 if(drainicecolumn) DrainWaterfraction(femmodel);
909 if(computebasalmeltingrates) ComputeBasalMeltingrate(femmodel);
910 if(isdynamicbasalspc) UpdateBasalConstraints(femmodel);
911
912}/*}}}*/
913void EnthalpyAnalysis::ComputeBasalMeltingrate(FemModel* femmodel){/*{{{*/
914 /*Compute basal melting rates: */
915 for(int i=0;i<femmodel->elements->Size();i++){
916 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
917 ComputeBasalMeltingrate(element);
918 }
919}/*}}}*/
920void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
921 /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
922 /* melting rate is positive when melting, negative when refreezing*/
923
924 /* Check if ice in element */
925 if(!element->IsIceInElement()) return;
926
927 /* Only compute melt rates at the base of grounded ice*/
928 if(!element->IsOnBase() || element->IsFloating()) return;
929
930 /* Intermediaries */
931 const int dim=3;
932 int i,is,state;
933 int vertexdown,vertexup,numvertices,numsegments;
934 const int enthalpy_enum=EnthalpyEnum;
935 IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim],d1pressure[dim];
936 IssmDouble basalfriction,alpha2,geothermalflux,heatflux;
937 IssmDouble dt,yts;
938 IssmDouble melting_overshoot,lambda;
939 IssmDouble vx,vy,vz;
940 IssmDouble *xyz_list = NULL;
941 IssmDouble *xyz_list_base = NULL;
942 int *pairindices = NULL;
943
944 /*Fetch parameters*/
945 element->GetVerticesCoordinates(&xyz_list);
946 element->GetVerticesCoordinatesBase(&xyz_list_base);
947 IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
948 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
949 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
950 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
951 IssmDouble kappa = EnthalpyDiffusionParameterVolume(element,EnthalpyEnum); _assert_(kappa>=0.);
952 IssmDouble kappa_mix;
953
954 /*retrieve inputs*/
955 Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
956 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
957 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
958 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
959 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
960 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
961
962 /*Build friction element, needed later: */
963 Friction* friction=new Friction(element,dim);
964
965 /******** MELTING RATES ************************************//*{{{*/
966 element->NormalBase(&normal_base[0],xyz_list_base);
967 element->VerticalSegmentIndices(&pairindices,&numsegments);
968 IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
969 IssmDouble* heating = xNew<IssmDouble>(numsegments);
970
971 numvertices=element->GetNumberOfVertices();
972 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
973 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
974 IssmDouble* watercolumns = xNew<IssmDouble>(numvertices);
975 IssmDouble* basalmeltingrates = xNew<IssmDouble>(numvertices);
976 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
977 element->GetInputListOnVertices(pressures,PressureEnum);
978 element->GetInputListOnVertices(watercolumns,WatercolumnEnum);
979 element->GetInputListOnVertices(basalmeltingrates,BasalforcingsGroundediceMeltingRateEnum);
980
981 Gauss* gauss=element->NewGauss();
982 for(is=0;is<numsegments;is++){
983 vertexdown = pairindices[is*2+0];
984 vertexup = pairindices[is*2+1];
985 gauss->GaussVertex(vertexdown);
986
987 state=GetThermalBasalCondition(element, enthalpies[vertexdown], enthalpies[vertexup], pressures[vertexdown], pressures[vertexup], watercolumns[vertexdown], basalmeltingrates[vertexdown]);
988 switch (state) {
989 case 0:
990 // cold, dry base: apply basal surface forcing
991 for(i=0;i<3;i++) vec_heatflux[i]=0.;
992 break;
993 case 1:
994 // cold, wet base: keep at pressure melting point
995 case 2:
996 // temperate, thin refreezing base: release spc
997
998 case 3:
999 // temperate, thin melting base: set spc
1000 // enthalpies[vertexdown]=element->PureIceEnthalpy(pressures[vertexdown]);
1001 enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
1002 for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
1003 break;
1004 case 4:
1005 // temperate, thick melting base: set grad H*n=0
1006 kappa_mix=GetWetIceConductivity(element, enthalpies[vertexdown], pressures[vertexdown]);
1007 pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
1008 for(i=0;i<3;i++) vec_heatflux[i]=kappa_mix*beta*d1pressure[i];
1009 break;
1010 default:
1011 _printf0_(" unknown thermal basal state found!");
1012 }
1013 if(state==0) meltingrate_enthalpy[is]=0.;
1014 else{
1015 /*heat flux along normal*/
1016 heatflux=0.;
1017 for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
1018
1019 /*basal friction*/
1020 friction->GetAlpha2(&alpha2,gauss);
1021 vx_input->GetInputValue(&vx,gauss); vy_input->GetInputValue(&vy,gauss); vz_input->GetInputValue(&vz,gauss);
1022 basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
1023 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
1024 /* -Mb= Fb-(q-q_geo)/((1-w)*L*rho), and (1-w)*rho=rho_ice, cf Aschwanden 2012, eqs.1, 2, 66*/
1025 heating[is]=(heatflux+basalfriction+geothermalflux);
1026 meltingrate_enthalpy[is]=heating[is]/(latentheat*rho_ice); // m/s water equivalent
1027 }
1028 }/*}}}*/
1029
1030 /******** UPDATE MELTINGRATES AND WATERCOLUMN **************//*{{{*/
1031 element->FindParam(&dt,TimesteppingTimeStepEnum);
1032 element->FindParam(&yts, ConstantsYtsEnum);
1033 for(is=0;is<numsegments;is++){
1034 vertexdown = pairindices[is*2+0];
1035 vertexup = pairindices[is*2+1];
1036 if(dt!=0.){
1037 if(watercolumns[vertexdown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
1038 lambda = -watercolumns[vertexdown]/(dt*meltingrate_enthalpy[is]); _assert_(lambda>=0.); _assert_(lambda<1.);
1039 watercolumns[vertexdown]=0.;
1040 basalmeltingrates[vertexdown]=lambda*meltingrate_enthalpy[is]; // restrict freeze on only to size of watercolumn
1041 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
1042 }
1043 else{
1044 basalmeltingrates[vertexdown]=meltingrate_enthalpy[is];
1045 watercolumns[vertexdown]+=dt*meltingrate_enthalpy[is];
1046 }
1047 }
1048 else{
1049 basalmeltingrates[vertexdown]=meltingrate_enthalpy[is];
1050 if(watercolumns[vertexdown]+meltingrate_enthalpy[is]<0.)
1051 watercolumns[vertexdown]=0.;
1052 else
1053 watercolumns[vertexdown]+=meltingrate_enthalpy[is];
1054 }
1055 basalmeltingrates[vertexdown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
1056 _assert_(watercolumns[vertexdown]>=0.);
1057 }/*}}}*/
1058
1059 /*feed updated variables back into model*/
1060 element->AddInput(EnthalpyEnum,enthalpies,P1Enum); //TODO: distinguis for steadystate and transient run
1061 element->AddInput(WatercolumnEnum,watercolumns,P1Enum);
1062 element->AddInput(BasalforcingsGroundediceMeltingRateEnum,basalmeltingrates,P1Enum);
1063
1064 /*Clean up and return*/
1065 delete gauss;
1066 delete friction;
1067 xDelete<int>(pairindices);
1068 xDelete<IssmDouble>(enthalpies);
1069 xDelete<IssmDouble>(pressures);
1070 xDelete<IssmDouble>(watercolumns);
1071 xDelete<IssmDouble>(basalmeltingrates);
1072 xDelete<IssmDouble>(meltingrate_enthalpy);
1073 xDelete<IssmDouble>(heating);
1074 xDelete<IssmDouble>(xyz_list);
1075 xDelete<IssmDouble>(xyz_list_base);
1076}/*}}}*/
1077void EnthalpyAnalysis::DrainWaterfraction(FemModel* femmodel){/*{{{*/
1078 /*Drain excess water fraction in ice column: */
1079 for(int i=0;i<femmodel->elements->Size();i++){
1080 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
1081 DrainWaterfractionIcecolumn(element);
1082 }
1083}/*}}}*/
1084void EnthalpyAnalysis::DrainWaterfractionIcecolumn(Element* element){/*{{{*/
1085
1086 /* Check if ice in element */
1087 if(!element->IsIceInElement()) return;
1088
1089 /* Only drain waterfraction of ice column from element at base*/
1090 if(!element->IsOnBase()) return; //FIXME: allow freeze on for floating elements
1091
1092 /* Intermediaries*/
1093 int is, numvertices, numsegments;
1094 int *pairindices = NULL;
1095
1096 numvertices=element->GetNumberOfVertices();
1097 element->VerticalSegmentIndices(&pairindices,&numsegments);
1098
1099 IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
1100 IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments);
1101 IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
1102
1103 element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
1104
1105 for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
1106 Element* elementi = element;
1107 for(;;){
1108 for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
1109 DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
1110 for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
1111
1112 if(elementi->IsOnSurface()) break;
1113 elementi=elementi->GetUpperElement();
1114 }
1115 /* add drained water to water column*/
1116 for(is=0;is<numsegments;is++) watercolumn[is]+=drainrate_column[is];
1117 /* Feed updated water column back into model */
1118 element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
1119
1120 xDelete<int>(pairindices);
1121 xDelete<IssmDouble>(drainrate_column);
1122 xDelete<IssmDouble>(drainrate_element);
1123 xDelete<IssmDouble>(watercolumn);
1124}/*}}}*/
1125void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
1126
1127 /* Check if ice in element */
1128 if(!element->IsIceInElement()) return;
1129
1130 /*Intermediaries*/
1131 int iv,is,vertexdown,vertexup,numsegments;
1132 IssmDouble dt, height_element;
1133 IssmDouble rho_water, rho_ice;
1134 int numvertices = element->GetNumberOfVertices();
1135
1136 IssmDouble* xyz_list = NULL;
1137 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1138 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1139 IssmDouble* temperatures = xNew<IssmDouble>(numvertices);
1140 IssmDouble* waterfractions = xNew<IssmDouble>(numvertices);
1141 IssmDouble* deltawaterfractions = xNew<IssmDouble>(numvertices);
1142 int *pairindices = NULL;
1143
1144 rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
1145 rho_water=element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
1146
1147 element->GetVerticesCoordinates(&xyz_list);
1148 element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
1149 element->GetInputListOnVertices(pressures,PressureEnum);
1150
1151 element->FindParam(&dt,TimesteppingTimeStepEnum);
1152 for(iv=0;iv<numvertices;iv++){
1153 element->EnthalpyToThermal(&temperatures[iv],&waterfractions[iv], enthalpies[iv],pressures[iv]);
1154 deltawaterfractions[iv]=DrainageFunctionWaterfraction(waterfractions[iv], dt);
1155 }
1156
1157 /*drain waterfraction, feed updated variables back into model*/
1158 for(iv=0;iv<numvertices;iv++){
1159 if(reCast<bool,IssmDouble>(dt))
1160 waterfractions[iv]-=deltawaterfractions[iv]*dt;
1161 else
1162 waterfractions[iv]-=deltawaterfractions[iv];
1163 element->ThermalToEnthalpy(&enthalpies[iv], temperatures[iv], waterfractions[iv], pressures[iv]);
1164 }
1165 element->AddInput(EnthalpyEnum,enthalpies,P1Enum);
1166 element->AddInput(WaterfractionEnum,waterfractions,P1Enum);
1167
1168 /*return meltwater column equivalent to drained water*/
1169 element->VerticalSegmentIndices(&pairindices,&numsegments);
1170 for(is=0;is<numsegments;is++){
1171 vertexdown = pairindices[is*2+0];
1172 vertexup = pairindices[is*2+1];
1173 height_element=fabs(xyz_list[vertexup*3+2]-xyz_list[vertexdown*3+2]);
1174 pdrainrate_element[is]=(deltawaterfractions[vertexdown]+deltawaterfractions[vertexup])/2.*height_element; // return water equivalent of drainage
1175 _assert_(pdrainrate_element[is]>=0.);
1176 }
1177
1178 /*Clean up and return*/
1179 xDelete<int>(pairindices);
1180 xDelete<IssmDouble>(xyz_list);
1181 xDelete<IssmDouble>(enthalpies);
1182 xDelete<IssmDouble>(pressures);
1183 xDelete<IssmDouble>(temperatures);
1184 xDelete<IssmDouble>(waterfractions);
1185 xDelete<IssmDouble>(deltawaterfractions);
1186}/*}}}*/
1187void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
1188 /*Update basal dirichlet BCs for enthalpy: */
1189 for(int i=0;i<femmodel->elements->Size();i++){
1190 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
1191 UpdateBasalConstraints(element);
1192 }
1193 femmodel->UpdateConstraintsx();
1194}/*}}}*/
1195void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
1196
1197 /* Check if ice in element */
1198 if(!element->IsIceInElement()) return;
1199
1200 /* Only update Constraints at the base of grounded ice*/
1201 if(!(element->IsOnBase()) || element->IsFloating()) return;
1202
1203 /*Intermediary*/
1204 bool isdynamicbasalspc;
1205 IssmDouble dt;
1206
1207 /*Check wether dynamic basal boundary conditions are activated */
1208 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
1209 if(!isdynamicbasalspc) return;
1210
1211 element->FindParam(&dt,TimesteppingTimeStepEnum);
1212 if(dt==0.){
1213 UpdateBasalConstraintsSteadystate(element);
1214 }
1215 else{
1216 UpdateBasalConstraintsTransient(element);
1217 }
1218}/*}}}*/
1219void EnthalpyAnalysis::UpdateBasalConstraintsTransient(Element* element){/*{{{*/
1220
1221 /* Check if ice in element */
1222 if(!element->IsIceInElement()) return;
1223
1224 /* Only update Constraints at the base of grounded ice*/
1225 if(!(element->IsOnBase()) || element->IsFloating()) return;
1226
1227 /*Intermediary*/
1228 bool isdynamicbasalspc,setspc;
1229 int numindices, numindicesup, state;
1230 int *indices = NULL, *indicesup = NULL;
1231 Node* node = NULL;
1232 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1233
1234 /*Check wether dynamic basal boundary conditions are activated */
1235 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
1236 if(!isdynamicbasalspc) return;
1237
1238 /*Get parameters and inputs: */
1239 Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
1240 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
1241 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1242 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
1243
1244 /*Fetch indices of basal & surface nodes for this finite element*/
1245 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1246 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1247 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1248
1249 GaussPenta* gauss=new GaussPenta();
1250 GaussPenta* gaussup=new GaussPenta();
1251
1252 for(int i=0;i<numindices;i++){
1253 gauss->GaussNode(element->GetElementType(),indices[i]);
1254 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1255
1256 enthalpy_input->GetInputValue(&enthalpy,gauss);
1257 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1258 pressure_input->GetInputValue(&pressure,gauss);
1259 pressure_input->GetInputValue(&pressureup,gaussup);
1260 watercolumn_input->GetInputValue(&watercolumn,gauss);
1261 meltingrate_input->GetInputValue(&meltingrate,gauss);
1262
1263 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1264
1265 setspc=false;
1266 switch (state) {
1267 case 0:
1268 // cold, dry base: apply basal surface forcing
1269 break;
1270 case 1:
1271 // cold, wet base: keep at pressure melting point
1272 setspc=true;
1273 break;
1274 case 2:
1275 // temperate, thin refreezing base: release spc
1276 break;
1277 case 3:
1278 // temperate, thin melting base: set spc
1279 setspc=true;
1280 break;
1281 case 4:
1282 // temperate, thick melting base: set grad H*n=0
1283 break;
1284 default:
1285 _printf0_(" unknown thermal basal state found!");
1286 }
1287
1288 /*apply or release spc*/
1289 node=element->GetNode(indices[i]);
1290 if(setspc){
1291 pressure_input->GetInputValue(&pressure, gauss);
1292 node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
1293 }
1294 else
1295 node->DofInFSet(0);
1296 }
1297
1298 /*Free ressources:*/
1299 xDelete<int>(indices);
1300 xDelete<int>(indicesup);
1301 delete gauss;
1302 delete gaussup;
1303}/*}}}*/
1304void EnthalpyAnalysis::UpdateBasalConstraintsSteadystate(Element* element){/*{{{*/
1305
1306 /* Check if ice in element */
1307 if(!element->IsIceInElement()) return;
1308
1309 /* Only update Constraints at the base of grounded ice*/
1310 if(!(element->IsOnBase()) || element->IsFloating()) return;
1311
1312 /*Intermediary*/
1313 bool isdynamicbasalspc,setspc;
1314 int numindices, numindicesup, state;
1315 int *indices = NULL, *indicesup = NULL;
1316 Node* node = NULL;
1317 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1318
1319 /*Check wether dynamic basal boundary conditions are activated */
1320 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
1321 if(!isdynamicbasalspc) return;
1322
1323 /*Get parameters and inputs: */
1324 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
1325 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
1326 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1327 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
1328
1329 /*Fetch indices of basal & surface nodes for this finite element*/
1330 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1331 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1332 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1333
1334 GaussPenta* gauss=new GaussPenta();
1335 GaussPenta* gaussup=new GaussPenta();
1336 for(int i=0;i<numindices;i++){
1337 gauss->GaussNode(element->GetElementType(),indices[i]);
1338 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1339
1340 enthalpy_input->GetInputValue(&enthalpy,gauss);
1341 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1342 pressure_input->GetInputValue(&pressure,gauss);
1343 pressure_input->GetInputValue(&pressureup,gaussup);
1344 watercolumn_input->GetInputValue(&watercolumn,gauss);
1345 meltingrate_input->GetInputValue(&meltingrate,gauss);
1346
1347 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1348 setspc=false;
1349 switch (state) {
1350 case 0:
1351 // cold, dry base: apply basal surface forcing
1352 break;
1353 case 1:
1354 // cold, wet base: keep at pressure melting point
1355 setspc=true;
1356 break;
1357 case 2:
1358 // temperate, thin refreezing base: release spc
1359 break;
1360 case 3:
1361 // temperate, thin melting base: set spc
1362 setspc=true;
1363 break;
1364 case 4:
1365 // temperate, thick melting base: s
1366 setspc=true;
1367 break;
1368 default:
1369 _printf0_(" unknown thermal basal state found!");
1370 }
1371
1372 /*apply or release spc*/
1373 node=element->GetNode(indices[i]);
1374 if(setspc){
1375 pressure_input->GetInputValue(&pressure, gauss);
1376 node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
1377 }
1378 else
1379 node->DofInFSet(0);
1380 }
1381
1382 /*Free ressources:*/
1383 xDelete<int>(indices);
1384 xDelete<int>(indicesup);
1385 delete gauss;
1386 delete gaussup;
1387}/*}}}*/
1388int EnthalpyAnalysis::GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpyup, IssmDouble pressure, IssmDouble pressureup, IssmDouble watercolumn, IssmDouble meltingrate){/*{{{*/
1389
1390 /* Check if ice in element */
1391 if(!element->IsIceInElement()) return -1;
1392
1393 /* Only update Constraints at the base of grounded ice*/
1394 if(!(element->IsOnBase())) return -1;
1395
1396 /*Intermediary*/
1397 int state=-1;
1398 IssmDouble dt;
1399
1400 /*Get parameters and inputs: */
1401 element->FindParam(&dt,TimesteppingTimeStepEnum);
1402
1403 if(enthalpy<PureIceEnthalpy(element,pressure)){
1404 if(watercolumn<=0.) state=0; // cold, dry base
1405 else state=1; // cold, wet base (refreezing)
1406 }
1407 else{
1408 if(enthalpyup<PureIceEnthalpy(element,pressureup)){
1409 if((dt==0.) && (meltingrate<0.)) state=2; // refreezing temperate base (non-physical, only for steadystate solver)
1410 else state=3; // temperate base, but no temperate layer
1411 }
1412 else state=4; // temperate layer with positive thickness
1413 }
1414
1415 _assert_(state>=0);
1416 return state;
1417}/*}}}*/
1418IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
1419
1420 IssmDouble temperature, waterfraction;
1421 IssmDouble kappa_w = 0.6; // thermal conductivity of water (in W/m/K)
1422 IssmDouble kappa_i = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1423 element->EnthalpyToThermal(&temperature, &waterfraction, enthalpy, pressure);
1424
1425 return (1.-waterfraction)*kappa_i + waterfraction*kappa_w;
1426}/*}}}*/
1427
1428/*Intermediaries*/
1429IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
1430
1431 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1432 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
1433 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1434
1435 if(enthalpy < PureIceEnthalpy(element,pressure)){
1436 return thermalconductivity/heatcapacity;
1437 }
1438 else{
1439 return temperateiceconductivity/heatcapacity;
1440 }
1441}/*}}}*/
1442IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
1443
1444 int iv;
1445 IssmDouble lambda; /* fraction of cold ice */
1446 IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
1447 IssmDouble Hc,Ht;
1448
1449 /*Get pressures and enthalpies on vertices*/
1450 int numvertices = element->GetNumberOfVertices();
1451 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1452 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1453 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
1454 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
1455 element->GetInputListOnVertices(pressures,PressureEnum);
1456 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
1457 for(iv=0;iv<numvertices;iv++){
1458 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
1459 dHpmp[iv] = enthalpies[iv]-PIE[iv];
1460 }
1461
1462 bool allequalsign = true;
1463 if(dHpmp[0]<0.){
1464 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
1465 }
1466 else{
1467 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
1468 }
1469
1470 if(allequalsign){
1471 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
1472 }
1473 else{
1474 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
1475 cf Patankar 1980, pp44 */
1476 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
1477 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
1478 Hc=0.; Ht=0.;
1479 for(iv=0; iv<numvertices;iv++){
1480 if(enthalpies[iv]<PIE[iv])
1481 Hc+=(PIE[iv]-enthalpies[iv]);
1482 else
1483 Ht+=(enthalpies[iv]-PIE[iv]);
1484 }
1485 _assert_((Hc+Ht)>0.);
1486 lambda = Hc/(Hc+Ht);
1487 kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
1488 }
1489
1490 /*Clean up and return*/
1491 xDelete<IssmDouble>(PIE);
1492 xDelete<IssmDouble>(dHpmp);
1493 xDelete<IssmDouble>(pressures);
1494 xDelete<IssmDouble>(enthalpies);
1495 return kappa;
1496}/*}}}*/
1497IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
1498
1499 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1500 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
1501
1502 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1503}/*}}}*/
1504IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
1505
1506 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
1507 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
1508
1509 return meltingpoint-beta*pressure;
1510}/*}}}*/
Note: See TracBrowser for help on using the repository browser.