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