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

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

CHG: fixed Postprocessing of Enthalpy

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