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

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

CHG: added gamma as a parameter to frictionjosh

File size: 62.9 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 vertexdown,vertexup,numvertices,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->VerticalSegmentIndices(&pairindices,&numsegments);
360 IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
361 IssmDouble* heating = xNew<IssmDouble>(numsegments);
362
363 numvertices=element->GetNumberOfVertices();
364 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
365 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
366 IssmDouble* watercolumns = xNew<IssmDouble>(numvertices);
367 IssmDouble* basalmeltingrates = xNew<IssmDouble>(numvertices);
368 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
369 element->GetInputListOnVertices(pressures,PressureEnum);
370 element->GetInputListOnVertices(watercolumns,WatercolumnEnum);
371 element->GetInputListOnVertices(basalmeltingrates,BasalforcingsGroundediceMeltingRateEnum);
372
373 Gauss* gauss=element->NewGauss();
374 for(is=0;is<numsegments;is++){
375 vertexdown = pairindices[is*2+0];
376 vertexup = pairindices[is*2+1];
377 gauss->GaussVertex(vertexdown);
378
379 state=GetThermalBasalCondition(element, enthalpies[vertexdown], enthalpies[vertexup], pressures[vertexdown], pressures[vertexup], watercolumns[vertexdown], basalmeltingrates[vertexdown]);
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[vertexdown], pressures[vertexdown]);
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 vertexdown = pairindices[is*2+0];
421 vertexup = pairindices[is*2+1];
422 if(dt!=0.){
423 if(watercolumns[vertexdown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
424 lambda = -watercolumns[vertexdown]/(dt*meltingrate_enthalpy[is]); _assert_(lambda>=0.); _assert_(lambda<1.);
425 watercolumns[vertexdown]=0.;
426 basalmeltingrates[vertexdown]=lambda*meltingrate_enthalpy[is]; // restrict freeze on only to size of watercolumn
427 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
428 }
429 else{
430 basalmeltingrates[vertexdown]=meltingrate_enthalpy[is];
431 watercolumns[vertexdown]+=dt*meltingrate_enthalpy[is];
432 }
433 }
434 else{
435 basalmeltingrates[vertexdown]=meltingrate_enthalpy[is];
436 if(watercolumns[vertexdown]+meltingrate_enthalpy[is]<0.)
437 watercolumns[vertexdown]=0.;
438 else
439 watercolumns[vertexdown]+=meltingrate_enthalpy[is];
440 }
441 basalmeltingrates[vertexdown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
442 _assert_(watercolumns[vertexdown]>=0.);
443 }/*}}}*/
444
445 /*feed updated variables back into model*/
446 if(dt!=0.){
447 element->AddInput(enthalpy_enum,enthalpies,P1Enum); //TODO: distinguis for steadystate and transient run
448 element->AddInput(WatercolumnEnum,watercolumns,P1Enum);
449 }
450 element->AddInput(BasalforcingsGroundediceMeltingRateEnum,basalmeltingrates,P1Enum);
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, numvertices, numsegments;
1059 int *pairindices = NULL;
1060
1061 numvertices=element->GetNumberOfVertices();
1062 element->VerticalSegmentIndices(&pairindices,&numsegments);
1063
1064 IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
1065 IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments);
1066 IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
1067
1068 element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
1069
1070 for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
1071 Element* elementi = element;
1072 for(;;){
1073 for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
1074 DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
1075 for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
1076
1077 if(elementi->IsOnSurface()) break;
1078 elementi=elementi->GetUpperElement();
1079 }
1080 /* add drained water to water column*/
1081 for(is=0;is<numsegments;is++) watercolumn[is]+=drainrate_column[is];
1082 /* Feed updated water column back into model */
1083 element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
1084
1085 xDelete<int>(pairindices);
1086 xDelete<IssmDouble>(drainrate_column);
1087 xDelete<IssmDouble>(drainrate_element);
1088 xDelete<IssmDouble>(watercolumn);
1089}/*}}}*/
1090IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
1091
1092 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1093 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
1094 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1095
1096 if(enthalpy < PureIceEnthalpy(element,pressure)){
1097 return thermalconductivity/heatcapacity;
1098 }
1099 else{
1100 return temperateiceconductivity/heatcapacity;
1101 }
1102}/*}}}*/
1103IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
1104
1105 int iv;
1106 IssmDouble lambda; /* fraction of cold ice */
1107 IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
1108 IssmDouble Hc,Ht;
1109
1110 /*Get pressures and enthalpies on vertices*/
1111 int numvertices = element->GetNumberOfVertices();
1112 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1113 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1114 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
1115 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
1116 element->GetInputListOnVertices(pressures,PressureEnum);
1117 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
1118 for(iv=0;iv<numvertices;iv++){
1119 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
1120 dHpmp[iv] = enthalpies[iv]-PIE[iv];
1121 }
1122
1123 bool allequalsign = true;
1124 if(dHpmp[0]<0.){
1125 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
1126 }
1127 else{
1128 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
1129 }
1130
1131 if(allequalsign){
1132 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
1133 }
1134 else{
1135 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
1136 cf Patankar 1980, pp44 */
1137 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
1138 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
1139 Hc=0.; Ht=0.;
1140 for(iv=0; iv<numvertices;iv++){
1141 if(enthalpies[iv]<PIE[iv])
1142 Hc+=(PIE[iv]-enthalpies[iv]);
1143 else
1144 Ht+=(enthalpies[iv]-PIE[iv]);
1145 }
1146 _assert_((Hc+Ht)>0.);
1147 lambda = Hc/(Hc+Ht);
1148 kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
1149 }
1150
1151 /*Clean up and return*/
1152 xDelete<IssmDouble>(PIE);
1153 xDelete<IssmDouble>(dHpmp);
1154 xDelete<IssmDouble>(pressures);
1155 xDelete<IssmDouble>(enthalpies);
1156 return kappa;
1157}/*}}}*/
1158void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1159 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1160 * For node i, Bi' can be expressed in the actual coordinate system
1161 * by:
1162 * Bi_advec =[ h ]
1163 * [ h ]
1164 * [ h ]
1165 * where h is the interpolation function for node i.
1166 *
1167 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
1168 */
1169
1170 /*Fetch number of nodes for this finite element*/
1171 int numnodes = element->GetNumberOfNodes();
1172
1173 /*Get nodal functions*/
1174 IssmDouble* basis=xNew<IssmDouble>(numnodes);
1175 element->NodalFunctions(basis,gauss);
1176
1177 /*Build B: */
1178 for(int i=0;i<numnodes;i++){
1179 B[numnodes*0+i] = basis[i];
1180 B[numnodes*1+i] = basis[i];
1181 B[numnodes*2+i] = basis[i];
1182 }
1183
1184 /*Clean-up*/
1185 xDelete<IssmDouble>(basis);
1186}/*}}}*/
1187void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1188 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1189 * For node i, Bi' can be expressed in the actual coordinate system
1190 * by:
1191 * Biprime_advec=[ dh/dx ]
1192 * [ dh/dy ]
1193 * [ dh/dz ]
1194 * where h is the interpolation function for node i.
1195 *
1196 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
1197 */
1198
1199 /*Fetch number of nodes for this finite element*/
1200 int numnodes = element->GetNumberOfNodes();
1201
1202 /*Get nodal functions derivatives*/
1203 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
1204 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
1205
1206 /*Build B: */
1207 for(int i=0;i<numnodes;i++){
1208 B[numnodes*0+i] = dbasis[0*numnodes+i];
1209 B[numnodes*1+i] = dbasis[1*numnodes+i];
1210 B[numnodes*2+i] = dbasis[2*numnodes+i];
1211 }
1212
1213 /*Clean-up*/
1214 xDelete<IssmDouble>(dbasis);
1215}/*}}}*/
1216void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1217
1218 /*Intermediary*/
1219 bool isdynamicbasalspc;
1220 IssmDouble dt;
1221
1222 /*Check wether dynamic basal boundary conditions are activated */
1223 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
1224 if(!isdynamicbasalspc) return;
1225
1226 element->FindParam(&dt,TimesteppingTimeStepEnum);
1227 if(dt==0.){
1228 GetBasalConstraintsSteadystate(vec_spc,element);
1229 }
1230 else{
1231 GetBasalConstraintsTransient(vec_spc,element);
1232 }
1233}/*}}}*/
1234void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1235
1236 /* Check if ice in element */
1237 if(!element->IsIceInElement()) return;
1238
1239 /* Only update constraints at the base.
1240 * Floating ice is not affected by basal BC decision chart. */
1241 if(!(element->IsOnBase()) || element->IsFloating()) return;
1242
1243 /*Intermediary*/
1244 int numindices, numindicesup, state;
1245 int *indices = NULL, *indicesup = NULL;
1246 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1247
1248 /*Get parameters and inputs: */
1249 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
1250 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
1251 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1252 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
1253
1254 /*Fetch indices of basal & surface nodes for this finite element*/
1255 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1256 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1257 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1258
1259 GaussPenta* gauss=new GaussPenta();
1260 GaussPenta* gaussup=new GaussPenta();
1261 for(int i=0;i<numindices;i++){
1262 gauss->GaussNode(element->GetElementType(),indices[i]);
1263 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1264
1265 enthalpy_input->GetInputValue(&enthalpy,gauss);
1266 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1267 pressure_input->GetInputValue(&pressure,gauss);
1268 pressure_input->GetInputValue(&pressureup,gaussup);
1269 watercolumn_input->GetInputValue(&watercolumn,gauss);
1270 meltingrate_input->GetInputValue(&meltingrate,gauss);
1271
1272 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1273 switch (state) {
1274 case 0:
1275 // cold, dry base: apply basal surface forcing
1276 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1277 break;
1278 case 1:
1279 // cold, wet base: keep at pressure melting point
1280 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1281 break;
1282 case 2:
1283 // temperate, thin refreezing base:
1284 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1285 break;
1286 case 3:
1287 // temperate, thin melting base: set spc
1288 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1289 break;
1290 case 4:
1291 // temperate, thick melting base:
1292 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1293 break;
1294 default:
1295 _printf0_(" unknown thermal basal state found!");
1296 }
1297 }
1298
1299 /*Free ressources:*/
1300 xDelete<int>(indices);
1301 xDelete<int>(indicesup);
1302 delete gauss;
1303 delete gaussup;
1304}/*}}}*/
1305void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1306
1307 /* Check if ice in element */
1308 if(!element->IsIceInElement()) return;
1309
1310 /* Only update constraints at the base.
1311 * Floating ice is not affected by basal BC decision chart.*/
1312 if(!(element->IsOnBase()) || element->IsFloating()) return;
1313
1314 /*Intermediary*/
1315 int numindices, numindicesup, state;
1316 int *indices = NULL, *indicesup = NULL;
1317 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1318
1319 /*Get parameters and inputs: */
1320 Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
1321 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
1322 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1323 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
1324
1325 /*Fetch indices of basal & surface nodes for this finite element*/
1326 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1327 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1328 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1329
1330 GaussPenta* gauss=new GaussPenta();
1331 GaussPenta* gaussup=new GaussPenta();
1332
1333 for(int i=0;i<numindices;i++){
1334 gauss->GaussNode(element->GetElementType(),indices[i]);
1335 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1336
1337 enthalpy_input->GetInputValue(&enthalpy,gauss);
1338 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1339 pressure_input->GetInputValue(&pressure,gauss);
1340 pressure_input->GetInputValue(&pressureup,gaussup);
1341 watercolumn_input->GetInputValue(&watercolumn,gauss);
1342 meltingrate_input->GetInputValue(&meltingrate,gauss);
1343
1344 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1345
1346 switch (state) {
1347 case 0:
1348 // cold, dry base: apply basal surface forcing
1349 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1350 break;
1351 case 1:
1352 // cold, wet base: keep at pressure melting point
1353 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1354 break;
1355 case 2:
1356 // temperate, thin refreezing base: release spc
1357 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1358 break;
1359 case 3:
1360 // temperate, thin melting base: set spc
1361 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1362 break;
1363 case 4:
1364 // temperate, thick melting base: set grad H*n=0
1365 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1366 break;
1367 default:
1368 _printf0_(" unknown thermal basal state found!");
1369 }
1370
1371 }
1372
1373 /*Free ressources:*/
1374 xDelete<int>(indices);
1375 xDelete<int>(indicesup);
1376 delete gauss;
1377 delete gaussup;
1378}/*}}}*/
1379void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1380 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1381 * For node i, Bi' can be expressed in the actual coordinate system
1382 * by:
1383 * Bi_conduct=[ dh/dx ]
1384 * [ dh/dy ]
1385 * [ dh/dz ]
1386 * where h is the interpolation function for node i.
1387 *
1388 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
1389 */
1390
1391 /*Fetch number of nodes for this finite element*/
1392 int numnodes = element->GetNumberOfNodes();
1393
1394 /*Get nodal functions derivatives*/
1395 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
1396 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
1397
1398 /*Build B: */
1399 for(int i=0;i<numnodes;i++){
1400 B[numnodes*0+i] = dbasis[0*numnodes+i];
1401 B[numnodes*1+i] = dbasis[1*numnodes+i];
1402 B[numnodes*2+i] = dbasis[2*numnodes+i];
1403 }
1404
1405 /*Clean-up*/
1406 xDelete<IssmDouble>(dbasis);
1407}/*}}}*/
1408void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
1409 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
1410}/*}}}*/
1411int EnthalpyAnalysis::GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpyup, IssmDouble pressure, IssmDouble pressureup, IssmDouble watercolumn, IssmDouble meltingrate){/*{{{*/
1412
1413 /* Check if ice in element */
1414 if(!element->IsIceInElement()) return -1;
1415
1416 /* Only update Constraints at the base of grounded ice*/
1417 if(!(element->IsOnBase())) return -1;
1418
1419 /*Intermediary*/
1420 int state=-1;
1421 IssmDouble dt;
1422
1423 /*Get parameters and inputs: */
1424 element->FindParam(&dt,TimesteppingTimeStepEnum);
1425
1426 if(enthalpy<PureIceEnthalpy(element,pressure)){
1427 if(watercolumn<=0.) state=0; // cold, dry base
1428 else state=1; // cold, wet base (refreezing)
1429 }
1430 else{
1431 if(enthalpyup<PureIceEnthalpy(element,pressureup)){
1432 if((dt==0.) && (meltingrate<0.)) state=2; // refreezing temperate base (non-physical, only for steadystate solver)
1433 else state=3; // temperate base, but no temperate layer
1434 }
1435 else state=4; // temperate layer with positive thickness
1436 }
1437
1438 _assert_(state>=0);
1439 return state;
1440}/*}}}*/
1441IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
1442
1443 IssmDouble temperature, waterfraction;
1444 IssmDouble kappa_w = 0.6; // thermal conductivity of water (in W/m/K)
1445 IssmDouble kappa_i = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1446 element->EnthalpyToThermal(&temperature, &waterfraction, enthalpy, pressure);
1447
1448 return (1.-waterfraction)*kappa_i + waterfraction*kappa_w;
1449}/*}}}*/
1450void EnthalpyAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
1451 _error_("Not implemented yet");
1452}/*}}}*/
1453void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
1454
1455 bool converged;
1456 int i,rheology_law;
1457 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
1458 IssmDouble n=3.0;
1459 int *doflist = NULL;
1460 IssmDouble *xyz_list = NULL;
1461
1462 /*Fetch number of nodes and dof for this finite element*/
1463 int numnodes = element->GetNumberOfNodes();
1464
1465 /*Fetch dof list and allocate solution vector*/
1466 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
1467 IssmDouble* values = xNew<IssmDouble>(numnodes);
1468 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
1469 IssmDouble* surface = xNew<IssmDouble>(numnodes);
1470 IssmDouble* B = xNew<IssmDouble>(numnodes);
1471 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
1472 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
1473
1474 /*Use the dof list to index into the solution vector: */
1475 for(i=0;i<numnodes;i++){
1476 values[i]=solution[doflist[i]];
1477
1478 /*Check solution*/
1479 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
1480 if(xIsInf<IssmDouble>(values[i])) _error_("Inf found in solution vector");
1481 }
1482
1483 /*Get all inputs and parameters*/
1484 if(element->material->ObjectEnum()!=MatestarEnum) n=element->GetMaterialParameter(MaterialsRheologyNEnum);
1485 element->GetInputValue(&converged,ConvergedEnum);
1486 element->GetInputListOnNodes(&pressure[0],PressureEnum);
1487 if(converged){
1488 for(i=0;i<numnodes;i++){
1489 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
1490 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
1491 //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
1492 }
1493 element->AddInput(EnthalpyEnum,values,element->GetElementType());
1494 element->AddInput(WaterfractionEnum,waterfraction,element->GetElementType());
1495 element->AddInput(TemperatureEnum,temperature,element->GetElementType());
1496
1497 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
1498 * otherwise the rheology could be negative*/
1499 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
1500 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
1501 switch(rheology_law){
1502 case NoneEnum:
1503 /*Do nothing: B is not temperature dependent*/
1504 break;
1505 case BuddJackaEnum:
1506 for(i=0;i<numnodes;i++) B[i]=BuddJacka(temperature[i]);
1507 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1508 break;
1509 case CuffeyEnum:
1510 for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
1511 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1512 break;
1513 case CuffeyTemperateEnum:
1514 for(i=0;i<numnodes;i++) B[i]=CuffeyTemperate(temperature[i], waterfraction[i],n);
1515 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1516 break;
1517 case PatersonEnum:
1518 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
1519 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1520 break;
1521 case ArrheniusEnum:
1522 element->GetVerticesCoordinates(&xyz_list);
1523 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],n);
1524 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1525 break;
1526 case LliboutryDuvalEnum:
1527 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));
1528 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1529 break;
1530 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
1531 }
1532 }
1533 else{
1534 element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
1535 }
1536
1537 /*Free ressources:*/
1538 xDelete<IssmDouble>(values);
1539 xDelete<IssmDouble>(pressure);
1540 xDelete<IssmDouble>(surface);
1541 xDelete<IssmDouble>(B);
1542 xDelete<IssmDouble>(temperature);
1543 xDelete<IssmDouble>(waterfraction);
1544 xDelete<IssmDouble>(xyz_list);
1545 xDelete<int>(doflist);
1546}/*}}}*/
1547void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
1548
1549 /*Intermediaries*/
1550 bool computebasalmeltingrates=true;
1551 bool drainicecolumn=true;
1552 IssmDouble dt;
1553
1554 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1555
1556 if(drainicecolumn && (dt>0.)) DrainWaterfraction(femmodel);
1557 if(computebasalmeltingrates) ComputeBasalMeltingrate(femmodel);
1558
1559}/*}}}*/
1560IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
1561
1562 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1563 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
1564
1565 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1566}/*}}}*/
1567IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
1568
1569 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
1570 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
1571
1572 return meltingpoint-beta*pressure;
1573}/*}}}*/
1574void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
1575
1576 /*Update basal dirichlet BCs for enthalpy: */
1577 Vector<IssmDouble>* spc = NULL;
1578 IssmDouble* serial_spc = NULL;
1579
1580 spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes(EnthalpyAnalysisEnum));
1581 /*First create a vector to figure out what elements should be constrained*/
1582 for(int i=0;i<femmodel->elements->Size();i++){
1583 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
1584 GetBasalConstraints(spc,element);
1585 }
1586
1587 /*Assemble and serialize*/
1588 spc->Assemble();
1589 serial_spc=spc->ToMPISerial();
1590 delete spc;
1591
1592 /*Then update basal constraints nodes accordingly*/
1593 for(int i=0;i<femmodel->elements->Size();i++){
1594 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
1595 ApplyBasalConstraints(serial_spc,element);
1596 }
1597
1598 femmodel->UpdateConstraintsx();
1599
1600 /*Delete*/
1601 xDelete<IssmDouble>(serial_spc);
1602}/*}}}*/
1603void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
1604 SetActiveNodesLSMx(femmodel);
1605}/*}}}*/
Note: See TracBrowser for help on using the repository browser.