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