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, islevelset;
|
---|
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 | iomodel->Constant(&islevelset,TransientIslevelsetEnum);
|
---|
52 |
|
---|
53 | iomodel->FetchDataToInput(elements,ThicknessEnum);
|
---|
54 | iomodel->FetchDataToInput(elements,SurfaceEnum);
|
---|
55 | iomodel->FetchDataToInput(elements,BedEnum);
|
---|
56 | iomodel->FetchDataToInput(elements,FrictionCoefficientEnum);
|
---|
57 | iomodel->FetchDataToInput(elements,FrictionPEnum);
|
---|
58 | iomodel->FetchDataToInput(elements,FrictionQEnum);
|
---|
59 | iomodel->FetchDataToInput(elements,MaskIceLevelsetEnum);
|
---|
60 | iomodel->FetchDataToInput(elements,MaskGroundediceLevelsetEnum);
|
---|
61 | iomodel->FetchDataToInput(elements,MeshElementonbedEnum);
|
---|
62 | iomodel->FetchDataToInput(elements,MeshElementonsurfaceEnum);
|
---|
63 | iomodel->FetchDataToInput(elements,FlowequationElementEquationEnum);
|
---|
64 | iomodel->FetchDataToInput(elements,MaterialsRheologyBEnum);
|
---|
65 | iomodel->FetchDataToInput(elements,MaterialsRheologyNEnum);
|
---|
66 | iomodel->FetchDataToInput(elements,PressureEnum);
|
---|
67 | iomodel->FetchDataToInput(elements,TemperatureEnum);
|
---|
68 | iomodel->FetchDataToInput(elements,WaterfractionEnum);
|
---|
69 | iomodel->FetchDataToInput(elements,EnthalpyEnum);
|
---|
70 | iomodel->FetchDataToInput(elements,BasalforcingsGeothermalfluxEnum);
|
---|
71 | iomodel->FetchDataToInput(elements,WatercolumnEnum);
|
---|
72 | iomodel->FetchDataToInput(elements,BasalforcingsMeltingRateEnum);
|
---|
73 | iomodel->FetchDataToInput(elements,VxEnum);
|
---|
74 | iomodel->FetchDataToInput(elements,VyEnum);
|
---|
75 | iomodel->FetchDataToInput(elements,VzEnum);
|
---|
76 | InputUpdateFromConstantx(elements,0.,VxMeshEnum);
|
---|
77 | InputUpdateFromConstantx(elements,0.,VyMeshEnum);
|
---|
78 | InputUpdateFromConstantx(elements,0.,VzMeshEnum);
|
---|
79 | if(dakota_analysis){
|
---|
80 | elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
|
---|
81 | elements->InputDuplicate(BasalforcingsMeltingRateEnum,QmuMeltingEnum);
|
---|
82 | elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
|
---|
83 | elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
|
---|
84 | elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
|
---|
85 | }
|
---|
86 | if(islevelset){
|
---|
87 | iomodel->FetchDataToInput(elements,IceMaskNodeActivationEnum);
|
---|
88 | iomodel->FetchDataToInput(elements,MeshVertexonbedEnum); // required for updating active nodes
|
---|
89 | }
|
---|
90 |
|
---|
91 | /*Free data: */
|
---|
92 | iomodel->DeleteData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
|
---|
93 | }/*}}}*/
|
---|
94 | void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
|
---|
95 |
|
---|
96 | if(iomodel->meshtype==Mesh3DEnum) iomodel->FetchData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
|
---|
97 | ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,P1Enum);
|
---|
98 | iomodel->DeleteData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
|
---|
99 | }/*}}}*/
|
---|
100 | void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
101 |
|
---|
102 | /*Intermediary*/
|
---|
103 | int count;
|
---|
104 | int M,N;
|
---|
105 | bool spcpresent = false;
|
---|
106 | IssmDouble heatcapacity;
|
---|
107 | IssmDouble referencetemperature;
|
---|
108 |
|
---|
109 | /*Output*/
|
---|
110 | IssmDouble *spcvector = NULL;
|
---|
111 | IssmDouble* times=NULL;
|
---|
112 | IssmDouble* values=NULL;
|
---|
113 |
|
---|
114 | /*Fetch parameters: */
|
---|
115 | iomodel->Constant(&heatcapacity,MaterialsHeatcapacityEnum);
|
---|
116 | iomodel->Constant(&referencetemperature,ConstantsReferencetemperatureEnum);
|
---|
117 |
|
---|
118 | /*return if 2d mesh*/
|
---|
119 | if(iomodel->meshtype==Mesh2DhorizontalEnum) return;
|
---|
120 |
|
---|
121 | /*Fetch data: */
|
---|
122 | iomodel->FetchData(&spcvector,&M,&N,ThermalSpctemperatureEnum);
|
---|
123 |
|
---|
124 | //FIX ME: SHOULD USE IOMODELCREATECONSTRAINTS
|
---|
125 | /*Transient or static?:*/
|
---|
126 | if(M==iomodel->numberofvertices){
|
---|
127 | /*static: just create Constraints objects*/
|
---|
128 | count=0;
|
---|
129 |
|
---|
130 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
131 | /*keep only this partition's nodes:*/
|
---|
132 | if((iomodel->my_vertices[i])){
|
---|
133 |
|
---|
134 | if (!xIsNan<IssmDouble>(spcvector[i])){
|
---|
135 |
|
---|
136 | constraints->AddObject(new SpcStatic(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,heatcapacity*(spcvector[i]-referencetemperature),EnthalpyAnalysisEnum));
|
---|
137 | count++;
|
---|
138 |
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 | else if (M==(iomodel->numberofvertices+1)){
|
---|
144 | /*transient: create transient SpcTransient objects. Same logic, except we need to retrieve
|
---|
145 | * various times and values to initialize an SpcTransient object: */
|
---|
146 | count=0;
|
---|
147 |
|
---|
148 | /*figure out times: */
|
---|
149 | times=xNew<IssmDouble>(N);
|
---|
150 | for(int j=0;j<N;j++){
|
---|
151 | times[j]=spcvector[(M-1)*N+j];
|
---|
152 | }
|
---|
153 |
|
---|
154 | /*Create constraints from x,y,z: */
|
---|
155 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
156 |
|
---|
157 | /*keep only this partition's nodes:*/
|
---|
158 | if((iomodel->my_vertices[i])){
|
---|
159 |
|
---|
160 | /*figure out times and values: */
|
---|
161 | values=xNew<IssmDouble>(N);
|
---|
162 | spcpresent=false;
|
---|
163 | for(int j=0;j<N;j++){
|
---|
164 | values[j]=heatcapacity*(spcvector[i*N+j]-referencetemperature);
|
---|
165 | if(!xIsNan<IssmDouble>(values[j]))spcpresent=true; //NaN means no spc by default
|
---|
166 | }
|
---|
167 |
|
---|
168 | if(spcpresent){
|
---|
169 | constraints->AddObject(new SpcTransient(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,N,times,values,EnthalpyAnalysisEnum));
|
---|
170 | count++;
|
---|
171 | }
|
---|
172 | xDelete<IssmDouble>(values);
|
---|
173 | }
|
---|
174 | }
|
---|
175 | }
|
---|
176 | else{
|
---|
177 | _error_("Size of field " << EnumToStringx(ThermalSpctemperatureEnum) << " not supported");
|
---|
178 | }
|
---|
179 |
|
---|
180 | /*Free ressources:*/
|
---|
181 | iomodel->DeleteData(spcvector,ThermalSpctemperatureEnum);
|
---|
182 | xDelete<IssmDouble>(times);
|
---|
183 | xDelete<IssmDouble>(values);
|
---|
184 | }/*}}}*/
|
---|
185 | void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
186 |
|
---|
187 | /*No loads */
|
---|
188 | }/*}}}*/
|
---|
189 |
|
---|
190 | /*Finite Element Analysis*/
|
---|
191 | void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
192 | _error_("not implemented");
|
---|
193 | }/*}}}*/
|
---|
194 | ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
195 | /*Default, return NULL*/
|
---|
196 | return NULL;
|
---|
197 | }/*}}}*/
|
---|
198 | ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
199 | _error_("Not implemented");
|
---|
200 | }/*}}}*/
|
---|
201 | ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
202 |
|
---|
203 | /* Check if ice in element */
|
---|
204 | if(!element->IsIceInElement()) return NULL;
|
---|
205 |
|
---|
206 | /*compute all stiffness matrices for this element*/
|
---|
207 | ElementMatrix* Ke1=CreateKMatrixVolume(element);
|
---|
208 | ElementMatrix* Ke2=CreateKMatrixShelf(element);
|
---|
209 | ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
|
---|
210 |
|
---|
211 | /*clean-up and return*/
|
---|
212 | delete Ke1;
|
---|
213 | delete Ke2;
|
---|
214 | return Ke;
|
---|
215 | }/*}}}*/
|
---|
216 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
|
---|
217 |
|
---|
218 | /* Check if ice in element */
|
---|
219 | if(!element->IsIceInElement()) return NULL;
|
---|
220 |
|
---|
221 | /*Intermediaries */
|
---|
222 | int stabilization;
|
---|
223 | IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
|
---|
224 | IssmDouble h,hx,hy,hz,vx,vy,vz;
|
---|
225 | IssmDouble tau_parameter,diameter;
|
---|
226 | IssmDouble D_scalar;
|
---|
227 | IssmDouble* xyz_list = NULL;
|
---|
228 |
|
---|
229 | /*Fetch number of nodes and dof for this finite element*/
|
---|
230 | int numnodes = element->GetNumberOfNodes();
|
---|
231 |
|
---|
232 | /*Initialize Element vector and other vectors*/
|
---|
233 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
234 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
235 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
236 | IssmDouble* B = xNew<IssmDouble>(3*numnodes);
|
---|
237 | IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
|
---|
238 | IssmDouble D[3][3] = {0.};
|
---|
239 | IssmDouble K[3][3];
|
---|
240 |
|
---|
241 | /*Retrieve all inputs and parameters*/
|
---|
242 | element->GetVerticesCoordinates(&xyz_list);
|
---|
243 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
244 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
245 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
246 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
247 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
248 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
249 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
250 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
251 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
252 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
253 | Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
|
---|
254 | Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
|
---|
255 | Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
|
---|
256 | if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
|
---|
257 |
|
---|
258 | /*Enthalpy diffusion parameter*/
|
---|
259 | IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
260 |
|
---|
261 | /* Start looping on the number of gaussian points: */
|
---|
262 | Gauss* gauss=element->NewGauss(2);
|
---|
263 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
264 | gauss->GaussPoint(ig);
|
---|
265 |
|
---|
266 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
267 | D_scalar=gauss->weight*Jdet;
|
---|
268 | if(dt!=0.) D_scalar=D_scalar*dt;
|
---|
269 |
|
---|
270 | /*Conduction: */
|
---|
271 | GetBConduct(B,element,xyz_list,gauss);
|
---|
272 | D[0][0]=D_scalar*kappa/rho_ice;
|
---|
273 | D[1][1]=D_scalar*kappa/rho_ice;
|
---|
274 | D[2][2]=D_scalar*kappa/rho_ice;
|
---|
275 | TripleMultiply(B,3,numnodes,1,
|
---|
276 | &D[0][0],3,3,0,
|
---|
277 | B,3,numnodes,0,
|
---|
278 | &Ke->values[0],1);
|
---|
279 |
|
---|
280 | /*Advection: */
|
---|
281 | GetBAdvec(B,element,xyz_list,gauss);
|
---|
282 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
283 | vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
|
---|
284 | vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
|
---|
285 | vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
|
---|
286 | D[0][0]=D_scalar*vx;
|
---|
287 | D[1][1]=D_scalar*vy;
|
---|
288 | D[2][2]=D_scalar*vz;
|
---|
289 | TripleMultiply(B,3,numnodes,1,
|
---|
290 | &D[0][0],3,3,0,
|
---|
291 | Bprime,3,numnodes,0,
|
---|
292 | &Ke->values[0],1);
|
---|
293 |
|
---|
294 | /*Transient: */
|
---|
295 | if(dt!=0.){
|
---|
296 | D_scalar=gauss->weight*Jdet;
|
---|
297 | element->NodalFunctions(basis,gauss);
|
---|
298 | TripleMultiply(basis,numnodes,1,0,
|
---|
299 | &D_scalar,1,1,0,
|
---|
300 | basis,1,numnodes,0,
|
---|
301 | &Ke->values[0],1);
|
---|
302 | D_scalar=D_scalar*dt;
|
---|
303 | }
|
---|
304 |
|
---|
305 | /*Artifficial diffusivity*/
|
---|
306 | if(stabilization==1){
|
---|
307 | element->ElementSizes(&hx,&hy,&hz);
|
---|
308 | vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
|
---|
309 | h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
|
---|
310 | K[0][0]=h/(2.*vel)*vx*vx; K[0][1]=h/(2.*vel)*vx*vy; K[0][2]=h/(2.*vel)*vx*vz;
|
---|
311 | K[1][0]=h/(2.*vel)*vy*vx; K[1][1]=h/(2.*vel)*vy*vy; K[1][2]=h/(2.*vel)*vy*vz;
|
---|
312 | K[2][0]=h/(2.*vel)*vz*vx; K[2][1]=h/(2.*vel)*vz*vy; K[2][2]=h/(2.*vel)*vz*vz;
|
---|
313 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
|
---|
314 |
|
---|
315 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
316 | TripleMultiply(Bprime,3,numnodes,1,
|
---|
317 | &K[0][0],3,3,0,
|
---|
318 | Bprime,3,numnodes,0,
|
---|
319 | &Ke->values[0],1);
|
---|
320 | }
|
---|
321 | else if(stabilization==2){
|
---|
322 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
323 | tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
|
---|
324 | for(int i=0;i<numnodes;i++){
|
---|
325 | for(int j=0;j<numnodes;j++){
|
---|
326 | Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
|
---|
327 | ((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]);
|
---|
328 | }
|
---|
329 | }
|
---|
330 | if(dt!=0.){
|
---|
331 | D_scalar=gauss->weight*Jdet;
|
---|
332 | for(int i=0;i<numnodes;i++){
|
---|
333 | for(int j=0;j<numnodes;j++){
|
---|
334 | 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]);
|
---|
335 | }
|
---|
336 | }
|
---|
337 | }
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | /*Clean up and return*/
|
---|
342 | xDelete<IssmDouble>(xyz_list);
|
---|
343 | xDelete<IssmDouble>(basis);
|
---|
344 | xDelete<IssmDouble>(dbasis);
|
---|
345 | xDelete<IssmDouble>(B);
|
---|
346 | xDelete<IssmDouble>(Bprime);
|
---|
347 | delete gauss;
|
---|
348 | return Ke;
|
---|
349 | }/*}}}*/
|
---|
350 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
|
---|
351 |
|
---|
352 | /* Check if ice in element */
|
---|
353 | if(!element->IsIceInElement()) return NULL;
|
---|
354 |
|
---|
355 | /*Initialize Element matrix and return if necessary*/
|
---|
356 | if(!element->IsOnBed() || !element->IsFloating()) return NULL;
|
---|
357 |
|
---|
358 | /*Intermediaries*/
|
---|
359 | IssmDouble dt,Jdet,D;
|
---|
360 | IssmDouble *xyz_list_base = NULL;
|
---|
361 |
|
---|
362 | /*Fetch number of nodes for this finite element*/
|
---|
363 | int numnodes = element->GetNumberOfNodes();
|
---|
364 |
|
---|
365 | /*Initialize vectors*/
|
---|
366 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
367 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
368 |
|
---|
369 | /*Retrieve all inputs and parameters*/
|
---|
370 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
371 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
372 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
373 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
374 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
375 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
376 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
377 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
378 |
|
---|
379 | /* Start looping on the number of gaussian points: */
|
---|
380 | Gauss* gauss=element->NewGaussBase(2);
|
---|
381 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
382 | gauss->GaussPoint(ig);
|
---|
383 |
|
---|
384 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
385 | element->NodalFunctions(basis,gauss);
|
---|
386 |
|
---|
387 | D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
|
---|
388 | if(reCast<bool,IssmDouble>(dt)) D=dt*D;
|
---|
389 | TripleMultiply(basis,numnodes,1,0,
|
---|
390 | &D,1,1,0,
|
---|
391 | basis,1,numnodes,0,
|
---|
392 | &Ke->values[0],1);
|
---|
393 |
|
---|
394 | }
|
---|
395 |
|
---|
396 | /*Clean up and return*/
|
---|
397 | delete gauss;
|
---|
398 | xDelete<IssmDouble>(basis);
|
---|
399 | xDelete<IssmDouble>(xyz_list_base);
|
---|
400 | return Ke;
|
---|
401 | }/*}}}*/
|
---|
402 | ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
403 |
|
---|
404 | /* Check if ice in element */
|
---|
405 | if(!element->IsIceInElement()) return NULL;
|
---|
406 |
|
---|
407 | /*compute all load vectors for this element*/
|
---|
408 | ElementVector* pe1=CreatePVectorVolume(element);
|
---|
409 | ElementVector* pe2=CreatePVectorSheet(element);
|
---|
410 | ElementVector* pe3=CreatePVectorShelf(element);
|
---|
411 | ElementVector* pe =new ElementVector(pe1,pe2,pe3);
|
---|
412 |
|
---|
413 | /*clean-up and return*/
|
---|
414 | delete pe1;
|
---|
415 | delete pe2;
|
---|
416 | delete pe3;
|
---|
417 | return pe;
|
---|
418 | }/*}}}*/
|
---|
419 | ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
|
---|
420 |
|
---|
421 | /* Check if ice in element */
|
---|
422 | if(!element->IsIceInElement()) return NULL;
|
---|
423 |
|
---|
424 | /*Intermediaries*/
|
---|
425 | int i, stabilization;
|
---|
426 | IssmDouble Jdet,phi,dt;
|
---|
427 | IssmDouble enthalpy, Hpmp;
|
---|
428 | IssmDouble enthalpypicard, d1enthalpypicard[3];
|
---|
429 | IssmDouble pressure, d1pressure[3], d2pressure;
|
---|
430 | IssmDouble waterfractionpicard;
|
---|
431 | IssmDouble kappa,tau_parameter,diameter,kappa_w;
|
---|
432 | IssmDouble u,v,w;
|
---|
433 | IssmDouble scalar_def, scalar_sens ,scalar_transient;
|
---|
434 | IssmDouble* xyz_list = NULL;
|
---|
435 | IssmDouble d1H_d1P, d1P2;
|
---|
436 |
|
---|
437 | /*Fetch number of nodes and dof for this finite element*/
|
---|
438 | int numnodes = element->GetNumberOfNodes();
|
---|
439 | int numvertices = element->GetNumberOfVertices();
|
---|
440 |
|
---|
441 | /*Initialize Element vector*/
|
---|
442 | ElementVector* pe = element->NewElementVector();
|
---|
443 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
444 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
445 |
|
---|
446 | /*Retrieve all inputs and parameters*/
|
---|
447 | element->GetVerticesCoordinates(&xyz_list);
|
---|
448 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
449 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
450 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
451 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
452 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
453 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
454 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
455 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
456 | Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
|
---|
457 | Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
|
---|
458 | Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
|
---|
459 | Input* enthalpypicard_input=element->GetInput(EnthalpyPicardEnum); _assert_(enthalpypicard_input);
|
---|
460 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
461 | Input* enthalpy_input=NULL;
|
---|
462 | if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
|
---|
463 | if(stabilization==2){
|
---|
464 | diameter=element->MinEdgeLength(xyz_list);
|
---|
465 | kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
466 | }
|
---|
467 |
|
---|
468 | /* Start looping on the number of gaussian points: */
|
---|
469 | Gauss* gauss=element->NewGauss(3);
|
---|
470 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
471 | gauss->GaussPoint(ig);
|
---|
472 |
|
---|
473 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
474 | element->NodalFunctions(basis,gauss);
|
---|
475 |
|
---|
476 | /*viscous dissipation*/
|
---|
477 | element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
|
---|
478 |
|
---|
479 | scalar_def=phi/rho_ice*Jdet*gauss->weight;
|
---|
480 | if(dt!=0.) scalar_def=scalar_def*dt;
|
---|
481 |
|
---|
482 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
|
---|
483 |
|
---|
484 | /*sensible heat flux in temperate ice*/
|
---|
485 | enthalpypicard_input->GetInputValue(&enthalpypicard,gauss);
|
---|
486 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
487 | Hpmp=this->PureIceEnthalpy(element, pressure);
|
---|
488 |
|
---|
489 | if(enthalpypicard>=Hpmp){
|
---|
490 | enthalpypicard_input->GetInputDerivativeValue(&d1enthalpypicard[0],xyz_list,gauss);
|
---|
491 | pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
|
---|
492 | d2pressure=0.; // for linear elements, 2nd derivative is zero
|
---|
493 |
|
---|
494 | d1H_d1P=0.;
|
---|
495 | for(i=0;i<3;i++) d1H_d1P+=d1enthalpypicard[i]*d1pressure[i];
|
---|
496 | d1P2=0.;
|
---|
497 | for(i=0;i<3;i++) d1P2+=pow(d1pressure[i],2.);
|
---|
498 |
|
---|
499 | scalar_sens=-beta*((temperateiceconductivity - thermalconductivity)/latentheat*(d1H_d1P + beta*heatcapacity*d1P2))/rho_ice;
|
---|
500 | if(dt!=0.) scalar_sens=scalar_sens*dt;
|
---|
501 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_sens*basis[i];
|
---|
502 | }
|
---|
503 |
|
---|
504 | /* Build transient now */
|
---|
505 | if(reCast<bool,IssmDouble>(dt)){
|
---|
506 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
507 | scalar_transient=enthalpy*Jdet*gauss->weight;
|
---|
508 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
|
---|
509 | }
|
---|
510 |
|
---|
511 | if(stabilization==2){
|
---|
512 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
513 |
|
---|
514 | vx_input->GetInputValue(&u,gauss);
|
---|
515 | vy_input->GetInputValue(&v,gauss);
|
---|
516 | vz_input->GetInputValue(&w,gauss);
|
---|
517 | tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
|
---|
518 |
|
---|
519 | for(i=0;i<numnodes;i++) pe->values[i]+=tau_parameter*scalar_def*(u*dbasis[0*numnodes+i]+v*dbasis[1*numnodes+i]+w*dbasis[2*numnodes+i]);
|
---|
520 |
|
---|
521 | if(dt!=0.){
|
---|
522 | for(i=0;i<numnodes;i++) pe->values[i]+=tau_parameter*scalar_transient*(u*dbasis[0*numnodes+i]+v*dbasis[1*numnodes+i]+w*dbasis[2*numnodes+i]);
|
---|
523 | }
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | /*Clean up and return*/
|
---|
528 | xDelete<IssmDouble>(basis);
|
---|
529 | xDelete<IssmDouble>(dbasis);
|
---|
530 | xDelete<IssmDouble>(xyz_list);
|
---|
531 | delete gauss;
|
---|
532 | return pe;
|
---|
533 |
|
---|
534 | }/*}}}*/
|
---|
535 | ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
|
---|
536 |
|
---|
537 | /* Check if ice in element */
|
---|
538 | if(!element->IsIceInElement()) return NULL;
|
---|
539 |
|
---|
540 | /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
|
---|
541 | if(!element->IsOnBed() || element->IsFloating()) return NULL;
|
---|
542 |
|
---|
543 | IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
|
---|
544 | IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
|
---|
545 | IssmDouble *xyz_list_base = NULL;
|
---|
546 |
|
---|
547 | /*Fetch number of nodes for this finite element*/
|
---|
548 | int numnodes = element->GetNumberOfNodes();
|
---|
549 |
|
---|
550 | /*Initialize vectors*/
|
---|
551 | ElementVector* pe = element->NewElementVector();
|
---|
552 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
553 |
|
---|
554 | /*Retrieve all inputs and parameters*/
|
---|
555 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
556 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
557 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
558 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
559 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
560 | Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
|
---|
561 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
562 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
563 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
564 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
565 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
566 |
|
---|
567 | /*Build friction element, needed later: */
|
---|
568 | Friction* friction=new Friction(element,3);
|
---|
569 |
|
---|
570 | /* Start looping on the number of gaussian points: */
|
---|
571 | Gauss* gauss = element->NewGaussBase(2);
|
---|
572 | Gauss* gaussup = element->NewGaussTop(2);
|
---|
573 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
574 | gauss->GaussPoint(ig);
|
---|
575 |
|
---|
576 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
577 | element->NodalFunctions(basis,gauss);
|
---|
578 |
|
---|
579 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
580 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
581 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
582 |
|
---|
583 | if((watercolumn<=0.) && (enthalpy<PureIceEnthalpy(element,pressure))){
|
---|
584 | /* the above check is equivalent to
|
---|
585 | NOT [(watercolumn>0.) AND (enthalpy<PIE)] AND (enthalpy<PIE)*/
|
---|
586 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
587 |
|
---|
588 | friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
|
---|
589 | vx_input->GetInputValue(&vx,gauss);
|
---|
590 | vy_input->GetInputValue(&vy,gauss);
|
---|
591 | vz_input->GetInputValue(&vz,gauss);
|
---|
592 | basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
593 | heatflux = (basalfriction+geothermalflux)/(rho_ice);
|
---|
594 |
|
---|
595 | scalar = gauss->weight*Jdet*heatflux;
|
---|
596 | if(dt!=0.) scalar=dt*scalar;
|
---|
597 |
|
---|
598 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
|
---|
599 | }
|
---|
600 | else if(enthalpy >= PureIceEnthalpy(element,pressure)){
|
---|
601 | /* check positive thickness of temperate basal ice layer */
|
---|
602 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
603 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
604 | if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
|
---|
605 | // do nothing, set grad enthalpy*n=0.
|
---|
606 | }
|
---|
607 | else{
|
---|
608 | // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
|
---|
609 | }
|
---|
610 | }
|
---|
611 | else{
|
---|
612 | // base cold, but watercolumn positive. Set base to pressure melting point enthalpy
|
---|
613 | }
|
---|
614 | }
|
---|
615 |
|
---|
616 | /*Clean up and return*/
|
---|
617 | delete gauss;
|
---|
618 | delete gaussup;
|
---|
619 | delete friction;
|
---|
620 | xDelete<IssmDouble>(basis);
|
---|
621 | xDelete<IssmDouble>(xyz_list_base);
|
---|
622 | return pe;
|
---|
623 |
|
---|
624 | }/*}}}*/
|
---|
625 | ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
|
---|
626 |
|
---|
627 | /* Check if ice in element */
|
---|
628 | if(!element->IsIceInElement()) return NULL;
|
---|
629 |
|
---|
630 | /*Get basal element*/
|
---|
631 | if(!element->IsOnBed() || !element->IsFloating()) return NULL;
|
---|
632 |
|
---|
633 | IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
|
---|
634 | IssmDouble *xyz_list_base = NULL;
|
---|
635 |
|
---|
636 | /*Fetch number of nodes for this finite element*/
|
---|
637 | int numnodes = element->GetNumberOfNodes();
|
---|
638 |
|
---|
639 | /*Initialize vectors*/
|
---|
640 | ElementVector* pe = element->NewElementVector();
|
---|
641 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
642 |
|
---|
643 | /*Retrieve all inputs and parameters*/
|
---|
644 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
645 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
646 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
647 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
648 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
649 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
650 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
651 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
652 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
653 |
|
---|
654 | /* Start looping on the number of gaussian points: */
|
---|
655 | Gauss* gauss=element->NewGaussBase(2);
|
---|
656 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
657 | gauss->GaussPoint(ig);
|
---|
658 |
|
---|
659 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
660 | element->NodalFunctions(basis,gauss);
|
---|
661 |
|
---|
662 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
663 | h_pmp=element->PureIceEnthalpy(pressure);
|
---|
664 |
|
---|
665 | scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
|
---|
666 | if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
|
---|
667 |
|
---|
668 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
|
---|
669 | }
|
---|
670 |
|
---|
671 | /*Clean up and return*/
|
---|
672 | delete gauss;
|
---|
673 | xDelete<IssmDouble>(basis);
|
---|
674 | xDelete<IssmDouble>(xyz_list_base);
|
---|
675 | return pe;
|
---|
676 | }/*}}}*/
|
---|
677 | void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
678 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
679 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
680 | * by:
|
---|
681 | * Bi_conduct=[ dh/dx ]
|
---|
682 | * [ dh/dy ]
|
---|
683 | * [ dh/dz ]
|
---|
684 | * where h is the interpolation function for node i.
|
---|
685 | *
|
---|
686 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
687 | */
|
---|
688 |
|
---|
689 | /*Fetch number of nodes for this finite element*/
|
---|
690 | int numnodes = element->GetNumberOfNodes();
|
---|
691 |
|
---|
692 | /*Get nodal functions derivatives*/
|
---|
693 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
694 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
695 |
|
---|
696 | /*Build B: */
|
---|
697 | for(int i=0;i<numnodes;i++){
|
---|
698 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
699 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
700 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
701 | }
|
---|
702 |
|
---|
703 | /*Clean-up*/
|
---|
704 | xDelete<IssmDouble>(dbasis);
|
---|
705 | }/*}}}*/
|
---|
706 | void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
707 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
708 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
709 | * by:
|
---|
710 | * Bi_advec =[ h ]
|
---|
711 | * [ h ]
|
---|
712 | * [ h ]
|
---|
713 | * where h is the interpolation function for node i.
|
---|
714 | *
|
---|
715 | * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
|
---|
716 | */
|
---|
717 |
|
---|
718 | /*Fetch number of nodes for this finite element*/
|
---|
719 | int numnodes = element->GetNumberOfNodes();
|
---|
720 |
|
---|
721 | /*Get nodal functions*/
|
---|
722 | IssmDouble* basis=xNew<IssmDouble>(numnodes);
|
---|
723 | element->NodalFunctions(basis,gauss);
|
---|
724 |
|
---|
725 | /*Build B: */
|
---|
726 | for(int i=0;i<numnodes;i++){
|
---|
727 | B[numnodes*0+i] = basis[i];
|
---|
728 | B[numnodes*1+i] = basis[i];
|
---|
729 | B[numnodes*2+i] = basis[i];
|
---|
730 | }
|
---|
731 |
|
---|
732 | /*Clean-up*/
|
---|
733 | xDelete<IssmDouble>(basis);
|
---|
734 | }/*}}}*/
|
---|
735 | void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
736 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
737 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
738 | * by:
|
---|
739 | * Biprime_advec=[ dh/dx ]
|
---|
740 | * [ dh/dy ]
|
---|
741 | * [ dh/dz ]
|
---|
742 | * where h is the interpolation function for node i.
|
---|
743 | *
|
---|
744 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
745 | */
|
---|
746 |
|
---|
747 | /*Fetch number of nodes for this finite element*/
|
---|
748 | int numnodes = element->GetNumberOfNodes();
|
---|
749 |
|
---|
750 | /*Get nodal functions derivatives*/
|
---|
751 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
752 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
753 |
|
---|
754 | /*Build B: */
|
---|
755 | for(int i=0;i<numnodes;i++){
|
---|
756 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
757 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
758 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
759 | }
|
---|
760 |
|
---|
761 | /*Clean-up*/
|
---|
762 | xDelete<IssmDouble>(dbasis);
|
---|
763 | }/*}}}*/
|
---|
764 | void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
765 | element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
|
---|
766 | }/*}}}*/
|
---|
767 | void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
768 |
|
---|
769 | bool converged;
|
---|
770 | int i,rheology_law;
|
---|
771 | IssmDouble B_average,s_average,T_average=0.,P_average=0.;
|
---|
772 | int *doflist = NULL;
|
---|
773 | IssmDouble *xyz_list = NULL;
|
---|
774 |
|
---|
775 | /*Fetch number of nodes and dof for this finite element*/
|
---|
776 | int numnodes = element->GetNumberOfNodes();
|
---|
777 |
|
---|
778 | /*Fetch dof list and allocate solution vector*/
|
---|
779 | element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
780 | IssmDouble* values = xNew<IssmDouble>(numnodes);
|
---|
781 | IssmDouble* pressure = xNew<IssmDouble>(numnodes);
|
---|
782 | IssmDouble* surface = xNew<IssmDouble>(numnodes);
|
---|
783 | IssmDouble* B = xNew<IssmDouble>(numnodes);
|
---|
784 | IssmDouble* temperature = xNew<IssmDouble>(numnodes);
|
---|
785 | IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
|
---|
786 |
|
---|
787 | /*Use the dof list to index into the solution vector: */
|
---|
788 | for(i=0;i<numnodes;i++){
|
---|
789 | values[i]=solution[doflist[i]];
|
---|
790 |
|
---|
791 | /*Check solution*/
|
---|
792 | if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
|
---|
793 | }
|
---|
794 |
|
---|
795 | /*Get all inputs and parameters*/
|
---|
796 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
797 | element->GetInputListOnNodes(&pressure[0],PressureEnum);
|
---|
798 | if(converged){
|
---|
799 | for(i=0;i<numnodes;i++){
|
---|
800 | element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
|
---|
801 | if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
|
---|
802 | //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
|
---|
803 | }
|
---|
804 | element->AddInput(EnthalpyEnum,values,P1Enum);
|
---|
805 | element->AddInput(WaterfractionEnum,waterfraction,P1Enum);
|
---|
806 | element->AddInput(TemperatureEnum,temperature,P1Enum);
|
---|
807 |
|
---|
808 | /*Update Rheology only if converged (we must make sure that the temperature is below melting point
|
---|
809 | * otherwise the rheology could be negative*/
|
---|
810 | element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
|
---|
811 | element->GetInputListOnNodes(&surface[0],SurfaceEnum);
|
---|
812 | switch(rheology_law){
|
---|
813 | case NoneEnum:
|
---|
814 | /*Do nothing: B is not temperature dependent*/
|
---|
815 | break;
|
---|
816 | case CuffeyEnum:
|
---|
817 | for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
|
---|
818 | element->AddInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
819 | break;
|
---|
820 | case PatersonEnum:
|
---|
821 | for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
|
---|
822 | element->AddInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
823 | break;
|
---|
824 | case ArrheniusEnum:
|
---|
825 | element->GetVerticesCoordinates(&xyz_list);
|
---|
826 | for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
|
---|
827 | element->AddInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
828 | break;
|
---|
829 | case LliboutryDuvalEnum:
|
---|
830 | 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));
|
---|
831 | element->AddInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
832 | break;
|
---|
833 | default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
|
---|
834 | }
|
---|
835 | }
|
---|
836 | else{
|
---|
837 | element->AddInput(EnthalpyPicardEnum,values,P1Enum);
|
---|
838 | }
|
---|
839 |
|
---|
840 | /*Free ressources:*/
|
---|
841 | xDelete<IssmDouble>(values);
|
---|
842 | xDelete<IssmDouble>(pressure);
|
---|
843 | xDelete<IssmDouble>(surface);
|
---|
844 | xDelete<IssmDouble>(B);
|
---|
845 | xDelete<IssmDouble>(temperature);
|
---|
846 | xDelete<IssmDouble>(waterfraction);
|
---|
847 | xDelete<IssmDouble>(xyz_list);
|
---|
848 | xDelete<int>(doflist);
|
---|
849 | }/*}}}*/
|
---|
850 | void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
851 |
|
---|
852 | bool islevelset;
|
---|
853 | femmodel->parameters->FindParam(&islevelset,TransientIslevelsetEnum);
|
---|
854 | if(islevelset){
|
---|
855 | SetActiveNodesLSMx(femmodel);
|
---|
856 | }
|
---|
857 | return;
|
---|
858 | }/*}}}*/
|
---|
859 |
|
---|
860 | /*Modules*/
|
---|
861 | void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
|
---|
862 |
|
---|
863 | /*Intermediaries*/
|
---|
864 | int solution_type, i;
|
---|
865 | bool computebasalmeltingrates=true;
|
---|
866 | bool isdrainage=true;
|
---|
867 | bool updatebasalconstraints=true;
|
---|
868 |
|
---|
869 | if(isdrainage){
|
---|
870 | /*Drain excess water fraction in ice column: */
|
---|
871 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
872 | Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
873 | DrainWaterfractionIcecolumn(element);
|
---|
874 | }
|
---|
875 | }
|
---|
876 |
|
---|
877 | if(computebasalmeltingrates){
|
---|
878 | /*Compute basal melting rates: */
|
---|
879 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
880 | Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
881 | ComputeBasalMeltingrate(element);
|
---|
882 | }
|
---|
883 | }
|
---|
884 |
|
---|
885 | if(updatebasalconstraints){
|
---|
886 | /*Update basal dirichlet BCs for enthalpy in transient runs: */
|
---|
887 | femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
|
---|
888 | if(solution_type==TransientSolutionEnum){
|
---|
889 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
890 | Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
891 | UpdateBasalConstraints(element);
|
---|
892 | }
|
---|
893 | }
|
---|
894 | }
|
---|
895 | }/*}}}*/
|
---|
896 | void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
|
---|
897 | /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
|
---|
898 | /* melting rate is positive when melting, negative when refreezing*/
|
---|
899 |
|
---|
900 | /* Check if ice in element */
|
---|
901 | if(!element->IsIceInElement()) return;
|
---|
902 |
|
---|
903 | /* Only compute melt rates at the base of grounded ice*/
|
---|
904 | if(!element->IsOnBed() || element->IsFloating()) return;
|
---|
905 |
|
---|
906 | /* Intermediaries */
|
---|
907 | const int dim=3;
|
---|
908 | int i,is,vertexdown,vertexup,numvertices,numsegments;
|
---|
909 | IssmDouble heatflux;
|
---|
910 | IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim];
|
---|
911 | IssmDouble temperature, waterfraction;
|
---|
912 | IssmDouble basalfriction,alpha2;
|
---|
913 | IssmDouble dt,yts;
|
---|
914 | IssmDouble melting_overshoot,lambda;
|
---|
915 | IssmDouble geothermalflux;
|
---|
916 | IssmDouble vx,vy,vz;
|
---|
917 | IssmDouble *xyz_list = NULL;
|
---|
918 | IssmDouble *xyz_list_base = NULL;
|
---|
919 | int *pairindices = NULL;
|
---|
920 |
|
---|
921 | /*Fetch parameters and inputs */
|
---|
922 | element->GetVerticesCoordinates(&xyz_list);
|
---|
923 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
924 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
925 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
926 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
927 | Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
|
---|
928 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
929 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
930 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
931 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
932 | IssmDouble kappa=EnthalpyDiffusionParameterVolume(element,EnthalpyEnum); _assert_(kappa>=0.);
|
---|
933 | element->NormalBase(&normal_base[0],xyz_list_base);
|
---|
934 | element->VerticalSegmentIndices(&pairindices,&numsegments);
|
---|
935 | IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
|
---|
936 | IssmDouble* heating = xNew<IssmDouble>(numsegments);
|
---|
937 |
|
---|
938 | /*Build friction element, needed later: */
|
---|
939 | Friction* friction=new Friction(element,dim);
|
---|
940 |
|
---|
941 | /******** MELTING RATES ************************************/
|
---|
942 | numvertices=element->GetNumberOfVertices();
|
---|
943 | IssmDouble* enthalpy = xNew<IssmDouble>(numvertices);
|
---|
944 | IssmDouble* pressure = xNew<IssmDouble>(numvertices);
|
---|
945 | IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
|
---|
946 | IssmDouble* basalmeltingrate = xNew<IssmDouble>(numvertices);
|
---|
947 | element->GetInputListOnVertices(enthalpy,EnthalpyEnum);
|
---|
948 | element->GetInputListOnVertices(pressure,PressureEnum);
|
---|
949 | element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
|
---|
950 | element->GetInputListOnVertices(basalmeltingrate,BasalforcingsMeltingRateEnum);
|
---|
951 |
|
---|
952 | Gauss* gauss=element->NewGauss();
|
---|
953 |
|
---|
954 | for(int is=0;is<numsegments;is++){
|
---|
955 | vertexdown = pairindices[is*2+0];
|
---|
956 | vertexup = pairindices[is*2+1];
|
---|
957 | gauss->GaussVertex(vertexdown);
|
---|
958 |
|
---|
959 | bool checkpositivethickness=true;
|
---|
960 | _assert_(watercolumn[vertexdown]>=0.);
|
---|
961 |
|
---|
962 | /*Calculate basal meltingrate after Fig.5 of A.Aschwanden 2012*/
|
---|
963 | meltingrate_enthalpy[is]=0.;
|
---|
964 | heating[is]=0.;
|
---|
965 | if((watercolumn[vertexdown]>0.) && (enthalpy[vertexdown]<PureIceEnthalpy(element,pressure[vertexdown]))){
|
---|
966 | /*ensure that no ice is at T<Tm(p), if water layer present*/
|
---|
967 | enthalpy[vertexdown]=element->PureIceEnthalpy(pressure[vertexdown]);
|
---|
968 | }
|
---|
969 | else if(enthalpy[vertexdown]<element->PureIceEnthalpy(pressure[vertexdown])){
|
---|
970 | /*cold base: set q*n=q_geo*n+frictionheating as Neumann BC in Penta::CreatePVectorEnthalpySheet*/
|
---|
971 | checkpositivethickness=false; // cold base, skip next test
|
---|
972 | }
|
---|
973 | else{/*we have a temperate base, go to next test*/}
|
---|
974 |
|
---|
975 | if(checkpositivethickness){
|
---|
976 | /*From here on all basal ice is temperate. Check for positive thickness of layer of temperate ice. */
|
---|
977 | bool istemperatelayer=false;
|
---|
978 | if(enthalpy[vertexup]>=element->PureIceEnthalpy(pressure[vertexup])) istemperatelayer=true;
|
---|
979 | if(istemperatelayer) for(i=0;i<dim;i++) vec_heatflux[i]=0.; // TODO: add -k*nabla T_pmp
|
---|
980 | else{
|
---|
981 | enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
|
---|
982 | for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
|
---|
983 | }
|
---|
984 |
|
---|
985 | /*heat flux along normal*/
|
---|
986 | heatflux=0.;
|
---|
987 | for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
|
---|
988 |
|
---|
989 | /*basal friction*/
|
---|
990 | friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
|
---|
991 | vx_input->GetInputValue(&vx,gauss);
|
---|
992 | vy_input->GetInputValue(&vy,gauss);
|
---|
993 | vz_input->GetInputValue(&vz,gauss);
|
---|
994 | basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
995 |
|
---|
996 | element->EnthalpyToThermal(&temperature,&waterfraction,enthalpy[vertexdown],pressure[vertexdown]);
|
---|
997 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
998 | /* -Mb= Fb-(q-q_geo)/((1-w)*L), cf Aschwanden 2012, eq.66*/
|
---|
999 | heating[is]=(heatflux+basalfriction+geothermalflux);
|
---|
1000 | meltingrate_enthalpy[is]=heating[is]/((1-waterfraction)*latentheat*rho_water); // m/s water equivalent
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 | /******** UPDATE MELTINGRATES AND WATERCOLUMN **************/
|
---|
1004 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1005 | for(is=0;is<numsegments;is++){
|
---|
1006 | vertexdown = pairindices[is*2+0];
|
---|
1007 | vertexup = pairindices[is*2+1];
|
---|
1008 | if(dt!=0.){
|
---|
1009 | if(watercolumn[vertexdown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
|
---|
1010 | lambda = -watercolumn[vertexdown]/(dt*meltingrate_enthalpy[is]); _assert_(lambda>=0.); _assert_(lambda<1.);
|
---|
1011 | watercolumn[vertexdown]=0.;
|
---|
1012 | basalmeltingrate[vertexdown]=lambda*meltingrate_enthalpy[is]; // restrict freeze on only to size of watercolumn
|
---|
1013 | enthalpy[vertexdown]+=(1.-lambda)*meltingrate_enthalpy[is]*dt*latentheat; // use rest of energy to cool down base
|
---|
1014 | }
|
---|
1015 | else{
|
---|
1016 | basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
|
---|
1017 | watercolumn[vertexdown]+=dt*meltingrate_enthalpy[is];
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 | else{
|
---|
1021 | basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
|
---|
1022 | watercolumn[vertexdown]+=meltingrate_enthalpy[is];
|
---|
1023 | }
|
---|
1024 | basalmeltingrate[vertexdown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
|
---|
1025 | _assert_(watercolumn[vertexdown]>=0.);
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | /*feed updated variables back into model*/
|
---|
1029 | element->AddInput(EnthalpyEnum,enthalpy,P1Enum);
|
---|
1030 | element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
|
---|
1031 | element->AddInput(BasalforcingsMeltingRateEnum,basalmeltingrate,P1Enum);
|
---|
1032 |
|
---|
1033 | /*Clean up and return*/
|
---|
1034 | delete gauss;
|
---|
1035 | delete friction;
|
---|
1036 | xDelete<IssmDouble>(enthalpy);
|
---|
1037 | xDelete<IssmDouble>(pressure);
|
---|
1038 | xDelete<IssmDouble>(watercolumn);
|
---|
1039 | xDelete<IssmDouble>(basalmeltingrate);
|
---|
1040 | xDelete<IssmDouble>(meltingrate_enthalpy);
|
---|
1041 | xDelete<IssmDouble>(heating);
|
---|
1042 | xDelete<IssmDouble>(xyz_list);
|
---|
1043 | }/*}}}*/
|
---|
1044 | void EnthalpyAnalysis::DrainWaterfractionIcecolumn(Element* element){/*{{{*/
|
---|
1045 |
|
---|
1046 | /* Check if ice in element */
|
---|
1047 | if(!element->IsIceInElement()) return;
|
---|
1048 |
|
---|
1049 | /* Only drain waterfraction of ice column from element at base*/
|
---|
1050 | if(!element->IsOnBed()) return; //FIXME: allow freeze on for floating elements
|
---|
1051 |
|
---|
1052 | /* Intermediaries*/
|
---|
1053 | int is, numvertices, numsegments;
|
---|
1054 | int *pairindices = NULL;
|
---|
1055 |
|
---|
1056 | numvertices=element->GetNumberOfVertices();
|
---|
1057 | element->VerticalSegmentIndices(&pairindices,&numsegments);
|
---|
1058 |
|
---|
1059 | IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
|
---|
1060 | IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments);
|
---|
1061 | IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
|
---|
1062 |
|
---|
1063 | element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
|
---|
1064 |
|
---|
1065 | for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
|
---|
1066 | Element* elementi = element;
|
---|
1067 | for(;;){
|
---|
1068 | for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
|
---|
1069 | DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
|
---|
1070 | for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
|
---|
1071 |
|
---|
1072 | if(elementi->IsOnSurface()) break;
|
---|
1073 | elementi=elementi->GetUpperElement();
|
---|
1074 | }
|
---|
1075 | /* add drained water to water column*/
|
---|
1076 | for(is=0;is<numsegments;is++) watercolumn[is]+=drainrate_column[is];
|
---|
1077 | /* Feed updated water column back into model */
|
---|
1078 | element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
|
---|
1079 |
|
---|
1080 | delete pairindices;
|
---|
1081 | xDelete<IssmDouble>(drainrate_column);
|
---|
1082 | xDelete<IssmDouble>(drainrate_element);
|
---|
1083 | xDelete<IssmDouble>(watercolumn);
|
---|
1084 | }/*}}}*/
|
---|
1085 | void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
|
---|
1086 |
|
---|
1087 | /* Check if ice in element */
|
---|
1088 | if(!element->IsIceInElement()) return;
|
---|
1089 |
|
---|
1090 | /*Intermediaries*/
|
---|
1091 | int iv,is,vertexdown,vertexup,numsegments;
|
---|
1092 | IssmDouble dt, height_element;
|
---|
1093 | IssmDouble rho_water, rho_ice;
|
---|
1094 | int numvertices = element->GetNumberOfVertices();
|
---|
1095 |
|
---|
1096 | IssmDouble* xyz_list = NULL;
|
---|
1097 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
1098 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
1099 | IssmDouble* temperatures = xNew<IssmDouble>(numvertices);
|
---|
1100 | IssmDouble* waterfractions = xNew<IssmDouble>(numvertices);
|
---|
1101 | IssmDouble* deltawaterfractions = xNew<IssmDouble>(numvertices);
|
---|
1102 | int *pairindices = NULL;
|
---|
1103 |
|
---|
1104 | rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
1105 | rho_water=element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
1106 |
|
---|
1107 | element->GetVerticesCoordinates(&xyz_list);
|
---|
1108 | element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
|
---|
1109 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
1110 |
|
---|
1111 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1112 | for(iv=0;iv<numvertices;iv++){
|
---|
1113 | element->EnthalpyToThermal(&temperatures[iv],&waterfractions[iv], enthalpies[iv],pressures[iv]);
|
---|
1114 | deltawaterfractions[iv]=DrainageFunctionWaterfraction(waterfractions[iv], dt);
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | /*drain waterfraction, feed updated variables back into model*/
|
---|
1118 | for(iv=0;iv<numvertices;iv++){
|
---|
1119 | if(reCast<bool,IssmDouble>(dt))
|
---|
1120 | waterfractions[iv]-=deltawaterfractions[iv]*dt;
|
---|
1121 | else
|
---|
1122 | waterfractions[iv]-=deltawaterfractions[iv];
|
---|
1123 | element->ThermalToEnthalpy(&enthalpies[iv], temperatures[iv], waterfractions[iv], pressures[iv]);
|
---|
1124 | }
|
---|
1125 | element->AddInput(EnthalpyEnum,enthalpies,P1Enum);
|
---|
1126 | element->AddInput(WaterfractionEnum,waterfractions,P1Enum);
|
---|
1127 |
|
---|
1128 | /*return meltwater column equivalent to drained water*/
|
---|
1129 | element->VerticalSegmentIndices(&pairindices,&numsegments);
|
---|
1130 | for(is=0;is<numsegments;is++){
|
---|
1131 | vertexdown = pairindices[is*2+0];
|
---|
1132 | vertexup = pairindices[is*2+1];
|
---|
1133 | height_element=fabs(xyz_list[vertexup*3+2]-xyz_list[vertexdown*3+2]);
|
---|
1134 | pdrainrate_element[is]=(deltawaterfractions[vertexdown]+deltawaterfractions[vertexup])/2.*height_element; // return water equivalent of drainage
|
---|
1135 | _assert_(pdrainrate_element[is]>=0.);
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | /*Clean up and return*/
|
---|
1139 | xDelete<IssmDouble>(xyz_list);
|
---|
1140 | xDelete<IssmDouble>(enthalpies);
|
---|
1141 | xDelete<IssmDouble>(pressures);
|
---|
1142 | xDelete<IssmDouble>(temperatures);
|
---|
1143 | xDelete<IssmDouble>(waterfractions);
|
---|
1144 | xDelete<IssmDouble>(deltawaterfractions);
|
---|
1145 | }/*}}}*/
|
---|
1146 | void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
|
---|
1147 |
|
---|
1148 | /* Check if ice in element */
|
---|
1149 | if(!element->IsIceInElement()) return;
|
---|
1150 |
|
---|
1151 | /* Only update Constraints at the base of grounded ice*/
|
---|
1152 | if(!(element->IsOnBed()) || element->IsFloating()) return;
|
---|
1153 |
|
---|
1154 | /*Intermediary*/
|
---|
1155 | bool isdynamicbasalspc,setspc;
|
---|
1156 | int numindices, numindicesup;
|
---|
1157 | IssmDouble pressure, pressureup;
|
---|
1158 | IssmDouble h_pmp, enthalpy, enthalpyup;
|
---|
1159 | IssmDouble watercolumn;
|
---|
1160 | int *indices = NULL, *indicesup = NULL;
|
---|
1161 | Node* node = NULL;
|
---|
1162 |
|
---|
1163 | /*Check wether dynamic basal boundary conditions are activated */
|
---|
1164 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
1165 | if(!isdynamicbasalspc) return;
|
---|
1166 |
|
---|
1167 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
1168 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
1169 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
1170 | penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType());
|
---|
1171 | _assert_(numindices==numindicesup);
|
---|
1172 |
|
---|
1173 | /*Get parameters and inputs: */
|
---|
1174 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
1175 | Input* enthalpy_input=element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
|
---|
1176 | Input* watercolumn_input=element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
1177 |
|
---|
1178 | /*if there is a temperate layer of zero thickness, set spc enthalpy=h_pmp at that node*/
|
---|
1179 | GaussPenta* gauss=new GaussPenta();
|
---|
1180 | GaussPenta* gaussup=new GaussPenta();
|
---|
1181 | for(int i=0;i<numindices;i++){
|
---|
1182 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
1183 | gaussup->GaussNode(element->GetElementType(),indicesup[i]);
|
---|
1184 |
|
---|
1185 | /*Check wether there is a temperate layer at the base or not */
|
---|
1186 | /*check if node is temperate, else continue*/
|
---|
1187 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
1188 | pressure_input->GetInputValue(&pressure, gauss);
|
---|
1189 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
1190 | h_pmp=PureIceEnthalpy(element,pressure);
|
---|
1191 | if (enthalpy>=h_pmp){
|
---|
1192 | /*check if upper node is temperate, too.
|
---|
1193 | if yes, then we have a temperate layer of positive thickness and reset the spc.
|
---|
1194 | if not, apply dirichlet BC.*/
|
---|
1195 | enthalpy_input->GetInputValue(&enthalpyup, gaussup);
|
---|
1196 | pressure_input->GetInputValue(&pressureup, gaussup);
|
---|
1197 | setspc=((enthalpyup<PureIceEnthalpy(element,pressureup)) && (watercolumn>=0.))?true:false;
|
---|
1198 | }
|
---|
1199 | else
|
---|
1200 | setspc = false;
|
---|
1201 |
|
---|
1202 | node=element->GetNode(indices[i]);
|
---|
1203 | if (setspc)
|
---|
1204 | node->ApplyConstraint(1,h_pmp); /*apply spc*/
|
---|
1205 | else
|
---|
1206 | node->DofInFSet(0); /*remove spc*/
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | /*Free ressources:*/
|
---|
1210 | xDelete<int>(indices);
|
---|
1211 | xDelete<int>(indicesup);
|
---|
1212 | delete gauss;
|
---|
1213 | delete gaussup;
|
---|
1214 | }/*}}}*/
|
---|
1215 |
|
---|
1216 | /*Intermediaries*/
|
---|
1217 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
|
---|
1218 |
|
---|
1219 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
1220 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
1221 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
1222 |
|
---|
1223 | if(enthalpy < PureIceEnthalpy(element,pressure)){
|
---|
1224 | return thermalconductivity/heatcapacity;
|
---|
1225 | }
|
---|
1226 | else{
|
---|
1227 | return temperateiceconductivity/heatcapacity;
|
---|
1228 | }
|
---|
1229 | }/*}}}*/
|
---|
1230 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
|
---|
1231 |
|
---|
1232 | int iv;
|
---|
1233 | IssmDouble lambda; /* fraction of cold ice */
|
---|
1234 | IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
|
---|
1235 | IssmDouble Hc,Ht;
|
---|
1236 |
|
---|
1237 | /*Get pressures and enthalpies on vertices*/
|
---|
1238 | int numvertices = element->GetNumberOfVertices();
|
---|
1239 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
1240 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
1241 | IssmDouble* PIE = xNew<IssmDouble>(numvertices);
|
---|
1242 | IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
|
---|
1243 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
1244 | element->GetInputListOnVertices(enthalpies,enthalpy_enum);
|
---|
1245 | for(iv=0;iv<numvertices;iv++){
|
---|
1246 | PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
|
---|
1247 | dHpmp[iv] = enthalpies[iv]-PIE[iv];
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | bool allequalsign = true;
|
---|
1251 | if(dHpmp[0]<0.){
|
---|
1252 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
|
---|
1253 | }
|
---|
1254 | else{
|
---|
1255 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | if(allequalsign){
|
---|
1259 | kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
|
---|
1260 | }
|
---|
1261 | else{
|
---|
1262 | /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
|
---|
1263 | cf Patankar 1980, pp44 */
|
---|
1264 | kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
|
---|
1265 | kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
|
---|
1266 | Hc=0.; Ht=0.;
|
---|
1267 | for(iv=0; iv<numvertices;iv++){
|
---|
1268 | if(enthalpies[iv]<PIE[iv])
|
---|
1269 | Hc+=(PIE[iv]-enthalpies[iv]);
|
---|
1270 | else
|
---|
1271 | Ht+=(enthalpies[iv]-PIE[iv]);
|
---|
1272 | }
|
---|
1273 | _assert_((Hc+Ht)>0.);
|
---|
1274 | lambda = Hc/(Hc+Ht);
|
---|
1275 | kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | /*Clean up and return*/
|
---|
1279 | xDelete<IssmDouble>(PIE);
|
---|
1280 | xDelete<IssmDouble>(dHpmp);
|
---|
1281 | xDelete<IssmDouble>(pressures);
|
---|
1282 | xDelete<IssmDouble>(enthalpies);
|
---|
1283 | return kappa;
|
---|
1284 | }/*}}}*/
|
---|
1285 | IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
|
---|
1286 |
|
---|
1287 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
1288 | IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
|
---|
1289 |
|
---|
1290 | return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
|
---|
1291 | }/*}}}*/
|
---|
1292 | IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
|
---|
1293 |
|
---|
1294 | IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
|
---|
1295 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
1296 |
|
---|
1297 | return meltingpoint-beta*pressure;
|
---|
1298 | }/*}}}*/
|
---|