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

Last change on this file since 23697 was 23697, checked in by rueckamp, 6 years ago

CHG: added different computations for the Effective Conductivity.

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