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

Last change on this file since 17015 was 17015, checked in by Mathieu Morlighem, 11 years ago

BUG: fixed compilation error (Johannes, make sure you have --enable-debugging in your configure.sh)

File size: 47.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
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 /*drain excess water fraction: */
832 //for(int i=0;i<femmodel->elements->Size();i++){
833 // element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
834 // element->DrainWaterfraction();
835 //}
836
837 /*Update basal dirichlet BCs for enthalpy: */
838 for(int i=0;i<femmodel->elements->Size();i++){
839 Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
840 UpdateBasalConstraints(element);
841 }
842}/*}}}*/
843
844
845
846
847
848
849void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
850 /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
851 /* melting rate is positive when melting, negative when refreezing*/
852
853 /* Intermediaries */
854 int i,is,vertexdown,vertexup,dim=3,numvertices,numsegments;
855 IssmDouble heatflux;
856 IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim];
857 IssmDouble temperature, waterfraction;
858 IssmDouble basalfriction,alpha2;
859 IssmDouble dt,yts;
860 IssmDouble melting_overshoot,lambda;
861 IssmDouble geothermalflux;
862 IssmDouble vx,vy,vz;
863 IssmDouble *xyz_list = NULL;
864 IssmDouble *xyz_list_base = NULL;
865 int *pairindices = NULL;
866
867 /* Only compute melt rates at the base of grounded ice*/
868 if(!element->IsOnBed() || element->IsFloating()) return;
869
870 /*Fetch parameters and inputs */
871 element->GetVerticesCoordinates(&xyz_list);
872 element->GetVerticesCoordinatesBase(&xyz_list_base);
873 IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
874 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
875 Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
876 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
877 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
878 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
879 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
880 IssmDouble kappa=EnthalpyDiffusionParameterVolume(element,EnthalpyEnum); _assert_(kappa>0.);
881 element->NormalBase(&normal_base[0],xyz_list_base);
882 element->VerticalSegmentIndices(&pairindices,&numsegments);
883 IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
884 IssmDouble* heating = xNew<IssmDouble>(numsegments);
885
886 /*Build friction element, needed later: */
887 Friction* friction=new Friction(element,dim);
888
889 /******** MELTING RATES ************************************/
890 numvertices=element->GetNumberOfVertices();
891 IssmDouble* enthalpy = xNew<IssmDouble>(numvertices);
892 IssmDouble* pressure = xNew<IssmDouble>(numvertices);
893 IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
894 IssmDouble* basalmeltingrate = xNew<IssmDouble>(numvertices);
895 element->GetInputListOnVertices(enthalpy,EnthalpyEnum);
896 element->GetInputListOnVertices(pressure,PressureEnum);
897 element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
898 element->GetInputListOnVertices(basalmeltingrate,BasalforcingsMeltingRateEnum);
899
900 Gauss* gauss=element->NewGauss();
901
902 for(int is=0;is<numsegments;is++){
903 vertexdown = pairindices[is*2+0];
904 vertexup = pairindices[is*2+1];
905 gauss->GaussVertex(vertexdown);
906
907 bool checkpositivethickness=true;
908 _assert_(watercolumn[vertexdown]>=0.);
909
910 /*Calculate basal meltingrate after Fig.5 of A.Aschwanden 2012*/
911 meltingrate_enthalpy[is]=0.;
912 heating[is]=0.;
913 if((watercolumn[vertexdown]>0.) && (enthalpy[vertexdown]<PureIceEnthalpy(element,pressure[vertexdown]))){
914 /*ensure that no ice is at T<Tm(p), if water layer present*/
915 enthalpy[vertexdown]=element->PureIceEnthalpy(pressure[vertexdown]);
916 }
917 else if(enthalpy[vertexdown]<element->PureIceEnthalpy(pressure[vertexdown])){
918 /*cold base: set q*n=q_geo*n+frictionheating as Neumann BC in Penta::CreatePVectorEnthalpySheet*/
919 checkpositivethickness=false; // cold base, skip next test
920 }
921 else{/*we have a temperate base, go to next test*/}
922
923 if(checkpositivethickness){
924 /*From here on all basal ice is temperate. Check for positive thickness of layer of temperate ice. */
925 bool istemperatelayer=false;
926 if(enthalpy[vertexup]>=element->PureIceEnthalpy(pressure[vertexup])) istemperatelayer=true;
927 if(istemperatelayer) for(i=0;i<dim;i++) vec_heatflux[i]=0.; // TODO: add -k*nabla T_pmp
928 else{
929 enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
930 for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
931 }
932
933 /*heat flux along normal*/
934 heatflux=0.;
935 for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
936
937 /*basal friction*/
938 friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
939 vx_input->GetInputValue(&vx,gauss);
940 vy_input->GetInputValue(&vy,gauss);
941 vz_input->GetInputValue(&vz,gauss);
942 basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
943
944 element->EnthalpyToThermal(&temperature,&waterfraction,enthalpy[vertexdown],pressure[vertexdown]);
945 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
946 /* -Mb= Fb-(q-q_geo)/((1-w)*L), cf Aschwanden 2012, eq.66*/
947 heating[is]=(heatflux+basalfriction+geothermalflux);
948 meltingrate_enthalpy[is]=heating[is]/((1-waterfraction)*latentheat*rho_ice); // m/s water equivalent //????
949 }
950 }
951 /* enthalpy might have been changed, update */
952 //element->AddInput(EnthalpyEnum,enthalpy,P1Enum);
953
954 /******** DRAINAGE *****************************************/
955 IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments); //TODO: xDelete?
956 IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
957 for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
958 Element* elementi = element;
959 for(;;){
960 for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
961 DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
962 for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
963
964 if(elementi->IsOnSurface()) break;
965 elementi=elementi->GetUpperElement();
966 }
967 /* add drained water to melting rate*/
968 for(is=0;is<numsegments;is++) meltingrate_enthalpy[is]+=drainrate_column[is];
969
970 /******** UPDATE MELTINGRATES AND WATERCOLUMN **************/
971 element->FindParam(&dt,TimesteppingTimeStepEnum);
972 for(is=0;is<numsegments;is++){
973 vertexdown = pairindices[is*2+0];
974 vertexup = pairindices[is*2+1];
975 if(dt!=0.){
976 if(watercolumn[vertexdown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
977 melting_overshoot=watercolumn[vertexdown]+meltingrate_enthalpy[is]*dt;
978 lambda=melting_overshoot/(meltingrate_enthalpy[is]*dt); _assert_(lambda>0); _assert_(lambda<1);
979 basalmeltingrate[vertexdown]=(1.-lambda)*meltingrate_enthalpy[is];
980 watercolumn[vertexdown]=0.;
981 yts=365.*24.*60.*60.;
982 enthalpy[vertexdown]+=dt/yts*lambda*heating[is];
983 }
984 else{
985 basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
986 watercolumn[vertexdown]+=dt*meltingrate_enthalpy[is];
987 }
988 }
989 else{
990 basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
991 watercolumn[vertexdown]+=meltingrate_enthalpy[is];
992 }
993 _assert_(watercolumn[vertexdown]>=0.);
994 }
995
996 /*feed updated variables back into model*/
997 element->AddInput(EnthalpyEnum,enthalpy,P1Enum);
998 element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
999 element->AddInput(BasalforcingsMeltingRateEnum,basalmeltingrate,P1Enum);
1000
1001 /*Clean up and return*/
1002 delete gauss;
1003 delete friction;
1004 xDelete<IssmDouble>(enthalpy);
1005 xDelete<IssmDouble>(pressure);
1006 xDelete<IssmDouble>(watercolumn);
1007 xDelete<IssmDouble>(basalmeltingrate);
1008 xDelete<IssmDouble>(meltingrate_enthalpy);
1009 xDelete<IssmDouble>(heating);
1010 xDelete<IssmDouble>(drainrate_column);
1011 xDelete<IssmDouble>(drainrate_element);
1012}/*}}}*/
1013
1014void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
1015
1016 /*Intermediaries*/
1017 int iv,is,vertexdown,vertexup,numsegments;
1018 IssmDouble dt, height_element;
1019 IssmDouble rho_water, rho_ice;
1020 int numvertices = element->GetNumberOfVertices();
1021
1022 IssmDouble* xyz_list = NULL;
1023 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1024 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1025 IssmDouble* temperatures = xNew<IssmDouble>(numvertices);
1026 IssmDouble* waterfractions = xNew<IssmDouble>(numvertices);
1027 IssmDouble* deltawaterfractions = xNew<IssmDouble>(numvertices);
1028 int *pairindices = NULL;
1029
1030 rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
1031 rho_water=element->GetMaterialParameter(MaterialsRhoWaterEnum);
1032
1033 element->GetVerticesCoordinates(&xyz_list);
1034 element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
1035 element->GetInputListOnVertices(pressures,PressureEnum);
1036
1037 element->FindParam(&dt,TimesteppingTimeStepEnum);
1038 for(iv=0;iv<numvertices;iv++){
1039 element->EnthalpyToThermal(&temperatures[iv],&waterfractions[iv], enthalpies[iv],pressures[iv]);
1040 deltawaterfractions[iv]=DrainageFunctionWaterfraction(waterfractions[iv], dt);
1041 }
1042
1043 /*drain waterfraction, feed updated variables back into model*/
1044 for(iv=0;iv<numvertices;iv++){
1045 if(reCast<bool,IssmDouble>(dt))
1046 waterfractions[iv]-=deltawaterfractions[iv]*dt;
1047 else
1048 waterfractions[iv]-=deltawaterfractions[iv];
1049 element->ThermalToEnthalpy(&enthalpies[iv], temperatures[iv], waterfractions[iv], pressures[iv]);
1050 }
1051 element->AddInput(EnthalpyEnum,enthalpies,P1Enum);
1052 element->AddInput(WaterfractionEnum,waterfractions,P1Enum);
1053
1054 /*return meltwater column equivalent to drained water*/
1055 element->VerticalSegmentIndices(&pairindices,&numsegments);
1056 for(is=0;is<numsegments;is++){
1057 vertexdown = pairindices[is*2+0];
1058 vertexup = pairindices[is*2+1];
1059 height_element=fabs(xyz_list[vertexup*3+2]-xyz_list[vertexdown*3+2]);
1060 pdrainrate_element[is]=(deltawaterfractions[vertexdown]+deltawaterfractions[vertexup])/2.*rho_water/rho_ice*height_element;
1061 }
1062
1063 /*Clean up and return*/
1064 xDelete<IssmDouble>(xyz_list);
1065 xDelete<IssmDouble>(enthalpies);
1066 xDelete<IssmDouble>(pressures);
1067 xDelete<IssmDouble>(temperatures);
1068 xDelete<IssmDouble>(waterfractions);
1069 xDelete<IssmDouble>(deltawaterfractions);
1070}/*}}}*/
1071
1072
1073
1074
1075
1076void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
1077
1078 /* /\*Intermediary*\/ */
1079 /* bool isdynamicbasalspc,setspc; */
1080 /* int numindices, numindicesup; */
1081 /* IssmDouble pressure, pressureup; */
1082 /* IssmDouble h_pmp, enthalpy, enthalpyup; */
1083 /* IssmDouble watercolumn; */
1084 /* int *indices = NULL, *indicesup = NULL; */
1085
1086 /* /\* Only update Constraints at the base of grounded ice*\/ */
1087 /* if(!IsOnBed() || IsFloating()) return; */
1088
1089 /* /\*Check wether dynamic basal boundary conditions are activated *\/ */
1090 /* element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum); */
1091 /* if(!isdynamicbasalspc) return; */
1092
1093 /* /\*Fetch indices of basal & surface nodes for this finite element*\/ */
1094 /* // BasalNodeIndices(&numindices,&indices,this->element_type); */
1095 /* // SurfaceNodeIndices(&numindicesup,&indicesup,this->element_type); */
1096 /* // _assert_(numindices==numindicesup); */
1097
1098 /* /\*Get parameters and inputs: *\/ */
1099 /* Input* pressure_input=inputs->GetInput(PressureEnum); _assert_(pressure_input); */
1100 /* Input* enthalpy_input=inputs->GetInput(EnthalpyEnum); _assert_(enthalpy_input); */
1101 /* Input* watercolumn_input=inputs->GetInput(WatercolumnEnum); _assert_(watercolumn_input); */
1102
1103 /* /\*if there is a temperate layer of zero thickness, set spc enthalpy=h_pmp at that node*\/ */
1104 /* GaussPenta* gauss=new GaussPenta(); */
1105 /* GaussPenta* gaussup=new GaussPenta(); */
1106 /* for(int i=0;i<numindices;i++){ */
1107 /* gauss->GaussNode(this->element_type,indices[i]); */
1108 /* gaussup->GaussNode(this->element_type,indicesup[i]); */
1109
1110 /* /\*Check wether there is a temperate layer at the base or not *\/ */
1111 /* /\*check if node is temperate, if not, continue*\/ */
1112 /* enthalpy_input->GetInputValue(&enthalpy, gauss); */
1113 /* pressure_input->GetInputValue(&pressure, gauss); */
1114 /* watercolumn_input->GetInputValue(&watercolumn,gauss); */
1115 /* setspc = false; */
1116 /* // TODO: add case H<Hpmp && watercolumn>0.; */
1117 /* if (enthalpy>=element->PureIceEnthalpy(pressure)){ */
1118 /* /\*check if upper node is temperate, too. */
1119 /* if yes, then we have a temperate layer of positive thickness and reset the spc. */
1120 /* if not, apply dirichlet BC.*\/ */
1121 /* enthalpy_input->GetInputValue(&enthalpyup, gaussup); */
1122 /* pressure_input->GetInputValue(&pressureup, gaussup); */
1123 /* setspc=((enthalpyup<element->PureIceEnthalpy(pressureup)) && (watercolumn>=0.))?true:false; */
1124 /* } */
1125
1126 /* if (setspc) { */
1127 /* /\*Calculate enthalpy at pressure melting point *\/ */
1128 /* h_pmp=matpar->PureIceEnthalpy(pressure); */
1129 /* /\*Apply Dirichlet condition (dof = 0 here, since there is only one degree of freedom per node)*\/ */
1130 /* //element->ApplyConstraint(indices[i],1,h_pmp); */
1131 /* //nodes[indices[i]]->ApplyConstraint(1,h_pmp); */
1132 /* } */
1133 /* else { */
1134 /* /\*remove spc*\/ */
1135 /* //element->RemoveConstraint(indices[i],0); */
1136 /* //nodes[indices[i]]->DofInFSet(0); */
1137 /* } */
1138 /* } */
1139
1140 /* /\*Free ressources:*\/ */
1141 /* xDelete<int>(indices); */
1142 /* xDelete<int>(indicesup); */
1143 /* delete gauss; */
1144 /* delete gaussup; */
1145}/*}}}*/
1146
1147
1148
1149
1150
1151/*Intermediaries*/
1152IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
1153
1154 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1155 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
1156 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1157
1158 if(enthalpy < PureIceEnthalpy(element,pressure)){
1159 return thermalconductivity/heatcapacity;
1160 }
1161 else{
1162 return temperateiceconductivity/heatcapacity;
1163 }
1164}/*}}}*/
1165IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
1166
1167 int iv;
1168 IssmDouble lambda; /* fraction of cold ice */
1169 IssmDouble kappa ,kappa_c,kappa_t; /* enthalpy conductivities */
1170 IssmDouble Hc,Ht;
1171
1172
1173 /*Get pressures and enthalpies on vertices*/
1174 int numvertices = element->GetNumberOfVertices();
1175 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1176 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1177 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
1178 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
1179 element->GetInputListOnVertices(pressures,PressureEnum);
1180 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
1181 for(iv=0;iv<numvertices;iv++){
1182 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
1183 dHpmp[iv] = enthalpies[iv]-PIE[iv];
1184 }
1185
1186 bool allequalsign = true;
1187 if(dHpmp[0]<0.){
1188 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
1189 }
1190 else{
1191 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
1192 }
1193
1194 if(allequalsign){
1195 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
1196 }
1197 else{
1198 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
1199 cf Patankar 1980, pp44 */
1200 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
1201 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
1202 Hc=0.; Ht=0.;
1203 for(iv=0; iv<numvertices;iv++){
1204 if(enthalpies[iv]<PIE[iv])
1205 Hc+=(PIE[iv]-enthalpies[iv]);
1206 else
1207 Ht+=(enthalpies[iv]-PIE[iv]);
1208 }
1209 _assert_((Hc+Ht)>0.);
1210 lambda = Hc/(Hc+Ht);
1211 kappa = 1./(lambda/kappa_c + (1.-lambda)/kappa_t);
1212 }
1213
1214 /*Clean up and return*/
1215 xDelete<IssmDouble>(PIE);
1216 xDelete<IssmDouble>(dHpmp);
1217 xDelete<IssmDouble>(pressures);
1218 xDelete<IssmDouble>(enthalpies);
1219 return kappa;
1220}
1221/*}}}*/
1222IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
1223
1224 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1225 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
1226
1227 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1228}/*}}}*/
1229IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
1230
1231 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
1232 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
1233
1234 return meltingpoint-beta*pressure;
1235}/*}}}*/
Note: See TracBrowser for help on using the repository browser.