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

Last change on this file since 18656 was 18656, checked in by seroussi, 10 years ago

BUG: missing break in enthalpy cases

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