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

Last change on this file since 21718 was 21718, checked in by jbondzio, 8 years ago

CHG: adapting computation of basal melting rate (enthalpy) to higher-order elements

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