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