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

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

NEW: adding cores

File size: 33.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*/
186void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
187 _error_("not implemented");
188}/*}}}*/
189ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
190 /*Default, return NULL*/
191 return NULL;
192}/*}}}*/
193ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
194_error_("Not implemented");
195}/*}}}*/
196ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
197
198 /*compute all stiffness matrices for this element*/
199 ElementMatrix* Ke1=CreateKMatrixVolume(element);
200 ElementMatrix* Ke2=CreateKMatrixShelf(element);
201 ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
202
203 /*clean-up and return*/
204 delete Ke1;
205 delete Ke2;
206 return Ke;
207}/*}}}*/
208ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
209
210 /*Intermediaries */
211 int stabilization;
212 IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
213 IssmDouble h,hx,hy,hz,vx,vy,vz;
214 IssmDouble tau_parameter,diameter;
215 IssmDouble D_scalar;
216 IssmDouble* xyz_list = NULL;
217
218 /*Fetch number of nodes and dof for this finite element*/
219 int numnodes = element->GetNumberOfNodes();
220
221 /*Initialize Element vector and other vectors*/
222 ElementMatrix* Ke = element->NewElementMatrix();
223 IssmDouble* basis = xNew<IssmDouble>(numnodes);
224 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
225 IssmDouble* B = xNew<IssmDouble>(3*numnodes);
226 IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
227 IssmDouble D[3][3] = {0.};
228 IssmDouble K[3][3];
229
230 /*Retrieve all inputs and parameters*/
231 element->GetVerticesCoordinates(&xyz_list);
232 element->FindParam(&dt,TimesteppingTimeStepEnum);
233 element->FindParam(&stabilization,ThermalStabilizationEnum);
234 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
235 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
236 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
237 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
238 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
239 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
240 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
241 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
242 Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
243 Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
244 Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
245 if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
246
247 /*Enthalpy diffusion parameter*/
248 IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>0.);
249
250 /* Start looping on the number of gaussian points: */
251 Gauss* gauss=element->NewGauss(2);
252 for(int ig=gauss->begin();ig<gauss->end();ig++){
253 gauss->GaussPoint(ig);
254
255 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
256 D_scalar=gauss->weight*Jdet;
257 if(dt!=0.) D_scalar=D_scalar*dt;
258
259 /*Conduction: */
260 GetBConduct(B,element,xyz_list,gauss);
261 D[0][0]=D_scalar*kappa/rho_ice;
262 D[1][1]=D_scalar*kappa/rho_ice;
263 D[2][2]=D_scalar*kappa/rho_ice;
264 TripleMultiply(B,3,numnodes,1,
265 &D[0][0],3,3,0,
266 B,3,numnodes,0,
267 &Ke->values[0],1);
268
269 /*Advection: */
270 GetBAdvec(B,element,xyz_list,gauss);
271 GetBAdvecprime(Bprime,element,xyz_list,gauss);
272 vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
273 vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
274 vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
275 D[0][0]=D_scalar*vx;
276 D[1][1]=D_scalar*vy;
277 D[2][2]=D_scalar*vz;
278 TripleMultiply(B,3,numnodes,1,
279 &D[0][0],3,3,0,
280 Bprime,3,numnodes,0,
281 &Ke->values[0],1);
282
283 /*Transient: */
284 if(dt!=0.){
285 D_scalar=gauss->weight*Jdet;
286 element->NodalFunctions(basis,gauss);
287 TripleMultiply(basis,numnodes,1,0,
288 &D_scalar,1,1,0,
289 basis,1,numnodes,0,
290 &Ke->values[0],1);
291 D_scalar=D_scalar*dt;
292 }
293
294 /*Artifficial diffusivity*/
295 if(stabilization==1){
296 element->ElementSizes(&hx,&hy,&hz);
297 vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
298 h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
299 K[0][0]=h/(2.*vel)*vx*vx; K[0][1]=h/(2.*vel)*vx*vy; K[0][2]=h/(2.*vel)*vx*vz;
300 K[1][0]=h/(2.*vel)*vy*vx; K[1][1]=h/(2.*vel)*vy*vy; K[1][2]=h/(2.*vel)*vy*vz;
301 K[2][0]=h/(2.*vel)*vz*vx; K[2][1]=h/(2.*vel)*vz*vy; K[2][2]=h/(2.*vel)*vz*vz;
302 for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
303
304 GetBAdvecprime(Bprime,element,xyz_list,gauss);
305 TripleMultiply(Bprime,3,numnodes,1,
306 &K[0][0],3,3,0,
307 Bprime,3,numnodes,0,
308 &Ke->values[0],1);
309 }
310 else if(stabilization==2){
311 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
312 tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
313 for(int i=0;i<numnodes;i++){
314 for(int j=0;j<numnodes;j++){
315 Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
316 ((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]);
317 }
318 }
319 if(dt!=0.){
320 D_scalar=gauss->weight*Jdet;
321 for(int i=0;i<numnodes;i++){
322 for(int j=0;j<numnodes;j++){
323 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]);
324 }
325 }
326 }
327 }
328 }
329
330 /*Clean up and return*/
331 xDelete<IssmDouble>(xyz_list);
332 xDelete<IssmDouble>(basis);
333 xDelete<IssmDouble>(dbasis);
334 xDelete<IssmDouble>(B);
335 xDelete<IssmDouble>(Bprime);
336 delete gauss;
337 return Ke;
338}/*}}}*/
339ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
340
341 /*Initialize Element matrix and return if necessary*/
342 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
343
344 /*Intermediaries*/
345 IssmDouble dt,Jdet,D;
346 IssmDouble *xyz_list_base = NULL;
347
348 /*Fetch number of nodes for this finite element*/
349 int numnodes = element->GetNumberOfNodes();
350
351 /*Initialize vectors*/
352 ElementMatrix* Ke = element->NewElementMatrix();
353 IssmDouble* basis = xNew<IssmDouble>(numnodes);
354
355 /*Retrieve all inputs and parameters*/
356 element->GetVerticesCoordinatesBase(&xyz_list_base);
357 element->FindParam(&dt,TimesteppingTimeStepEnum);
358 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
359 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
360 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
361 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
362 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
363 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
364
365 /* Start looping on the number of gaussian points: */
366 Gauss* gauss=element->NewGaussBase(2);
367 for(int ig=gauss->begin();ig<gauss->end();ig++){
368 gauss->GaussPoint(ig);
369
370 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
371 element->NodalFunctions(basis,gauss);
372
373 D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
374 if(reCast<bool,IssmDouble>(dt)) D=dt*D;
375 TripleMultiply(basis,numnodes,1,0,
376 &D,1,1,0,
377 basis,1,numnodes,0,
378 &Ke->values[0],1);
379
380 }
381
382 /*Clean up and return*/
383 delete gauss;
384 xDelete<IssmDouble>(basis);
385 xDelete<IssmDouble>(xyz_list_base);
386 return Ke;
387}/*}}}*/
388ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
389
390 /*compute all load vectors for this element*/
391 ElementVector* pe1=CreatePVectorVolume(element);
392 ElementVector* pe2=CreatePVectorSheet(element);
393 ElementVector* pe3=CreatePVectorShelf(element);
394 ElementVector* pe =new ElementVector(pe1,pe2,pe3);
395
396 /*clean-up and return*/
397 delete pe1;
398 delete pe2;
399 delete pe3;
400 return pe;
401}/*}}}*/
402ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
403
404 /*Intermediaries*/
405 int stabilization;
406 IssmDouble Jdet,phi,dt;
407 IssmDouble enthalpy;
408 IssmDouble kappa,tau_parameter,diameter;
409 IssmDouble u,v,w;
410 IssmDouble scalar_def,scalar_transient;
411 IssmDouble* xyz_list = NULL;
412
413 /*Fetch number of nodes and dof for this finite element*/
414 int numnodes = element->GetNumberOfNodes();
415 int numvertices = element->GetNumberOfVertices();
416
417 /*Initialize Element vector*/
418 ElementVector* pe = element->NewElementVector();
419 IssmDouble* basis = xNew<IssmDouble>(numnodes);
420 IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
421
422 /*Retrieve all inputs and parameters*/
423 element->GetVerticesCoordinates(&xyz_list);
424 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
425 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
426 element->FindParam(&dt,TimesteppingTimeStepEnum);
427 element->FindParam(&stabilization,ThermalStabilizationEnum);
428 Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
429 Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
430 Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
431 Input* enthalpy_input = NULL;
432 if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
433 if(stabilization==2){
434 diameter=element->MinEdgeLength(xyz_list);
435 kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>0.);
436 }
437
438 /* Start looping on the number of gaussian points: */
439 Gauss* gauss=element->NewGauss(3);
440 for(int ig=gauss->begin();ig<gauss->end();ig++){
441 gauss->GaussPoint(ig);
442
443 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
444 element->NodalFunctions(basis,gauss);
445 element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
446
447 scalar_def=phi/rho_ice*Jdet*gauss->weight;
448 if(dt!=0.) scalar_def=scalar_def*dt;
449
450 /*TODO: add -beta*laplace T_m(p)*/
451 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
452
453 /* Build transient now */
454 if(reCast<bool,IssmDouble>(dt)){
455 enthalpy_input->GetInputValue(&enthalpy, gauss);
456 scalar_transient=enthalpy*Jdet*gauss->weight;
457 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
458 }
459
460 if(stabilization==2){
461 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
462
463 vx_input->GetInputValue(&u,gauss);
464 vy_input->GetInputValue(&v,gauss);
465 vz_input->GetInputValue(&w,gauss);
466 tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
467
468 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]);
469
470 if(dt!=0.){
471 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]);
472 }
473 }
474 }
475
476 /*Clean up and return*/
477 xDelete<IssmDouble>(basis);
478 xDelete<IssmDouble>(dbasis);
479 xDelete<IssmDouble>(xyz_list);
480 delete gauss;
481 return pe;
482
483}/*}}}*/
484ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
485
486 /* Geothermal flux on ice sheet base and basal friction */
487 if(!element->IsOnBed() || element->IsFloating()) return NULL;
488
489 IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
490 IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
491 IssmDouble *xyz_list_base = NULL;
492
493 /*Fetch number of nodes for this finite element*/
494 int numnodes = element->GetNumberOfNodes();
495
496 /*Initialize vectors*/
497 ElementVector* pe = element->NewElementVector();
498 IssmDouble* basis = xNew<IssmDouble>(numnodes);
499
500 /*Retrieve all inputs and parameters*/
501 element->GetVerticesCoordinatesBase(&xyz_list_base);
502 element->FindParam(&dt,TimesteppingTimeStepEnum);
503 Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
504 Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
505 Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
506 Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
507 Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
508 Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
509 Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
510 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
511 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
512
513 /*Build friction element, needed later: */
514 Friction* friction=new Friction(element,3);
515
516 /* Start looping on the number of gaussian points: */
517 Gauss* gauss = element->NewGaussBase(2);
518 Gauss* gaussup = element->NewGaussTop(2);
519 for(int ig=gauss->begin();ig<gauss->end();ig++){
520 gauss->GaussPoint(ig);
521
522 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
523 element->NodalFunctions(basis,gauss);
524
525 enthalpy_input->GetInputValue(&enthalpy,gauss);
526 pressure_input->GetInputValue(&pressure,gauss);
527 watercolumn_input->GetInputValue(&watercolumn,gauss);
528
529 if((watercolumn<=0.) && (enthalpy < PureIceEnthalpy(element,pressure))){
530 /* the above check is equivalent to
531 NOT ((watercolumn>0.) AND (enthalpy<PIE)) AND (enthalpy<PIE)*/
532 geothermalflux_input->GetInputValue(&geothermalflux,gauss);
533
534 friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
535 vx_input->GetInputValue(&vx,gauss);
536 vy_input->GetInputValue(&vy,gauss);
537 vz_input->GetInputValue(&vz,gauss);
538 basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
539 heatflux = (basalfriction+geothermalflux)/(rho_ice);
540
541 scalar = gauss->weight*Jdet*heatflux;
542 if(dt!=0.) scalar=dt*scalar;
543
544 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
545 }
546 else if(enthalpy >= PureIceEnthalpy(element,pressure)){
547 /* check positive thickness of temperate basal ice layer */
548 enthalpy_input->GetInputValue(&enthalpyup,gaussup);
549 pressure_input->GetInputValue(&pressureup,gaussup);
550 if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
551 // TODO: temperate ice has positive thickness: grad enthalpy*n=0.
552 }
553 else{
554 // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
555 }
556 }
557 else{
558 // base cold, but watercolumn positive. Set base to h_pmp.
559 }
560 }
561
562 /*Clean up and return*/
563 delete gauss;
564 delete gaussup;
565 delete friction;
566 xDelete<IssmDouble>(basis);
567 xDelete<IssmDouble>(xyz_list_base);
568 return pe;
569
570}/*}}}*/
571ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
572
573 /*Get basal element*/
574 if(!element->IsOnBed() || !element->IsFloating()) return NULL;
575
576 IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
577 IssmDouble *xyz_list_base = NULL;
578
579 /*Fetch number of nodes for this finite element*/
580 int numnodes = element->GetNumberOfNodes();
581
582 /*Initialize vectors*/
583 ElementVector* pe = element->NewElementVector();
584 IssmDouble* basis = xNew<IssmDouble>(numnodes);
585
586 /*Retrieve all inputs and parameters*/
587 element->GetVerticesCoordinatesBase(&xyz_list_base);
588 element->FindParam(&dt,TimesteppingTimeStepEnum);
589 Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
590 IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
591 IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
592 IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
593 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
594 IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
595 IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
596
597 /* Start looping on the number of gaussian points: */
598 Gauss* gauss=element->NewGaussBase(2);
599 for(int ig=gauss->begin();ig<gauss->end();ig++){
600 gauss->GaussPoint(ig);
601
602 element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
603 element->NodalFunctions(basis,gauss);
604
605 pressure_input->GetInputValue(&pressure,gauss);
606 h_pmp=element->PureIceEnthalpy(pressure);
607
608 scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
609 if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
610
611 for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
612 }
613
614 /*Clean up and return*/
615 delete gauss;
616 xDelete<IssmDouble>(basis);
617 xDelete<IssmDouble>(xyz_list_base);
618 return pe;
619}/*}}}*/
620void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
621 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
622 * For node i, Bi' can be expressed in the actual coordinate system
623 * by:
624 * Bi_conduct=[ dh/dx ]
625 * [ dh/dy ]
626 * [ dh/dz ]
627 * where h is the interpolation function for node i.
628 *
629 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
630 */
631
632 /*Fetch number of nodes for this finite element*/
633 int numnodes = element->GetNumberOfNodes();
634
635 /*Get nodal functions derivatives*/
636 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
637 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
638
639 /*Build B: */
640 for(int i=0;i<numnodes;i++){
641 B[numnodes*0+i] = dbasis[0*numnodes+i];
642 B[numnodes*1+i] = dbasis[1*numnodes+i];
643 B[numnodes*2+i] = dbasis[2*numnodes+i];
644 }
645
646 /*Clean-up*/
647 xDelete<IssmDouble>(dbasis);
648}/*}}}*/
649void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
650 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
651 * For node i, Bi' can be expressed in the actual coordinate system
652 * by:
653 * Bi_advec =[ h ]
654 * [ h ]
655 * [ h ]
656 * where h is the interpolation function for node i.
657 *
658 * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
659 */
660
661 /*Fetch number of nodes for this finite element*/
662 int numnodes = element->GetNumberOfNodes();
663
664 /*Get nodal functions*/
665 IssmDouble* basis=xNew<IssmDouble>(numnodes);
666 element->NodalFunctions(basis,gauss);
667
668 /*Build B: */
669 for(int i=0;i<numnodes;i++){
670 B[numnodes*0+i] = basis[i];
671 B[numnodes*1+i] = basis[i];
672 B[numnodes*2+i] = basis[i];
673 }
674
675 /*Clean-up*/
676 xDelete<IssmDouble>(basis);
677}/*}}}*/
678void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
679 /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
680 * For node i, Bi' can be expressed in the actual coordinate system
681 * by:
682 * Biprime_advec=[ dh/dx ]
683 * [ dh/dy ]
684 * [ dh/dz ]
685 * where h is the interpolation function for node i.
686 *
687 * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
688 */
689
690 /*Fetch number of nodes for this finite element*/
691 int numnodes = element->GetNumberOfNodes();
692
693 /*Get nodal functions derivatives*/
694 IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
695 element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
696
697 /*Build B: */
698 for(int i=0;i<numnodes;i++){
699 B[numnodes*0+i] = dbasis[0*numnodes+i];
700 B[numnodes*1+i] = dbasis[1*numnodes+i];
701 B[numnodes*2+i] = dbasis[2*numnodes+i];
702 }
703
704 /*Clean-up*/
705 xDelete<IssmDouble>(dbasis);
706}/*}}}*/
707void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
708 element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
709}/*}}}*/
710void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
711
712 bool converged;
713 int i,rheology_law;
714 IssmDouble B_average,s_average,T_average=0.,P_average=0.;
715 int *doflist = NULL;
716 IssmDouble *xyz_list = NULL;
717
718 /*Fetch number of nodes and dof for this finite element*/
719 int numnodes = element->GetNumberOfNodes();
720
721 /*Fetch dof list and allocate solution vector*/
722 element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
723 IssmDouble* values = xNew<IssmDouble>(numnodes);
724 IssmDouble* pressure = xNew<IssmDouble>(numnodes);
725 IssmDouble* surface = xNew<IssmDouble>(numnodes);
726 IssmDouble* B = xNew<IssmDouble>(numnodes);
727 IssmDouble* temperature = xNew<IssmDouble>(numnodes);
728 IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
729
730 /*Use the dof list to index into the solution vector: */
731 for(i=0;i<numnodes;i++){
732 values[i]=solution[doflist[i]];
733
734 /*Check solution*/
735 if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
736 }
737
738 /*Get all inputs and parameters*/
739 element->GetInputValue(&converged,ConvergedEnum);
740 element->GetInputListOnNodes(&pressure[0],PressureEnum);
741 if(converged){
742 for(i=0;i<numnodes;i++){
743 element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
744 if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
745 if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
746 }
747 element->AddInput(EnthalpyEnum,values,P1Enum);
748 element->AddInput(WaterfractionEnum,waterfraction,P1Enum);
749 element->AddInput(TemperatureEnum,temperature,P1Enum);
750
751 /*Update Rheology only if converged (we must make sure that the temperature is below melting point
752 * otherwise the rheology could be negative*/
753 element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
754 element->GetInputListOnNodes(&surface[0],SurfaceEnum);
755 switch(rheology_law){
756 case NoneEnum:
757 /*Do nothing: B is not temperature dependent*/
758 break;
759 case PatersonEnum:
760 for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
761 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
762 break;
763 case ArrheniusEnum:
764 element->GetVerticesCoordinates(&xyz_list);
765 for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
766 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
767 break;
768 case LliboutryDuvalEnum:
769 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));
770 element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
771 break;
772 default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
773 }
774 }
775 else{
776 element->AddInput(EnthalpyPicardEnum,values,P1Enum);
777 }
778
779 /*Free ressources:*/
780 xDelete<IssmDouble>(values);
781 xDelete<IssmDouble>(pressure);
782 xDelete<IssmDouble>(surface);
783 xDelete<IssmDouble>(B);
784 xDelete<IssmDouble>(temperature);
785 xDelete<IssmDouble>(waterfraction);
786 xDelete<IssmDouble>(xyz_list);
787 xDelete<int>(doflist);
788}/*}}}*/
789
790
791/*Modules*/
792void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
793
794 /*Compute basal melting rates: */
795 for(int i=0;i<femmodel->elements->Size();i++){
796 Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
797 ComputeBasalMeltingrate(element);
798 }
799
800 /*drain excess water fraction: */
801 //for(int i=0;i<femmodel->elements->Size();i++){
802 // element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
803 // element->DrainWaterfraction();
804 //}
805
806 /*Update basal dirichlet BCs for enthalpy: */
807 for(int i=0;i<femmodel->elements->Size();i++){
808 Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
809 UpdateBasalConstraints(element);
810 }
811}/*}}}*/
812void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
813
814}/*}}}*/
815void EnthalpyAnalysis::DrainWaterfraction(Element* element){/*{{{*/
816
817}/*}}}*/
818void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
819
820}/*}}}*/
821
822/*Intermediaries*/
823IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
824
825 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
826 IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
827 IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
828
829 if(enthalpy < PureIceEnthalpy(element,pressure)){
830 return thermalconductivity/heatcapacity;
831 }
832 else{
833 return temperateiceconductivity/heatcapacity;
834 }
835}/*}}}*/
836IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
837
838 int iv;
839 IssmDouble lambda; /* fraction of cold ice */
840 IssmDouble kappa ,kappa_c,kappa_t; /* enthalpy conductivities */
841 IssmDouble Hc,Ht;
842
843
844 /*Get pressures and enthalpies on vertices*/
845 int numvertices = element->GetNumberOfVertices();
846 IssmDouble* pressures = xNew<IssmDouble>(numvertices);
847 IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
848 IssmDouble* PIE = xNew<IssmDouble>(numvertices);
849 IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
850 element->GetInputListOnVertices(pressures,PressureEnum);
851 element->GetInputListOnVertices(enthalpies,enthalpy_enum);
852 for(iv=0;iv<numvertices;iv++){
853 PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
854 dHpmp[iv] = enthalpies[iv]-PIE[iv];
855 }
856
857 bool allequalsign = true;
858 if(dHpmp[0]<0.){
859 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
860 }
861 else{
862 for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
863 }
864
865 if(allequalsign){
866 kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
867 }
868 else{
869 /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
870 cf Patankar 1980, pp44 */
871 kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
872 kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
873 Hc=0.; Ht=0.;
874 for(iv=0; iv<numvertices;iv++){
875 if(enthalpies[iv]<PIE[iv])
876 Hc+=(PIE[iv]-enthalpies[iv]);
877 else
878 Ht+=(enthalpies[iv]-PIE[iv]);
879 }
880 _assert_((Hc+Ht)>0.);
881 lambda = Hc/(Hc+Ht);
882 kappa = 1./(lambda/kappa_c + (1.-lambda)/kappa_t);
883 }
884
885 /*Clean up and return*/
886 xDelete<IssmDouble>(PIE);
887 xDelete<IssmDouble>(dHpmp);
888 xDelete<IssmDouble>(pressures);
889 xDelete<IssmDouble>(enthalpies);
890 return kappa;
891}
892/*}}}*/
893IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
894
895 IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
896 IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
897
898 return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
899}/*}}}*/
900IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
901
902 IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
903 IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
904
905 return meltingpoint-beta*pressure;
906}/*}}}*/
Note: See TracBrowser for help on using the repository browser.