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

Last change on this file since 23585 was 23585, checked in by Mathieu Morlighem, 6 years ago

CHG: AMR now uses a lot more of the model processor functions. In some cases, we now have to pass the flag isAMR so that fields from iomodel are not loaded

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