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

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

CHG: no need to get flowequations

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