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

Last change on this file since 21565 was 21565, checked in by jcuzzone, 8 years ago

CHG: minor

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