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