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