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