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