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

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

NEW: ESTAR thermal model capability

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