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