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

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

CHG: added friction law to enthalpy

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