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

Last change on this file since 20155 was 20155, checked in by Eric.Larour, 9 years ago

CHG: introducing sealevel in all the analyses.

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