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

Last change on this file since 21548 was 21548, checked in by Mathieu Morlighem, 8 years ago

NEW: enable dynamic spcs for enthalpy model (required for PDD scheme)

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