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
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;
[21546]15 int finiteelement;
[18930]16 IssmDouble heatcapacity;
17 IssmDouble referencetemperature;
[16604]18
[18930]19 /*Output*/
20 IssmDouble *spcvector = NULL;
21 IssmDouble* times=NULL;
22 IssmDouble* values=NULL;
[16604]23
[18930]24 /*Fetch parameters: */
[20690]25 iomodel->FindConstant(&heatcapacity,"md.materials.heatcapacity");
26 iomodel->FindConstant(&referencetemperature,"md.constants.referencetemperature");
[21546]27 iomodel->FindConstant(&finiteelement,"md.thermal.fe");
[18732]28
[18930]29 /*return if 2d mesh*/
30 if(iomodel->domaintype==Domain2DhorizontalEnum) return;
31
32 /*Fetch data: */
[20690]33 iomodel->FetchData(&spcvector,&M,&N,"md.thermal.spctemperature");
[18930]34
[21546]35 /*Convert spcs from temperatures to enthalpy*/
36 _assert_(N>0); _assert_(M>=iomodel->numberofvertices);
37 for(int i=0;i<iomodel->numberofvertices;i++){
[21549]38 for(int j=0;j<N;j++){
39 spcvector[i*N+j] = heatcapacity*(spcvector[i*N+j]-referencetemperature);
[18930]40 }
41 }
42
[21548]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){
[21560]53 IoModelToDynamicConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement);
[21548]54 }
55 else{
56 IoModelToConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement);
57 }
58
[18930]59 /*Free ressources:*/
[20690]60 iomodel->DeleteData(spcvector,"md.thermal.spctemperature");
[18930]61 xDelete<IssmDouble>(times);
62 xDelete<IssmDouble>(values);
[16539]63}/*}}}*/
[18930]64void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
65
66 /*No loads */
67}/*}}}*/
68void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
69
[21542]70 int finiteelement;
71 iomodel->FindConstant(&finiteelement,"md.thermal.fe");
72
[20690]73 if(iomodel->domaintype==Domain3DEnum) iomodel->FetchData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
[21542]74 ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,finiteelement);
[20690]75 iomodel->DeleteData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
[18930]76}/*}}}*/
77int EnthalpyAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
78 return 1;
79}/*}}}*/
[16539]80void EnthalpyAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
81
[20459]82 bool dakota_analysis,ismovingfront,isenthalpy;
[21382]83 int frictionlaw,basalforcing_model,materialstype;
[19161]84 int FrictionCoupling;
85
[16539]86 /*Now, is the model 3d? otherwise, do nothing: */
[17700]87 if(iomodel->domaintype==Domain2DhorizontalEnum)return;
[16539]88
89 /*Is enthalpy requested?*/
[20690]90 iomodel->FindConstant(&isenthalpy,"md.thermal.isenthalpy");
[16539]91 if(!isenthalpy) return;
92
93 /*Fetch data needed: */
[20690]94 iomodel->FetchData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
[16539]95
[21542]96 /*Finite element type*/
97 int finiteelement;
98 iomodel->FindConstant(&finiteelement,"md.thermal.fe");
99
[16539]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);
[21542]105 element->Update(i,iomodel,analysis_counter,analysis_type,finiteelement);
[16539]106 counter++;
107 }
108 }
109
[20690]110 iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
111 iomodel->FindConstant(&ismovingfront,"md.transient.ismovingfront");
112 iomodel->FindConstant(&frictionlaw,"md.friction.law");
[21382]113 iomodel->FindConstant(&materialstype,"md.materials.type");
[16539]114
[20690]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);
[17886]121 if(iomodel->domaintype!=Domain2DhorizontalEnum){
[20690]122 iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum);
123 iomodel->FetchDataToInput(elements,"md.mesh.vertexonsurface",MeshVertexonsurfaceEnum);
[17886]124 }
[20690]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);
[16539]134 InputUpdateFromConstantx(elements,0.,VxMeshEnum);
135 InputUpdateFromConstantx(elements,0.,VyMeshEnum);
136 InputUpdateFromConstantx(elements,0.,VzMeshEnum);
[20459]137 if(ismovingfront){
[20690]138 iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum); // required for updating active nodes
[17434]139 }
[20020]140
141 /*Basal forcings variables*/
[20690]142 iomodel->FindConstant(&basalforcing_model,"md.basalforcings.model");
[20020]143 switch(basalforcing_model){
144 case MantlePlumeGeothermalFluxEnum:
145 break;
146 default:
[20690]147 iomodel->FetchDataToInput(elements,"md.basalforcings.geothermalflux",BasalforcingsGeothermalfluxEnum);
[20020]148 break;
149 }
[21382]150
151 /*Rheology type*/
152 iomodel->FetchDataToInput(elements,"md.materials.rheology_B",MaterialsRheologyBEnum);
153 switch(materialstype){
[21389]154 case MatenhancediceEnum:
155 iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
156 iomodel->FetchDataToInput(elements,"md.materials.rheology_E",MaterialsRheologyEEnum);
157 break;
[21382]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 }
[17952]171
172 /*Friction law variables*/
173 switch(frictionlaw){
174 case 1:
[20690]175 iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
176 iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
177 iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
[17952]178 break;
179 case 2:
[20690]180 iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
181 iomodel->FetchDataToInput(elements,"md.friction.m",FrictionMEnum);
[17952]182 break;
[18778]183 case 3:
[20690]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);
[19161]188 if (FrictionCoupling==0){
[20690]189 iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);
[19161]190 }
[18778]191 break;
[18732]192 case 4:
[20690]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);
[18732]198 break;
[18772]199 case 5:
[20690]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);
[18772]204 break;
[18804]205 case 6:
[20690]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);
[18804]210 break;
[21556]211 case 9:
212 iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
213 iomodel->FetchDataToInput(elements,"md.friction.pressure_adjusted_temperature",FrictionPressureAdjustedTemperatureEnum);
[21565]214 InputUpdateFromConstantx(elements,1.,FrictionPEnum);
215 InputUpdateFromConstantx(elements,1.,FrictionQEnum);
[21556]216 break;
[17952]217 default:
218 _error_("not supported");
219 }
[20690]220
[16539]221 /*Free data: */
[20690]222 iomodel->DeleteData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
223
[16539]224}/*}}}*/
[18930]225void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
[16539]226
[18930]227 int numoutputs;
228 char** requestedoutputs = NULL;
229
[20690]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));
[18930]236
[20690]237 iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.thermal.requested_outputs");
[18930]238 parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
239 if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
[20690]240 iomodel->DeleteData(&requestedoutputs,numoutputs,"md.thermal.requested_outputs");
[18930]241
242 /*Deal with friction parameters*/
243 int frictionlaw;
[20690]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));
[16539]247}/*}}}*/
248
[18930]249/*Finite Element Analysis*/
250void EnthalpyAnalysis::ApplyBasalConstraints(IssmDouble* serial_spc,Element* element){/*{{{*/
[16539]251
[21481]252 /* Do not check if ice in element, this may lead to inconsistencies between cpu partitions */
[20213]253 /* Only update constraints at the base. */
254 if(!(element->IsOnBase())) return;
[16539]255
[18930]256 /*Intermediary*/
257 bool isdynamicbasalspc;
258 int numindices;
259 int *indices = NULL;
260 Node* node = NULL;
261 IssmDouble pressure;
[16539]262
[18930]263 /*Check wether dynamic basal boundary conditions are activated */
264 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
265 if(!isdynamicbasalspc) return;
[16539]266
[18930]267 /*Get parameters and inputs: */
268 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
[16539]269
[18930]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());
[16539]273
[18930]274 GaussPenta* gauss=new GaussPenta();
275 for(int i=0;i<numindices;i++){
276 gauss->GaussNode(element->GetElementType(),indices[i]);
[16539]277
[18930]278 pressure_input->GetInputValue(&pressure,gauss);
[16539]279
[18930]280 /*apply or release spc*/
281 node=element->GetNode(indices[i]);
[21481]282 if(!node->IsActive()) continue;
[18930]283 if(serial_spc[node->Sid()]==1.){
284 pressure_input->GetInputValue(&pressure, gauss);
285 node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
[16539]286 }
[21481]287 else {
[18930]288 node->DofInFSet(0);
[21481]289 }
[16539]290 }
291
[18930]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*/
[16539]306
[18930]307 /* Check if ice in element */
308 if(!element->IsIceInElement()) return;
[16539]309
[18930]310 /* Only compute melt rates at the base of grounded ice*/
311 if(!element->IsOnBase() || element->IsFloating()) return;
[16539]312
[18930]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;
[16539]327
[18930]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
[16539]427 }
[18930]428 else{
429 basalmeltingrates[vertexdown]=meltingrate_enthalpy[is];
430 watercolumns[vertexdown]+=dt*meltingrate_enthalpy[is];
431 }
[16539]432 }
[18930]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);
[16539]448 }
[18930]449 element->AddInput(BasalforcingsGroundediceMeltingRateEnum,basalmeltingrates,P1Enum);
[16539]450
[18930]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);
[16539]463}/*}}}*/
[18930]464void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
[21160]465
466 IssmDouble dt;
467 bool isdynamicbasalspc;
468
469 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
470 femmodel->parameters->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
471
[18591]472 if(VerboseSolution()) _printf0_(" computing enthalpy\n");
473 femmodel->SetCurrentConfiguration(EnthalpyAnalysisEnum);
[21160]474 if((dt>0.) && isdynamicbasalspc) UpdateBasalConstraints(femmodel);
[18591]475 solutionsequence_thermal_nonlinear(femmodel);
476
477 /*transfer enthalpy to enthalpy picard for the next step: */
478 InputDuplicatex(femmodel,EnthalpyEnum,EnthalpyPicardEnum);
479
[21161]480 PostProcessing(femmodel);
[18591]481
[17005]482}/*}}}*/
[17000]483ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
484 /*Default, return NULL*/
485 return NULL;
486}/*}}}*/
[16992]487ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
488_error_("Not implemented");
489}/*}}}*/
[16782]490ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
[16888]491
[17434]492 /* Check if ice in element */
493 if(!element->IsIceInElement()) return NULL;
494
[16888]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;
[16782]504}/*}}}*/
[16888]505ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
506
[17434]507 /* Check if ice in element */
508 if(!element->IsIceInElement()) return NULL;
509
[16888]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);
[17946]534 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
[16888]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*/
[17027]548 IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
[16888]549
550 /* Start looping on the number of gaussian points: */
[19637]551 Gauss* gauss=element->NewGauss(4);
[16888]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
[21382]594 /*Artificial diffusivity*/
[16888]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));
[18484]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);
[16888]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*
[16895]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]);
[16888]617 }
618 }
619 if(dt!=0.){
[16896]620 D_scalar=gauss->weight*Jdet;
[16888]621 for(int i=0;i<numnodes;i++){
622 for(int j=0;j<numnodes;j++){
[16895]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]);
[16888]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
[17434]641 /* Check if ice in element */
642 if(!element->IsIceInElement()) return NULL;
643
[16888]644 /*Initialize Element matrix and return if necessary*/
[17585]645 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
[16888]646
[16986]647 /*Intermediaries*/
[16888]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);
[17946]662 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
[16888]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: */
[19637]669 Gauss* gauss=element->NewGaussBase(4);
[16888]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}/*}}}*/
[16782]691ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
[16812]692
[17434]693 /* Check if ice in element */
694 if(!element->IsIceInElement()) return NULL;
695
[16812]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;
[16782]707}/*}}}*/
[16812]708ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
709
[17434]710 /* Check if ice in element */
711 if(!element->IsIceInElement()) return NULL;
712
[16812]713 /*Intermediaries*/
[17014]714 int i, stabilization;
[16812]715 IssmDouble Jdet,phi,dt;
[17014]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;
[16812]721 IssmDouble u,v,w;
[17014]722 IssmDouble scalar_def, scalar_sens ,scalar_transient;
[16812]723 IssmDouble* xyz_list = NULL;
[17014]724 IssmDouble d1H_d1P, d1P2;
[16812]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);
[17014]738 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
[16812]739 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
[17014]740 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
741 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
742 IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
[16812]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);
[17014]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;
[16812]751 if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
752 if(stabilization==2){
753 diameter=element->MinEdgeLength(xyz_list);
[17027]754 kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
[16812]755 }
756
757 /* Start looping on the number of gaussian points: */
[19637]758 Gauss* gauss=element->NewGauss(4);
[16812]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);
[17014]764
765 /*viscous dissipation*/
[16812]766 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
767
768 scalar_def=phi/rho_ice*Jdet*gauss->weight;
[16895]769 if(dt!=0.) scalar_def=scalar_def*dt;
[16812]770
[17014]771 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
[16812]772
[17014]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
[16812]793 /* Build transient now */
794 if(reCast<bool,IssmDouble>(dt)){
795 enthalpy_input->GetInputValue(&enthalpy, gauss);
796 scalar_transient=enthalpy*Jdet*gauss->weight;
[17014]797 for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
[16812]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);
[16895]806 tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
[16812]807
[17014]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]);
[16895]809
810 if(dt!=0.){
[17014]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]);
[16812]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){/*{{{*/
[16888]825
[17434]826 /* Check if ice in element */
827 if(!element->IsIceInElement()) return NULL;
828
[17014]829 /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
[17585]830 if(!element->IsOnBase() || element->IsFloating()) return NULL;
[16888]831
[20272]832 bool converged, isdynamicbasalspc;
[18612]833 int i, state;
[20272]834 int enthalpy_enum;
[18612]835 IssmDouble dt,Jdet,scalar;
836 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
837 IssmDouble vx,vy,vz;
838 IssmDouble alpha2,basalfriction,geothermalflux,heatflux;
[16888]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);
[18622]851 element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
[20272]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
[16888]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);
[20272]858 Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
[18612]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);
[16888]862 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
[18612]863 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
[16888]864
865 /*Build friction element, needed later: */
866 Friction* friction=new Friction(element,3);
867
868 /* Start looping on the number of gaussian points: */
[19637]869 Gauss* gauss=element->NewGaussBase(4);
870 Gauss* gaussup=element->NewGaussTop(4);
[16888]871 for(int ig=gauss->begin();ig<gauss->end();ig++){
872 gauss->GaussPoint(ig);
[18665]873 gaussup->GaussPoint(ig);
[16888]874
875 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
876 element->NodalFunctions(basis,gauss);
877
[18622]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;
[16888]889
[18612]890 switch (state) {
[20272]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.
[18612]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!");
[16888]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
[16812]926}/*}}}*/
927ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
928
[17434]929 /* Check if ice in element */
930 if(!element->IsIceInElement()) return NULL;
931
[16888]932 /*Get basal element*/
[17585]933 if(!element->IsOnBase() || !element->IsFloating()) return NULL;
[16888]934
[18612]935 IssmDouble Hpmp,dt,Jdet,scalar_ocean,pressure;
[16812]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);
[17946]950 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
[16812]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: */
[19637]957 Gauss* gauss=element->NewGaussBase(4);
[16812]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);
[18612]965 Hpmp=element->PureIceEnthalpy(pressure);
[16812]966
[18612]967 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*Hpmp/(heatcapacity*rho_ice);
[16812]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}/*}}}*/
[18930]979void EnthalpyAnalysis::DrainWaterfraction(FemModel* femmodel){/*{{{*/
980 /*Drain excess water fraction in ice column: */
[18612]981 for(int i=0;i<femmodel->elements->Size();i++){
982 Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
[18930]983 DrainWaterfractionIcecolumn(element);
[17166]984 }
[17002]985}/*}}}*/
[18930]986void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
[17002]987
[17434]988 /* Check if ice in element */
989 if(!element->IsIceInElement()) return;
990
[18930]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();
[17434]996
[18930]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);
[17014]1003 int *pairindices = NULL;
[18930]1004
1005 rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
1006 rho_water=element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
[17014]1007
1008 element->GetVerticesCoordinates(&xyz_list);
[18930]1009 element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
1010 element->GetInputListOnVertices(pressures,PressureEnum);
1011
[18667]1012 element->FindParam(&dt,TimesteppingTimeStepEnum);
[18930]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);
[18667]1028
[18930]1029 /*return meltwater column equivalent to drained water*/
[17014]1030 element->VerticalSegmentIndices(&pairindices,&numsegments);
[18612]1031 for(is=0;is<numsegments;is++){
[17014]1032 vertexdown = pairindices[is*2+0];
1033 vertexup = pairindices[is*2+1];
[18930]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.);
[18667]1037 }
[17014]1038
1039 /*Clean up and return*/
[17981]1040 xDelete<int>(pairindices);
[18930]1041 xDelete<IssmDouble>(xyz_list);
[18612]1042 xDelete<IssmDouble>(enthalpies);
1043 xDelete<IssmDouble>(pressures);
[18930]1044 xDelete<IssmDouble>(temperatures);
1045 xDelete<IssmDouble>(waterfractions);
1046 xDelete<IssmDouble>(deltawaterfractions);
[17166]1047}/*}}}*/
[18930]1048void EnthalpyAnalysis::DrainWaterfractionIcecolumn(Element* element){/*{{{*/
[17166]1049
[17434]1050 /* Check if ice in element */
1051 if(!element->IsIceInElement()) return;
1052
[17166]1053 /* Only drain waterfraction of ice column from element at base*/
[17585]1054 if(!element->IsOnBase()) return; //FIXME: allow freeze on for floating elements
[17166]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
[17608]1084 xDelete<int>(pairindices);
[17014]1085 xDelete<IssmDouble>(drainrate_column);
1086 xDelete<IssmDouble>(drainrate_element);
[17166]1087 xDelete<IssmDouble>(watercolumn);
[17002]1088}/*}}}*/
[18930]1089IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
[17014]1090
[18930]1091 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1092 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
1093 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
[17434]1094
[18930]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){/*{{{*/
[17014]1103
[18930]1104 int iv;
1105 IssmDouble lambda; /* fraction of cold ice */
1106 IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
1107 IssmDouble Hc,Ht;
[17014]1108
[18930]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);
[17014]1115 element->GetInputListOnVertices(pressures,PressureEnum);
[18930]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 }
[17014]1121
[18930]1122 bool allequalsign = true;
1123 if(dHpmp[0]<0.){
1124 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
[17014]1125 }
[18930]1126 else{
1127 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
[17014]1128 }
1129
[18930]1130 if(allequalsign){
1131 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
[17014]1132 }
[18930]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 }
[17014]1149
1150 /*Clean up and return*/
[18930]1151 xDelete<IssmDouble>(PIE);
1152 xDelete<IssmDouble>(dHpmp);
1153 xDelete<IssmDouble>(pressures);
[17014]1154 xDelete<IssmDouble>(enthalpies);
[18930]1155 return kappa;
[17002]1156}/*}}}*/
[18930]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 */
[18659]1168
[18930]1169 /*Fetch number of nodes for this finite element*/
1170 int numnodes = element->GetNumberOfNodes();
[18659]1171
[18930]1172 /*Get nodal functions*/
1173 IssmDouble* basis=xNew<IssmDouble>(numnodes);
1174 element->NodalFunctions(basis,gauss);
[18659]1175
[18930]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];
[18659]1181 }
1182
[18930]1183 /*Clean-up*/
1184 xDelete<IssmDouble>(basis);
[18612]1185}/*}}}*/
[18930]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 */
[17002]1197
[18930]1198 /*Fetch number of nodes for this finite element*/
1199 int numnodes = element->GetNumberOfNodes();
[17434]1200
[18930]1201 /*Get nodal functions derivatives*/
1202 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
1203 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
[17434]1204
[18930]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];
[18659]1210 }
1211
[18930]1212 /*Clean-up*/
1213 xDelete<IssmDouble>(dbasis);
[18659]1214}/*}}}*/
[18930]1215void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
[18659]1216
1217 /*Intermediary*/
1218 bool isdynamicbasalspc;
[18612]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.){
[18659]1227 GetBasalConstraintsSteadystate(vec_spc,element);
[18612]1228 }
1229 else{
[18659]1230 GetBasalConstraintsTransient(vec_spc,element);
[18612]1231 }
1232}/*}}}*/
[18930]1233void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
[18612]1234
1235 /* Check if ice in element */
1236 if(!element->IsIceInElement()) return;
1237
[20213]1238 /* Only update constraints at the base.
1239 * Floating ice is not affected by basal BC decision chart. */
[18612]1240 if(!(element->IsOnBase()) || element->IsFloating()) return;
1241
1242 /*Intermediary*/
1243 int numindices, numindicesup, state;
[17027]1244 int *indices = NULL, *indicesup = NULL;
[18612]1245 IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
[17014]1246
[18612]1247 /*Get parameters and inputs: */
[18930]1248 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
[18612]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
[17027]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());
[18612]1256 penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
[17014]1257
[18612]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]);
[18930]1263
[18612]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
[18659]1275 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
[18612]1276 break;
1277 case 1:
1278 // cold, wet base: keep at pressure melting point
[18659]1279 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
[18612]1280 break;
1281 case 2:
[20098]1282 // temperate, thin refreezing base:
1283 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
[18612]1284 break;
1285 case 3:
1286 // temperate, thin melting base: set spc
[18659]1287 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
[18612]1288 break;
1289 case 4:
[20098]1290 // temperate, thick melting base:
[18930]1291 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
[18612]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}/*}}}*/
[18930]1304void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
[18612]1305
1306 /* Check if ice in element */
1307 if(!element->IsIceInElement()) return;
1308
[20213]1309 /* Only update constraints at the base.
1310 * Floating ice is not affected by basal BC decision chart.*/
[18612]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
[17027]1318 /*Get parameters and inputs: */
[18930]1319 Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
[18612]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);
[17014]1323
[18612]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
[17027]1329 GaussPenta* gauss=new GaussPenta();
1330 GaussPenta* gaussup=new GaussPenta();
[18930]1331
[17027]1332 for(int i=0;i<numindices;i++){
1333 gauss->GaussNode(element->GetElementType(),indices[i]);
1334 gaussup->GaussNode(element->GetElementType(),indicesup[i]);
[18930]1335
[18612]1336 enthalpy_input->GetInputValue(&enthalpy,gauss);
1337 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
1338 pressure_input->GetInputValue(&pressure,gauss);
1339 pressure_input->GetInputValue(&pressureup,gaussup);
[17027]1340 watercolumn_input->GetInputValue(&watercolumn,gauss);
[18612]1341 meltingrate_input->GetInputValue(&meltingrate,gauss);
1342
1343 state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
[18930]1344
[18612]1345 switch (state) {
1346 case 0:
1347 // cold, dry base: apply basal surface forcing
[18659]1348 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
[18612]1349 break;
1350 case 1:
1351 // cold, wet base: keep at pressure melting point
[18659]1352 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
[18612]1353 break;
1354 case 2:
1355 // temperate, thin refreezing base: release spc
[18659]1356 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
[18612]1357 break;
1358 case 3:
1359 // temperate, thin melting base: set spc
[18659]1360 vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
[18612]1361 break;
1362 case 4:
[18930]1363 // temperate, thick melting base: set grad H*n=0
1364 vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
[18612]1365 break;
1366 default:
1367 _printf0_(" unknown thermal basal state found!");
[17027]1368 }
[18930]1369
[17027]1370 }
[17014]1371
[17027]1372 /*Free ressources:*/
1373 xDelete<int>(indices);
1374 xDelete<int>(indicesup);
1375 delete gauss;
1376 delete gaussup;
[17002]1377}/*}}}*/
[18930]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 */
[17002]1389
[18930]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
[18612]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
[18620]1425 if(enthalpy<PureIceEnthalpy(element,pressure)){
1426 if(watercolumn<=0.) state=0; // cold, dry base
1427 else state=1; // cold, wet base (refreezing)
[18612]1428 }
[18620]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
[18612]1433 }
[18620]1434 else state=4; // temperate layer with positive thickness
[18612]1435 }
1436
1437 _assert_(state>=0);
1438 return state;
1439}/*}}}*/
[18930]1440IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
[18612]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}/*}}}*/
[18930]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){/*{{{*/
[18612]1453
[18930]1454 bool converged;
1455 int i,rheology_law;
1456 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
[21382]1457 IssmDouble n=3.0;
[18930]1458 int *doflist = NULL;
1459 IssmDouble *xyz_list = NULL;
[16888]1460
[18930]1461 /*Fetch number of nodes and dof for this finite element*/
1462 int numnodes = element->GetNumberOfNodes();
[16888]1463
[18930]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);
[16888]1472
[18930]1473 /*Use the dof list to index into the solution vector: */
1474 for(i=0;i<numnodes;i++){
1475 values[i]=solution[doflist[i]];
[16888]1476
[18930]1477 /*Check solution*/
1478 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
[20669]1479 if(xIsInf<IssmDouble>(values[i])) _error_("Inf found in solution vector");
[16888]1480 }
1481
[18930]1482 /*Get all inputs and parameters*/
[21382]1483 if(element->material->ObjectEnum()!=MatestarEnum) n=element->GetMaterialParameter(MaterialsRheologyNEnum);
[18930]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;
[21377]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;
[18930]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;
[20625]1512 case CuffeyTemperateEnum:
[21382]1513 for(i=0;i<numnodes;i++) B[i]=CuffeyTemperate(temperature[i], waterfraction[i],n);
[20625]1514 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1515 break;
[18930]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);
[21382]1522 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],n);
[18930]1523 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1524 break;
1525 case LliboutryDuvalEnum:
[21382]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));
[18930]1527 element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
1528 break;
1529 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
1530 }
[16888]1531 }
1532 else{
[18930]1533 element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
[16888]1534 }
1535
[18930]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){/*{{{*/
[16888]1547
[18930]1548 /*Intermediaries*/
1549 bool computebasalmeltingrates=true;
1550 bool drainicecolumn=true;
1551 IssmDouble dt;
1552
1553 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
1554
[21161]1555 if(drainicecolumn && (dt>0.)) DrainWaterfraction(femmodel);
[18930]1556 if(computebasalmeltingrates) ComputeBasalMeltingrate(femmodel);
1557
[17027]1558}/*}}}*/
[18930]1559IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
[16888]1560
1561 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
1562 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
1563
1564 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
1565}/*}}}*/
[18930]1566IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
[16888]1567
1568 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
1569 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
1570
1571 return meltingpoint-beta*pressure;
1572}/*}}}*/
[18930]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){/*{{{*/
[20453]1603 SetActiveNodesLSMx(femmodel);
[18930]1604}/*}}}*/
Note: See TracBrowser for help on using the repository browser.