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

Last change on this file since 17027 was 17027, checked in by jbondzio, 11 years ago

CHG: moved ComputeBasalMeltingrate and UpdateBasalConstraints to EnthalpyAnalysis. Minor fixes to the LliboutryDuval rheology.

File size: 46.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
7/*Model processing*/
8int EnthalpyAnalysis::DofsPerNode(int** doflist,int meshtype,int approximation){/*{{{*/
9 return 1;
10}/*}}}*/
11void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
12
13 int numoutputs;
14 char** requestedoutputs = NULL;
15
16 parameters->AddObject(iomodel->CopyConstantObject(ThermalStabilizationEnum));
17 parameters->AddObject(iomodel->CopyConstantObject(ThermalIsenthalpyEnum));
18 parameters->AddObject(iomodel->CopyConstantObject(ThermalIsdynamicbasalspcEnum));
19
20 iomodel->FetchData(&requestedoutputs,&numoutputs,ThermalRequestedOutputsEnum);
21 parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
22 if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
23 iomodel->DeleteData(&requestedoutputs,numoutputs,ThermalRequestedOutputsEnum);
24}/*}}}*/
25void EnthalpyAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
26
27 bool dakota_analysis;
28 bool isenthalpy;
29
30 /*Now, is the model 3d? otherwise, do nothing: */
31 if(iomodel->meshtype==Mesh2DhorizontalEnum)return;
32
33 /*Is enthalpy requested?*/
34 iomodel->Constant(&isenthalpy,ThermalIsenthalpyEnum);
35 if(!isenthalpy) return;
36
37 /*Fetch data needed: */
38 iomodel->FetchData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
39
40 /*Update elements: */
41 int counter=0;
42 for(int i=0;i<iomodel->numberofelements;i++){
43 if(iomodel->my_elements[i]){
44 Element* element=(Element*)elements->GetObjectByOffset(counter);
45 element->Update(i,iomodel,analysis_counter,analysis_type,P1Enum);
46 counter++;
47 }
48 }
49
50 iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
51
52 iomodel->FetchDataToInput(elements,ThicknessEnum);
53 iomodel->FetchDataToInput(elements,SurfaceEnum);
54 iomodel->FetchDataToInput(elements,BedEnum);
55 iomodel->FetchDataToInput(elements,FrictionCoefficientEnum);
56 iomodel->FetchDataToInput(elements,FrictionPEnum);
57 iomodel->FetchDataToInput(elements,FrictionQEnum);
58 iomodel->FetchDataToInput(elements,MaskIceLevelsetEnum);
59 iomodel->FetchDataToInput(elements,MaskGroundediceLevelsetEnum);
60 iomodel->FetchDataToInput(elements,MeshElementonbedEnum);
61 iomodel->FetchDataToInput(elements,MeshElementonsurfaceEnum);
62 iomodel->FetchDataToInput(elements,FlowequationElementEquationEnum);
63 iomodel->FetchDataToInput(elements,MaterialsRheologyBEnum);
64 iomodel->FetchDataToInput(elements,MaterialsRheologyNEnum);
65 iomodel->FetchDataToInput(elements,PressureEnum);
66 iomodel->FetchDataToInput(elements,TemperatureEnum);
67 iomodel->FetchDataToInput(elements,WaterfractionEnum);
68 iomodel->FetchDataToInput(elements,EnthalpyEnum);
69 iomodel->FetchDataToInput(elements,BasalforcingsGeothermalfluxEnum);
70 iomodel->FetchDataToInput(elements,WatercolumnEnum);
71 iomodel->FetchDataToInput(elements,BasalforcingsMeltingRateEnum);
72 iomodel->FetchDataToInput(elements,VxEnum);
73 iomodel->FetchDataToInput(elements,VyEnum);
74 iomodel->FetchDataToInput(elements,VzEnum);
75 InputUpdateFromConstantx(elements,0.,VxMeshEnum);
76 InputUpdateFromConstantx(elements,0.,VyMeshEnum);
77 InputUpdateFromConstantx(elements,0.,VzMeshEnum);
78 if(dakota_analysis){
79 elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
80 elements->InputDuplicate(BasalforcingsMeltingRateEnum,QmuMeltingEnum);
81 elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
82 elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
83 elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
84 }
85
86 /*Free data: */
87 iomodel->DeleteData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
88}/*}}}*/
89void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
90
91 if(iomodel->meshtype==Mesh3DEnum) iomodel->FetchData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
92 ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,P1Enum);
93 iomodel->DeleteData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
94}/*}}}*/
95void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
96
97 /*Intermediary*/
98 int count;
99 int M,N;
100 bool spcpresent = false;
101 IssmDouble heatcapacity;
102 IssmDouble referencetemperature;
103
104 /*Output*/
105 IssmDouble *spcvector = NULL;
106 IssmDouble* times=NULL;
107 IssmDouble* values=NULL;
108
109 /*Fetch parameters: */
110 iomodel->Constant(&heatcapacity,MaterialsHeatcapacityEnum);
111 iomodel->Constant(&referencetemperature,ConstantsReferencetemperatureEnum);
112
113 /*return if 2d mesh*/
114 if(iomodel->meshtype==Mesh2DhorizontalEnum) return;
115
116 /*Fetch data: */
117 iomodel->FetchData(&spcvector,&M,&N,ThermalSpctemperatureEnum);
118
119 //FIX ME: SHOULD USE IOMODELCREATECONSTRAINTS
120 /*Transient or static?:*/
121 if(M==iomodel->numberofvertices){
122 /*static: just create Constraints objects*/
123 count=0;
124
125 for(int i=0;i<iomodel->numberofvertices;i++){
126 /*keep only this partition's nodes:*/
127 if((iomodel->my_vertices[i])){
128
129 if (!xIsNan<IssmDouble>(spcvector[i])){
130
131 constraints->AddObject(new SpcStatic(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,heatcapacity*(spcvector[i]-referencetemperature),EnthalpyAnalysisEnum));
132 count++;
133
134 }
135 }
136 }
137 }
138 else if (M==(iomodel->numberofvertices+1)){
139 /*transient: create transient SpcTransient objects. Same logic, except we need to retrieve
140 * various times and values to initialize an SpcTransient object: */
141 count=0;
142
143 /*figure out times: */
144 times=xNew<IssmDouble>(N);
145 for(int j=0;j<N;j++){
146 times[j]=spcvector[(M-1)*N+j];
147 }
148
149 /*Create constraints from x,y,z: */
150 for(int i=0;i<iomodel->numberofvertices;i++){
151
152 /*keep only this partition's nodes:*/
153 if((iomodel->my_vertices[i])){
154
155 /*figure out times and values: */
156 values=xNew<IssmDouble>(N);
157 spcpresent=false;
158 for(int j=0;j<N;j++){
159 values[j]=heatcapacity*(spcvector[i*N+j]-referencetemperature);
160 if(!xIsNan<IssmDouble>(values[j]))spcpresent=true; //NaN means no spc by default
161 }
162
163 if(spcpresent){
164 constraints->AddObject(new SpcTransient(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,N,times,values,EnthalpyAnalysisEnum));
165 count++;
166 }
167 xDelete<IssmDouble>(values);
168 }
169 }
170 }
171 else{
172 _error_("Size of field " << EnumToStringx(ThermalSpctemperatureEnum) << " not supported");
173 }
174
175 /*Free ressources:*/
176 iomodel->DeleteData(spcvector,ThermalSpctemperatureEnum);
177 xDelete<IssmDouble>(times);
178 xDelete<IssmDouble>(values);
179}/*}}}*/
180void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
181
182 /*No loads */
183}/*}}}*/
184
185/*Finite Element Analysis*/
186void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
187 _error_("not implemented");
188}/*}}}*/
189ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
190 /*Default, return NULL*/
191 return NULL;
192}/*}}}*/
193ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
194_error_("Not implemented");
195}/*}}}*/
196ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
197
198 /*compute all stiffness matrices for this element*/
199 ElementMatrix* Ke1=CreateKMatrixVolume(element);
200 ElementMatrix* Ke2=CreateKMatrixShelf(element);
201 ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
202
203 /*clean-up and return*/
204 delete Ke1;
205 delete Ke2;
206 return Ke;
207}/*}}}*/
208ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
209
210 /*Intermediaries */
211 int stabilization;
212 IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
213 IssmDouble h,hx,hy,hz,vx,vy,vz;
214 IssmDouble tau_parameter,diameter;
215 IssmDouble D_scalar;
216 IssmDouble* xyz_list = NULL;
217
218 /*Fetch number of nodes and dof for this finite element*/
219 int numnodes = element->GetNumberOfNodes();
220
221 /*Initialize Element vector and other vectors*/
222 ElementMatrix* Ke = element->NewElementMatrix();
223 IssmDouble* basis = xNew<IssmDouble>(numnodes);
224 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
225 IssmDouble* B = xNew<IssmDouble>(3*numnodes);
226 IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
227 IssmDouble D[3][3] = {0.};
228 IssmDouble K[3][3];
229
230 /*Retrieve all inputs and parameters*/
231 element->GetVerticesCoordinates(&xyz_list);
232 element->FindParam(&dt,TimesteppingTimeStepEnum);
233 element->FindParam(&stabilization,ThermalStabilizationEnum);
234 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
235 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
236 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
237 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
238 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
239 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
240 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
241 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
242 Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
243 Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
244 Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
245 if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
246
247 /*Enthalpy diffusion parameter*/
248 IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
249
250 /* Start looping on the number of gaussian points: */
251 Gauss* gauss=element->NewGauss(2);
252 for(int ig=gauss->begin();ig<gauss->end();ig++){
253 gauss->GaussPoint(ig);
254
255 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
256 D_scalar=gauss->weight*Jdet;
257 if(dt!=0.) D_scalar=D_scalar*dt;
258
259 /*Conduction: */
260 GetBConduct(B,element,xyz_list,gauss);
261 D[0][0]=D_scalar*kappa/rho_ice;
262 D[1][1]=D_scalar*kappa/rho_ice;
263 D[2][2]=D_scalar*kappa/rho_ice;
264 TripleMultiply(B,3,numnodes,1,
265 &D[0][0],3,3,0,
266 B,3,numnodes,0,
267 &Ke->values[0],1);
268
269 /*Advection: */
270 GetBAdvec(B,element,xyz_list,gauss);
271 GetBAdvecprime(Bprime,element,xyz_list,gauss);
272 vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
273 vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
274 vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
275 D[0][0]=D_scalar*vx;
276 D[1][1]=D_scalar*vy;
277 D[2][2]=D_scalar*vz;
278 TripleMultiply(B,3,numnodes,1,
279 &D[0][0],3,3,0,
280 Bprime,3,numnodes,0,
281 &Ke->values[0],1);
282
283 /*Transient: */
284 if(dt!=0.){
285 D_scalar=gauss->weight*Jdet;
286 element->NodalFunctions(basis,gauss);
287 TripleMultiply(basis,numnodes,1,0,
288 &D_scalar,1,1,0,
289 basis,1,numnodes,0,
290 &Ke->values[0],1);
291 D_scalar=D_scalar*dt;
292 }
293
294 /*Artifficial diffusivity*/
295 if(stabilization==1){
296 element->ElementSizes(&hx,&hy,&hz);
297 vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
298 h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
299 K[0][0]=h/(2.*vel)*vx*vx; K[0][1]=h/(2.*vel)*vx*vy; K[0][2]=h/(2.*vel)*vx*vz;
300 K[1][0]=h/(2.*vel)*vy*vx; K[1][1]=h/(2.*vel)*vy*vy; K[1][2]=h/(2.*vel)*vy*vz;
301 K[2][0]=h/(2.*vel)*vz*vx; K[2][1]=h/(2.*vel)*vz*vy; K[2][2]=h/(2.*vel)*vz*vz;
302 for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
303
304 GetBAdvecprime(Bprime,element,xyz_list,gauss);
305 TripleMultiply(Bprime,3,numnodes,1,
306 &K[0][0],3,3,0,
307 Bprime,3,numnodes,0,
308 &Ke->values[0],1);
309 }
310 else if(stabilization==2){
311 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
312 tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
313 for(int i=0;i<numnodes;i++){
314 for(int j=0;j<numnodes;j++){
315 Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
316 ((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]);
317 }
318 }
319 if(dt!=0.){
320 D_scalar=gauss->weight*Jdet;
321 for(int i=0;i<numnodes;i++){
322 for(int j=0;j<numnodes;j++){
323 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]);
324 }
325 }
326 }
327 }
328 }
329
330 /*Clean up and return*/
331 xDelete<IssmDouble>(xyz_list);
332 xDelete<IssmDouble>(basis);
333 xDelete<IssmDouble>(dbasis);
334 xDelete<IssmDouble>(B);
335 xDelete<IssmDouble>(Bprime);
336 delete gauss;
337 return Ke;
338}/*}}}*/
339ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
340
341 /*Initialize Element matrix and return if necessary*/
342 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
343
344 /*Intermediaries*/
345 IssmDouble dt,Jdet,D;
346 IssmDouble *xyz_list_base = NULL;
347
348 /*Fetch number of nodes for this finite element*/
349 int numnodes = element->GetNumberOfNodes();
350
351 /*Initialize vectors*/
352 ElementMatrix* Ke = element->NewElementMatrix();
353 IssmDouble* basis = xNew<IssmDouble>(numnodes);
354
355 /*Retrieve all inputs and parameters*/
356 element->GetVerticesCoordinatesBase(&xyz_list_base);
357 element->FindParam(&dt,TimesteppingTimeStepEnum);
358 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
359 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
360 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
361 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
362 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
363 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
364
365 /* Start looping on the number of gaussian points: */
366 Gauss* gauss=element->NewGaussBase(2);
367 for(int ig=gauss->begin();ig<gauss->end();ig++){
368 gauss->GaussPoint(ig);
369
370 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
371 element->NodalFunctions(basis,gauss);
372
373 D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
374 if(reCast<bool,IssmDouble>(dt)) D=dt*D;
375 TripleMultiply(basis,numnodes,1,0,
376 &D,1,1,0,
377 basis,1,numnodes,0,
378 &Ke->values[0],1);
379
380 }
381
382 /*Clean up and return*/
383 delete gauss;
384 xDelete<IssmDouble>(basis);
385 xDelete<IssmDouble>(xyz_list_base);
386 return Ke;
387}/*}}}*/
388ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
389
390 /*compute all load vectors for this element*/
391 ElementVector* pe1=CreatePVectorVolume(element);
392 ElementVector* pe2=CreatePVectorSheet(element);
393 ElementVector* pe3=CreatePVectorShelf(element);
394 ElementVector* pe =new ElementVector(pe1,pe2,pe3);
395
396 /*clean-up and return*/
397 delete pe1;
398 delete pe2;
399 delete pe3;
400 return pe;
401}/*}}}*/
402ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
403
404 /*Intermediaries*/
405 int i, stabilization;
406 IssmDouble Jdet,phi,dt;
407 IssmDouble enthalpy, Hpmp;
408 IssmDouble enthalpypicard, d1enthalpypicard[3];
409 IssmDouble pressure, d1pressure[3], d2pressure;
410 IssmDouble waterfractionpicard;
411 IssmDouble kappa,tau_parameter,diameter,kappa_w;
412 IssmDouble u,v,w;
413 IssmDouble scalar_def, scalar_sens ,scalar_transient;
414 IssmDouble* xyz_list = NULL;
415 IssmDouble d1H_d1P, d1P2;
416
417 /*Fetch number of nodes and dof for this finite element*/
418 int numnodes = element->GetNumberOfNodes();
419 int numvertices = element->GetNumberOfVertices();
420
421 /*Initialize Element vector*/
422 ElementVector* pe = element->NewElementVector();
423 IssmDouble* basis = xNew<IssmDouble>(numnodes);
424 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
425
426 /*Retrieve all inputs and parameters*/
427 element->GetVerticesCoordinates(&xyz_list);
428 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
429 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
430 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
431 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
432 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
433 IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
434 element->FindParam(&dt,TimesteppingTimeStepEnum);
435 element->FindParam(&stabilization,ThermalStabilizationEnum);
436 Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
437 Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
438 Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
439 Input* enthalpypicard_input=element->GetInput(EnthalpyPicardEnum); _assert_(enthalpypicard_input);
440 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
441 Input* enthalpy_input=NULL;
442 if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
443 if(stabilization==2){
444 diameter=element->MinEdgeLength(xyz_list);
445 kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
446 }
447
448 /* Start looping on the number of gaussian points: */
449 Gauss* gauss=element->NewGauss(3);
450 for(int ig=gauss->begin();ig<gauss->end();ig++){
451 gauss->GaussPoint(ig);
452
453 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
454 element->NodalFunctions(basis,gauss);
455
456 /*viscous dissipation*/
457 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
458
459 scalar_def=phi/rho_ice*Jdet*gauss->weight;
460 if(dt!=0.) scalar_def=scalar_def*dt;
461
462 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
463
464 /*sensible heat flux in temperate ice*/
465 enthalpypicard_input->GetInputValue(&enthalpypicard,gauss);
466 pressure_input->GetInputValue(&pressure,gauss);
467 Hpmp=this->PureIceEnthalpy(element, pressure);
468
469 if(enthalpypicard>=Hpmp){
470 enthalpypicard_input->GetInputDerivativeValue(&d1enthalpypicard[0],xyz_list,gauss);
471 pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
472 d2pressure=0.; // for linear elements, 2nd derivative is zero
473
474 d1H_d1P=0.;
475 for(i=0;i<3;i++) d1H_d1P+=d1enthalpypicard[i]*d1pressure[i];
476 d1P2=0.;
477 for(i=0;i<3;i++) d1P2+=pow(d1pressure[i],2.);
478
479 scalar_sens=-beta*((temperateiceconductivity - thermalconductivity)/latentheat*(d1H_d1P + beta*heatcapacity*d1P2))/rho_ice;
480 if(dt!=0.) scalar_sens=scalar_sens*dt;
481 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_sens*basis[i];
482 }
483
484 /* Build transient now */
485 if(reCast<bool,IssmDouble>(dt)){
486 enthalpy_input->GetInputValue(&enthalpy, gauss);
487 scalar_transient=enthalpy*Jdet*gauss->weight;
488 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
489 }
490
491 if(stabilization==2){
492 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
493
494 vx_input->GetInputValue(&u,gauss);
495 vy_input->GetInputValue(&v,gauss);
496 vz_input->GetInputValue(&w,gauss);
497 tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
498
499 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]);
500
501 if(dt!=0.){
502 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]);
503 }
504 }
505 }
506
507 /*Clean up and return*/
508 xDelete<IssmDouble>(basis);
509 xDelete<IssmDouble>(dbasis);
510 xDelete<IssmDouble>(xyz_list);
511 delete gauss;
512 return pe;
513
514}/*}}}*/
515ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
516
517 /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
518 if(!element->IsOnBed() || element->IsFloating()) return NULL;
519
520 IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
521 IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
522 IssmDouble *xyz_list_base = NULL;
523
524 /*Fetch number of nodes for this finite element*/
525 int numnodes = element->GetNumberOfNodes();
526
527 /*Initialize vectors*/
528 ElementVector* pe = element->NewElementVector();
529 IssmDouble* basis = xNew<IssmDouble>(numnodes);
530
531 /*Retrieve all inputs and parameters*/
532 element->GetVerticesCoordinatesBase(&xyz_list_base);
533 element->FindParam(&dt,TimesteppingTimeStepEnum);
534 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
535 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
536 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
537 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
538 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
539 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
540 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
541 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
542 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
543
544 /*Build friction element, needed later: */
545 Friction* friction=new Friction(element,3);
546
547 /* Start looping on the number of gaussian points: */
548 Gauss* gauss = element->NewGaussBase(2);
549 Gauss* gaussup = element->NewGaussTop(2);
550 for(int ig=gauss->begin();ig<gauss->end();ig++){
551 gauss->GaussPoint(ig);
552
553 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
554 element->NodalFunctions(basis,gauss);
555
556 enthalpy_input->GetInputValue(&enthalpy,gauss);
557 pressure_input->GetInputValue(&pressure,gauss);
558 watercolumn_input->GetInputValue(&watercolumn,gauss);
559
560 if((watercolumn<=0.) && (enthalpy<PureIceEnthalpy(element,pressure))){
561 /* the above check is equivalent to
562 NOT [(watercolumn>0.) AND (enthalpy<PIE)] AND (enthalpy<PIE)*/
563 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
564
565 friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
566 vx_input->GetInputValue(&vx,gauss);
567 vy_input->GetInputValue(&vy,gauss);
568 vz_input->GetInputValue(&vz,gauss);
569 basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
570 heatflux = (basalfriction+geothermalflux)/(rho_ice);
571
572 scalar = gauss->weight*Jdet*heatflux;
573 if(dt!=0.) scalar=dt*scalar;
574
575 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
576 }
577 else if(enthalpy >= PureIceEnthalpy(element,pressure)){
578 /* check positive thickness of temperate basal ice layer */
579 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
580 pressure_input->GetInputValue(&pressureup,gaussup);
581 if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
582 // do nothing, set grad enthalpy*n=0.
583 }
584 else{
585 // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
586 }
587 }
588 else{
589 // base cold, but watercolumn positive. Set base to pressure melting point enthalpy
590 }
591 }
592
593 /*Clean up and return*/
594 delete gauss;
595 delete gaussup;
596 delete friction;
597 xDelete<IssmDouble>(basis);
598 xDelete<IssmDouble>(xyz_list_base);
599 return pe;
600
601}/*}}}*/
602ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
603
604 /*Get basal element*/
605 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
606
607 IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
608 IssmDouble *xyz_list_base = NULL;
609
610 /*Fetch number of nodes for this finite element*/
611 int numnodes = element->GetNumberOfNodes();
612
613 /*Initialize vectors*/
614 ElementVector* pe = element->NewElementVector();
615 IssmDouble* basis = xNew<IssmDouble>(numnodes);
616
617 /*Retrieve all inputs and parameters*/
618 element->GetVerticesCoordinatesBase(&xyz_list_base);
619 element->FindParam(&dt,TimesteppingTimeStepEnum);
620 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
621 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
622 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
623 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
624 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
625 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
626 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
627
628 /* Start looping on the number of gaussian points: */
629 Gauss* gauss=element->NewGaussBase(2);
630 for(int ig=gauss->begin();ig<gauss->end();ig++){
631 gauss->GaussPoint(ig);
632
633 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
634 element->NodalFunctions(basis,gauss);
635
636 pressure_input->GetInputValue(&pressure,gauss);
637 h_pmp=element->PureIceEnthalpy(pressure);
638
639 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
640 if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
641
642 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
643 }
644
645 /*Clean up and return*/
646 delete gauss;
647 xDelete<IssmDouble>(basis);
648 xDelete<IssmDouble>(xyz_list_base);
649 return pe;
650}/*}}}*/
651void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
652 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
653 * For node i, Bi' can be expressed in the actual coordinate system
654 * by:
655 * Bi_conduct=[ dh/dx ]
656 * [ dh/dy ]
657 * [ dh/dz ]
658 * where h is the interpolation function for node i.
659 *
660 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
661 */
662
663 /*Fetch number of nodes for this finite element*/
664 int numnodes = element->GetNumberOfNodes();
665
666 /*Get nodal functions derivatives*/
667 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
668 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
669
670 /*Build B: */
671 for(int i=0;i<numnodes;i++){
672 B[numnodes*0+i] = dbasis[0*numnodes+i];
673 B[numnodes*1+i] = dbasis[1*numnodes+i];
674 B[numnodes*2+i] = dbasis[2*numnodes+i];
675 }
676
677 /*Clean-up*/
678 xDelete<IssmDouble>(dbasis);
679}/*}}}*/
680void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
681 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
682 * For node i, Bi' can be expressed in the actual coordinate system
683 * by:
684 * Bi_advec =[ h ]
685 * [ h ]
686 * [ h ]
687 * where h is the interpolation function for node i.
688 *
689 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
690 */
691
692 /*Fetch number of nodes for this finite element*/
693 int numnodes = element->GetNumberOfNodes();
694
695 /*Get nodal functions*/
696 IssmDouble* basis=xNew<IssmDouble>(numnodes);
697 element->NodalFunctions(basis,gauss);
698
699 /*Build B: */
700 for(int i=0;i<numnodes;i++){
701 B[numnodes*0+i] = basis[i];
702 B[numnodes*1+i] = basis[i];
703 B[numnodes*2+i] = basis[i];
704 }
705
706 /*Clean-up*/
707 xDelete<IssmDouble>(basis);
708}/*}}}*/
709void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
710 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
711 * For node i, Bi' can be expressed in the actual coordinate system
712 * by:
713 * Biprime_advec=[ dh/dx ]
714 * [ dh/dy ]
715 * [ dh/dz ]
716 * where h is the interpolation function for node i.
717 *
718 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
719 */
720
721 /*Fetch number of nodes for this finite element*/
722 int numnodes = element->GetNumberOfNodes();
723
724 /*Get nodal functions derivatives*/
725 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
726 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
727
728 /*Build B: */
729 for(int i=0;i<numnodes;i++){
730 B[numnodes*0+i] = dbasis[0*numnodes+i];
731 B[numnodes*1+i] = dbasis[1*numnodes+i];
732 B[numnodes*2+i] = dbasis[2*numnodes+i];
733 }
734
735 /*Clean-up*/
736 xDelete<IssmDouble>(dbasis);
737}/*}}}*/
738void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
739 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
740}/*}}}*/
741void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
742
743 bool converged;
744 int i,rheology_law;
745 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
746 int *doflist = NULL;
747 IssmDouble *xyz_list = NULL;
748
749 /*Fetch number of nodes and dof for this finite element*/
750 int numnodes = element->GetNumberOfNodes();
751
752 /*Fetch dof list and allocate solution vector*/
753 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
754 IssmDouble* values = xNew<IssmDouble>(numnodes);
755 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
756 IssmDouble* surface = xNew<IssmDouble>(numnodes);
757 IssmDouble* B = xNew<IssmDouble>(numnodes);
758 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
759 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
760
761 /*Use the dof list to index into the solution vector: */
762 for(i=0;i<numnodes;i++){
763 values[i]=solution[doflist[i]];
764
765 /*Check solution*/
766 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
767 }
768
769 /*Get all inputs and parameters*/
770 element->GetInputValue(&converged,ConvergedEnum);
771 element->GetInputListOnNodes(&pressure[0],PressureEnum);
772 if(converged){
773 for(i=0;i<numnodes;i++){
774 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
775 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
776 if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
777 }
778 element->AddInput(EnthalpyEnum,values,P1Enum);
779 element->AddInput(WaterfractionEnum,waterfraction,P1Enum);
780 element->AddInput(TemperatureEnum,temperature,P1Enum);
781
782 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
783 * otherwise the rheology could be negative*/
784 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
785 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
786 switch(rheology_law){
787 case NoneEnum:
788 /*Do nothing: B is not temperature dependent*/
789 break;
790 case PatersonEnum:
791 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
792 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
793 break;
794 case ArrheniusEnum:
795 element->GetVerticesCoordinates(&xyz_list);
796 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
797 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
798 break;
799 case LliboutryDuvalEnum:
800 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));
801 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
802 break;
803 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
804 }
805 }
806 else{
807 element->AddInput(EnthalpyPicardEnum,values,P1Enum);
808 }
809
810 /*Free ressources:*/
811 xDelete<IssmDouble>(values);
812 xDelete<IssmDouble>(pressure);
813 xDelete<IssmDouble>(surface);
814 xDelete<IssmDouble>(B);
815 xDelete<IssmDouble>(temperature);
816 xDelete<IssmDouble>(waterfraction);
817 xDelete<IssmDouble>(xyz_list);
818 xDelete<int>(doflist);
819}/*}}}*/
820
821
822/*Modules*/
823void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
824
825 /*Compute basal melting rates: */
826 for(int i=0;i<femmodel->elements->Size();i++){
827 Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
828 ComputeBasalMeltingrate(element);
829 }
830
831 /*Update basal dirichlet BCs for enthalpy: */
832 for(int i=0;i<femmodel->elements->Size();i++){
833 Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
834 UpdateBasalConstraints(element);
835 }
836}/*}}}*/
837
838void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
839 /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
840 /* melting rate is positive when melting, negative when refreezing*/
841
842 /* Intermediaries */
843 int i,is,vertexdown,vertexup,dim=3,numvertices,numsegments;
844 IssmDouble heatflux;
845 IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim];
846 IssmDouble temperature, waterfraction;
847 IssmDouble basalfriction,alpha2;
848 IssmDouble dt,yts;
849 IssmDouble melting_overshoot,lambda;
850 IssmDouble geothermalflux;
851 IssmDouble vx,vy,vz;
852 IssmDouble *xyz_list = NULL;
853 IssmDouble *xyz_list_base = NULL;
854 int *pairindices = NULL;
855
856 /* Only compute melt rates at the base of grounded ice*/
857 if(!element->IsOnBed() || element->IsFloating()) return;
858
859 /*Fetch parameters and inputs */
860 element->GetVerticesCoordinates(&xyz_list);
861 element->GetVerticesCoordinatesBase(&xyz_list_base);
862 IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
863 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
864 Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
865 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
866 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
867 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
868 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
869 IssmDouble kappa=EnthalpyDiffusionParameterVolume(element,EnthalpyEnum); _assert_(kappa>=0.);
870 element->NormalBase(&normal_base[0],xyz_list_base);
871 element->VerticalSegmentIndices(&pairindices,&numsegments);
872 IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
873 IssmDouble* heating = xNew<IssmDouble>(numsegments);
874
875 /*Build friction element, needed later: */
876 Friction* friction=new Friction(element,dim);
877
878 /******** MELTING RATES ************************************/
879 numvertices=element->GetNumberOfVertices();
880 IssmDouble* enthalpy = xNew<IssmDouble>(numvertices);
881 IssmDouble* pressure = xNew<IssmDouble>(numvertices);
882 IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
883 IssmDouble* basalmeltingrate = xNew<IssmDouble>(numvertices);
884 element->GetInputListOnVertices(enthalpy,EnthalpyEnum);
885 element->GetInputListOnVertices(pressure,PressureEnum);
886 element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
887 element->GetInputListOnVertices(basalmeltingrate,BasalforcingsMeltingRateEnum);
888
889 Gauss* gauss=element->NewGauss();
890
891 for(int is=0;is<numsegments;is++){
892 vertexdown = pairindices[is*2+0];
893 vertexup = pairindices[is*2+1];
894 gauss->GaussVertex(vertexdown);
895
896 bool checkpositivethickness=true;
897 _assert_(watercolumn[vertexdown]>=0.);
898
899 /*Calculate basal meltingrate after Fig.5 of A.Aschwanden 2012*/
900 meltingrate_enthalpy[is]=0.;
901 heating[is]=0.;
902 if((watercolumn[vertexdown]>0.) && (enthalpy[vertexdown]<PureIceEnthalpy(element,pressure[vertexdown]))){
903 /*ensure that no ice is at T<Tm(p), if water layer present*/
904 enthalpy[vertexdown]=element->PureIceEnthalpy(pressure[vertexdown]);
905 }
906 else if(enthalpy[vertexdown]<element->PureIceEnthalpy(pressure[vertexdown])){
907 /*cold base: set q*n=q_geo*n+frictionheating as Neumann BC in Penta::CreatePVectorEnthalpySheet*/
908 checkpositivethickness=false; // cold base, skip next test
909 }
910 else{/*we have a temperate base, go to next test*/}
911
912 if(checkpositivethickness){
913 /*From here on all basal ice is temperate. Check for positive thickness of layer of temperate ice. */
914 bool istemperatelayer=false;
915 if(enthalpy[vertexup]>=element->PureIceEnthalpy(pressure[vertexup])) istemperatelayer=true;
916 if(istemperatelayer) for(i=0;i<dim;i++) vec_heatflux[i]=0.; // TODO: add -k*nabla T_pmp
917 else{
918 enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
919 for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
920 }
921
922 /*heat flux along normal*/
923 heatflux=0.;
924 for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
925
926 /*basal friction*/
927 friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
928 vx_input->GetInputValue(&vx,gauss);
929 vy_input->GetInputValue(&vy,gauss);
930 vz_input->GetInputValue(&vz,gauss);
931 basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
932
933 element->EnthalpyToThermal(&temperature,&waterfraction,enthalpy[vertexdown],pressure[vertexdown]);
934 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
935 /* -Mb= Fb-(q-q_geo)/((1-w)*L), cf Aschwanden 2012, eq.66*/
936 heating[is]=(heatflux+basalfriction+geothermalflux);
937 meltingrate_enthalpy[is]=heating[is]/((1-waterfraction)*latentheat*rho_ice); // m/s water equivalent //????
938 }
939 }
940 /* enthalpy might have been changed, update */
941 //element->AddInput(EnthalpyEnum,enthalpy,P1Enum);
942
943 /******** DRAINAGE *****************************************/
944 IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments); //TODO: xDelete?
945 IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
946 for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
947 Element* elementi = element;
948 for(;;){
949 for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
950 DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
951 for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
952
953 if(elementi->IsOnSurface()) break;
954 elementi=elementi->GetUpperElement();
955 }
956 /* add drained water to melting rate*/
957 for(is=0;is<numsegments;is++) meltingrate_enthalpy[is]+=drainrate_column[is];
958
959 /******** UPDATE MELTINGRATES AND WATERCOLUMN **************/
960 element->FindParam(&dt,TimesteppingTimeStepEnum);
961 for(is=0;is<numsegments;is++){
962 vertexdown = pairindices[is*2+0];
963 vertexup = pairindices[is*2+1];
964 if(dt!=0.){
965 if(watercolumn[vertexdown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
966 melting_overshoot=watercolumn[vertexdown]+meltingrate_enthalpy[is]*dt;
967 lambda=melting_overshoot/(meltingrate_enthalpy[is]*dt); _assert_(lambda>0); _assert_(lambda<1);
968 basalmeltingrate[vertexdown]=(1.-lambda)*meltingrate_enthalpy[is];
969 watercolumn[vertexdown]=0.;
970 yts=365.*24.*60.*60.;
971 enthalpy[vertexdown]+=dt/yts*lambda*heating[is];
972 }
973 else{
974 basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
975 watercolumn[vertexdown]+=dt*meltingrate_enthalpy[is];
976 }
977 }
978 else{
979 basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
980 watercolumn[vertexdown]+=meltingrate_enthalpy[is];
981 }
982 _assert_(watercolumn[vertexdown]>=0.);
983 }
984
985 /*feed updated variables back into model*/
986 element->AddInput(EnthalpyEnum,enthalpy,P1Enum);
987 element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
988 element->AddInput(BasalforcingsMeltingRateEnum,basalmeltingrate,P1Enum);
989
990 /*Clean up and return*/
991 delete gauss;
992 delete friction;
993 xDelete<IssmDouble>(enthalpy);
994 xDelete<IssmDouble>(pressure);
995 xDelete<IssmDouble>(watercolumn);
996 xDelete<IssmDouble>(basalmeltingrate);
997 xDelete<IssmDouble>(meltingrate_enthalpy);
998 xDelete<IssmDouble>(heating);
999 xDelete<IssmDouble>(drainrate_column);
1000 xDelete<IssmDouble>(drainrate_element);
1001 xDelete<IssmDouble>(xyz_list);
1002}/*}}}*/
1003
1004void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
1005
1006 /*Intermediaries*/
1007 int iv,is,vertexdown,vertexup,numsegments;
1008 IssmDouble dt, height_element;
1009 IssmDouble rho_water, rho_ice;
1010 int numvertices = element->GetNumberOfVertices();
1011
1012 IssmDouble* xyz_list = NULL;
1013 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1014 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1015 IssmDouble* temperatures = xNew<IssmDouble>(numvertices);
1016 IssmDouble* waterfractions = xNew<IssmDouble>(numvertices);
1017 IssmDouble* deltawaterfractions = xNew<IssmDouble>(numvertices);
1018 int *pairindices = NULL;
1019
1020 rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
1021 rho_water=element->GetMaterialParameter(MaterialsRhoWaterEnum);
1022
1023 element->GetVerticesCoordinates(&xyz_list);
1024 element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
1025 element->GetInputListOnVertices(pressures,PressureEnum);
1026
1027 element->FindParam(&dt,TimesteppingTimeStepEnum);
1028 for(iv=0;iv<numvertices;iv++){
1029 element->EnthalpyToThermal(&temperatures[iv],&waterfractions[iv], enthalpies[iv],pressures[iv]);
1030 deltawaterfractions[iv]=DrainageFunctionWaterfraction(waterfractions[iv], dt);
1031 }
1032
1033 /*drain waterfraction, feed updated variables back into model*/
1034 for(iv=0;iv<numvertices;iv++){
1035 if(reCast<bool,IssmDouble>(dt))
1036 waterfractions[iv]-=deltawaterfractions[iv]*dt;
1037 else
1038 waterfractions[iv]-=deltawaterfractions[iv];
1039 element->ThermalToEnthalpy(&enthalpies[iv], temperatures[iv], waterfractions[iv], pressures[iv]);
1040 }
1041 element->AddInput(EnthalpyEnum,enthalpies,P1Enum);
1042 element->AddInput(WaterfractionEnum,waterfractions,P1Enum);
1043
1044 /*return meltwater column equivalent to drained water*/
1045 element->VerticalSegmentIndices(&pairindices,&numsegments);
1046 for(is=0;is<numsegments;is++){
1047 vertexdown = pairindices[is*2+0];
1048 vertexup = pairindices[is*2+1];
1049 height_element=fabs(xyz_list[vertexup*3+2]-xyz_list[vertexdown*3+2]);
1050 pdrainrate_element[is]=(deltawaterfractions[vertexdown]+deltawaterfractions[vertexup])/2.*rho_water/rho_ice*height_element;
1051 }
1052
1053 /*Clean up and return*/
1054 xDelete<IssmDouble>(xyz_list);
1055 xDelete<IssmDouble>(enthalpies);
1056 xDelete<IssmDouble>(pressures);
1057 xDelete<IssmDouble>(temperatures);
1058 xDelete<IssmDouble>(waterfractions);
1059 xDelete<IssmDouble>(deltawaterfractions);
1060}/*}}}*/
1061
1062void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
1063
1064 /*Intermediary*/
1065 bool isdynamicbasalspc,setspc;
1066 int numindices, numindicesup;
1067 IssmDouble pressure, pressureup;
1068 IssmDouble h_pmp, enthalpy, enthalpyup;
1069 IssmDouble watercolumn;
1070 int *indices = NULL, *indicesup = NULL;
1071 Node* node = NULL;
1072
1073 /* Only update Constraints at the base of grounded ice*/
1074 if(!(element->IsOnBed()) || element->IsFloating()) return;
1075
1076 /*Check wether dynamic basal boundary conditions are activated */
1077 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
1078 if(!isdynamicbasalspc) return;
1079
1080 /*Fetch indices of basal & surface nodes for this finite element*/
1081 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1082 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1083 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType());
1084 _assert_(numindices==numindicesup);
1085
1086 /*Get parameters and inputs: */
1087 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
1088 Input* enthalpy_input=element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
1089 Input* watercolumn_input=element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1090
1091 /*if there is a temperate layer of zero thickness, set spc enthalpy=h_pmp at that node*/
1092 GaussPenta* gauss=new GaussPenta();
1093 GaussPenta* gaussup=new GaussPenta();
1094 for(int i=0;i<numindices;i++){
1095 gauss->GaussNode(element->GetElementType(),indices[i]);
1096 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1097
1098 /*Check wether there is a temperate layer at the base or not */
1099 /*check if node is temperate, else continue*/
1100 enthalpy_input->GetInputValue(&enthalpy, gauss);
1101 pressure_input->GetInputValue(&pressure, gauss);
1102 watercolumn_input->GetInputValue(&watercolumn,gauss);
1103 h_pmp=PureIceEnthalpy(element,pressure);
1104 if (enthalpy>=h_pmp){
1105 /*check if upper node is temperate, too.
1106 if yes, then we have a temperate layer of positive thickness and reset the spc.
1107 if not, apply dirichlet BC.*/
1108 enthalpy_input->GetInputValue(&enthalpyup, gaussup);
1109 pressure_input->GetInputValue(&pressureup, gaussup);
1110 setspc=((enthalpyup<PureIceEnthalpy(element,pressureup)) && (watercolumn>=0.))?true:false;
1111 }
1112 else if(watercolumn>0.) // case H<Hpmp && watercolumn>0.
1113 setspc=true;
1114 else
1115 setspc = false;
1116
1117 node=element->GetNode(indices[i]);
1118 if (setspc)
1119 node->ApplyConstraint(1,h_pmp); /*apply spc*/ //nodes[indices[i]]->ApplyConstraint(1,h_pmp);
1120 else
1121 node->DofInFSet(0); /*remove spc*/ //nodes[indices[i]]->DofInFSet(0);
1122 }
1123
1124 /*Free ressources:*/
1125 xDelete<int>(indices);
1126 xDelete<int>(indicesup);
1127 delete gauss;
1128 delete gaussup;
1129}/*}}}*/
1130
1131/*Intermediaries*/
1132IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
1133
1134 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1135 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
1136 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1137
1138 if(enthalpy < PureIceEnthalpy(element,pressure)){
1139 return thermalconductivity/heatcapacity;
1140 }
1141 else{
1142 return temperateiceconductivity/heatcapacity;
1143 }
1144}/*}}}*/
1145IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
1146
1147 int iv;
1148 IssmDouble lambda; /* fraction of cold ice */
1149 IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
1150 IssmDouble Hc,Ht;
1151
1152 /*Get pressures and enthalpies on vertices*/
1153 int numvertices = element->GetNumberOfVertices();
1154 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1155 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1156 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
1157 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
1158 element->GetInputListOnVertices(pressures,PressureEnum);
1159 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
1160 for(iv=0;iv<numvertices;iv++){
1161 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
1162 dHpmp[iv] = enthalpies[iv]-PIE[iv];
1163 }
1164
1165 bool allequalsign = true;
1166 if(dHpmp[0]<0.){
1167 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
1168 }
1169 else{
1170 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
1171 }
1172
1173 if(allequalsign){
1174 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
1175 }
1176 else{
1177 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
1178 cf Patankar 1980, pp44 */
1179 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
1180 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
1181 Hc=0.; Ht=0.;
1182 for(iv=0; iv<numvertices;iv++){
1183 if(enthalpies[iv]<PIE[iv])
1184 Hc+=(PIE[iv]-enthalpies[iv]);
1185 else
1186 Ht+=(enthalpies[iv]-PIE[iv]);
1187 }
1188 _assert_((Hc+Ht)>0.);
1189 lambda = Hc/(Hc+Ht);
1190 kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
1191 }
1192
1193 /*Clean up and return*/
1194 xDelete<IssmDouble>(PIE);
1195 xDelete<IssmDouble>(dHpmp);
1196 xDelete<IssmDouble>(pressures);
1197 xDelete<IssmDouble>(enthalpies);
1198 return kappa;
1199}/*}}}*/
1200IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
1201
1202 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1203 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
1204
1205 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1206}/*}}}*/
1207IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
1208
1209 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
1210 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
1211
1212 return meltingpoint-beta*pressure;
1213}/*}}}*/
Note: See TracBrowser for help on using the repository browser.