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

Last change on this file since 21160 was 21160, checked in by jbondzio, 9 years ago

BUG: update enthalpy basal BCs before run: newly activated, grounded elements at ice front might cause inconsistencies in basal BCs otherwise

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