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

Last change on this file since 18667 was 18667, checked in by jbondzio, 10 years ago

CHG: For computation of basal melting rate, use enthalpypicard for steady state, if not converged yet. Update Enthalpy and water column only in case of transient runs.

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