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

Last change on this file since 16894 was 16894, checked in by Mathieu Morlighem, 11 years ago

BUG: fixing enthalpy (fabs not used in stabilization)

File size: 32.2 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
7/*Model processing*/
8int EnthalpyAnalysis::DofsPerNode(int** doflist,int meshtype,int approximation){/*{{{*/
9 return 1;
10}/*}}}*/
11void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
12
13 int numoutputs;
14 char** requestedoutputs = NULL;
15
16 parameters->AddObject(iomodel->CopyConstantObject(ThermalStabilizationEnum));
17 parameters->AddObject(iomodel->CopyConstantObject(ThermalIsenthalpyEnum));
18 parameters->AddObject(iomodel->CopyConstantObject(ThermalIsdynamicbasalspcEnum));
19
20 iomodel->FetchData(&requestedoutputs,&numoutputs,ThermalRequestedOutputsEnum);
21 parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
22 if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
23 iomodel->DeleteData(&requestedoutputs,numoutputs,ThermalRequestedOutputsEnum);
24}/*}}}*/
25void EnthalpyAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
26
27 bool dakota_analysis;
28 bool isenthalpy;
29
30 /*Now, is the model 3d? otherwise, do nothing: */
31 if(iomodel->meshtype==Mesh2DhorizontalEnum)return;
32
33 /*Is enthalpy requested?*/
34 iomodel->Constant(&isenthalpy,ThermalIsenthalpyEnum);
35 if(!isenthalpy) return;
36
37 /*Fetch data needed: */
38 iomodel->FetchData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
39
40 /*Update elements: */
41 int counter=0;
42 for(int i=0;i<iomodel->numberofelements;i++){
43 if(iomodel->my_elements[i]){
44 Element* element=(Element*)elements->GetObjectByOffset(counter);
45 element->Update(i,iomodel,analysis_counter,analysis_type,P1Enum);
46 counter++;
47 }
48 }
49
50 iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
51
52 iomodel->FetchDataToInput(elements,ThicknessEnum);
53 iomodel->FetchDataToInput(elements,SurfaceEnum);
54 iomodel->FetchDataToInput(elements,BedEnum);
55 iomodel->FetchDataToInput(elements,FrictionCoefficientEnum);
56 iomodel->FetchDataToInput(elements,FrictionPEnum);
57 iomodel->FetchDataToInput(elements,FrictionQEnum);
58 iomodel->FetchDataToInput(elements,MaskIceLevelsetEnum);
59 iomodel->FetchDataToInput(elements,MaskGroundediceLevelsetEnum);
60 iomodel->FetchDataToInput(elements,MeshElementonbedEnum);
61 iomodel->FetchDataToInput(elements,MeshElementonsurfaceEnum);
62 iomodel->FetchDataToInput(elements,FlowequationElementEquationEnum);
63 iomodel->FetchDataToInput(elements,MaterialsRheologyBEnum);
64 iomodel->FetchDataToInput(elements,MaterialsRheologyNEnum);
65 iomodel->FetchDataToInput(elements,PressureEnum);
66 iomodel->FetchDataToInput(elements,TemperatureEnum);
67 iomodel->FetchDataToInput(elements,WaterfractionEnum);
68 iomodel->FetchDataToInput(elements,EnthalpyEnum);
69 iomodel->FetchDataToInput(elements,BasalforcingsGeothermalfluxEnum);
70 iomodel->FetchDataToInput(elements,WatercolumnEnum);
71 iomodel->FetchDataToInput(elements,BasalforcingsMeltingRateEnum);
72 iomodel->FetchDataToInput(elements,VxEnum);
73 iomodel->FetchDataToInput(elements,VyEnum);
74 iomodel->FetchDataToInput(elements,VzEnum);
75 InputUpdateFromConstantx(elements,0.,VxMeshEnum);
76 InputUpdateFromConstantx(elements,0.,VyMeshEnum);
77 InputUpdateFromConstantx(elements,0.,VzMeshEnum);
78 if(dakota_analysis){
79 elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
80 elements->InputDuplicate(BasalforcingsMeltingRateEnum,QmuMeltingEnum);
81 elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
82 elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
83 elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
84 }
85
86 /*Free data: */
87 iomodel->DeleteData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
88}/*}}}*/
89void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
90
91 if(iomodel->meshtype==Mesh3DEnum) iomodel->FetchData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
92 ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,P1Enum);
93 iomodel->DeleteData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
94}/*}}}*/
95void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
96
97 /*Intermediary*/
98 int count;
99 int M,N;
100 bool spcpresent = false;
101 IssmDouble heatcapacity;
102 IssmDouble referencetemperature;
103
104 /*Output*/
105 IssmDouble *spcvector = NULL;
106 IssmDouble* times=NULL;
107 IssmDouble* values=NULL;
108
109 /*Fetch parameters: */
110 iomodel->Constant(&heatcapacity,MaterialsHeatcapacityEnum);
111 iomodel->Constant(&referencetemperature,ConstantsReferencetemperatureEnum);
112
113 /*return if 2d mesh*/
114 if(iomodel->meshtype==Mesh2DhorizontalEnum) return;
115
116 /*Fetch data: */
117 iomodel->FetchData(&spcvector,&M,&N,ThermalSpctemperatureEnum);
118
119 //FIX ME: SHOULD USE IOMODELCREATECONSTRAINTS
120 /*Transient or static?:*/
121 if(M==iomodel->numberofvertices){
122 /*static: just create Constraints objects*/
123 count=0;
124
125 for(int i=0;i<iomodel->numberofvertices;i++){
126 /*keep only this partition's nodes:*/
127 if((iomodel->my_vertices[i])){
128
129 if (!xIsNan<IssmDouble>(spcvector[i])){
130
131 constraints->AddObject(new SpcStatic(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,heatcapacity*(spcvector[i]-referencetemperature),EnthalpyAnalysisEnum));
132 count++;
133
134 }
135 }
136 }
137 }
138 else if (M==(iomodel->numberofvertices+1)){
139 /*transient: create transient SpcTransient objects. Same logic, except we need to retrieve
140 * various times and values to initialize an SpcTransient object: */
141 count=0;
142
143 /*figure out times: */
144 times=xNew<IssmDouble>(N);
145 for(int j=0;j<N;j++){
146 times[j]=spcvector[(M-1)*N+j];
147 }
148
149 /*Create constraints from x,y,z: */
150 for(int i=0;i<iomodel->numberofvertices;i++){
151
152 /*keep only this partition's nodes:*/
153 if((iomodel->my_vertices[i])){
154
155 /*figure out times and values: */
156 values=xNew<IssmDouble>(N);
157 spcpresent=false;
158 for(int j=0;j<N;j++){
159 values[j]=heatcapacity*(spcvector[i*N+j]-referencetemperature);
160 if(!xIsNan<IssmDouble>(values[j]))spcpresent=true; //NaN means no spc by default
161 }
162
163 if(spcpresent){
164 constraints->AddObject(new SpcTransient(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,N,times,values,EnthalpyAnalysisEnum));
165 count++;
166 }
167 xDelete<IssmDouble>(values);
168 }
169 }
170 }
171 else{
172 _error_("Size of field " << EnumToStringx(ThermalSpctemperatureEnum) << " not supported");
173 }
174
175 /*Free ressources:*/
176 iomodel->DeleteData(spcvector,ThermalSpctemperatureEnum);
177 xDelete<IssmDouble>(times);
178 xDelete<IssmDouble>(values);
179}/*}}}*/
180void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
181
182 /*No loads */
183}/*}}}*/
184
185/*Finite Element Analysis*/
186ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
187
188 /*compute all stiffness matrices for this element*/
189 ElementMatrix* Ke1=CreateKMatrixVolume(element);
190 ElementMatrix* Ke2=CreateKMatrixShelf(element);
191 ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
192
193 /*clean-up and return*/
194 delete Ke1;
195 delete Ke2;
196 return Ke;
197}/*}}}*/
198ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
199
200 /*Intermediaries */
201 int stabilization;
202 IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
203 IssmDouble h,hx,hy,hz,vx,vy,vz;
204 IssmDouble tau_parameter,diameter;
205 IssmDouble D_scalar;
206 IssmDouble* xyz_list = NULL;
207
208 /*Fetch number of nodes and dof for this finite element*/
209 int numnodes = element->GetNumberOfNodes();
210
211 /*Initialize Element vector and other vectors*/
212 ElementMatrix* Ke = element->NewElementMatrix();
213 IssmDouble* basis = xNew<IssmDouble>(numnodes);
214 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
215 IssmDouble* B = xNew<IssmDouble>(3*numnodes);
216 IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
217 IssmDouble D[3][3] = {0.};
218 IssmDouble K[3][3];
219
220 /*Retrieve all inputs and parameters*/
221 element->GetVerticesCoordinates(&xyz_list);
222 element->FindParam(&dt,TimesteppingTimeStepEnum);
223 element->FindParam(&stabilization,ThermalStabilizationEnum);
224 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
225 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
226 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
227 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
228 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
229 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
230 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
231 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
232 Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
233 Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
234 Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
235 if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
236
237 /*Enthalpy diffusion parameter*/
238 IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element); _assert_(kappa>0.);
239
240 /* Start looping on the number of gaussian points: */
241 Gauss* gauss=element->NewGauss(2);
242 for(int ig=gauss->begin();ig<gauss->end();ig++){
243 gauss->GaussPoint(ig);
244
245 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
246 D_scalar=gauss->weight*Jdet;
247 if(dt!=0.) D_scalar=D_scalar*dt;
248
249 /*Conduction: */
250 GetBConduct(B,element,xyz_list,gauss);
251 D[0][0]=D_scalar*kappa/rho_ice;
252 D[1][1]=D_scalar*kappa/rho_ice;
253 D[2][2]=D_scalar*kappa/rho_ice;
254 TripleMultiply(B,3,numnodes,1,
255 &D[0][0],3,3,0,
256 B,3,numnodes,0,
257 &Ke->values[0],1);
258
259 /*Advection: */
260 GetBAdvec(B,element,xyz_list,gauss);
261 GetBAdvecprime(Bprime,element,xyz_list,gauss);
262 vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
263 vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
264 vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
265 D[0][0]=D_scalar*vx;
266 D[1][1]=D_scalar*vy;
267 D[2][2]=D_scalar*vz;
268 TripleMultiply(B,3,numnodes,1,
269 &D[0][0],3,3,0,
270 Bprime,3,numnodes,0,
271 &Ke->values[0],1);
272
273 /*Transient: */
274 if(dt!=0.){
275 D_scalar=gauss->weight*Jdet;
276 element->NodalFunctions(basis,gauss);
277 TripleMultiply(basis,numnodes,1,0,
278 &D_scalar,1,1,0,
279 basis,1,numnodes,0,
280 &Ke->values[0],1);
281 D_scalar=D_scalar*dt;
282 }
283
284 /*Artifficial diffusivity*/
285 if(stabilization==1){
286 element->ElementSizes(&hx,&hy,&hz);
287 vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
288 h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
289 K[0][0]=h/(2.*vel)*vx*vx; K[0][1]=h/(2.*vel)*vx*vy; K[0][2]=h/(2.*vel)*vx*vz;
290 K[1][0]=h/(2.*vel)*vy*vx; K[1][1]=h/(2.*vel)*vy*vy; K[1][2]=h/(2.*vel)*vy*vz;
291 K[2][0]=h/(2.*vel)*vz*vx; K[2][1]=h/(2.*vel)*vz*vy; K[2][2]=h/(2.*vel)*vz*vz;
292 for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
293
294 GetBAdvecprime(Bprime,element,xyz_list,gauss);
295 TripleMultiply(Bprime,3,numnodes,1,
296 &K[0][0],3,3,0,
297 Bprime,3,numnodes,0,
298 &Ke->values[0],1);
299 }
300 else if(stabilization==2){
301 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
302 tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
303 for(int i=0;i<numnodes;i++){
304 for(int j=0;j<numnodes;j++){
305 Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
306 ((u-um)*dbasis[0*3+i]+(v-vm)*dbasis[1*3+i]+(w-wm)*dbasis[2*3+i])*((u-um)*dbasis[0*3+j]+(v-vm)*dbasis[1*3+j]+(w-wm)*dbasis[2*3+j]);
307 }
308 }
309 if(dt!=0.){
310 for(int i=0;i<numnodes;i++){
311 for(int j=0;j<numnodes;j++){
312 Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*basis[j]*((u-um)*dbasis[0*3+i]+(v-vm)*dbasis[1*3+i]+(w-wm)*dbasis[2*3+i]);
313 }
314 }
315 }
316 }
317 }
318
319 /*Clean up and return*/
320 xDelete<IssmDouble>(xyz_list);
321 xDelete<IssmDouble>(basis);
322 xDelete<IssmDouble>(dbasis);
323 xDelete<IssmDouble>(B);
324 xDelete<IssmDouble>(Bprime);
325 delete gauss;
326 return Ke;
327}/*}}}*/
328ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
329
330 /*Initialize Element matrix and return if necessary*/
331 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
332
333 IssmDouble dt,Jdet,D;
334 IssmDouble *xyz_list_base = NULL;
335
336 /*Get basal element*/
337 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
338
339 /*Fetch number of nodes for this finite element*/
340 int numnodes = element->GetNumberOfNodes();
341
342 /*Initialize vectors*/
343 ElementMatrix* Ke = element->NewElementMatrix();
344 IssmDouble* basis = xNew<IssmDouble>(numnodes);
345
346 /*Retrieve all inputs and parameters*/
347 element->GetVerticesCoordinatesBase(&xyz_list_base);
348 element->FindParam(&dt,TimesteppingTimeStepEnum);
349 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
350 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
351 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
352 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
353 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
354 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
355
356 /* Start looping on the number of gaussian points: */
357 Gauss* gauss=element->NewGaussBase(2);
358 for(int ig=gauss->begin();ig<gauss->end();ig++){
359 gauss->GaussPoint(ig);
360
361 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
362 element->NodalFunctions(basis,gauss);
363
364 D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
365 if(reCast<bool,IssmDouble>(dt)) D=dt*D;
366 TripleMultiply(basis,numnodes,1,0,
367 &D,1,1,0,
368 basis,1,numnodes,0,
369 &Ke->values[0],1);
370
371 }
372
373 /*Clean up and return*/
374 delete gauss;
375 xDelete<IssmDouble>(basis);
376 xDelete<IssmDouble>(xyz_list_base);
377 return Ke;
378}/*}}}*/
379ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
380
381 /*compute all load vectors for this element*/
382 ElementVector* pe1=CreatePVectorVolume(element);
383 ElementVector* pe2=CreatePVectorSheet(element);
384 ElementVector* pe3=CreatePVectorShelf(element);
385 ElementVector* pe =new ElementVector(pe1,pe2,pe3);
386
387 /*clean-up and return*/
388 delete pe1;
389 delete pe2;
390 delete pe3;
391 return pe;
392}/*}}}*/
393ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
394
395 /*Intermediaries*/
396 int stabilization;
397 IssmDouble Jdet,phi,dt;
398 IssmDouble enthalpy;
399 IssmDouble kappa,tau_parameter,diameter;
400 IssmDouble u,v,w;
401 IssmDouble scalar_def,scalar_transient;
402 IssmDouble* xyz_list = NULL;
403
404 /*Fetch number of nodes and dof for this finite element*/
405 int numnodes = element->GetNumberOfNodes();
406 int numvertices = element->GetNumberOfVertices();
407
408 /*Initialize Element vector*/
409 ElementVector* pe = element->NewElementVector();
410 IssmDouble* basis = xNew<IssmDouble>(numnodes);
411 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
412 IssmDouble* pressure = xNew<IssmDouble>(numvertices);
413 IssmDouble* enthalpypicard = xNew<IssmDouble>(numvertices);
414
415 /*Retrieve all inputs and parameters*/
416 element->GetVerticesCoordinates(&xyz_list);
417 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
418 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
419 element->FindParam(&dt,TimesteppingTimeStepEnum);
420 element->FindParam(&stabilization,ThermalStabilizationEnum);
421 Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
422 Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
423 Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
424 Input* enthalpy_input = NULL;
425 if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
426 if(stabilization==2){
427 element->GetInputListOnVertices(enthalpypicard,EnthalpyPicardEnum);
428 element->GetInputListOnVertices(pressure,PressureEnum);
429 diameter=element->MinEdgeLength(xyz_list);
430 }
431
432 /* Start looping on the number of gaussian points: */
433 Gauss* gauss=element->NewGauss(3);
434 for(int ig=gauss->begin();ig<gauss->end();ig++){
435 gauss->GaussPoint(ig);
436
437 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
438 element->NodalFunctions(basis,gauss);
439 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
440
441 scalar_def=phi/rho_ice*Jdet*gauss->weight;
442 if(reCast<bool,IssmDouble>(dt)) scalar_def=scalar_def*dt;
443
444 /*TODO: add -beta*laplace T_m(p)*/
445 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
446
447 /* Build transient now */
448 if(reCast<bool,IssmDouble>(dt)){
449 enthalpy_input->GetInputValue(&enthalpy, gauss);
450 scalar_transient=enthalpy*Jdet*gauss->weight;
451 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
452 }
453
454 if(stabilization==2){
455 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
456
457 vx_input->GetInputValue(&u,gauss);
458 vy_input->GetInputValue(&v,gauss);
459 vz_input->GetInputValue(&w,gauss);
460 kappa = element->EnthalpyDiffusionParameterVolume(numvertices,enthalpypicard,pressure) / rho_ice;
461 tau_parameter = element->StabilizationParameter(u,v,w,diameter,kappa);
462
463 for(int i=0;i<numnodes;i++) pe->values[i]+=tau_parameter*scalar_def*(u*dbasis[0*3+i]+v*dbasis[1*3+i]+w*dbasis[2*3+i]);
464 if(reCast<bool,IssmDouble>(dt)){
465 for(int i=0;i<numnodes;i++) pe->values[i]+=tau_parameter*scalar_transient*(u*dbasis[0*3+i]+v*dbasis[1*3+i]+w*dbasis[2*3+i]);
466 }
467 }
468 }
469
470 /*Clean up and return*/
471 xDelete<IssmDouble>(basis);
472 xDelete<IssmDouble>(dbasis);
473 xDelete<IssmDouble>(pressure);
474 xDelete<IssmDouble>(enthalpypicard);
475 xDelete<IssmDouble>(xyz_list);
476 delete gauss;
477 return pe;
478
479}/*}}}*/
480ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
481
482 /* Geothermal flux on ice sheet base and basal friction */
483 if(!element->IsOnBed() || element->IsFloating()) return NULL;
484
485 IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
486 IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
487 IssmDouble *xyz_list_base = NULL;
488
489 /*Fetch number of nodes for this finite element*/
490 int numnodes = element->GetNumberOfNodes();
491
492 /*Initialize vectors*/
493 ElementVector* pe = element->NewElementVector();
494 IssmDouble* basis = xNew<IssmDouble>(numnodes);
495
496 /*Retrieve all inputs and parameters*/
497 element->GetVerticesCoordinatesBase(&xyz_list_base);
498 element->FindParam(&dt,TimesteppingTimeStepEnum);
499 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
500 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
501 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
502 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
503 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
504 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
505 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
506 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
507 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
508
509 /*Build friction element, needed later: */
510 Friction* friction=new Friction(element,3);
511
512 /* Start looping on the number of gaussian points: */
513 Gauss* gauss = element->NewGaussBase(2);
514 Gauss* gaussup = element->NewGaussTop(2);
515 for(int ig=gauss->begin();ig<gauss->end();ig++){
516 gauss->GaussPoint(ig);
517
518 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
519 element->NodalFunctions(basis,gauss);
520
521 enthalpy_input->GetInputValue(&enthalpy,gauss);
522 pressure_input->GetInputValue(&pressure,gauss);
523 watercolumn_input->GetInputValue(&watercolumn,gauss);
524
525 if((watercolumn<=0.) && (enthalpy < PureIceEnthalpy(element,pressure))){
526 /* the above check is equivalent to
527 NOT ((watercolumn>0.) AND (enthalpy<PIE)) AND (enthalpy<PIE)*/
528 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
529
530 friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
531 vx_input->GetInputValue(&vx,gauss);
532 vy_input->GetInputValue(&vy,gauss);
533 vz_input->GetInputValue(&vz,gauss);
534 basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
535 heatflux = (basalfriction+geothermalflux)/(rho_ice);
536
537 scalar = gauss->weight*Jdet*heatflux;
538 if(dt!=0.) scalar=dt*scalar;
539
540 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
541 }
542 else if(enthalpy >= PureIceEnthalpy(element,pressure)){
543 /* check positive thickness of temperate basal ice layer */
544 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
545 pressure_input->GetInputValue(&pressureup,gaussup);
546 if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
547 // TODO: temperate ice has positive thickness: grad enthalpy*n=0.
548 }
549 else{
550 // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
551 }
552 }
553 else{
554 // base cold, but watercolumn positive. Set base to h_pmp.
555 }
556 }
557
558 /*Clean up and return*/
559 delete gauss;
560 delete gaussup;
561 delete friction;
562 xDelete<IssmDouble>(basis);
563 xDelete<IssmDouble>(xyz_list_base);
564 return pe;
565
566}/*}}}*/
567ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
568
569 /*Get basal element*/
570 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
571
572 IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
573 IssmDouble *xyz_list_base = NULL;
574
575 /*Fetch number of nodes for this finite element*/
576 int numnodes = element->GetNumberOfNodes();
577
578 /*Initialize vectors*/
579 ElementVector* pe = element->NewElementVector();
580 IssmDouble* basis = xNew<IssmDouble>(numnodes);
581
582 /*Retrieve all inputs and parameters*/
583 element->GetVerticesCoordinatesBase(&xyz_list_base);
584 element->FindParam(&dt,TimesteppingTimeStepEnum);
585 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
586 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
587 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
588 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
589 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
590 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
591 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
592
593 /* Start looping on the number of gaussian points: */
594 Gauss* gauss=element->NewGaussBase(2);
595 for(int ig=gauss->begin();ig<gauss->end();ig++){
596 gauss->GaussPoint(ig);
597
598 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
599 element->NodalFunctions(basis,gauss);
600
601 pressure_input->GetInputValue(&pressure,gauss);
602 h_pmp=element->PureIceEnthalpy(pressure);
603
604 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
605 if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
606
607 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
608 }
609
610 /*Clean up and return*/
611 delete gauss;
612 xDelete<IssmDouble>(basis);
613 xDelete<IssmDouble>(xyz_list_base);
614 return pe;
615}/*}}}*/
616void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
617 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
618 * For node i, Bi' can be expressed in the actual coordinate system
619 * by:
620 * Bi_conduct=[ dh/dx ]
621 * [ dh/dy ]
622 * [ dh/dz ]
623 * where h is the interpolation function for node i.
624 *
625 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
626 */
627
628 /*Fetch number of nodes for this finite element*/
629 int numnodes = element->GetNumberOfNodes();
630
631 /*Get nodal functions derivatives*/
632 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
633 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
634
635 /*Build B: */
636 for(int i=0;i<numnodes;i++){
637 B[numnodes*0+i] = dbasis[0*numnodes+i];
638 B[numnodes*1+i] = dbasis[1*numnodes+i];
639 B[numnodes*2+i] = dbasis[2*numnodes+i];
640 }
641
642 /*Clean-up*/
643 xDelete<IssmDouble>(dbasis);
644}/*}}}*/
645void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
646 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
647 * For node i, Bi' can be expressed in the actual coordinate system
648 * by:
649 * Bi_advec =[ h ]
650 * [ h ]
651 * [ h ]
652 * where h is the interpolation function for node i.
653 *
654 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
655 */
656
657 /*Fetch number of nodes for this finite element*/
658 int numnodes = element->GetNumberOfNodes();
659
660 /*Get nodal functions*/
661 IssmDouble* basis=xNew<IssmDouble>(numnodes);
662 element->NodalFunctions(basis,gauss);
663
664 /*Build B: */
665 for(int i=0;i<numnodes;i++){
666 B[numnodes*0+i] = basis[i];
667 B[numnodes*1+i] = basis[i];
668 B[numnodes*2+i] = basis[i];
669 }
670
671 /*Clean-up*/
672 xDelete<IssmDouble>(basis);
673}/*}}}*/
674void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
675 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
676 * For node i, Bi' can be expressed in the actual coordinate system
677 * by:
678 * Biprime_advec=[ dh/dx ]
679 * [ dh/dy ]
680 * [ dh/dz ]
681 * where h is the interpolation function for node i.
682 *
683 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
684 */
685
686 /*Fetch number of nodes for this finite element*/
687 int numnodes = element->GetNumberOfNodes();
688
689 /*Get nodal functions derivatives*/
690 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
691 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
692
693 /*Build B: */
694 for(int i=0;i<numnodes;i++){
695 B[numnodes*0+i] = dbasis[0*numnodes+i];
696 B[numnodes*1+i] = dbasis[1*numnodes+i];
697 B[numnodes*2+i] = dbasis[2*numnodes+i];
698 }
699
700 /*Clean-up*/
701 xDelete<IssmDouble>(dbasis);
702}/*}}}*/
703void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
704 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
705}/*}}}*/
706void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
707
708 bool converged;
709 int i,rheology_law;
710 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
711 int *doflist = NULL;
712 IssmDouble *xyz_list = NULL;
713
714 /*Fetch number of nodes and dof for this finite element*/
715 int numnodes = element->GetNumberOfNodes();
716
717 /*Fetch dof list and allocate solution vector*/
718 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
719 IssmDouble* values = xNew<IssmDouble>(numnodes);
720 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
721 IssmDouble* surface = xNew<IssmDouble>(numnodes);
722 IssmDouble* B = xNew<IssmDouble>(numnodes);
723 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
724 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
725
726 /*Use the dof list to index into the solution vector: */
727 for(i=0;i<numnodes;i++){
728 values[i]=solution[doflist[i]];
729
730 /*Check solution*/
731 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
732 }
733
734 /*Get all inputs and parameters*/
735 element->GetInputValue(&converged,ConvergedEnum);
736 element->GetInputListOnNodes(&pressure[0],PressureEnum);
737 if(converged){
738 for(i=0;i<numnodes;i++){
739 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
740 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
741 if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
742 }
743 element->AddInput(EnthalpyEnum,values,P1Enum);
744 element->AddInput(WaterfractionEnum,waterfraction,P1Enum);
745 element->AddInput(TemperatureEnum,temperature,P1Enum);
746
747 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
748 * otherwise the rheology could be negative*/
749 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
750 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
751 switch(rheology_law){
752 case NoneEnum:
753 /*Do nothing: B is not temperature dependent*/
754 break;
755 case PatersonEnum:
756 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
757 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
758 break;
759 case ArrheniusEnum:
760 element->GetVerticesCoordinates(&xyz_list);
761 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
762 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
763 break;
764 case LliboutryDuvalEnum:
765 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));
766 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
767 break;
768 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
769 }
770 }
771 else{
772 element->AddInput(EnthalpyPicardEnum,values,P1Enum);
773 }
774
775 /*Free ressources:*/
776 xDelete<IssmDouble>(values);
777 xDelete<IssmDouble>(pressure);
778 xDelete<IssmDouble>(surface);
779 xDelete<IssmDouble>(B);
780 xDelete<IssmDouble>(temperature);
781 xDelete<IssmDouble>(waterfraction);
782 xDelete<IssmDouble>(xyz_list);
783 xDelete<int>(doflist);
784}/*}}}*/
785
786/*Intermediaries*/
787IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
788
789 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
790 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
791 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
792
793 if(enthalpy < PureIceEnthalpy(element,pressure)){
794 return thermalconductivity/heatcapacity;
795 }
796 else{
797 return temperateiceconductivity/heatcapacity;
798 }
799}/*}}}*/
800IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element){/*{{{*/
801
802 int iv;
803 IssmDouble lambda; /* fraction of cold ice */
804 IssmDouble kappa ,kappa_c,kappa_t; /* enthalpy conductivities */
805 IssmDouble Hc,Ht;
806
807
808 /*Get pressures and enthalpies on vertices*/
809 int numvertices = element->GetNumberOfVertices();
810 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
811 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
812 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
813 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
814 element->GetInputListOnVertices(pressures,PressureEnum);
815 element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
816 for(iv=0;iv<numvertices;iv++){
817 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
818 dHpmp[iv] = enthalpies[iv]-PIE[iv];
819 }
820
821 bool allequalsign = true;
822 if(dHpmp[0]<0.){
823 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
824 }
825 else{
826 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
827 }
828
829 if(allequalsign){
830 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
831 }
832 else{
833 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
834 cf Patankar 1980, pp44 */
835 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
836 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
837 Hc=0.; Ht=0.;
838 for(iv=0; iv<numvertices;iv++){
839 if(enthalpies[iv]<PIE[iv])
840 Hc+=(PIE[iv]-enthalpies[iv]);
841 else
842 Ht+=(enthalpies[iv]-PIE[iv]);
843 }
844 _assert_((Hc+Ht)>0.);
845 lambda = Hc/(Hc+Ht);
846 kappa = 1./(lambda/kappa_c + (1.-lambda)/kappa_t);
847 }
848
849 /*Clean up and return*/
850 xDelete<IssmDouble>(PIE);
851 xDelete<IssmDouble>(dHpmp);
852 xDelete<IssmDouble>(pressures);
853 xDelete<IssmDouble>(enthalpies);
854 return kappa;
855}
856/*}}}*/
857IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
858
859 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
860 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
861
862 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
863}/*}}}*/
864IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
865
866 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
867 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
868
869 return meltingpoint-beta*pressure;
870}/*}}}*/
Note: See TracBrowser for help on using the repository browser.