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 | #include "../solutionsequences/solutionsequences.h"
|
---|
7 | #include "../cores/cores.h"
|
---|
8 |
|
---|
9 | /*Model processing*/
|
---|
10 | void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
11 |
|
---|
12 | /*Intermediary*/
|
---|
13 | int count;
|
---|
14 | int M,N;
|
---|
15 | bool spcpresent = false;
|
---|
16 | int finiteelement;
|
---|
17 | IssmDouble heatcapacity;
|
---|
18 | IssmDouble referencetemperature;
|
---|
19 |
|
---|
20 | /*Output*/
|
---|
21 | IssmDouble *spcvector = NULL;
|
---|
22 | IssmDouble *spcvectorstatic = NULL;
|
---|
23 | IssmDouble* times=NULL;
|
---|
24 | IssmDouble* values=NULL;
|
---|
25 | IssmDouble* issurface = NULL;
|
---|
26 |
|
---|
27 | /*Fetch parameters: */
|
---|
28 | iomodel->FindConstant(&heatcapacity,"md.materials.heatcapacity");
|
---|
29 | iomodel->FindConstant(&referencetemperature,"md.constants.referencetemperature");
|
---|
30 | iomodel->FindConstant(&finiteelement,"md.thermal.fe");
|
---|
31 |
|
---|
32 | /*return if 2d mesh*/
|
---|
33 | if(iomodel->domaintype==Domain2DhorizontalEnum) return;
|
---|
34 |
|
---|
35 | /*Fetch data: */
|
---|
36 | iomodel->FetchData(&issurface,&M,&N,"md.mesh.vertexonsurface"); _assert_(N>0); _assert_(M==iomodel->numberofvertices);
|
---|
37 | iomodel->FetchData(&spcvector,&M,&N,"md.thermal.spctemperature");
|
---|
38 | iomodel->FetchData(&spcvectorstatic,&M,&N,"md.thermal.spctemperature");
|
---|
39 |
|
---|
40 | /*Specific case for PDD, we want the constaints to be updated by the PDD scheme itself*/
|
---|
41 | bool isdynamic = false;
|
---|
42 | if (iomodel->solution_enum==TransientSolutionEnum){
|
---|
43 | int smb_model;
|
---|
44 | iomodel->FindConstant(&smb_model,"md.smb.model");
|
---|
45 | if(smb_model==SMBpddEnum) isdynamic=true;
|
---|
46 | if(smb_model==SMBd18opddEnum) isdynamic=true;
|
---|
47 | if(smb_model==SMBpddSicopolisEnum) isdynamic=true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /*Convert spcs from temperatures to enthalpy*/
|
---|
51 | _assert_(N>0); _assert_(M>=iomodel->numberofvertices);
|
---|
52 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
53 | for(int j=0;j<N;j++){
|
---|
54 | if (isdynamic){
|
---|
55 | if (issurface[i]==1){
|
---|
56 | spcvector[i*N+j] = heatcapacity*(spcvector[i*N+j]-referencetemperature);
|
---|
57 | spcvectorstatic[i*N+j] = NAN;
|
---|
58 | }
|
---|
59 | else{
|
---|
60 | spcvector[i*N+j] = NAN;
|
---|
61 | spcvectorstatic[i*N+j] = heatcapacity*(spcvectorstatic[i*N+j]-referencetemperature);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | else{
|
---|
65 | spcvector[i*N+j] = heatcapacity*(spcvector[i*N+j]-referencetemperature);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | if(isdynamic){
|
---|
71 | IoModelToDynamicConstraintsx(constraints,iomodel,spcvector,iomodel->numberofvertices,1,EnthalpyAnalysisEnum,finiteelement);
|
---|
72 | IoModelToConstraintsx(constraints,iomodel,spcvectorstatic,M,N,EnthalpyAnalysisEnum,finiteelement);
|
---|
73 | }
|
---|
74 | else{
|
---|
75 | IoModelToConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement);
|
---|
76 | }
|
---|
77 |
|
---|
78 | /*Free ressources:*/
|
---|
79 | iomodel->DeleteData(spcvector,"md.thermal.spctemperature");
|
---|
80 | iomodel->DeleteData(spcvectorstatic,"md.thermal.spctemperature");
|
---|
81 | iomodel->DeleteData(issurface,"md.mesh.vertexonsurface");
|
---|
82 | xDelete<IssmDouble>(times);
|
---|
83 | xDelete<IssmDouble>(values);
|
---|
84 | }/*}}}*/
|
---|
85 | void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
86 |
|
---|
87 | /*No loads */
|
---|
88 | }/*}}}*/
|
---|
89 | void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
|
---|
90 |
|
---|
91 | int finiteelement;
|
---|
92 | iomodel->FindConstant(&finiteelement,"md.thermal.fe");
|
---|
93 |
|
---|
94 | if(iomodel->domaintype==Domain3DEnum) iomodel->FetchData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
|
---|
95 | ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,finiteelement);
|
---|
96 | iomodel->DeleteData(2,"md.mesh.vertexonbase","md.mesh.vertexonsurface");
|
---|
97 | }/*}}}*/
|
---|
98 | int EnthalpyAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
99 | return 1;
|
---|
100 | }/*}}}*/
|
---|
101 | void EnthalpyAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
102 |
|
---|
103 | bool dakota_analysis,ismovingfront,isenthalpy;
|
---|
104 | int frictionlaw,basalforcing_model,materialstype;
|
---|
105 | int FrictionCoupling;
|
---|
106 |
|
---|
107 | /*Now, is the model 3d? otherwise, do nothing: */
|
---|
108 | if(iomodel->domaintype==Domain2DhorizontalEnum)return;
|
---|
109 |
|
---|
110 | /*Is enthalpy requested?*/
|
---|
111 | iomodel->FindConstant(&isenthalpy,"md.thermal.isenthalpy");
|
---|
112 | if(!isenthalpy) return;
|
---|
113 |
|
---|
114 | /*Fetch data needed: */
|
---|
115 | iomodel->FetchData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
|
---|
116 |
|
---|
117 | /*Finite element type*/
|
---|
118 | int finiteelement;
|
---|
119 | iomodel->FindConstant(&finiteelement,"md.thermal.fe");
|
---|
120 |
|
---|
121 | /*Update elements: */
|
---|
122 | int counter=0;
|
---|
123 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
124 | if(iomodel->my_elements[i]){
|
---|
125 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
126 | element->Update(i,iomodel,analysis_counter,analysis_type,finiteelement);
|
---|
127 | counter++;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
---|
132 | iomodel->FindConstant(&ismovingfront,"md.transient.ismovingfront");
|
---|
133 | iomodel->FindConstant(&frictionlaw,"md.friction.law");
|
---|
134 | iomodel->FindConstant(&materialstype,"md.materials.type");
|
---|
135 |
|
---|
136 | iomodel->FetchDataToInput(elements,"md.geometry.thickness",ThicknessEnum);
|
---|
137 | iomodel->FetchDataToInput(elements,"md.geometry.surface",SurfaceEnum);
|
---|
138 | iomodel->FetchDataToInput(elements,"md.slr.sealevel",SealevelEnum,0);
|
---|
139 | iomodel->FetchDataToInput(elements,"md.geometry.base",BaseEnum);
|
---|
140 | iomodel->FetchDataToInput(elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
---|
141 | iomodel->FetchDataToInput(elements,"md.mask.groundedice_levelset",MaskGroundediceLevelsetEnum);
|
---|
142 | if(iomodel->domaintype!=Domain2DhorizontalEnum){
|
---|
143 | iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum);
|
---|
144 | iomodel->FetchDataToInput(elements,"md.mesh.vertexonsurface",MeshVertexonsurfaceEnum);
|
---|
145 | }
|
---|
146 | iomodel->FetchDataToInput(elements,"md.initialization.pressure",PressureEnum);
|
---|
147 | iomodel->FetchDataToInput(elements,"md.initialization.temperature",TemperatureEnum);
|
---|
148 | iomodel->FetchDataToInput(elements,"md.initialization.waterfraction",WaterfractionEnum);
|
---|
149 | iomodel->FetchDataToInput(elements,"md.initialization.enthalpy",EnthalpyEnum);
|
---|
150 | iomodel->FetchDataToInput(elements,"md.initialization.watercolumn",WatercolumnEnum);
|
---|
151 | iomodel->FetchDataToInput(elements,"md.basalforcings.groundedice_melting_rate",BasalforcingsGroundediceMeltingRateEnum);
|
---|
152 | iomodel->FetchDataToInput(elements,"md.initialization.vx",VxEnum);
|
---|
153 | iomodel->FetchDataToInput(elements,"md.initialization.vy",VyEnum);
|
---|
154 | iomodel->FetchDataToInput(elements,"md.initialization.vz",VzEnum);
|
---|
155 | InputUpdateFromConstantx(elements,0.,VxMeshEnum);
|
---|
156 | InputUpdateFromConstantx(elements,0.,VyMeshEnum);
|
---|
157 | InputUpdateFromConstantx(elements,0.,VzMeshEnum);
|
---|
158 | if(ismovingfront){
|
---|
159 | iomodel->FetchDataToInput(elements,"md.mesh.vertexonbase",MeshVertexonbaseEnum); // required for updating active nodes
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*Basal forcings variables*/
|
---|
163 | iomodel->FindConstant(&basalforcing_model,"md.basalforcings.model");
|
---|
164 | switch(basalforcing_model){
|
---|
165 | case MantlePlumeGeothermalFluxEnum:
|
---|
166 | break;
|
---|
167 | default:
|
---|
168 | iomodel->FetchDataToInput(elements,"md.basalforcings.geothermalflux",BasalforcingsGeothermalfluxEnum);
|
---|
169 | break;
|
---|
170 | }
|
---|
171 |
|
---|
172 | /*Rheology type*/
|
---|
173 | iomodel->FetchDataToInput(elements,"md.materials.rheology_B",MaterialsRheologyBEnum);
|
---|
174 | switch(materialstype){
|
---|
175 | case MatenhancediceEnum:
|
---|
176 | iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
|
---|
177 | iomodel->FetchDataToInput(elements,"md.materials.rheology_E",MaterialsRheologyEEnum);
|
---|
178 | break;
|
---|
179 | case MatdamageiceEnum:
|
---|
180 | iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
|
---|
181 | break;
|
---|
182 | case MatestarEnum:
|
---|
183 | iomodel->FetchDataToInput(elements,"md.materials.rheology_Ec",MaterialsRheologyEcEnum);
|
---|
184 | iomodel->FetchDataToInput(elements,"md.materials.rheology_Es",MaterialsRheologyEsEnum);
|
---|
185 | break;
|
---|
186 | case MaticeEnum:
|
---|
187 | iomodel->FetchDataToInput(elements,"md.materials.rheology_n",MaterialsRheologyNEnum);
|
---|
188 | break;
|
---|
189 | default:
|
---|
190 | _error_("not supported");
|
---|
191 | }
|
---|
192 |
|
---|
193 | /*Friction law variables*/
|
---|
194 | switch(frictionlaw){
|
---|
195 | case 1:
|
---|
196 | iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
|
---|
197 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
198 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
199 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
200 | if (FrictionCoupling==3){
|
---|
201 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);}
|
---|
202 | else if(FrictionCoupling==4){
|
---|
203 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",EffectivePressureEnum);
|
---|
204 | }
|
---|
205 | break;
|
---|
206 | case 2:
|
---|
207 | iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
|
---|
208 | iomodel->FetchDataToInput(elements,"md.friction.m",FrictionMEnum);
|
---|
209 | break;
|
---|
210 | case 3:
|
---|
211 | iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
|
---|
212 | iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
|
---|
213 | iomodel->FetchDataToInput(elements,"md.friction.As",FrictionAsEnum);
|
---|
214 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
215 | if (FrictionCoupling==3){
|
---|
216 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);}
|
---|
217 | else if(FrictionCoupling==4){
|
---|
218 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",EffectivePressureEnum);
|
---|
219 | }
|
---|
220 | break;
|
---|
221 | case 4:
|
---|
222 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
223 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
224 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
225 | iomodel->FetchDataToInput(elements,"md.initialization.pressure",PressureEnum);
|
---|
226 | iomodel->FetchDataToInput(elements,"md.initialization.temperature",TemperatureEnum);
|
---|
227 | iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
|
---|
228 | break;
|
---|
229 | case 5:
|
---|
230 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
231 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
232 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
233 | iomodel->FetchDataToInput(elements,"md.friction.water_layer",FrictionWaterLayerEnum);
|
---|
234 | break;
|
---|
235 | case 6:
|
---|
236 | iomodel->FetchDataToInput(elements,"md.friction.C",FrictionCEnum);
|
---|
237 | iomodel->FetchDataToInput(elements,"md.friction.m",FrictionMEnum);
|
---|
238 | iomodel->FetchDataToInput(elements,"md.initialization.pressure",PressureEnum);
|
---|
239 | iomodel->FetchDataToInput(elements,"md.initialization.temperature",TemperatureEnum);
|
---|
240 | break;
|
---|
241 | case 7:
|
---|
242 | iomodel->FindConstant(&FrictionCoupling,"md.friction.coupling");
|
---|
243 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
244 | iomodel->FetchDataToInput(elements,"md.friction.coefficientcoulomb",FrictionCoefficientcoulombEnum);
|
---|
245 | iomodel->FetchDataToInput(elements,"md.friction.p",FrictionPEnum);
|
---|
246 | iomodel->FetchDataToInput(elements,"md.friction.q",FrictionQEnum);
|
---|
247 | if (FrictionCoupling==3){
|
---|
248 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",FrictionEffectivePressureEnum);}
|
---|
249 | else if(FrictionCoupling==4){
|
---|
250 | iomodel->FetchDataToInput(elements,"md.friction.effective_pressure",EffectivePressureEnum);
|
---|
251 | }
|
---|
252 | break;
|
---|
253 | case 9:
|
---|
254 | iomodel->FetchDataToInput(elements,"md.friction.coefficient",FrictionCoefficientEnum);
|
---|
255 | iomodel->FetchDataToInput(elements,"md.friction.pressure_adjusted_temperature",FrictionPressureAdjustedTemperatureEnum);
|
---|
256 | InputUpdateFromConstantx(elements,1.,FrictionPEnum);
|
---|
257 | InputUpdateFromConstantx(elements,1.,FrictionQEnum);
|
---|
258 | break;
|
---|
259 | default:
|
---|
260 | _error_("friction law not supported");
|
---|
261 | }
|
---|
262 |
|
---|
263 | /*Free data: */
|
---|
264 | iomodel->DeleteData(3,"md.initialization.temperature","md.initialization.waterfraction","md.initialization.pressure");
|
---|
265 |
|
---|
266 | }/*}}}*/
|
---|
267 | void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
268 |
|
---|
269 | int numoutputs;
|
---|
270 | char** requestedoutputs = NULL;
|
---|
271 |
|
---|
272 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.stabilization",ThermalStabilizationEnum));
|
---|
273 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.maxiter",ThermalMaxiterEnum));
|
---|
274 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.reltol",ThermalReltolEnum));
|
---|
275 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.isenthalpy",ThermalIsenthalpyEnum));
|
---|
276 | parameters->AddObject(iomodel->CopyConstantObject("md.thermal.isdynamicbasalspc",ThermalIsdynamicbasalspcEnum));
|
---|
277 | parameters->AddObject(iomodel->CopyConstantObject("md.friction.law",FrictionLawEnum));
|
---|
278 |
|
---|
279 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.thermal.requested_outputs");
|
---|
280 | parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
|
---|
281 | if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
282 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.thermal.requested_outputs");
|
---|
283 |
|
---|
284 | /*Deal with friction parameters*/
|
---|
285 | int frictionlaw;
|
---|
286 | iomodel->FindConstant(&frictionlaw,"md.friction.law");
|
---|
287 | if(frictionlaw==4 || frictionlaw==6){
|
---|
288 | parameters->AddObject(iomodel->CopyConstantObject("md.friction.gamma",FrictionGammaEnum));
|
---|
289 | }
|
---|
290 | if(frictionlaw==3 || frictionlaw==1 || frictionlaw==7){
|
---|
291 | parameters->AddObject(iomodel->CopyConstantObject("md.friction.coupling",FrictionCouplingEnum));
|
---|
292 | }
|
---|
293 | if(frictionlaw==9){
|
---|
294 | parameters->AddObject(iomodel->CopyConstantObject("md.friction.gamma",FrictionGammaEnum));
|
---|
295 | parameters->AddObject(new IntParam(FrictionCouplingEnum,0));
|
---|
296 | }
|
---|
297 | }/*}}}*/
|
---|
298 |
|
---|
299 | /*Finite Element Analysis*/
|
---|
300 | void EnthalpyAnalysis::ApplyBasalConstraints(IssmDouble* serial_spc,Element* element){/*{{{*/
|
---|
301 |
|
---|
302 | /* Do not check if ice in element, this may lead to inconsistencies between cpu partitions */
|
---|
303 | /* Only update constraints at the base. */
|
---|
304 | if(!(element->IsOnBase())) return;
|
---|
305 |
|
---|
306 | /*Intermediary*/
|
---|
307 | bool isdynamicbasalspc;
|
---|
308 | int numindices;
|
---|
309 | int *indices = NULL;
|
---|
310 | Node* node = NULL;
|
---|
311 | IssmDouble pressure;
|
---|
312 |
|
---|
313 | /*Check wether dynamic basal boundary conditions are activated */
|
---|
314 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
315 | if(!isdynamicbasalspc) return;
|
---|
316 |
|
---|
317 | /*Get parameters and inputs: */
|
---|
318 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
319 |
|
---|
320 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
321 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
322 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
323 |
|
---|
324 | GaussPenta* gauss=new GaussPenta();
|
---|
325 | for(int i=0;i<numindices;i++){
|
---|
326 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
327 |
|
---|
328 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
329 |
|
---|
330 | /*apply or release spc*/
|
---|
331 | node=element->GetNode(indices[i]);
|
---|
332 | if(!node->IsActive()) continue;
|
---|
333 | if(serial_spc[node->Sid()]==1.){
|
---|
334 | pressure_input->GetInputValue(&pressure, gauss);
|
---|
335 | node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
|
---|
336 | }
|
---|
337 | else {
|
---|
338 | node->DofInFSet(0);
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | /*Free ressources:*/
|
---|
343 | xDelete<int>(indices);
|
---|
344 | delete gauss;
|
---|
345 | }/*}}}*/
|
---|
346 | void EnthalpyAnalysis::ComputeBasalMeltingrate(FemModel* femmodel){/*{{{*/
|
---|
347 | /*Compute basal melting rates: */
|
---|
348 | for(int i=0;i<femmodel->elements->Size();i++){
|
---|
349 | Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
350 | ComputeBasalMeltingrate(element);
|
---|
351 | }
|
---|
352 |
|
---|
353 | /*extrude inputs*/
|
---|
354 | femmodel->parameters->SetParam(BasalforcingsGroundediceMeltingRateEnum,InputToExtrudeEnum);
|
---|
355 | extrudefrombase_core(femmodel);
|
---|
356 | }/*}}}*/
|
---|
357 | void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
|
---|
358 | /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
|
---|
359 | /* melting rate is positive when melting, negative when refreezing*/
|
---|
360 |
|
---|
361 | /* Check if ice in element */
|
---|
362 | if(!element->IsIceInElement()) return;
|
---|
363 |
|
---|
364 | /* Only compute melt rates at the base of grounded ice*/
|
---|
365 | if(!element->IsOnBase() || element->IsFloating()) return;
|
---|
366 |
|
---|
367 | /* Intermediaries */
|
---|
368 | bool converged;
|
---|
369 | const int dim=3;
|
---|
370 | int i,is,state;
|
---|
371 | int nodedown,nodeup,numnodes,numsegments;
|
---|
372 | int enthalpy_enum;
|
---|
373 | IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim],d1pressure[dim];
|
---|
374 | IssmDouble basalfriction,alpha2,geothermalflux,heatflux;
|
---|
375 | IssmDouble dt,yts;
|
---|
376 | IssmDouble melting_overshoot,lambda;
|
---|
377 | IssmDouble vx,vy,vz;
|
---|
378 | IssmDouble *xyz_list = NULL;
|
---|
379 | IssmDouble *xyz_list_base = NULL;
|
---|
380 | int *pairindices = NULL;
|
---|
381 |
|
---|
382 | /*Fetch parameters*/
|
---|
383 | element->GetVerticesCoordinates(&xyz_list);
|
---|
384 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
385 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
386 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
387 | element->FindParam(&yts, ConstantsYtsEnum);
|
---|
388 |
|
---|
389 | if(dt==0. && !converged) enthalpy_enum=EnthalpyPicardEnum;
|
---|
390 | else enthalpy_enum=EnthalpyEnum;
|
---|
391 |
|
---|
392 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
393 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
394 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
|
---|
395 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
396 | IssmDouble kappa = EnthalpyDiffusionParameterVolume(element,enthalpy_enum); _assert_(kappa>=0.);
|
---|
397 | IssmDouble kappa_mix;
|
---|
398 |
|
---|
399 | /*retrieve inputs*/
|
---|
400 | Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
|
---|
401 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
402 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
403 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
404 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
405 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
406 |
|
---|
407 | /*Build friction element, needed later: */
|
---|
408 | Friction* friction=new Friction(element,dim);
|
---|
409 |
|
---|
410 | /******** MELTING RATES ************************************//*{{{*/
|
---|
411 | element->NormalBase(&normal_base[0],xyz_list_base);
|
---|
412 | element->VerticalSegmentIndicesBase(&pairindices,&numsegments);
|
---|
413 | IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
|
---|
414 | IssmDouble* heating = xNew<IssmDouble>(numsegments);
|
---|
415 |
|
---|
416 | numnodes=element->GetNumberOfNodes();
|
---|
417 | IssmDouble* enthalpies = xNew<IssmDouble>(numnodes);
|
---|
418 | IssmDouble* pressures = xNew<IssmDouble>(numnodes);
|
---|
419 | IssmDouble* watercolumns = xNew<IssmDouble>(numnodes);
|
---|
420 | IssmDouble* basalmeltingrates = xNew<IssmDouble>(numnodes);
|
---|
421 | element->GetInputListOnNodes(enthalpies,enthalpy_enum);
|
---|
422 | element->GetInputListOnNodes(pressures,PressureEnum);
|
---|
423 | element->GetInputListOnNodes(watercolumns,WatercolumnEnum);
|
---|
424 | element->GetInputListOnNodes(basalmeltingrates,BasalforcingsGroundediceMeltingRateEnum);
|
---|
425 |
|
---|
426 | Gauss* gauss=element->NewGauss();
|
---|
427 | for(is=0;is<numsegments;is++){
|
---|
428 | nodedown = pairindices[is*2+0];
|
---|
429 | nodeup = pairindices[is*2+1];
|
---|
430 | gauss->GaussNode(element->GetElementType(),nodedown);
|
---|
431 |
|
---|
432 | state=GetThermalBasalCondition(element, enthalpies[nodedown], enthalpies[nodeup], pressures[nodedown], pressures[nodeup], watercolumns[nodedown], basalmeltingrates[nodedown]);
|
---|
433 | switch (state) {
|
---|
434 | case 0:
|
---|
435 | // cold, dry base: apply basal surface forcing
|
---|
436 | for(i=0;i<3;i++) vec_heatflux[i]=0.;
|
---|
437 | break;
|
---|
438 | case 1: case 2: case 3:
|
---|
439 | // case 1 : cold, wet base: keep at pressure melting point
|
---|
440 | // case 2: temperate, thin refreezing base: release spc
|
---|
441 | // case 3: temperate, thin melting base: set spc
|
---|
442 | enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
|
---|
443 | for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
|
---|
444 | break;
|
---|
445 | case 4:
|
---|
446 | // temperate, thick melting base: set grad H*n=0
|
---|
447 | kappa_mix=GetWetIceConductivity(element, enthalpies[nodedown], pressures[nodedown]);
|
---|
448 | pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
|
---|
449 | for(i=0;i<3;i++) vec_heatflux[i]=kappa_mix*beta*d1pressure[i];
|
---|
450 | break;
|
---|
451 | default:
|
---|
452 | _printf0_(" unknown thermal basal state found!");
|
---|
453 | }
|
---|
454 | if(state==0) meltingrate_enthalpy[is]=0.;
|
---|
455 | else{
|
---|
456 | /*heat flux along normal*/
|
---|
457 | heatflux=0.;
|
---|
458 | for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
|
---|
459 |
|
---|
460 | /*basal friction*/
|
---|
461 | friction->GetAlpha2(&alpha2,gauss);
|
---|
462 | vx_input->GetInputValue(&vx,gauss); vy_input->GetInputValue(&vy,gauss); vz_input->GetInputValue(&vz,gauss);
|
---|
463 | basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
464 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
465 | /* -Mb= Fb-(q-q_geo)/((1-w)*L*rho), and (1-w)*rho=rho_ice, cf Aschwanden 2012, eqs.1, 2, 66*/
|
---|
466 | heating[is]=(heatflux+basalfriction+geothermalflux);
|
---|
467 | meltingrate_enthalpy[is]=heating[is]/(latentheat*rho_ice); // m/s water equivalent
|
---|
468 | }
|
---|
469 | }/*}}}*/
|
---|
470 |
|
---|
471 | /******** UPDATE MELTINGRATES AND WATERCOLUMN **************//*{{{*/
|
---|
472 | for(is=0;is<numsegments;is++){
|
---|
473 | nodedown = pairindices[is*2+0];
|
---|
474 | nodeup = pairindices[is*2+1];
|
---|
475 | if(dt!=0.){
|
---|
476 | if(watercolumns[nodedown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
|
---|
477 | lambda = -watercolumns[nodedown]/(dt*meltingrate_enthalpy[is]); _assert_(lambda>=0.); _assert_(lambda<1.);
|
---|
478 | watercolumns[nodedown]=0.;
|
---|
479 | basalmeltingrates[nodedown]=lambda*meltingrate_enthalpy[is]; // restrict freeze on only to size of watercolumn
|
---|
480 | enthalpies[nodedown]+=(1.-lambda)*dt/yts*meltingrate_enthalpy[is]*latentheat*rho_ice; // use rest of energy to cool down base: dE=L*m, m=(1-lambda)*meltingrate*rho_ice
|
---|
481 | }
|
---|
482 | else{
|
---|
483 | basalmeltingrates[nodedown]=meltingrate_enthalpy[is];
|
---|
484 | watercolumns[nodedown]+=dt*meltingrate_enthalpy[is];
|
---|
485 | }
|
---|
486 | }
|
---|
487 | else{
|
---|
488 | basalmeltingrates[nodedown]=meltingrate_enthalpy[is];
|
---|
489 | if(watercolumns[nodedown]+meltingrate_enthalpy[is]<0.)
|
---|
490 | watercolumns[nodedown]=0.;
|
---|
491 | else
|
---|
492 | watercolumns[nodedown]+=meltingrate_enthalpy[is];
|
---|
493 | }
|
---|
494 | basalmeltingrates[nodedown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
|
---|
495 | _assert_(watercolumns[nodedown]>=0.);
|
---|
496 | }/*}}}*/
|
---|
497 |
|
---|
498 | /*feed updated variables back into model*/
|
---|
499 | if(dt!=0.){
|
---|
500 | element->AddInput(enthalpy_enum,enthalpies,element->GetElementType());
|
---|
501 | element->AddInput(WatercolumnEnum,watercolumns,element->GetElementType());
|
---|
502 | }
|
---|
503 | element->AddInput(BasalforcingsGroundediceMeltingRateEnum,basalmeltingrates,element->GetElementType());
|
---|
504 |
|
---|
505 | /*Clean up and return*/
|
---|
506 | delete gauss;
|
---|
507 | delete friction;
|
---|
508 | xDelete<int>(pairindices);
|
---|
509 | xDelete<IssmDouble>(enthalpies);
|
---|
510 | xDelete<IssmDouble>(pressures);
|
---|
511 | xDelete<IssmDouble>(watercolumns);
|
---|
512 | xDelete<IssmDouble>(basalmeltingrates);
|
---|
513 | xDelete<IssmDouble>(meltingrate_enthalpy);
|
---|
514 | xDelete<IssmDouble>(heating);
|
---|
515 | xDelete<IssmDouble>(xyz_list);
|
---|
516 | xDelete<IssmDouble>(xyz_list_base);
|
---|
517 | }/*}}}*/
|
---|
518 | void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
519 |
|
---|
520 | IssmDouble dt;
|
---|
521 | bool isdynamicbasalspc;
|
---|
522 |
|
---|
523 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
524 | femmodel->parameters->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
525 |
|
---|
526 | if(VerboseSolution()) _printf0_(" computing enthalpy\n");
|
---|
527 | femmodel->SetCurrentConfiguration(EnthalpyAnalysisEnum);
|
---|
528 | if((dt>0.) && isdynamicbasalspc) UpdateBasalConstraints(femmodel);
|
---|
529 | solutionsequence_thermal_nonlinear(femmodel);
|
---|
530 |
|
---|
531 | /*transfer enthalpy to enthalpy picard for the next step: */
|
---|
532 | InputDuplicatex(femmodel,EnthalpyEnum,EnthalpyPicardEnum);
|
---|
533 |
|
---|
534 | PostProcessing(femmodel);
|
---|
535 |
|
---|
536 | }/*}}}*/
|
---|
537 | ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
538 | /*Default, return NULL*/
|
---|
539 | return NULL;
|
---|
540 | }/*}}}*/
|
---|
541 | ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
542 | _error_("Not implemented");
|
---|
543 | }/*}}}*/
|
---|
544 | ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
545 |
|
---|
546 | /* Check if ice in element */
|
---|
547 | if(!element->IsIceInElement()) return NULL;
|
---|
548 |
|
---|
549 | /*compute all stiffness matrices for this element*/
|
---|
550 | ElementMatrix* Ke1=CreateKMatrixVolume(element);
|
---|
551 | ElementMatrix* Ke2=CreateKMatrixShelf(element);
|
---|
552 | ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
|
---|
553 |
|
---|
554 | /*clean-up and return*/
|
---|
555 | delete Ke1;
|
---|
556 | delete Ke2;
|
---|
557 | return Ke;
|
---|
558 | }/*}}}*/
|
---|
559 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
|
---|
560 |
|
---|
561 | /* Check if ice in element */
|
---|
562 | if(!element->IsIceInElement()) return NULL;
|
---|
563 |
|
---|
564 | /*Intermediaries */
|
---|
565 | int stabilization;
|
---|
566 | IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
|
---|
567 | IssmDouble h,hx,hy,hz,vx,vy,vz;
|
---|
568 | IssmDouble tau_parameter,diameter;
|
---|
569 | IssmDouble D_scalar;
|
---|
570 | IssmDouble* xyz_list = NULL;
|
---|
571 |
|
---|
572 | /*Fetch number of nodes and dof for this finite element*/
|
---|
573 | int numnodes = element->GetNumberOfNodes();
|
---|
574 |
|
---|
575 | /*Initialize Element vector and other vectors*/
|
---|
576 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
577 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
578 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
579 | IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
|
---|
580 | IssmDouble K[3][3];
|
---|
581 |
|
---|
582 | /*Retrieve all inputs and parameters*/
|
---|
583 | element->GetVerticesCoordinates(&xyz_list);
|
---|
584 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
585 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
586 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
587 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
588 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
589 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
590 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
591 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
592 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
593 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
594 | Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
|
---|
595 | Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
|
---|
596 | Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
|
---|
597 | if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
|
---|
598 |
|
---|
599 | /*Enthalpy diffusion parameter*/
|
---|
600 | IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
601 |
|
---|
602 | /* Start looping on the number of gaussian points: */
|
---|
603 | Gauss* gauss=element->NewGauss(4);
|
---|
604 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
605 | gauss->GaussPoint(ig);
|
---|
606 |
|
---|
607 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
608 | element->NodalFunctions(basis,gauss);
|
---|
609 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
610 |
|
---|
611 | D_scalar=gauss->weight*Jdet;
|
---|
612 | if(dt!=0.) D_scalar=D_scalar*dt;
|
---|
613 |
|
---|
614 | /*Conduction: */
|
---|
615 | for(int i=0;i<numnodes;i++){
|
---|
616 | for(int j=0;j<numnodes;j++){
|
---|
617 | Ke->values[i*numnodes+j] += D_scalar*kappa/rho_ice*(
|
---|
618 | dbasis[0*numnodes+j]*dbasis[0*numnodes+i] + dbasis[1*numnodes+j]*dbasis[1*numnodes+i] + dbasis[2*numnodes+j]*dbasis[2*numnodes+i]
|
---|
619 | );
|
---|
620 | }
|
---|
621 | }
|
---|
622 |
|
---|
623 | /*Advection: */
|
---|
624 | vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
|
---|
625 | vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
|
---|
626 | vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
|
---|
627 | for(int i=0;i<numnodes;i++){
|
---|
628 | for(int j=0;j<numnodes;j++){
|
---|
629 | Ke->values[i*numnodes+j] += D_scalar*(
|
---|
630 | vx*dbasis[0*numnodes+j]*basis[i] + vy*dbasis[1*numnodes+j]*basis[i] +vz*dbasis[2*numnodes+j]*basis[i]
|
---|
631 | );
|
---|
632 | }
|
---|
633 | }
|
---|
634 |
|
---|
635 | /*Transient: */
|
---|
636 | if(dt!=0.){
|
---|
637 | D_scalar=gauss->weight*Jdet;
|
---|
638 | for(int i=0;i<numnodes;i++){
|
---|
639 | for(int j=0;j<numnodes;j++){
|
---|
640 | Ke->values[i*numnodes+j] += D_scalar*basis[j]*basis[i];
|
---|
641 | }
|
---|
642 | }
|
---|
643 | D_scalar=D_scalar*dt;
|
---|
644 | }
|
---|
645 |
|
---|
646 | /*Artificial diffusivity*/
|
---|
647 | if(stabilization==1){
|
---|
648 | element->ElementSizes(&hx,&hy,&hz);
|
---|
649 | vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
|
---|
650 | h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
|
---|
651 | K[0][0]=h/(2.*vel)*fabs(vx*vx); K[0][1]=h/(2.*vel)*fabs(vx*vy); K[0][2]=h/(2.*vel)*fabs(vx*vz);
|
---|
652 | K[1][0]=h/(2.*vel)*fabs(vy*vx); K[1][1]=h/(2.*vel)*fabs(vy*vy); K[1][2]=h/(2.*vel)*fabs(vy*vz);
|
---|
653 | K[2][0]=h/(2.*vel)*fabs(vz*vx); K[2][1]=h/(2.*vel)*fabs(vz*vy); K[2][2]=h/(2.*vel)*fabs(vz*vz);
|
---|
654 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
|
---|
655 |
|
---|
656 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
657 | TripleMultiply(Bprime,3,numnodes,1,
|
---|
658 | &K[0][0],3,3,0,
|
---|
659 | Bprime,3,numnodes,0,
|
---|
660 | &Ke->values[0],1);
|
---|
661 | }
|
---|
662 | else if(stabilization==2){
|
---|
663 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
664 | tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
|
---|
665 | for(int i=0;i<numnodes;i++){
|
---|
666 | for(int j=0;j<numnodes;j++){
|
---|
667 | Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
|
---|
668 | ((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]);
|
---|
669 | }
|
---|
670 | }
|
---|
671 | if(dt!=0.){
|
---|
672 | D_scalar=gauss->weight*Jdet;
|
---|
673 | for(int i=0;i<numnodes;i++){
|
---|
674 | for(int j=0;j<numnodes;j++){
|
---|
675 | 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]);
|
---|
676 | }
|
---|
677 | }
|
---|
678 | }
|
---|
679 | }
|
---|
680 | }
|
---|
681 |
|
---|
682 | /*Clean up and return*/
|
---|
683 | xDelete<IssmDouble>(xyz_list);
|
---|
684 | xDelete<IssmDouble>(basis);
|
---|
685 | xDelete<IssmDouble>(dbasis);
|
---|
686 | xDelete<IssmDouble>(Bprime);
|
---|
687 | delete gauss;
|
---|
688 | return Ke;
|
---|
689 | }/*}}}*/
|
---|
690 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
|
---|
691 |
|
---|
692 | /* Check if ice in element */
|
---|
693 | if(!element->IsIceInElement()) return NULL;
|
---|
694 |
|
---|
695 | /*Initialize Element matrix and return if necessary*/
|
---|
696 | if(!element->IsOnBase() || !element->IsFloating()) return NULL;
|
---|
697 |
|
---|
698 | /*Intermediaries*/
|
---|
699 | IssmDouble dt,Jdet,D;
|
---|
700 | IssmDouble *xyz_list_base = NULL;
|
---|
701 |
|
---|
702 | /*Fetch number of nodes for this finite element*/
|
---|
703 | int numnodes = element->GetNumberOfNodes();
|
---|
704 |
|
---|
705 | /*Initialize vectors*/
|
---|
706 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
707 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
708 |
|
---|
709 | /*Retrieve all inputs and parameters*/
|
---|
710 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
711 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
712 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
713 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
714 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
715 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
716 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
717 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
718 |
|
---|
719 | /* Start looping on the number of gaussian points: */
|
---|
720 | Gauss* gauss=element->NewGaussBase(4);
|
---|
721 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
722 | gauss->GaussPoint(ig);
|
---|
723 |
|
---|
724 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
725 | element->NodalFunctions(basis,gauss);
|
---|
726 |
|
---|
727 | D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
|
---|
728 | if(reCast<bool,IssmDouble>(dt)) D=dt*D;
|
---|
729 | TripleMultiply(basis,numnodes,1,0,
|
---|
730 | &D,1,1,0,
|
---|
731 | basis,1,numnodes,0,
|
---|
732 | &Ke->values[0],1);
|
---|
733 |
|
---|
734 | }
|
---|
735 |
|
---|
736 | /*Clean up and return*/
|
---|
737 | delete gauss;
|
---|
738 | xDelete<IssmDouble>(basis);
|
---|
739 | xDelete<IssmDouble>(xyz_list_base);
|
---|
740 | return Ke;
|
---|
741 | }/*}}}*/
|
---|
742 | ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
743 |
|
---|
744 | /* Check if ice in element */
|
---|
745 | if(!element->IsIceInElement()) return NULL;
|
---|
746 |
|
---|
747 | /*compute all load vectors for this element*/
|
---|
748 | ElementVector* pe1=CreatePVectorVolume(element);
|
---|
749 | ElementVector* pe2=CreatePVectorSheet(element);
|
---|
750 | ElementVector* pe3=CreatePVectorShelf(element);
|
---|
751 | ElementVector* pe =new ElementVector(pe1,pe2,pe3);
|
---|
752 |
|
---|
753 | /*clean-up and return*/
|
---|
754 | delete pe1;
|
---|
755 | delete pe2;
|
---|
756 | delete pe3;
|
---|
757 | return pe;
|
---|
758 | }/*}}}*/
|
---|
759 | ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
|
---|
760 |
|
---|
761 | /* Check if ice in element */
|
---|
762 | if(!element->IsIceInElement()) return NULL;
|
---|
763 |
|
---|
764 | /*Intermediaries*/
|
---|
765 | int i, stabilization;
|
---|
766 | IssmDouble Jdet,phi,dt;
|
---|
767 | IssmDouble enthalpy, Hpmp;
|
---|
768 | IssmDouble enthalpypicard, d1enthalpypicard[3];
|
---|
769 | IssmDouble pressure, d1pressure[3], d2pressure;
|
---|
770 | IssmDouble waterfractionpicard;
|
---|
771 | IssmDouble kappa,tau_parameter,diameter,kappa_w;
|
---|
772 | IssmDouble u,v,w;
|
---|
773 | IssmDouble scalar_def, scalar_sens ,scalar_transient;
|
---|
774 | IssmDouble* xyz_list = NULL;
|
---|
775 | IssmDouble d1H_d1P, d1P2;
|
---|
776 |
|
---|
777 | /*Fetch number of nodes and dof for this finite element*/
|
---|
778 | int numnodes = element->GetNumberOfNodes();
|
---|
779 | int numvertices = element->GetNumberOfVertices();
|
---|
780 |
|
---|
781 | /*Initialize Element vector*/
|
---|
782 | ElementVector* pe = element->NewElementVector();
|
---|
783 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
784 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
785 |
|
---|
786 | /*Retrieve all inputs and parameters*/
|
---|
787 | element->GetVerticesCoordinates(&xyz_list);
|
---|
788 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
789 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
790 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
791 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
792 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
793 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
794 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
795 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
796 | Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
|
---|
797 | Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
|
---|
798 | Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
|
---|
799 | Input* enthalpypicard_input=element->GetInput(EnthalpyPicardEnum); _assert_(enthalpypicard_input);
|
---|
800 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
801 | Input* enthalpy_input=NULL;
|
---|
802 | if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
|
---|
803 | if(stabilization==2){
|
---|
804 | diameter=element->MinEdgeLength(xyz_list);
|
---|
805 | kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
806 | }
|
---|
807 |
|
---|
808 | /* Start looping on the number of gaussian points: */
|
---|
809 | Gauss* gauss=element->NewGauss(4);
|
---|
810 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
811 | gauss->GaussPoint(ig);
|
---|
812 |
|
---|
813 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
814 | element->NodalFunctions(basis,gauss);
|
---|
815 |
|
---|
816 | /*viscous dissipation*/
|
---|
817 | element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
|
---|
818 |
|
---|
819 | scalar_def=phi/rho_ice*Jdet*gauss->weight;
|
---|
820 | if(dt!=0.) scalar_def=scalar_def*dt;
|
---|
821 |
|
---|
822 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
|
---|
823 |
|
---|
824 | /*sensible heat flux in temperate ice*/
|
---|
825 | enthalpypicard_input->GetInputValue(&enthalpypicard,gauss);
|
---|
826 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
827 | Hpmp=this->PureIceEnthalpy(element, pressure);
|
---|
828 |
|
---|
829 | if(enthalpypicard>=Hpmp){
|
---|
830 | enthalpypicard_input->GetInputDerivativeValue(&d1enthalpypicard[0],xyz_list,gauss);
|
---|
831 | pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
|
---|
832 | d2pressure=0.; // for linear elements, 2nd derivative is zero
|
---|
833 |
|
---|
834 | d1H_d1P=0.;
|
---|
835 | for(i=0;i<3;i++) d1H_d1P+=d1enthalpypicard[i]*d1pressure[i];
|
---|
836 | d1P2=0.;
|
---|
837 | for(i=0;i<3;i++) d1P2+=pow(d1pressure[i],2.);
|
---|
838 |
|
---|
839 | scalar_sens=-beta*((temperateiceconductivity - thermalconductivity)/latentheat*(d1H_d1P + beta*heatcapacity*d1P2))/rho_ice;
|
---|
840 | if(dt!=0.) scalar_sens=scalar_sens*dt;
|
---|
841 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_sens*basis[i];
|
---|
842 | }
|
---|
843 |
|
---|
844 | /* Build transient now */
|
---|
845 | if(reCast<bool,IssmDouble>(dt)){
|
---|
846 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
847 | scalar_transient=enthalpy*Jdet*gauss->weight;
|
---|
848 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
|
---|
849 | }
|
---|
850 |
|
---|
851 | if(stabilization==2){
|
---|
852 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
853 |
|
---|
854 | vx_input->GetInputValue(&u,gauss);
|
---|
855 | vy_input->GetInputValue(&v,gauss);
|
---|
856 | vz_input->GetInputValue(&w,gauss);
|
---|
857 | tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
|
---|
858 |
|
---|
859 | 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]);
|
---|
860 |
|
---|
861 | if(dt!=0.){
|
---|
862 | 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]);
|
---|
863 | }
|
---|
864 | }
|
---|
865 | }
|
---|
866 |
|
---|
867 | /*Clean up and return*/
|
---|
868 | xDelete<IssmDouble>(basis);
|
---|
869 | xDelete<IssmDouble>(dbasis);
|
---|
870 | xDelete<IssmDouble>(xyz_list);
|
---|
871 | delete gauss;
|
---|
872 | return pe;
|
---|
873 |
|
---|
874 | }/*}}}*/
|
---|
875 | ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
|
---|
876 |
|
---|
877 | /* Check if ice in element */
|
---|
878 | if(!element->IsIceInElement()) return NULL;
|
---|
879 |
|
---|
880 | /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
|
---|
881 | if(!element->IsOnBase() || element->IsFloating()) return NULL;
|
---|
882 |
|
---|
883 | bool converged, isdynamicbasalspc;
|
---|
884 | int i, state;
|
---|
885 | int enthalpy_enum;
|
---|
886 | IssmDouble dt,Jdet,scalar;
|
---|
887 | IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
|
---|
888 | IssmDouble vx,vy,vz;
|
---|
889 | IssmDouble alpha2,basalfriction,geothermalflux,heatflux;
|
---|
890 | IssmDouble *xyz_list_base = NULL;
|
---|
891 |
|
---|
892 | /*Fetch number of nodes for this finite element*/
|
---|
893 | int numnodes = element->GetNumberOfNodes();
|
---|
894 |
|
---|
895 | /*Initialize vectors*/
|
---|
896 | ElementVector* pe = element->NewElementVector();
|
---|
897 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
898 |
|
---|
899 | /*Retrieve all inputs and parameters*/
|
---|
900 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
901 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
902 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
903 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
904 | if(dt==0. && !converged) enthalpy_enum=EnthalpyPicardEnum; // use enthalpy from last iteration
|
---|
905 | else enthalpy_enum=EnthalpyEnum; // use enthalpy from last time step
|
---|
906 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
907 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
908 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
909 | Input* enthalpy_input = element->GetInput(enthalpy_enum); _assert_(enthalpy_input);
|
---|
910 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
911 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
912 | Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
|
---|
913 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
914 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
915 |
|
---|
916 | /*Build friction element, needed later: */
|
---|
917 | Friction* friction=new Friction(element,3);
|
---|
918 |
|
---|
919 | /* Start looping on the number of gaussian points: */
|
---|
920 | Gauss* gauss=element->NewGaussBase(4);
|
---|
921 | Gauss* gaussup=element->NewGaussTop(4);
|
---|
922 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
923 | gauss->GaussPoint(ig);
|
---|
924 | gaussup->GaussPoint(ig);
|
---|
925 |
|
---|
926 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
927 | element->NodalFunctions(basis,gauss);
|
---|
928 |
|
---|
929 | if(isdynamicbasalspc){
|
---|
930 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
931 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
932 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
933 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
934 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
935 | meltingrate_input->GetInputValue(&meltingrate,gauss);
|
---|
936 | state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
|
---|
937 | }
|
---|
938 | else
|
---|
939 | state=0;
|
---|
940 |
|
---|
941 | switch (state) {
|
---|
942 | case 0: case 1: case 2: case 3:
|
---|
943 | // cold, dry base; cold, wet base; refreezing temperate base; thin temperate base:
|
---|
944 | // Apply basal surface forcing.
|
---|
945 | // Interpolated values of enthalpy on gauss nodes may indicate cold base,
|
---|
946 | // although one node might have become temperate. So keep heat flux switched on.
|
---|
947 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
948 | friction->GetAlpha2(&alpha2,gauss);
|
---|
949 | vx_input->GetInputValue(&vx,gauss);
|
---|
950 | vy_input->GetInputValue(&vy,gauss);
|
---|
951 | vz_input->GetInputValue(&vz,gauss);
|
---|
952 | basalfriction=alpha2*(vx*vx+vy*vy+vz*vz);
|
---|
953 | heatflux=(basalfriction+geothermalflux)/(rho_ice);
|
---|
954 | scalar=gauss->weight*Jdet*heatflux;
|
---|
955 | if(dt!=0.) scalar=dt*scalar;
|
---|
956 | for(i=0;i<numnodes;i++)
|
---|
957 | pe->values[i]+=scalar*basis[i];
|
---|
958 | break;
|
---|
959 | case 4:
|
---|
960 | // temperate, thick melting base: set grad H*n=0
|
---|
961 | for(i=0;i<numnodes;i++)
|
---|
962 | pe->values[i]+=0.;
|
---|
963 | break;
|
---|
964 | default:
|
---|
965 | _printf0_(" unknown thermal basal state found!");
|
---|
966 | }
|
---|
967 | }
|
---|
968 |
|
---|
969 | /*Clean up and return*/
|
---|
970 | delete gauss;
|
---|
971 | delete gaussup;
|
---|
972 | delete friction;
|
---|
973 | xDelete<IssmDouble>(basis);
|
---|
974 | xDelete<IssmDouble>(xyz_list_base);
|
---|
975 | return pe;
|
---|
976 |
|
---|
977 | }/*}}}*/
|
---|
978 | ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
|
---|
979 |
|
---|
980 | /* Check if ice in element */
|
---|
981 | if(!element->IsIceInElement()) return NULL;
|
---|
982 |
|
---|
983 | /*Get basal element*/
|
---|
984 | if(!element->IsOnBase() || !element->IsFloating()) return NULL;
|
---|
985 |
|
---|
986 | IssmDouble Hpmp,dt,Jdet,scalar_ocean,pressure;
|
---|
987 | IssmDouble *xyz_list_base = NULL;
|
---|
988 |
|
---|
989 | /*Fetch number of nodes for this finite element*/
|
---|
990 | int numnodes = element->GetNumberOfNodes();
|
---|
991 |
|
---|
992 | /*Initialize vectors*/
|
---|
993 | ElementVector* pe = element->NewElementVector();
|
---|
994 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
995 |
|
---|
996 | /*Retrieve all inputs and parameters*/
|
---|
997 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
998 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
999 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
1000 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
1001 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
1002 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
1003 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
1004 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
1005 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
1006 |
|
---|
1007 | /* Start looping on the number of gaussian points: */
|
---|
1008 | Gauss* gauss=element->NewGaussBase(4);
|
---|
1009 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
1010 | gauss->GaussPoint(ig);
|
---|
1011 |
|
---|
1012 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
1013 | element->NodalFunctions(basis,gauss);
|
---|
1014 |
|
---|
1015 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
1016 | Hpmp=element->PureIceEnthalpy(pressure);
|
---|
1017 |
|
---|
1018 | scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*Hpmp/(heatcapacity*rho_ice);
|
---|
1019 | if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
|
---|
1020 |
|
---|
1021 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | /*Clean up and return*/
|
---|
1025 | delete gauss;
|
---|
1026 | xDelete<IssmDouble>(basis);
|
---|
1027 | xDelete<IssmDouble>(xyz_list_base);
|
---|
1028 | return pe;
|
---|
1029 | }/*}}}*/
|
---|
1030 | void EnthalpyAnalysis::DrainWaterfraction(FemModel* femmodel){/*{{{*/
|
---|
1031 | /*Drain excess water fraction in ice column: */
|
---|
1032 | ComputeWaterfractionDrainage(femmodel);
|
---|
1033 | DrainageUpdateWatercolumn(femmodel);
|
---|
1034 | DrainageUpdateEnthalpy(femmodel);
|
---|
1035 | }/*}}}*/
|
---|
1036 | void EnthalpyAnalysis::ComputeWaterfractionDrainage(FemModel* femmodel){/*{{{*/
|
---|
1037 |
|
---|
1038 | int i,k,numnodes;
|
---|
1039 | IssmDouble dt;
|
---|
1040 | Element* element= NULL;
|
---|
1041 |
|
---|
1042 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1043 |
|
---|
1044 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
1045 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
1046 | numnodes=element->GetNumberOfNodes();
|
---|
1047 | IssmDouble* waterfractions= xNew<IssmDouble>(numnodes);
|
---|
1048 | IssmDouble* drainage= xNew<IssmDouble>(numnodes);
|
---|
1049 |
|
---|
1050 | element->GetInputListOnNodes(waterfractions,WaterfractionEnum);
|
---|
1051 | for(k=0; k<numnodes;k++){
|
---|
1052 | drainage[k]=DrainageFunctionWaterfraction(waterfractions[k], dt);
|
---|
1053 | }
|
---|
1054 | element->AddInput(WaterfractionDrainageEnum,drainage,element->GetElementType());
|
---|
1055 |
|
---|
1056 | xDelete<IssmDouble>(waterfractions);
|
---|
1057 | xDelete<IssmDouble>(drainage);
|
---|
1058 | }
|
---|
1059 | }/*}}}*/
|
---|
1060 | void EnthalpyAnalysis::DrainageUpdateWatercolumn(FemModel* femmodel){/*{{{*/
|
---|
1061 |
|
---|
1062 | int i,k,numnodes, numbasalnodes;
|
---|
1063 | IssmDouble dt;
|
---|
1064 | int* basalnodeindices=NULL;
|
---|
1065 | Element* element= NULL;
|
---|
1066 |
|
---|
1067 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1068 |
|
---|
1069 | /*depth-integrate the drained water fraction */
|
---|
1070 | femmodel->parameters->SetParam(WaterfractionDrainageEnum,InputToDepthaverageInEnum);
|
---|
1071 | femmodel->parameters->SetParam(WaterfractionDrainageIntegratedEnum,InputToDepthaverageOutEnum);
|
---|
1072 | depthaverage_core(femmodel);
|
---|
1073 | femmodel->parameters->SetParam(WaterfractionDrainageIntegratedEnum,InputToExtrudeEnum);
|
---|
1074 | extrudefrombase_core(femmodel);
|
---|
1075 | /*multiply depth-average by ice thickness*/
|
---|
1076 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
1077 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
1078 | numnodes=element->GetNumberOfNodes();
|
---|
1079 | IssmDouble* drainage_int= xNew<IssmDouble>(numnodes);
|
---|
1080 | IssmDouble* thicknesses= xNew<IssmDouble>(numnodes);
|
---|
1081 |
|
---|
1082 | element->GetInputListOnNodes(drainage_int,WaterfractionDrainageIntegratedEnum);
|
---|
1083 | element->GetInputListOnNodes(thicknesses,ThicknessEnum);
|
---|
1084 | for(k=0;k<numnodes;k++){
|
---|
1085 | drainage_int[k]*=thicknesses[k];
|
---|
1086 | }
|
---|
1087 | element->AddInput(WaterfractionDrainageIntegratedEnum, drainage_int, element->GetElementType());
|
---|
1088 |
|
---|
1089 | xDelete<IssmDouble>(drainage_int);
|
---|
1090 | xDelete<IssmDouble>(thicknesses);
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | /*update water column*/
|
---|
1094 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
1095 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
1096 | /* Check if ice in element */
|
---|
1097 | if(!element->IsIceInElement()) continue;
|
---|
1098 | if(!element->IsOnBase()) continue;
|
---|
1099 |
|
---|
1100 | numnodes=element->GetNumberOfNodes();
|
---|
1101 | IssmDouble* watercolumn= xNew<IssmDouble>(numnodes);
|
---|
1102 | IssmDouble* drainage_int= xNew<IssmDouble>(numnodes);
|
---|
1103 | element->GetInputListOnNodes(watercolumn,WatercolumnEnum);
|
---|
1104 | element->GetInputListOnNodes(drainage_int,WaterfractionDrainageIntegratedEnum);
|
---|
1105 |
|
---|
1106 | element->BasalNodeIndices(&numbasalnodes,&basalnodeindices,element->GetElementType());
|
---|
1107 | for(k=0;k<numbasalnodes;k++){
|
---|
1108 | watercolumn[basalnodeindices[k]]+=dt*drainage_int[basalnodeindices[k]];
|
---|
1109 | }
|
---|
1110 | element->AddInput(WatercolumnEnum, watercolumn, element->GetElementType());
|
---|
1111 |
|
---|
1112 | xDelete<IssmDouble>(watercolumn);
|
---|
1113 | xDelete<IssmDouble>(drainage_int);
|
---|
1114 | xDelete<int>(basalnodeindices);
|
---|
1115 | }
|
---|
1116 | }/*}}}*/
|
---|
1117 | void EnthalpyAnalysis::DrainageUpdateEnthalpy(FemModel* femmodel){/*{{{*/
|
---|
1118 |
|
---|
1119 | int i,k,numnodes;
|
---|
1120 | IssmDouble dt;
|
---|
1121 | Element* element= NULL;
|
---|
1122 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1123 |
|
---|
1124 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
1125 | element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
1126 | numnodes=element->GetNumberOfNodes();
|
---|
1127 | IssmDouble* enthalpies= xNew<IssmDouble>(numnodes);
|
---|
1128 | IssmDouble* pressures= xNew<IssmDouble>(numnodes);
|
---|
1129 | IssmDouble* temperatures= xNew<IssmDouble>(numnodes);
|
---|
1130 | IssmDouble* waterfractions= xNew<IssmDouble>(numnodes);
|
---|
1131 | IssmDouble* drainage= xNew<IssmDouble>(numnodes);
|
---|
1132 |
|
---|
1133 | element->GetInputListOnNodes(pressures,PressureEnum);
|
---|
1134 | element->GetInputListOnNodes(temperatures,TemperatureEnum);
|
---|
1135 | element->GetInputListOnNodes(waterfractions,WaterfractionEnum);
|
---|
1136 | element->GetInputListOnNodes(drainage,WaterfractionDrainageEnum);
|
---|
1137 |
|
---|
1138 | for(k=0;k<numnodes;k++){
|
---|
1139 | waterfractions[k]-=dt*drainage[k];
|
---|
1140 | element->ThermalToEnthalpy(&enthalpies[k], temperatures[k], waterfractions[k], pressures[k]);
|
---|
1141 | }
|
---|
1142 | element->AddInput(WaterfractionEnum,waterfractions,element->GetElementType());
|
---|
1143 | element->AddInput(EnthalpyEnum,enthalpies,element->GetElementType());
|
---|
1144 |
|
---|
1145 | xDelete<IssmDouble>(enthalpies);
|
---|
1146 | xDelete<IssmDouble>(pressures);
|
---|
1147 | xDelete<IssmDouble>(temperatures);
|
---|
1148 | xDelete<IssmDouble>(waterfractions);
|
---|
1149 | xDelete<IssmDouble>(drainage);
|
---|
1150 | }
|
---|
1151 | }/*}}}*/
|
---|
1152 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
|
---|
1153 |
|
---|
1154 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
1155 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
1156 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
1157 |
|
---|
1158 | if(enthalpy < PureIceEnthalpy(element,pressure)){
|
---|
1159 | return thermalconductivity/heatcapacity;
|
---|
1160 | }
|
---|
1161 | else{
|
---|
1162 | return temperateiceconductivity/heatcapacity;
|
---|
1163 | }
|
---|
1164 | }/*}}}*/
|
---|
1165 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
|
---|
1166 |
|
---|
1167 | int iv;
|
---|
1168 | IssmDouble lambda; /* fraction of cold ice */
|
---|
1169 | IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
|
---|
1170 | IssmDouble Hc,Ht;
|
---|
1171 |
|
---|
1172 | /*Get pressures and enthalpies on vertices*/
|
---|
1173 | int numvertices = element->GetNumberOfVertices();
|
---|
1174 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
1175 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
1176 | IssmDouble* PIE = xNew<IssmDouble>(numvertices);
|
---|
1177 | IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
|
---|
1178 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
1179 | element->GetInputListOnVertices(enthalpies,enthalpy_enum);
|
---|
1180 | for(iv=0;iv<numvertices;iv++){
|
---|
1181 | PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
|
---|
1182 | dHpmp[iv] = enthalpies[iv]-PIE[iv];
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | bool allequalsign = true;
|
---|
1186 | if(dHpmp[0]<0.){
|
---|
1187 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
|
---|
1188 | }
|
---|
1189 | else{
|
---|
1190 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | if(allequalsign){
|
---|
1194 | kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
|
---|
1195 | }
|
---|
1196 | else{
|
---|
1197 | /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
|
---|
1198 | cf Patankar 1980, pp44 */
|
---|
1199 | kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
|
---|
1200 | kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
|
---|
1201 | Hc=0.; Ht=0.;
|
---|
1202 | for(iv=0; iv<numvertices;iv++){
|
---|
1203 | if(enthalpies[iv]<PIE[iv])
|
---|
1204 | Hc+=(PIE[iv]-enthalpies[iv]);
|
---|
1205 | else
|
---|
1206 | Ht+=(enthalpies[iv]-PIE[iv]);
|
---|
1207 | }
|
---|
1208 | _assert_((Hc+Ht)>0.);
|
---|
1209 | lambda = Hc/(Hc+Ht);
|
---|
1210 | _assert_(lambda>=0.);
|
---|
1211 | _assert_(lambda<=1.);
|
---|
1212 | kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | /*Clean up and return*/
|
---|
1216 | xDelete<IssmDouble>(PIE);
|
---|
1217 | xDelete<IssmDouble>(dHpmp);
|
---|
1218 | xDelete<IssmDouble>(pressures);
|
---|
1219 | xDelete<IssmDouble>(enthalpies);
|
---|
1220 | return kappa;
|
---|
1221 | }/*}}}*/
|
---|
1222 | void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
1223 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
1224 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
1225 | * by:
|
---|
1226 | * Bi_advec =[ h ]
|
---|
1227 | * [ h ]
|
---|
1228 | * [ h ]
|
---|
1229 | * where h is the interpolation function for node i.
|
---|
1230 | *
|
---|
1231 | * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
|
---|
1232 | */
|
---|
1233 |
|
---|
1234 | /*Fetch number of nodes for this finite element*/
|
---|
1235 | int numnodes = element->GetNumberOfNodes();
|
---|
1236 |
|
---|
1237 | /*Get nodal functions*/
|
---|
1238 | IssmDouble* basis=xNew<IssmDouble>(numnodes);
|
---|
1239 | element->NodalFunctions(basis,gauss);
|
---|
1240 |
|
---|
1241 | /*Build B: */
|
---|
1242 | for(int i=0;i<numnodes;i++){
|
---|
1243 | B[numnodes*0+i] = basis[i];
|
---|
1244 | B[numnodes*1+i] = basis[i];
|
---|
1245 | B[numnodes*2+i] = basis[i];
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | /*Clean-up*/
|
---|
1249 | xDelete<IssmDouble>(basis);
|
---|
1250 | }/*}}}*/
|
---|
1251 | void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
1252 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
1253 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
1254 | * by:
|
---|
1255 | * Biprime_advec=[ dh/dx ]
|
---|
1256 | * [ dh/dy ]
|
---|
1257 | * [ dh/dz ]
|
---|
1258 | * where h is the interpolation function for node i.
|
---|
1259 | *
|
---|
1260 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
1261 | */
|
---|
1262 |
|
---|
1263 | /*Fetch number of nodes for this finite element*/
|
---|
1264 | int numnodes = element->GetNumberOfNodes();
|
---|
1265 |
|
---|
1266 | /*Get nodal functions derivatives*/
|
---|
1267 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
1268 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
1269 |
|
---|
1270 | /*Build B: */
|
---|
1271 | for(int i=0;i<numnodes;i++){
|
---|
1272 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
1273 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
1274 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | /*Clean-up*/
|
---|
1278 | xDelete<IssmDouble>(dbasis);
|
---|
1279 | }/*}}}*/
|
---|
1280 | void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
|
---|
1281 |
|
---|
1282 | /*Intermediary*/
|
---|
1283 | bool isdynamicbasalspc;
|
---|
1284 | IssmDouble dt;
|
---|
1285 |
|
---|
1286 | /*Check wether dynamic basal boundary conditions are activated */
|
---|
1287 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
1288 | if(!isdynamicbasalspc) return;
|
---|
1289 |
|
---|
1290 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1291 | if(dt==0.){
|
---|
1292 | GetBasalConstraintsSteadystate(vec_spc,element);
|
---|
1293 | }
|
---|
1294 | else{
|
---|
1295 | GetBasalConstraintsTransient(vec_spc,element);
|
---|
1296 | }
|
---|
1297 | }/*}}}*/
|
---|
1298 | void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
|
---|
1299 |
|
---|
1300 | /* Check if ice in element */
|
---|
1301 | if(!element->IsIceInElement()) return;
|
---|
1302 |
|
---|
1303 | /* Only update constraints at the base.
|
---|
1304 | * Floating ice is not affected by basal BC decision chart. */
|
---|
1305 | if(!(element->IsOnBase()) || element->IsFloating()) return;
|
---|
1306 |
|
---|
1307 | /*Intermediary*/
|
---|
1308 | int numindices, numindicesup, state;
|
---|
1309 | int *indices = NULL, *indicesup = NULL;
|
---|
1310 | IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
|
---|
1311 |
|
---|
1312 | /*Get parameters and inputs: */
|
---|
1313 | Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
|
---|
1314 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
1315 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
1316 | Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
|
---|
1317 |
|
---|
1318 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
1319 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
1320 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
1321 | penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
|
---|
1322 |
|
---|
1323 | GaussPenta* gauss=new GaussPenta();
|
---|
1324 | GaussPenta* gaussup=new GaussPenta();
|
---|
1325 | for(int i=0;i<numindices;i++){
|
---|
1326 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
1327 | gaussup->GaussNode(element->GetElementType(),indicesup[i]);
|
---|
1328 |
|
---|
1329 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
1330 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
1331 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
1332 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
1333 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
1334 | meltingrate_input->GetInputValue(&meltingrate,gauss);
|
---|
1335 |
|
---|
1336 | state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
|
---|
1337 | switch (state) {
|
---|
1338 | case 0:
|
---|
1339 | // cold, dry base: apply basal surface forcing
|
---|
1340 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
1341 | break;
|
---|
1342 | case 1:
|
---|
1343 | // cold, wet base: keep at pressure melting point
|
---|
1344 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
1345 | break;
|
---|
1346 | case 2:
|
---|
1347 | // temperate, thin refreezing base:
|
---|
1348 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
1349 | break;
|
---|
1350 | case 3:
|
---|
1351 | // temperate, thin melting base: set spc
|
---|
1352 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
1353 | break;
|
---|
1354 | case 4:
|
---|
1355 | // temperate, thick melting base:
|
---|
1356 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
1357 | break;
|
---|
1358 | default:
|
---|
1359 | _printf0_(" unknown thermal basal state found!");
|
---|
1360 | }
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | /*Free ressources:*/
|
---|
1364 | xDelete<int>(indices);
|
---|
1365 | xDelete<int>(indicesup);
|
---|
1366 | delete gauss;
|
---|
1367 | delete gaussup;
|
---|
1368 | }/*}}}*/
|
---|
1369 | void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
|
---|
1370 |
|
---|
1371 | /* Check if ice in element */
|
---|
1372 | if(!element->IsIceInElement()) return;
|
---|
1373 |
|
---|
1374 | /* Only update constraints at the base.
|
---|
1375 | * Floating ice is not affected by basal BC decision chart.*/
|
---|
1376 | if(!(element->IsOnBase()) || element->IsFloating()) return;
|
---|
1377 |
|
---|
1378 | /*Intermediary*/
|
---|
1379 | int numindices, numindicesup, state;
|
---|
1380 | int *indices = NULL, *indicesup = NULL;
|
---|
1381 | IssmDouble enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
|
---|
1382 |
|
---|
1383 | /*Get parameters and inputs: */
|
---|
1384 | Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
|
---|
1385 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
1386 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
1387 | Input* meltingrate_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(meltingrate_input);
|
---|
1388 |
|
---|
1389 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
1390 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
1391 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
1392 | penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType()); _assert_(numindices==numindicesup);
|
---|
1393 |
|
---|
1394 | GaussPenta* gauss=new GaussPenta();
|
---|
1395 | GaussPenta* gaussup=new GaussPenta();
|
---|
1396 |
|
---|
1397 | for(int i=0;i<numindices;i++){
|
---|
1398 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
1399 | gaussup->GaussNode(element->GetElementType(),indicesup[i]);
|
---|
1400 |
|
---|
1401 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
1402 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
1403 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
1404 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
1405 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
1406 | meltingrate_input->GetInputValue(&meltingrate,gauss);
|
---|
1407 |
|
---|
1408 | state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
|
---|
1409 |
|
---|
1410 | switch (state) {
|
---|
1411 | case 0:
|
---|
1412 | // cold, dry base: apply basal surface forcing
|
---|
1413 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
1414 | break;
|
---|
1415 | case 1:
|
---|
1416 | // cold, wet base: keep at pressure melting point
|
---|
1417 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
1418 | break;
|
---|
1419 | case 2:
|
---|
1420 | // temperate, thin refreezing base: release spc
|
---|
1421 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
1422 | break;
|
---|
1423 | case 3:
|
---|
1424 | // temperate, thin melting base: set spc
|
---|
1425 | vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
|
---|
1426 | break;
|
---|
1427 | case 4:
|
---|
1428 | // temperate, thick melting base: set grad H*n=0
|
---|
1429 | vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
|
---|
1430 | break;
|
---|
1431 | default:
|
---|
1432 | _printf0_(" unknown thermal basal state found!");
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | /*Free ressources:*/
|
---|
1438 | xDelete<int>(indices);
|
---|
1439 | xDelete<int>(indicesup);
|
---|
1440 | delete gauss;
|
---|
1441 | delete gaussup;
|
---|
1442 | }/*}}}*/
|
---|
1443 | void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
1444 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
1445 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
1446 | * by:
|
---|
1447 | * Bi_conduct=[ dh/dx ]
|
---|
1448 | * [ dh/dy ]
|
---|
1449 | * [ dh/dz ]
|
---|
1450 | * where h is the interpolation function for node i.
|
---|
1451 | *
|
---|
1452 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
1453 | */
|
---|
1454 |
|
---|
1455 | /*Fetch number of nodes for this finite element*/
|
---|
1456 | int numnodes = element->GetNumberOfNodes();
|
---|
1457 |
|
---|
1458 | /*Get nodal functions derivatives*/
|
---|
1459 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
1460 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
1461 |
|
---|
1462 | /*Build B: */
|
---|
1463 | for(int i=0;i<numnodes;i++){
|
---|
1464 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
1465 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
1466 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
1467 | }
|
---|
1468 |
|
---|
1469 | /*Clean-up*/
|
---|
1470 | xDelete<IssmDouble>(dbasis);
|
---|
1471 | }/*}}}*/
|
---|
1472 | void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
1473 | element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
|
---|
1474 | }/*}}}*/
|
---|
1475 | int EnthalpyAnalysis::GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpyup, IssmDouble pressure, IssmDouble pressureup, IssmDouble watercolumn, IssmDouble meltingrate){/*{{{*/
|
---|
1476 |
|
---|
1477 | /* Check if ice in element */
|
---|
1478 | if(!element->IsIceInElement()) return -1;
|
---|
1479 |
|
---|
1480 | /* Only update Constraints at the base of grounded ice*/
|
---|
1481 | if(!(element->IsOnBase())) return -1;
|
---|
1482 |
|
---|
1483 | /*Intermediary*/
|
---|
1484 | int state=-1;
|
---|
1485 | IssmDouble dt;
|
---|
1486 |
|
---|
1487 | /*Get parameters and inputs: */
|
---|
1488 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1489 |
|
---|
1490 | if(enthalpy<PureIceEnthalpy(element,pressure)){
|
---|
1491 | if(watercolumn<=0.) state=0; // cold, dry base
|
---|
1492 | else state=1; // cold, wet base (refreezing)
|
---|
1493 | }
|
---|
1494 | else{
|
---|
1495 | if(enthalpyup<PureIceEnthalpy(element,pressureup)){
|
---|
1496 | if((dt==0.) && (meltingrate<0.)) state=2; // refreezing temperate base (non-physical, only for steadystate solver)
|
---|
1497 | else state=3; // temperate base, but no temperate layer
|
---|
1498 | }
|
---|
1499 | else state=4; // temperate layer with positive thickness
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | _assert_(state>=0);
|
---|
1503 | return state;
|
---|
1504 | }/*}}}*/
|
---|
1505 | IssmDouble EnthalpyAnalysis::GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure){/*{{{*/
|
---|
1506 |
|
---|
1507 | IssmDouble temperature, waterfraction;
|
---|
1508 | IssmDouble kappa_w = 0.6; // thermal conductivity of water (in W/m/K)
|
---|
1509 | IssmDouble kappa_i = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
1510 | element->EnthalpyToThermal(&temperature, &waterfraction, enthalpy, pressure);
|
---|
1511 |
|
---|
1512 | return (1.-waterfraction)*kappa_i + waterfraction*kappa_w;
|
---|
1513 | }/*}}}*/
|
---|
1514 | void EnthalpyAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
|
---|
1515 | _error_("Not implemented yet");
|
---|
1516 | }/*}}}*/
|
---|
1517 | void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
1518 |
|
---|
1519 | bool converged;
|
---|
1520 | int i,rheology_law;
|
---|
1521 | IssmDouble B_average,s_average,T_average=0.,P_average=0.;
|
---|
1522 | IssmDouble n=3.0;
|
---|
1523 | int *doflist = NULL;
|
---|
1524 | IssmDouble *xyz_list = NULL;
|
---|
1525 |
|
---|
1526 | /*Fetch number of nodes and dof for this finite element*/
|
---|
1527 | int numnodes = element->GetNumberOfNodes();
|
---|
1528 |
|
---|
1529 | /*Fetch dof list and allocate solution vector*/
|
---|
1530 | element->GetDofListLocal(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
1531 | IssmDouble* values = xNew<IssmDouble>(numnodes);
|
---|
1532 | IssmDouble* pressure = xNew<IssmDouble>(numnodes);
|
---|
1533 | IssmDouble* surface = xNew<IssmDouble>(numnodes);
|
---|
1534 | IssmDouble* B = xNew<IssmDouble>(numnodes);
|
---|
1535 | IssmDouble* temperature = xNew<IssmDouble>(numnodes);
|
---|
1536 | IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
|
---|
1537 |
|
---|
1538 | /*Use the dof list to index into the solution vector: */
|
---|
1539 | for(i=0;i<numnodes;i++){
|
---|
1540 | values[i]=solution[doflist[i]];
|
---|
1541 |
|
---|
1542 | /*Check solution*/
|
---|
1543 | if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
|
---|
1544 | if(xIsInf<IssmDouble>(values[i])) _error_("Inf found in solution vector");
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | /*Get all inputs and parameters*/
|
---|
1548 | if(element->material->ObjectEnum()!=MatestarEnum) n=element->GetMaterialParameter(MaterialsRheologyNEnum);
|
---|
1549 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
1550 | element->GetInputListOnNodes(&pressure[0],PressureEnum);
|
---|
1551 | if(converged){
|
---|
1552 | for(i=0;i<numnodes;i++){
|
---|
1553 | element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
|
---|
1554 | if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
|
---|
1555 | //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
|
---|
1556 | }
|
---|
1557 | element->AddInput(EnthalpyEnum,values,element->GetElementType());
|
---|
1558 | element->AddInput(WaterfractionEnum,waterfraction,element->GetElementType());
|
---|
1559 | element->AddInput(TemperatureEnum,temperature,element->GetElementType());
|
---|
1560 |
|
---|
1561 | /*Update Rheology only if converged (we must make sure that the temperature is below melting point
|
---|
1562 | * otherwise the rheology could be negative*/
|
---|
1563 | rheology_law=element->GetIntegerMaterialParameter(MaterialsRheologyLawEnum);
|
---|
1564 | element->GetInputListOnNodes(&surface[0],SurfaceEnum);
|
---|
1565 | switch(rheology_law){
|
---|
1566 | case NoneEnum:
|
---|
1567 | /*Do nothing: B is not temperature dependent*/
|
---|
1568 | break;
|
---|
1569 | case BuddJackaEnum:
|
---|
1570 | for(i=0;i<numnodes;i++) B[i]=BuddJacka(temperature[i]);
|
---|
1571 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
1572 | break;
|
---|
1573 | case CuffeyEnum:
|
---|
1574 | for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
|
---|
1575 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
1576 | break;
|
---|
1577 | case CuffeyTemperateEnum:
|
---|
1578 | for(i=0;i<numnodes;i++) B[i]=CuffeyTemperate(temperature[i], waterfraction[i],n);
|
---|
1579 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
1580 | break;
|
---|
1581 | case PatersonEnum:
|
---|
1582 | for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
|
---|
1583 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
1584 | break;
|
---|
1585 | case ArrheniusEnum:
|
---|
1586 | element->GetVerticesCoordinates(&xyz_list);
|
---|
1587 | for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],n);
|
---|
1588 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
1589 | break;
|
---|
1590 | case LliboutryDuvalEnum:
|
---|
1591 | for(i=0;i<numnodes;i++) B[i]=LliboutryDuval(values[i],pressure[i],n,element->GetMaterialParameter(MaterialsBetaEnum),element->GetMaterialParameter(ConstantsReferencetemperatureEnum),element->GetMaterialParameter(MaterialsHeatcapacityEnum),element->GetMaterialParameter(MaterialsLatentheatEnum));
|
---|
1592 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
1593 | break;
|
---|
1594 | default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
|
---|
1595 | }
|
---|
1596 | }
|
---|
1597 | else{
|
---|
1598 | element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | /*Free ressources:*/
|
---|
1602 | xDelete<IssmDouble>(values);
|
---|
1603 | xDelete<IssmDouble>(pressure);
|
---|
1604 | xDelete<IssmDouble>(surface);
|
---|
1605 | xDelete<IssmDouble>(B);
|
---|
1606 | xDelete<IssmDouble>(temperature);
|
---|
1607 | xDelete<IssmDouble>(waterfraction);
|
---|
1608 | xDelete<IssmDouble>(xyz_list);
|
---|
1609 | xDelete<int>(doflist);
|
---|
1610 | }/*}}}*/
|
---|
1611 | void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
|
---|
1612 |
|
---|
1613 | /*Intermediaries*/
|
---|
1614 | bool computebasalmeltingrates=true;
|
---|
1615 | bool drainicecolumn=true;
|
---|
1616 | IssmDouble dt;
|
---|
1617 |
|
---|
1618 | femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
1619 |
|
---|
1620 | if(drainicecolumn && (dt>0.)) DrainWaterfraction(femmodel);
|
---|
1621 | if(computebasalmeltingrates) ComputeBasalMeltingrate(femmodel);
|
---|
1622 |
|
---|
1623 | }/*}}}*/
|
---|
1624 | IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
|
---|
1625 |
|
---|
1626 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
1627 | IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
|
---|
1628 |
|
---|
1629 | return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
|
---|
1630 | }/*}}}*/
|
---|
1631 | IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
|
---|
1632 |
|
---|
1633 | IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
|
---|
1634 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
1635 |
|
---|
1636 | return meltingpoint-beta*pressure;
|
---|
1637 | }/*}}}*/
|
---|
1638 | void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
|
---|
1639 |
|
---|
1640 | /*Update basal dirichlet BCs for enthalpy: */
|
---|
1641 | Vector<IssmDouble>* spc = NULL;
|
---|
1642 | IssmDouble* serial_spc = NULL;
|
---|
1643 |
|
---|
1644 | spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes());
|
---|
1645 | /*First create a vector to figure out what elements should be constrained*/
|
---|
1646 | for(int i=0;i<femmodel->elements->Size();i++){
|
---|
1647 | Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
1648 | GetBasalConstraints(spc,element);
|
---|
1649 | }
|
---|
1650 |
|
---|
1651 | /*Assemble and serialize*/
|
---|
1652 | spc->Assemble();
|
---|
1653 | serial_spc=spc->ToMPISerial();
|
---|
1654 | delete spc;
|
---|
1655 |
|
---|
1656 | /*Then update basal constraints nodes accordingly*/
|
---|
1657 | for(int i=0;i<femmodel->elements->Size();i++){
|
---|
1658 | Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
1659 | ApplyBasalConstraints(serial_spc,element);
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | femmodel->UpdateConstraintsx();
|
---|
1663 |
|
---|
1664 | /*Delete*/
|
---|
1665 | xDelete<IssmDouble>(serial_spc);
|
---|
1666 | }/*}}}*/
|
---|
1667 | void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
1668 | SetActiveNodesLSMx(femmodel);
|
---|
1669 | }/*}}}*/
|
---|