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