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

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

CHG: fixed Enthalpy

File size: 32.0 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,EnthalpyEnum); _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*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]);
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*numnodes+i]+(v-vm)*dbasis[1*numnodes+i]+(w-wm)*dbasis[2*numnodes+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
413 /*Retrieve all inputs and parameters*/
414 element->GetVerticesCoordinates(&xyz_list);
415 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
416 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
417 element->FindParam(&dt,TimesteppingTimeStepEnum);
418 element->FindParam(&stabilization,ThermalStabilizationEnum);
419 Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
420 Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
421 Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
422 Input* enthalpy_input = NULL;
423 if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
424 if(stabilization==2){
425 diameter=element->MinEdgeLength(xyz_list);
426 kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>0.);
427 }
428
429 /* Start looping on the number of gaussian points: */
430 Gauss* gauss=element->NewGauss(2);
431 for(int ig=gauss->begin();ig<gauss->end();ig++){
432 gauss->GaussPoint(ig);
433
434 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
435 element->NodalFunctions(basis,gauss);
436 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
437
438 scalar_def=phi/rho_ice*Jdet*gauss->weight;
439 if(dt!=0.) scalar_def=scalar_def*dt;
440
441 /*TODO: add -beta*laplace T_m(p)*/
442 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
443
444 /* Build transient now */
445 if(reCast<bool,IssmDouble>(dt)){
446 enthalpy_input->GetInputValue(&enthalpy, gauss);
447 scalar_transient=enthalpy*Jdet*gauss->weight;
448 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
449 }
450
451 if(stabilization==2){
452 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
453
454 vx_input->GetInputValue(&u,gauss);
455 vy_input->GetInputValue(&v,gauss);
456 vz_input->GetInputValue(&w,gauss);
457 tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
458
459 for(int 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]);
460
461 if(dt!=0.){
462 for(int 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]);
463 }
464 }
465 }
466
467 /*Clean up and return*/
468 xDelete<IssmDouble>(basis);
469 xDelete<IssmDouble>(dbasis);
470 xDelete<IssmDouble>(xyz_list);
471 delete gauss;
472 return pe;
473
474}/*}}}*/
475ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
476
477 /* Geothermal flux on ice sheet base and basal friction */
478 if(!element->IsOnBed() || element->IsFloating()) return NULL;
479
480 IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
481 IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
482 IssmDouble *xyz_list_base = NULL;
483
484 /*Fetch number of nodes for this finite element*/
485 int numnodes = element->GetNumberOfNodes();
486
487 /*Initialize vectors*/
488 ElementVector* pe = element->NewElementVector();
489 IssmDouble* basis = xNew<IssmDouble>(numnodes);
490
491 /*Retrieve all inputs and parameters*/
492 element->GetVerticesCoordinatesBase(&xyz_list_base);
493 element->FindParam(&dt,TimesteppingTimeStepEnum);
494 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
495 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
496 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
497 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
498 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
499 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
500 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
501 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
502 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
503
504 /*Build friction element, needed later: */
505 Friction* friction=new Friction(element,3);
506
507 /* Start looping on the number of gaussian points: */
508 Gauss* gauss = element->NewGaussBase(2);
509 Gauss* gaussup = element->NewGaussTop(2);
510 for(int ig=gauss->begin();ig<gauss->end();ig++){
511 gauss->GaussPoint(ig);
512
513 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
514 element->NodalFunctions(basis,gauss);
515
516 enthalpy_input->GetInputValue(&enthalpy,gauss);
517 pressure_input->GetInputValue(&pressure,gauss);
518 watercolumn_input->GetInputValue(&watercolumn,gauss);
519
520 if((watercolumn<=0.) && (enthalpy < PureIceEnthalpy(element,pressure))){
521 /* the above check is equivalent to
522 NOT ((watercolumn>0.) AND (enthalpy<PIE)) AND (enthalpy<PIE)*/
523 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
524
525 friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
526 vx_input->GetInputValue(&vx,gauss);
527 vy_input->GetInputValue(&vy,gauss);
528 vz_input->GetInputValue(&vz,gauss);
529 basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
530 heatflux = (basalfriction+geothermalflux)/(rho_ice);
531
532 scalar = gauss->weight*Jdet*heatflux;
533 if(dt!=0.) scalar=dt*scalar;
534
535 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
536 }
537 else if(enthalpy >= PureIceEnthalpy(element,pressure)){
538 /* check positive thickness of temperate basal ice layer */
539 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
540 pressure_input->GetInputValue(&pressureup,gaussup);
541 if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
542 // TODO: temperate ice has positive thickness: grad enthalpy*n=0.
543 }
544 else{
545 // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
546 }
547 }
548 else{
549 // base cold, but watercolumn positive. Set base to h_pmp.
550 }
551 }
552
553 /*Clean up and return*/
554 delete gauss;
555 delete gaussup;
556 delete friction;
557 xDelete<IssmDouble>(basis);
558 xDelete<IssmDouble>(xyz_list_base);
559 return pe;
560
561}/*}}}*/
562ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
563
564 /*Get basal element*/
565 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
566
567 IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
568 IssmDouble *xyz_list_base = NULL;
569
570 /*Fetch number of nodes for this finite element*/
571 int numnodes = element->GetNumberOfNodes();
572
573 /*Initialize vectors*/
574 ElementVector* pe = element->NewElementVector();
575 IssmDouble* basis = xNew<IssmDouble>(numnodes);
576
577 /*Retrieve all inputs and parameters*/
578 element->GetVerticesCoordinatesBase(&xyz_list_base);
579 element->FindParam(&dt,TimesteppingTimeStepEnum);
580 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
581 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
582 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
583 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
584 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
585 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
586 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
587
588 /* Start looping on the number of gaussian points: */
589 Gauss* gauss=element->NewGaussBase(2);
590 for(int ig=gauss->begin();ig<gauss->end();ig++){
591 gauss->GaussPoint(ig);
592
593 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
594 element->NodalFunctions(basis,gauss);
595
596 pressure_input->GetInputValue(&pressure,gauss);
597 h_pmp=element->PureIceEnthalpy(pressure);
598
599 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
600 if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
601
602 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
603 }
604
605 /*Clean up and return*/
606 delete gauss;
607 xDelete<IssmDouble>(basis);
608 xDelete<IssmDouble>(xyz_list_base);
609 return pe;
610}/*}}}*/
611void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
612 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
613 * For node i, Bi' can be expressed in the actual coordinate system
614 * by:
615 * Bi_conduct=[ dh/dx ]
616 * [ dh/dy ]
617 * [ dh/dz ]
618 * where h is the interpolation function for node i.
619 *
620 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
621 */
622
623 /*Fetch number of nodes for this finite element*/
624 int numnodes = element->GetNumberOfNodes();
625
626 /*Get nodal functions derivatives*/
627 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
628 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
629
630 /*Build B: */
631 for(int i=0;i<numnodes;i++){
632 B[numnodes*0+i] = dbasis[0*numnodes+i];
633 B[numnodes*1+i] = dbasis[1*numnodes+i];
634 B[numnodes*2+i] = dbasis[2*numnodes+i];
635 }
636
637 /*Clean-up*/
638 xDelete<IssmDouble>(dbasis);
639}/*}}}*/
640void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
641 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
642 * For node i, Bi' can be expressed in the actual coordinate system
643 * by:
644 * Bi_advec =[ h ]
645 * [ h ]
646 * [ h ]
647 * where h is the interpolation function for node i.
648 *
649 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
650 */
651
652 /*Fetch number of nodes for this finite element*/
653 int numnodes = element->GetNumberOfNodes();
654
655 /*Get nodal functions*/
656 IssmDouble* basis=xNew<IssmDouble>(numnodes);
657 element->NodalFunctions(basis,gauss);
658
659 /*Build B: */
660 for(int i=0;i<numnodes;i++){
661 B[numnodes*0+i] = basis[i];
662 B[numnodes*1+i] = basis[i];
663 B[numnodes*2+i] = basis[i];
664 }
665
666 /*Clean-up*/
667 xDelete<IssmDouble>(basis);
668}/*}}}*/
669void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
670 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
671 * For node i, Bi' can be expressed in the actual coordinate system
672 * by:
673 * Biprime_advec=[ dh/dx ]
674 * [ dh/dy ]
675 * [ dh/dz ]
676 * where h is the interpolation function for node i.
677 *
678 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
679 */
680
681 /*Fetch number of nodes for this finite element*/
682 int numnodes = element->GetNumberOfNodes();
683
684 /*Get nodal functions derivatives*/
685 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
686 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
687
688 /*Build B: */
689 for(int i=0;i<numnodes;i++){
690 B[numnodes*0+i] = dbasis[0*numnodes+i];
691 B[numnodes*1+i] = dbasis[1*numnodes+i];
692 B[numnodes*2+i] = dbasis[2*numnodes+i];
693 }
694
695 /*Clean-up*/
696 xDelete<IssmDouble>(dbasis);
697}/*}}}*/
698void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
699 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
700}/*}}}*/
701void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
702
703 bool converged;
704 int i,rheology_law;
705 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
706 int *doflist = NULL;
707 IssmDouble *xyz_list = NULL;
708
709 /*Fetch number of nodes and dof for this finite element*/
710 int numnodes = element->GetNumberOfNodes();
711
712 /*Fetch dof list and allocate solution vector*/
713 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
714 IssmDouble* values = xNew<IssmDouble>(numnodes);
715 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
716 IssmDouble* surface = xNew<IssmDouble>(numnodes);
717 IssmDouble* B = xNew<IssmDouble>(numnodes);
718 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
719 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
720
721 /*Use the dof list to index into the solution vector: */
722 for(i=0;i<numnodes;i++){
723 values[i]=solution[doflist[i]];
724
725 /*Check solution*/
726 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
727 }
728
729 /*Get all inputs and parameters*/
730 element->GetInputValue(&converged,ConvergedEnum);
731 element->GetInputListOnNodes(&pressure[0],PressureEnum);
732 if(converged){
733 for(i=0;i<numnodes;i++){
734 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
735 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
736 if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
737 }
738 element->AddInput(EnthalpyEnum,values,P1Enum);
739 element->AddInput(WaterfractionEnum,waterfraction,P1Enum);
740 element->AddInput(TemperatureEnum,temperature,P1Enum);
741
742 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
743 * otherwise the rheology could be negative*/
744 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
745 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
746 switch(rheology_law){
747 case NoneEnum:
748 /*Do nothing: B is not temperature dependent*/
749 break;
750 case PatersonEnum:
751 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
752 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
753 break;
754 case ArrheniusEnum:
755 element->GetVerticesCoordinates(&xyz_list);
756 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
757 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
758 break;
759 case LliboutryDuvalEnum:
760 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));
761 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
762 break;
763 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
764 }
765 }
766 else{
767 element->AddInput(EnthalpyPicardEnum,values,P1Enum);
768 }
769
770 /*Free ressources:*/
771 xDelete<IssmDouble>(values);
772 xDelete<IssmDouble>(pressure);
773 xDelete<IssmDouble>(surface);
774 xDelete<IssmDouble>(B);
775 xDelete<IssmDouble>(temperature);
776 xDelete<IssmDouble>(waterfraction);
777 xDelete<IssmDouble>(xyz_list);
778 xDelete<int>(doflist);
779}/*}}}*/
780
781/*Intermediaries*/
782IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
783
784 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
785 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
786 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
787
788 if(enthalpy < PureIceEnthalpy(element,pressure)){
789 return thermalconductivity/heatcapacity;
790 }
791 else{
792 return temperateiceconductivity/heatcapacity;
793 }
794}/*}}}*/
795IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
796
797 int iv;
798 IssmDouble lambda; /* fraction of cold ice */
799 IssmDouble kappa ,kappa_c,kappa_t; /* enthalpy conductivities */
800 IssmDouble Hc,Ht;
801
802
803 /*Get pressures and enthalpies on vertices*/
804 int numvertices = element->GetNumberOfVertices();
805 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
806 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
807 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
808 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
809 element->GetInputListOnVertices(pressures,PressureEnum);
810 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
811 for(iv=0;iv<numvertices;iv++){
812 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
813 dHpmp[iv] = enthalpies[iv]-PIE[iv];
814 }
815
816 bool allequalsign = true;
817 if(dHpmp[0]<0.){
818 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
819 }
820 else{
821 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
822 }
823
824 if(allequalsign){
825 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
826 }
827 else{
828 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
829 cf Patankar 1980, pp44 */
830 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
831 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
832 Hc=0.; Ht=0.;
833 for(iv=0; iv<numvertices;iv++){
834 if(enthalpies[iv]<PIE[iv])
835 Hc+=(PIE[iv]-enthalpies[iv]);
836 else
837 Ht+=(enthalpies[iv]-PIE[iv]);
838 }
839 _assert_((Hc+Ht)>0.);
840 lambda = Hc/(Hc+Ht);
841 kappa = 1./(lambda/kappa_c + (1.-lambda)/kappa_t);
842 }
843
844 /*Clean up and return*/
845 xDelete<IssmDouble>(PIE);
846 xDelete<IssmDouble>(dHpmp);
847 xDelete<IssmDouble>(pressures);
848 xDelete<IssmDouble>(enthalpies);
849 return kappa;
850}
851/*}}}*/
852IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
853
854 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
855 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
856
857 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
858}/*}}}*/
859IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
860
861 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
862 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
863
864 return meltingpoint-beta*pressure;
865}/*}}}*/
Note: See TracBrowser for help on using the repository browser.