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

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

CHG: no need to change enthalpy at base to compute basal melting

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