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

Last change on this file since 18732 was 18732, checked in by Mathieu Morlighem, 10 years ago

NEW: added new friction law based on Tpmp, request from martin.rueckamp@…

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