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