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

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

CHG: Enthalpy, dynamic basal boundary conditions (steady state): allow no refreeze, since this prevents SS solver from converging

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