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