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