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

Last change on this file since 21377 was 21377, checked in by felicity, 8 years ago

NEW:added BuddJacka flow parameter

File size: 62.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
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 PostProcessing(femmodel);
478
479}/*}}}*/
480ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
481 /*Default, return NULL*/
482 return NULL;
483}/*}}}*/
484ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
485_error_("Not implemented");
486}/*}}}*/
487ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
488
489 /* Check if ice in element */
490 if(!element->IsIceInElement()) return NULL;
491
492 /*compute all stiffness matrices for this element*/
493 ElementMatrix* Ke1=CreateKMatrixVolume(element);
494 ElementMatrix* Ke2=CreateKMatrixShelf(element);
495 ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
496
497 /*clean-up and return*/
498 delete Ke1;
499 delete Ke2;
500 return Ke;
501}/*}}}*/
502ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
503
504 /* Check if ice in element */
505 if(!element->IsIceInElement()) return NULL;
506
507 /*Intermediaries */
508 int stabilization;
509 IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
510 IssmDouble h,hx,hy,hz,vx,vy,vz;
511 IssmDouble tau_parameter,diameter;
512 IssmDouble D_scalar;
513 IssmDouble* xyz_list = NULL;
514
515 /*Fetch number of nodes and dof for this finite element*/
516 int numnodes = element->GetNumberOfNodes();
517
518 /*Initialize Element vector and other vectors*/
519 ElementMatrix* Ke = element->NewElementMatrix();
520 IssmDouble* basis = xNew<IssmDouble>(numnodes);
521 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
522 IssmDouble* B = xNew<IssmDouble>(3*numnodes);
523 IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
524 IssmDouble D[3][3] = {0.};
525 IssmDouble K[3][3];
526
527 /*Retrieve all inputs and parameters*/
528 element->GetVerticesCoordinates(&xyz_list);
529 element->FindParam(&dt,TimesteppingTimeStepEnum);
530 element->FindParam(&stabilization,ThermalStabilizationEnum);
531 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
532 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
533 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
534 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
535 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
536 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
537 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
538 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
539 Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
540 Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
541 Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
542 if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
543
544 /*Enthalpy diffusion parameter*/
545 IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
546
547 /* Start looping on the number of gaussian points: */
548 Gauss* gauss=element->NewGauss(4);
549 for(int ig=gauss->begin();ig<gauss->end();ig++){
550 gauss->GaussPoint(ig);
551
552 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
553 D_scalar=gauss->weight*Jdet;
554 if(dt!=0.) D_scalar=D_scalar*dt;
555
556 /*Conduction: */
557 GetBConduct(B,element,xyz_list,gauss);
558 D[0][0]=D_scalar*kappa/rho_ice;
559 D[1][1]=D_scalar*kappa/rho_ice;
560 D[2][2]=D_scalar*kappa/rho_ice;
561 TripleMultiply(B,3,numnodes,1,
562 &D[0][0],3,3,0,
563 B,3,numnodes,0,
564 &Ke->values[0],1);
565
566 /*Advection: */
567 GetBAdvec(B,element,xyz_list,gauss);
568 GetBAdvecprime(Bprime,element,xyz_list,gauss);
569 vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
570 vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
571 vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
572 D[0][0]=D_scalar*vx;
573 D[1][1]=D_scalar*vy;
574 D[2][2]=D_scalar*vz;
575 TripleMultiply(B,3,numnodes,1,
576 &D[0][0],3,3,0,
577 Bprime,3,numnodes,0,
578 &Ke->values[0],1);
579
580 /*Transient: */
581 if(dt!=0.){
582 D_scalar=gauss->weight*Jdet;
583 element->NodalFunctions(basis,gauss);
584 TripleMultiply(basis,numnodes,1,0,
585 &D_scalar,1,1,0,
586 basis,1,numnodes,0,
587 &Ke->values[0],1);
588 D_scalar=D_scalar*dt;
589 }
590
591 /*Artifficial diffusivity*/
592 if(stabilization==1){
593 element->ElementSizes(&hx,&hy,&hz);
594 vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
595 h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
596 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);
597 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);
598 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);
599 for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
600
601 GetBAdvecprime(Bprime,element,xyz_list,gauss);
602 TripleMultiply(Bprime,3,numnodes,1,
603 &K[0][0],3,3,0,
604 Bprime,3,numnodes,0,
605 &Ke->values[0],1);
606 }
607 else if(stabilization==2){
608 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
609 tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
610 for(int i=0;i<numnodes;i++){
611 for(int j=0;j<numnodes;j++){
612 Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
613 ((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]);
614 }
615 }
616 if(dt!=0.){
617 D_scalar=gauss->weight*Jdet;
618 for(int i=0;i<numnodes;i++){
619 for(int j=0;j<numnodes;j++){
620 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]);
621 }
622 }
623 }
624 }
625 }
626
627 /*Clean up and return*/
628 xDelete<IssmDouble>(xyz_list);
629 xDelete<IssmDouble>(basis);
630 xDelete<IssmDouble>(dbasis);
631 xDelete<IssmDouble>(B);
632 xDelete<IssmDouble>(Bprime);
633 delete gauss;
634 return Ke;
635}/*}}}*/
636ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
637
638 /* Check if ice in element */
639 if(!element->IsIceInElement()) return NULL;
640
641 /*Initialize Element matrix and return if necessary*/
642 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
643
644 /*Intermediaries*/
645 IssmDouble dt,Jdet,D;
646 IssmDouble *xyz_list_base = NULL;
647
648 /*Fetch number of nodes for this finite element*/
649 int numnodes = element->GetNumberOfNodes();
650
651 /*Initialize vectors*/
652 ElementMatrix* Ke = element->NewElementMatrix();
653 IssmDouble* basis = xNew<IssmDouble>(numnodes);
654
655 /*Retrieve all inputs and parameters*/
656 element->GetVerticesCoordinatesBase(&xyz_list_base);
657 element->FindParam(&dt,TimesteppingTimeStepEnum);
658 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
659 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
660 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
661 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
662 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
663 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
664
665 /* Start looping on the number of gaussian points: */
666 Gauss* gauss=element->NewGaussBase(4);
667 for(int ig=gauss->begin();ig<gauss->end();ig++){
668 gauss->GaussPoint(ig);
669
670 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
671 element->NodalFunctions(basis,gauss);
672
673 D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
674 if(reCast<bool,IssmDouble>(dt)) D=dt*D;
675 TripleMultiply(basis,numnodes,1,0,
676 &D,1,1,0,
677 basis,1,numnodes,0,
678 &Ke->values[0],1);
679
680 }
681
682 /*Clean up and return*/
683 delete gauss;
684 xDelete<IssmDouble>(basis);
685 xDelete<IssmDouble>(xyz_list_base);
686 return Ke;
687}/*}}}*/
688ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
689
690 /* Check if ice in element */
691 if(!element->IsIceInElement()) return NULL;
692
693 /*compute all load vectors for this element*/
694 ElementVector* pe1=CreatePVectorVolume(element);
695 ElementVector* pe2=CreatePVectorSheet(element);
696 ElementVector* pe3=CreatePVectorShelf(element);
697 ElementVector* pe =new ElementVector(pe1,pe2,pe3);
698
699 /*clean-up and return*/
700 delete pe1;
701 delete pe2;
702 delete pe3;
703 return pe;
704}/*}}}*/
705ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
706
707 /* Check if ice in element */
708 if(!element->IsIceInElement()) return NULL;
709
710 /*Intermediaries*/
711 int i, stabilization;
712 IssmDouble Jdet,phi,dt;
713 IssmDouble enthalpy, Hpmp;
714 IssmDouble enthalpypicard, d1enthalpypicard[3];
715 IssmDouble pressure, d1pressure[3], d2pressure;
716 IssmDouble waterfractionpicard;
717 IssmDouble kappa,tau_parameter,diameter,kappa_w;
718 IssmDouble u,v,w;
719 IssmDouble scalar_def, scalar_sens ,scalar_transient;
720 IssmDouble* xyz_list = NULL;
721 IssmDouble d1H_d1P, d1P2;
722
723 /*Fetch number of nodes and dof for this finite element*/
724 int numnodes = element->GetNumberOfNodes();
725 int numvertices = element->GetNumberOfVertices();
726
727 /*Initialize Element vector*/
728 ElementVector* pe = element->NewElementVector();
729 IssmDouble* basis = xNew<IssmDouble>(numnodes);
730 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
731
732 /*Retrieve all inputs and parameters*/
733 element->GetVerticesCoordinates(&xyz_list);
734 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
735 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
736 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
737 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
738 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
739 IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
740 element->FindParam(&dt,TimesteppingTimeStepEnum);
741 element->FindParam(&stabilization,ThermalStabilizationEnum);
742 Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
743 Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
744 Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
745 Input* enthalpypicard_input=element->GetInput(EnthalpyPicardEnum); _assert_(enthalpypicard_input);
746 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
747 Input* enthalpy_input=NULL;
748 if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
749 if(stabilization==2){
750 diameter=element->MinEdgeLength(xyz_list);
751 kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
752 }
753
754 /* Start looping on the number of gaussian points: */
755 Gauss* gauss=element->NewGauss(4);
756 for(int ig=gauss->begin();ig<gauss->end();ig++){
757 gauss->GaussPoint(ig);
758
759 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
760 element->NodalFunctions(basis,gauss);
761
762 /*viscous dissipation*/
763 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
764
765 scalar_def=phi/rho_ice*Jdet*gauss->weight;
766 if(dt!=0.) scalar_def=scalar_def*dt;
767
768 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
769
770 /*sensible heat flux in temperate ice*/
771 enthalpypicard_input->GetInputValue(&enthalpypicard,gauss);
772 pressure_input->GetInputValue(&pressure,gauss);
773 Hpmp=this->PureIceEnthalpy(element, pressure);
774
775 if(enthalpypicard>=Hpmp){
776 enthalpypicard_input->GetInputDerivativeValue(&d1enthalpypicard[0],xyz_list,gauss);
777 pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
778 d2pressure=0.; // for linear elements, 2nd derivative is zero
779
780 d1H_d1P=0.;
781 for(i=0;i<3;i++) d1H_d1P+=d1enthalpypicard[i]*d1pressure[i];
782 d1P2=0.;
783 for(i=0;i<3;i++) d1P2+=pow(d1pressure[i],2.);
784
785 scalar_sens=-beta*((temperateiceconductivity - thermalconductivity)/latentheat*(d1H_d1P + beta*heatcapacity*d1P2))/rho_ice;
786 if(dt!=0.) scalar_sens=scalar_sens*dt;
787 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_sens*basis[i];
788 }
789
790 /* Build transient now */
791 if(reCast<bool,IssmDouble>(dt)){
792 enthalpy_input->GetInputValue(&enthalpy, gauss);
793 scalar_transient=enthalpy*Jdet*gauss->weight;
794 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
795 }
796
797 if(stabilization==2){
798 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
799
800 vx_input->GetInputValue(&u,gauss);
801 vy_input->GetInputValue(&v,gauss);
802 vz_input->GetInputValue(&w,gauss);
803 tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
804
805 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]);
806
807 if(dt!=0.){
808 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]);
809 }
810 }
811 }
812
813 /*Clean up and return*/
814 xDelete<IssmDouble>(basis);
815 xDelete<IssmDouble>(dbasis);
816 xDelete<IssmDouble>(xyz_list);
817 delete gauss;
818 return pe;
819
820}/*}}}*/
821ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
822
823 /* Check if ice in element */
824 if(!element->IsIceInElement()) return NULL;
825
826 /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
827 if(!element->IsOnBase() || element->IsFloating()) return NULL;
828
829 bool converged, isdynamicbasalspc;
830 int i, state;
831 int enthalpy_enum;
832 IssmDouble dt,Jdet,scalar;
833 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
834 IssmDouble vx,vy,vz;
835 IssmDouble alpha2,basalfriction,geothermalflux,heatflux;
836 IssmDouble *xyz_list_base = NULL;
837
838 /*Fetch number of nodes for this finite element*/
839 int numnodes = element->GetNumberOfNodes();
840
841 /*Initialize vectors*/
842 ElementVector* pe = element->NewElementVector();
843 IssmDouble* basis = xNew<IssmDouble>(numnodes);
844
845 /*Retrieve all inputs and parameters*/
846 element->GetVerticesCoordinatesBase(&xyz_list_base);
847 element->FindParam(&dt,TimesteppingTimeStepEnum);
848 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
849 element->GetInputValue(&converged,ConvergedEnum);
850 if(dt==0. && !converged) enthalpy_enum=EnthalpyPicardEnum; // use enthalpy from last iteration
851 else enthalpy_enum=EnthalpyEnum; // use enthalpy from last time step
852 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
853 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
854 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
855 Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
856 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
857 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
858 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
859 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
860 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
861
862 /*Build friction element, needed later: */
863 Friction* friction=new Friction(element,3);
864
865 /* Start looping on the number of gaussian points: */
866 Gauss* gauss=element->NewGaussBase(4);
867 Gauss* gaussup=element->NewGaussTop(4);
868 for(int ig=gauss->begin();ig<gauss->end();ig++){
869 gauss->GaussPoint(ig);
870 gaussup->GaussPoint(ig);
871
872 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
873 element->NodalFunctions(basis,gauss);
874
875 if(isdynamicbasalspc){
876 enthalpy_input->GetInputValue(&enthalpy,gauss);
877 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
878 pressure_input->GetInputValue(&pressure,gauss);
879 pressure_input->GetInputValue(&pressureup,gaussup);
880 watercolumn_input->GetInputValue(&watercolumn,gauss);
881 meltingrate_input->GetInputValue(&meltingrate,gauss);
882 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
883 }
884 else
885 state=0;
886
887 switch (state) {
888 case 0: case 1: case 2: case 3:
889 // cold, dry base; cold, wet base; refreezing temperate base; thin temperate base:
890 // Apply basal surface forcing.
891 // Interpolated values of enthalpy on gauss nodes may indicate cold base,
892 // although one node might have become temperate. So keep heat flux switched on.
893 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
894 friction->GetAlpha2(&alpha2,gauss);
895 vx_input->GetInputValue(&vx,gauss);
896 vy_input->GetInputValue(&vy,gauss);
897 vz_input->GetInputValue(&vz,gauss);
898 basalfriction=alpha2*(vx*vx+vy*vy+vz*vz);
899 heatflux=(basalfriction+geothermalflux)/(rho_ice);
900 scalar=gauss->weight*Jdet*heatflux;
901 if(dt!=0.) scalar=dt*scalar;
902 for(i=0;i<numnodes;i++)
903 pe->values[i]+=scalar*basis[i];
904 break;
905 case 4:
906 // temperate, thick melting base: set grad H*n=0
907 for(i=0;i<numnodes;i++)
908 pe->values[i]+=0.;
909 break;
910 default:
911 _printf0_(" unknown thermal basal state found!");
912 }
913 }
914
915 /*Clean up and return*/
916 delete gauss;
917 delete gaussup;
918 delete friction;
919 xDelete<IssmDouble>(basis);
920 xDelete<IssmDouble>(xyz_list_base);
921 return pe;
922
923}/*}}}*/
924ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
925
926 /* Check if ice in element */
927 if(!element->IsIceInElement()) return NULL;
928
929 /*Get basal element*/
930 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
931
932 IssmDouble Hpmp,dt,Jdet,scalar_ocean,pressure;
933 IssmDouble *xyz_list_base = NULL;
934
935 /*Fetch number of nodes for this finite element*/
936 int numnodes = element->GetNumberOfNodes();
937
938 /*Initialize vectors*/
939 ElementVector* pe = element->NewElementVector();
940 IssmDouble* basis = xNew<IssmDouble>(numnodes);
941
942 /*Retrieve all inputs and parameters*/
943 element->GetVerticesCoordinatesBase(&xyz_list_base);
944 element->FindParam(&dt,TimesteppingTimeStepEnum);
945 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
946 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
947 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
948 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
949 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
950 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
951 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
952
953 /* Start looping on the number of gaussian points: */
954 Gauss* gauss=element->NewGaussBase(4);
955 for(int ig=gauss->begin();ig<gauss->end();ig++){
956 gauss->GaussPoint(ig);
957
958 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
959 element->NodalFunctions(basis,gauss);
960
961 pressure_input->GetInputValue(&pressure,gauss);
962 Hpmp=element->PureIceEnthalpy(pressure);
963
964 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*Hpmp/(heatcapacity*rho_ice);
965 if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
966
967 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
968 }
969
970 /*Clean up and return*/
971 delete gauss;
972 xDelete<IssmDouble>(basis);
973 xDelete<IssmDouble>(xyz_list_base);
974 return pe;
975}/*}}}*/
976void EnthalpyAnalysis::DrainWaterfraction(FemModel* femmodel){/*{{{*/
977 /*Drain excess water fraction in ice column: */
978 for(int i=0;i<femmodel->elements->Size();i++){
979 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
980 DrainWaterfractionIcecolumn(element);
981 }
982}/*}}}*/
983void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
984
985 /* Check if ice in element */
986 if(!element->IsIceInElement()) return;
987
988 /*Intermediaries*/
989 int iv,is,vertexdown,vertexup,numsegments;
990 IssmDouble dt, height_element;
991 IssmDouble rho_water, rho_ice;
992 int numvertices = element->GetNumberOfVertices();
993
994 IssmDouble* xyz_list = NULL;
995 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
996 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
997 IssmDouble* temperatures = xNew<IssmDouble>(numvertices);
998 IssmDouble* waterfractions = xNew<IssmDouble>(numvertices);
999 IssmDouble* deltawaterfractions = xNew<IssmDouble>(numvertices);
1000 int *pairindices = NULL;
1001
1002 rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
1003 rho_water=element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
1004
1005 element->GetVerticesCoordinates(&xyz_list);
1006 element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
1007 element->GetInputListOnVertices(pressures,PressureEnum);
1008
1009 element->FindParam(&dt,TimesteppingTimeStepEnum);
1010 for(iv=0;iv<numvertices;iv++){
1011 element->EnthalpyToThermal(&temperatures[iv],&waterfractions[iv], enthalpies[iv],pressures[iv]);
1012 deltawaterfractions[iv]=DrainageFunctionWaterfraction(waterfractions[iv], dt);
1013 }
1014
1015 /*drain waterfraction, feed updated variables back into model*/
1016 for(iv=0;iv<numvertices;iv++){
1017 if(reCast<bool,IssmDouble>(dt))
1018 waterfractions[iv]-=deltawaterfractions[iv]*dt;
1019 else
1020 waterfractions[iv]-=deltawaterfractions[iv];
1021 element->ThermalToEnthalpy(&enthalpies[iv], temperatures[iv], waterfractions[iv], pressures[iv]);
1022 }
1023 element->AddInput(EnthalpyEnum,enthalpies,P1Enum);
1024 element->AddInput(WaterfractionEnum,waterfractions,P1Enum);
1025
1026 /*return meltwater column equivalent to drained water*/
1027 element->VerticalSegmentIndices(&pairindices,&numsegments);
1028 for(is=0;is<numsegments;is++){
1029 vertexdown = pairindices[is*2+0];
1030 vertexup = pairindices[is*2+1];
1031 height_element=fabs(xyz_list[vertexup*3+2]-xyz_list[vertexdown*3+2]);
1032 pdrainrate_element[is]=(deltawaterfractions[vertexdown]+deltawaterfractions[vertexup])/2.*height_element; // return water equivalent of drainage
1033 _assert_(pdrainrate_element[is]>=0.);
1034 }
1035
1036 /*Clean up and return*/
1037 xDelete<int>(pairindices);
1038 xDelete<IssmDouble>(xyz_list);
1039 xDelete<IssmDouble>(enthalpies);
1040 xDelete<IssmDouble>(pressures);
1041 xDelete<IssmDouble>(temperatures);
1042 xDelete<IssmDouble>(waterfractions);
1043 xDelete<IssmDouble>(deltawaterfractions);
1044}/*}}}*/
1045void EnthalpyAnalysis::DrainWaterfractionIcecolumn(Element* element){/*{{{*/
1046
1047 /* Check if ice in element */
1048 if(!element->IsIceInElement()) return;
1049
1050 /* Only drain waterfraction of ice column from element at base*/
1051 if(!element->IsOnBase()) return; //FIXME: allow freeze on for floating elements
1052
1053 /* Intermediaries*/
1054 int is, numvertices, numsegments;
1055 int *pairindices = NULL;
1056
1057 numvertices=element->GetNumberOfVertices();
1058 element->VerticalSegmentIndices(&pairindices,&numsegments);
1059
1060 IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
1061 IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments);
1062 IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
1063
1064 element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
1065
1066 for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
1067 Element* elementi = element;
1068 for(;;){
1069 for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
1070 DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
1071 for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
1072
1073 if(elementi->IsOnSurface()) break;
1074 elementi=elementi->GetUpperElement();
1075 }
1076 /* add drained water to water column*/
1077 for(is=0;is<numsegments;is++) watercolumn[is]+=drainrate_column[is];
1078 /* Feed updated water column back into model */
1079 element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
1080
1081 xDelete<int>(pairindices);
1082 xDelete<IssmDouble>(drainrate_column);
1083 xDelete<IssmDouble>(drainrate_element);
1084 xDelete<IssmDouble>(watercolumn);
1085}/*}}}*/
1086IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
1087
1088 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1089 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
1090 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1091
1092 if(enthalpy < PureIceEnthalpy(element,pressure)){
1093 return thermalconductivity/heatcapacity;
1094 }
1095 else{
1096 return temperateiceconductivity/heatcapacity;
1097 }
1098}/*}}}*/
1099IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
1100
1101 int iv;
1102 IssmDouble lambda; /* fraction of cold ice */
1103 IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
1104 IssmDouble Hc,Ht;
1105
1106 /*Get pressures and enthalpies on vertices*/
1107 int numvertices = element->GetNumberOfVertices();
1108 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
1109 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
1110 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
1111 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
1112 element->GetInputListOnVertices(pressures,PressureEnum);
1113 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
1114 for(iv=0;iv<numvertices;iv++){
1115 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
1116 dHpmp[iv] = enthalpies[iv]-PIE[iv];
1117 }
1118
1119 bool allequalsign = true;
1120 if(dHpmp[0]<0.){
1121 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
1122 }
1123 else{
1124 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
1125 }
1126
1127 if(allequalsign){
1128 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
1129 }
1130 else{
1131 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
1132 cf Patankar 1980, pp44 */
1133 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
1134 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
1135 Hc=0.; Ht=0.;
1136 for(iv=0; iv<numvertices;iv++){
1137 if(enthalpies[iv]<PIE[iv])
1138 Hc+=(PIE[iv]-enthalpies[iv]);
1139 else
1140 Ht+=(enthalpies[iv]-PIE[iv]);
1141 }
1142 _assert_((Hc+Ht)>0.);
1143 lambda = Hc/(Hc+Ht);
1144 kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
1145 }
1146
1147 /*Clean up and return*/
1148 xDelete<IssmDouble>(PIE);
1149 xDelete<IssmDouble>(dHpmp);
1150 xDelete<IssmDouble>(pressures);
1151 xDelete<IssmDouble>(enthalpies);
1152 return kappa;
1153}/*}}}*/
1154void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1155 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1156 * For node i, Bi' can be expressed in the actual coordinate system
1157 * by:
1158 * Bi_advec =[ h ]
1159 * [ h ]
1160 * [ h ]
1161 * where h is the interpolation function for node i.
1162 *
1163 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
1164 */
1165
1166 /*Fetch number of nodes for this finite element*/
1167 int numnodes = element->GetNumberOfNodes();
1168
1169 /*Get nodal functions*/
1170 IssmDouble* basis=xNew<IssmDouble>(numnodes);
1171 element->NodalFunctions(basis,gauss);
1172
1173 /*Build B: */
1174 for(int i=0;i<numnodes;i++){
1175 B[numnodes*0+i] = basis[i];
1176 B[numnodes*1+i] = basis[i];
1177 B[numnodes*2+i] = basis[i];
1178 }
1179
1180 /*Clean-up*/
1181 xDelete<IssmDouble>(basis);
1182}/*}}}*/
1183void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1184 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1185 * For node i, Bi' can be expressed in the actual coordinate system
1186 * by:
1187 * Biprime_advec=[ dh/dx ]
1188 * [ dh/dy ]
1189 * [ dh/dz ]
1190 * where h is the interpolation function for node i.
1191 *
1192 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
1193 */
1194
1195 /*Fetch number of nodes for this finite element*/
1196 int numnodes = element->GetNumberOfNodes();
1197
1198 /*Get nodal functions derivatives*/
1199 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
1200 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
1201
1202 /*Build B: */
1203 for(int i=0;i<numnodes;i++){
1204 B[numnodes*0+i] = dbasis[0*numnodes+i];
1205 B[numnodes*1+i] = dbasis[1*numnodes+i];
1206 B[numnodes*2+i] = dbasis[2*numnodes+i];
1207 }
1208
1209 /*Clean-up*/
1210 xDelete<IssmDouble>(dbasis);
1211}/*}}}*/
1212void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1213
1214 /*Intermediary*/
1215 bool isdynamicbasalspc;
1216 IssmDouble dt;
1217
1218 /*Check wether dynamic basal boundary conditions are activated */
1219 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
1220 if(!isdynamicbasalspc) return;
1221
1222 element->FindParam(&dt,TimesteppingTimeStepEnum);
1223 if(dt==0.){
1224 GetBasalConstraintsSteadystate(vec_spc,element);
1225 }
1226 else{
1227 GetBasalConstraintsTransient(vec_spc,element);
1228 }
1229}/*}}}*/
1230void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1231
1232 /* Check if ice in element */
1233 if(!element->IsIceInElement()) return;
1234
1235 /* Only update constraints at the base.
1236 * Floating ice is not affected by basal BC decision chart. */
1237 if(!(element->IsOnBase()) || element->IsFloating()) return;
1238
1239 /*Intermediary*/
1240 int numindices, numindicesup, state;
1241 int *indices = NULL, *indicesup = NULL;
1242 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1243
1244 /*Get parameters and inputs: */
1245 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
1246 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
1247 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1248 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
1249
1250 /*Fetch indices of basal & surface nodes for this finite element*/
1251 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1252 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1253 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1254
1255 GaussPenta* gauss=new GaussPenta();
1256 GaussPenta* gaussup=new GaussPenta();
1257 for(int i=0;i<numindices;i++){
1258 gauss->GaussNode(element->GetElementType(),indices[i]);
1259 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1260
1261 enthalpy_input->GetInputValue(&enthalpy,gauss);
1262 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1263 pressure_input->GetInputValue(&pressure,gauss);
1264 pressure_input->GetInputValue(&pressureup,gaussup);
1265 watercolumn_input->GetInputValue(&watercolumn,gauss);
1266 meltingrate_input->GetInputValue(&meltingrate,gauss);
1267
1268 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1269 switch (state) {
1270 case 0:
1271 // cold, dry base: apply basal surface forcing
1272 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1273 break;
1274 case 1:
1275 // cold, wet base: keep at pressure melting point
1276 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1277 break;
1278 case 2:
1279 // temperate, thin refreezing base:
1280 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1281 break;
1282 case 3:
1283 // temperate, thin melting base: set spc
1284 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1285 break;
1286 case 4:
1287 // temperate, thick melting base:
1288 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1289 break;
1290 default:
1291 _printf0_(" unknown thermal basal state found!");
1292 }
1293 }
1294
1295 /*Free ressources:*/
1296 xDelete<int>(indices);
1297 xDelete<int>(indicesup);
1298 delete gauss;
1299 delete gaussup;
1300}/*}}}*/
1301void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
1302
1303 /* Check if ice in element */
1304 if(!element->IsIceInElement()) return;
1305
1306 /* Only update constraints at the base.
1307 * Floating ice is not affected by basal BC decision chart.*/
1308 if(!(element->IsOnBase()) || element->IsFloating()) return;
1309
1310 /*Intermediary*/
1311 int numindices, numindicesup, state;
1312 int *indices = NULL, *indicesup = NULL;
1313 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
1314
1315 /*Get parameters and inputs: */
1316 Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
1317 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
1318 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
1319 Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
1320
1321 /*Fetch indices of basal & surface nodes for this finite element*/
1322 Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
1323 penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
1324 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
1325
1326 GaussPenta* gauss=new GaussPenta();
1327 GaussPenta* gaussup=new GaussPenta();
1328
1329 for(int i=0;i<numindices;i++){
1330 gauss->GaussNode(element->GetElementType(),indices[i]);
1331 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
1332
1333 enthalpy_input->GetInputValue(&enthalpy,gauss);
1334 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1335 pressure_input->GetInputValue(&pressure,gauss);
1336 pressure_input->GetInputValue(&pressureup,gaussup);
1337 watercolumn_input->GetInputValue(&watercolumn,gauss);
1338 meltingrate_input->GetInputValue(&meltingrate,gauss);
1339
1340 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
1341
1342 switch (state) {
1343 case 0:
1344 // cold, dry base: apply basal surface forcing
1345 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1346 break;
1347 case 1:
1348 // cold, wet base: keep at pressure melting point
1349 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1350 break;
1351 case 2:
1352 // temperate, thin refreezing base: release spc
1353 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1354 break;
1355 case 3:
1356 // temperate, thin melting base: set spc
1357 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
1358 break;
1359 case 4:
1360 // temperate, thick melting base: set grad H*n=0
1361 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
1362 break;
1363 default:
1364 _printf0_(" unknown thermal basal state found!");
1365 }
1366
1367 }
1368
1369 /*Free ressources:*/
1370 xDelete<int>(indices);
1371 xDelete<int>(indicesup);
1372 delete gauss;
1373 delete gaussup;
1374}/*}}}*/
1375void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
1376 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
1377 * For node i, Bi' can be expressed in the actual coordinate system
1378 * by:
1379 * Bi_conduct=[ dh/dx ]
1380 * [ dh/dy ]
1381 * [ dh/dz ]
1382 * where h is the interpolation function for node i.
1383 *
1384 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
1385 */
1386
1387 /*Fetch number of nodes for this finite element*/
1388 int numnodes = element->GetNumberOfNodes();
1389
1390 /*Get nodal functions derivatives*/
1391 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
1392 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
1393
1394 /*Build B: */
1395 for(int i=0;i<numnodes;i++){
1396 B[numnodes*0+i] = dbasis[0*numnodes+i];
1397 B[numnodes*1+i] = dbasis[1*numnodes+i];
1398 B[numnodes*2+i] = dbasis[2*numnodes+i];
1399 }
1400
1401 /*Clean-up*/
1402 xDelete<IssmDouble>(dbasis);
1403}/*}}}*/
1404void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
1405 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
1406}/*}}}*/
1407int EnthalpyAnalysis::GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpyup, IssmDouble pressure, IssmDouble pressureup, IssmDouble watercolumn, IssmDouble meltingrate){/*{{{*/
1408
1409 /* Check if ice in element */
1410 if(!element->IsIceInElement()) return -1;
1411
1412 /* Only update Constraints at the base of grounded ice*/
1413 if(!(element->IsOnBase())) return -1;
1414
1415 /*Intermediary*/
1416 int state=-1;
1417 IssmDouble dt;
1418
1419 /*Get parameters and inputs: */
1420 element->FindParam(&dt,TimesteppingTimeStepEnum);
1421
1422 if(enthalpy<PureIceEnthalpy(element,pressure)){
1423 if(watercolumn<=0.) state=0; // cold, dry base
1424 else state=1; // cold, wet base (refreezing)
1425 }
1426 else{
1427 if(enthalpyup<PureIceEnthalpy(element,pressureup)){
1428 if((dt==0.) && (meltingrate<0.)) state=2; // refreezing temperate base (non-physical, only for steadystate solver)
1429 else state=3; // temperate base, but no temperate layer
1430 }
1431 else state=4; // temperate layer with positive thickness
1432 }
1433
1434 _assert_(state>=0);
1435 return state;
1436}/*}}}*/
1437IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
1438
1439 IssmDouble temperature, waterfraction;
1440 IssmDouble kappa_w = 0.6; // thermal conductivity of water (in W/m/K)
1441 IssmDouble kappa_i = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
1442 element->EnthalpyToThermal(&temperature, &waterfraction, enthalpy, pressure);
1443
1444 return (1.-waterfraction)*kappa_i + waterfraction*kappa_w;
1445}/*}}}*/
1446void EnthalpyAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
1447 _error_("Not implemented yet");
1448}/*}}}*/
1449void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
1450
1451 bool converged;
1452 int i,rheology_law;
1453 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
1454 int *doflist = NULL;
1455 IssmDouble *xyz_list = NULL;
1456
1457 /*Fetch number of nodes and dof for this finite element*/
1458 int numnodes = element->GetNumberOfNodes();
1459
1460 /*Fetch dof list and allocate solution vector*/
1461 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
1462 IssmDouble* values = xNew<IssmDouble>(numnodes);
1463 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
1464 IssmDouble* surface = xNew<IssmDouble>(numnodes);
1465 IssmDouble* B = xNew<IssmDouble>(numnodes);
1466 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
1467 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
1468
1469 /*Use the dof list to index into the solution vector: */
1470 for(i=0;i<numnodes;i++){
1471 values[i]=solution[doflist[i]];
1472
1473 /*Check solution*/
1474 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
1475 if(xIsInf<IssmDouble>(values[i])) _error_("Inf found in solution vector");
1476 }
1477
1478 /*Get all inputs and parameters*/
1479 element->GetInputValue(&converged,ConvergedEnum);
1480 element->GetInputListOnNodes(&pressure[0],PressureEnum);
1481 if(converged){
1482 for(i=0;i<numnodes;i++){
1483 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
1484 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
1485 //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
1486 }
1487 element->AddInput(EnthalpyEnum,values,element->GetElementType());
1488 element->AddInput(WaterfractionEnum,waterfraction,element->GetElementType());
1489 element->AddInput(TemperatureEnum,temperature,element->GetElementType());
1490
1491 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
1492 * otherwise the rheology could be negative*/
1493 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
1494 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
1495 switch(rheology_law){
1496 case NoneEnum:
1497 /*Do nothing: B is not temperature dependent*/
1498 break;
1499 case BuddJackaEnum:
1500 for(i=0;i<numnodes;i++) B[i]=BuddJacka(temperature[i]);
1501 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1502 break;
1503 case CuffeyEnum:
1504 for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
1505 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1506 break;
1507 case CuffeyTemperateEnum:
1508 for(i=0;i<numnodes;i++) B[i]=CuffeyTemperate(temperature[i], waterfraction[i], element->GetMaterialParameter(MaterialsRheologyNEnum));
1509 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1510 break;
1511 case PatersonEnum:
1512 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
1513 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1514 break;
1515 case ArrheniusEnum:
1516 element->GetVerticesCoordinates(&xyz_list);
1517 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
1518 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1519 break;
1520 case LliboutryDuvalEnum:
1521 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));
1522 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1523 break;
1524 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
1525 }
1526 }
1527 else{
1528 element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
1529 }
1530
1531 /*Free ressources:*/
1532 xDelete<IssmDouble>(values);
1533 xDelete<IssmDouble>(pressure);
1534 xDelete<IssmDouble>(surface);
1535 xDelete<IssmDouble>(B);
1536 xDelete<IssmDouble>(temperature);
1537 xDelete<IssmDouble>(waterfraction);
1538 xDelete<IssmDouble>(xyz_list);
1539 xDelete<int>(doflist);
1540}/*}}}*/
1541void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
1542
1543 /*Intermediaries*/
1544 bool computebasalmeltingrates=true;
1545 bool drainicecolumn=true;
1546 IssmDouble dt;
1547
1548 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1549
1550 if(drainicecolumn && (dt>0.)) DrainWaterfraction(femmodel);
1551 if(computebasalmeltingrates) ComputeBasalMeltingrate(femmodel);
1552
1553}/*}}}*/
1554IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
1555
1556 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1557 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
1558
1559 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1560}/*}}}*/
1561IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
1562
1563 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
1564 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
1565
1566 return meltingpoint-beta*pressure;
1567}/*}}}*/
1568void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
1569
1570 /*Update basal dirichlet BCs for enthalpy: */
1571 Vector<IssmDouble>* spc = NULL;
1572 IssmDouble* serial_spc = NULL;
1573
1574 spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes(EnthalpyAnalysisEnum));
1575 /*First create a vector to figure out what elements should be constrained*/
1576 for(int i=0;i<femmodel->elements->Size();i++){
1577 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
1578 GetBasalConstraints(spc,element);
1579 }
1580
1581 /*Assemble and serialize*/
1582 spc->Assemble();
1583 serial_spc=spc->ToMPISerial();
1584 delete spc;
1585
1586 /*Then update basal constraints nodes accordingly*/
1587 for(int i=0;i<femmodel->elements->Size();i++){
1588 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
1589 ApplyBasalConstraints(serial_spc,element);
1590 }
1591
1592 femmodel->UpdateConstraintsx();
1593
1594 /*Delete*/
1595 xDelete<IssmDouble>(serial_spc);
1596}/*}}}*/
1597void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
1598 SetActiveNodesLSMx(femmodel);
1599}/*}}}*/
Note: See TracBrowser for help on using the repository browser.