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