[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"
|
---|
| 6 |
|
---|
| 7 | /*Model processing*/
|
---|
[17686] | 8 | int EnthalpyAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
[16534] | 9 | return 1;
|
---|
| 10 | }/*}}}*/
|
---|
[16542] | 11 | void EnthalpyAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
[16604] | 12 |
|
---|
| 13 | int numoutputs;
|
---|
| 14 | char** requestedoutputs = NULL;
|
---|
| 15 |
|
---|
| 16 | parameters->AddObject(iomodel->CopyConstantObject(ThermalStabilizationEnum));
|
---|
| 17 | parameters->AddObject(iomodel->CopyConstantObject(ThermalIsenthalpyEnum));
|
---|
| 18 | parameters->AddObject(iomodel->CopyConstantObject(ThermalIsdynamicbasalspcEnum));
|
---|
| 19 |
|
---|
| 20 | iomodel->FetchData(&requestedoutputs,&numoutputs,ThermalRequestedOutputsEnum);
|
---|
| 21 | parameters->AddObject(new IntParam(ThermalNumRequestedOutputsEnum,numoutputs));
|
---|
| 22 | if(numoutputs)parameters->AddObject(new StringArrayParam(ThermalRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
| 23 | iomodel->DeleteData(&requestedoutputs,numoutputs,ThermalRequestedOutputsEnum);
|
---|
[16539] | 24 | }/*}}}*/
|
---|
| 25 | void EnthalpyAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
| 26 |
|
---|
[17434] | 27 | bool dakota_analysis, islevelset;
|
---|
[16539] | 28 | bool isenthalpy;
|
---|
| 29 |
|
---|
| 30 | /*Now, is the model 3d? otherwise, do nothing: */
|
---|
[17700] | 31 | if(iomodel->domaintype==Domain2DhorizontalEnum)return;
|
---|
[16539] | 32 |
|
---|
| 33 | /*Is enthalpy requested?*/
|
---|
| 34 | iomodel->Constant(&isenthalpy,ThermalIsenthalpyEnum);
|
---|
| 35 | if(!isenthalpy) return;
|
---|
| 36 |
|
---|
| 37 | /*Fetch data needed: */
|
---|
| 38 | iomodel->FetchData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
|
---|
| 39 |
|
---|
| 40 | /*Update elements: */
|
---|
| 41 | int counter=0;
|
---|
| 42 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
| 43 | if(iomodel->my_elements[i]){
|
---|
| 44 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
| 45 | element->Update(i,iomodel,analysis_counter,analysis_type,P1Enum);
|
---|
| 46 | counter++;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
|
---|
[17434] | 51 | iomodel->Constant(&islevelset,TransientIslevelsetEnum);
|
---|
[16539] | 52 |
|
---|
| 53 | iomodel->FetchDataToInput(elements,ThicknessEnum);
|
---|
| 54 | iomodel->FetchDataToInput(elements,SurfaceEnum);
|
---|
[17555] | 55 | iomodel->FetchDataToInput(elements,BaseEnum);
|
---|
[16539] | 56 | iomodel->FetchDataToInput(elements,FrictionCoefficientEnum);
|
---|
| 57 | iomodel->FetchDataToInput(elements,FrictionPEnum);
|
---|
| 58 | iomodel->FetchDataToInput(elements,FrictionQEnum);
|
---|
| 59 | iomodel->FetchDataToInput(elements,MaskIceLevelsetEnum);
|
---|
| 60 | iomodel->FetchDataToInput(elements,MaskGroundediceLevelsetEnum);
|
---|
[17886] | 61 | if(iomodel->domaintype!=Domain2DhorizontalEnum){
|
---|
| 62 | iomodel->FetchDataToInput(elements,MeshVertexonbaseEnum);
|
---|
| 63 | iomodel->FetchDataToInput(elements,MeshVertexonsurfaceEnum);
|
---|
| 64 | }
|
---|
[16539] | 65 | iomodel->FetchDataToInput(elements,FlowequationElementEquationEnum);
|
---|
| 66 | iomodel->FetchDataToInput(elements,MaterialsRheologyBEnum);
|
---|
| 67 | iomodel->FetchDataToInput(elements,MaterialsRheologyNEnum);
|
---|
| 68 | iomodel->FetchDataToInput(elements,PressureEnum);
|
---|
| 69 | iomodel->FetchDataToInput(elements,TemperatureEnum);
|
---|
| 70 | iomodel->FetchDataToInput(elements,WaterfractionEnum);
|
---|
| 71 | iomodel->FetchDataToInput(elements,EnthalpyEnum);
|
---|
| 72 | iomodel->FetchDataToInput(elements,BasalforcingsGeothermalfluxEnum);
|
---|
| 73 | iomodel->FetchDataToInput(elements,WatercolumnEnum);
|
---|
| 74 | iomodel->FetchDataToInput(elements,BasalforcingsMeltingRateEnum);
|
---|
| 75 | iomodel->FetchDataToInput(elements,VxEnum);
|
---|
| 76 | iomodel->FetchDataToInput(elements,VyEnum);
|
---|
| 77 | iomodel->FetchDataToInput(elements,VzEnum);
|
---|
| 78 | InputUpdateFromConstantx(elements,0.,VxMeshEnum);
|
---|
| 79 | InputUpdateFromConstantx(elements,0.,VyMeshEnum);
|
---|
| 80 | InputUpdateFromConstantx(elements,0.,VzMeshEnum);
|
---|
| 81 | if(dakota_analysis){
|
---|
| 82 | elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
|
---|
| 83 | elements->InputDuplicate(BasalforcingsMeltingRateEnum,QmuMeltingEnum);
|
---|
| 84 | elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
|
---|
| 85 | elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
|
---|
| 86 | elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
|
---|
| 87 | }
|
---|
[17434] | 88 | if(islevelset){
|
---|
| 89 | iomodel->FetchDataToInput(elements,IceMaskNodeActivationEnum);
|
---|
[17610] | 90 | iomodel->FetchDataToInput(elements,MeshVertexonbaseEnum); // required for updating active nodes
|
---|
[17434] | 91 | }
|
---|
[16539] | 92 |
|
---|
| 93 | /*Free data: */
|
---|
| 94 | iomodel->DeleteData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
|
---|
| 95 | }/*}}}*/
|
---|
[16542] | 96 | void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
|
---|
[16539] | 97 |
|
---|
[17700] | 98 | if(iomodel->domaintype==Domain3DEnum) iomodel->FetchData(2,MeshVertexonbaseEnum,MeshVertexonsurfaceEnum);
|
---|
[16542] | 99 | ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,P1Enum);
|
---|
[17610] | 100 | iomodel->DeleteData(2,MeshVertexonbaseEnum,MeshVertexonsurfaceEnum);
|
---|
[16539] | 101 | }/*}}}*/
|
---|
[16542] | 102 | void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
[16539] | 103 |
|
---|
| 104 | /*Intermediary*/
|
---|
| 105 | int count;
|
---|
| 106 | int M,N;
|
---|
| 107 | bool spcpresent = false;
|
---|
| 108 | IssmDouble heatcapacity;
|
---|
| 109 | IssmDouble referencetemperature;
|
---|
| 110 |
|
---|
| 111 | /*Output*/
|
---|
| 112 | IssmDouble *spcvector = NULL;
|
---|
| 113 | IssmDouble* times=NULL;
|
---|
| 114 | IssmDouble* values=NULL;
|
---|
| 115 |
|
---|
| 116 | /*Fetch parameters: */
|
---|
| 117 | iomodel->Constant(&heatcapacity,MaterialsHeatcapacityEnum);
|
---|
| 118 | iomodel->Constant(&referencetemperature,ConstantsReferencetemperatureEnum);
|
---|
| 119 |
|
---|
| 120 | /*return if 2d mesh*/
|
---|
[17700] | 121 | if(iomodel->domaintype==Domain2DhorizontalEnum) return;
|
---|
[16539] | 122 |
|
---|
| 123 | /*Fetch data: */
|
---|
| 124 | iomodel->FetchData(&spcvector,&M,&N,ThermalSpctemperatureEnum);
|
---|
| 125 |
|
---|
| 126 | //FIX ME: SHOULD USE IOMODELCREATECONSTRAINTS
|
---|
| 127 | /*Transient or static?:*/
|
---|
| 128 | if(M==iomodel->numberofvertices){
|
---|
| 129 | /*static: just create Constraints objects*/
|
---|
| 130 | count=0;
|
---|
| 131 |
|
---|
| 132 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
| 133 | /*keep only this partition's nodes:*/
|
---|
| 134 | if((iomodel->my_vertices[i])){
|
---|
| 135 |
|
---|
| 136 | if (!xIsNan<IssmDouble>(spcvector[i])){
|
---|
| 137 |
|
---|
[17600] | 138 | constraints->AddObject(new SpcStatic(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,0,heatcapacity*(spcvector[i]-referencetemperature),EnthalpyAnalysisEnum));
|
---|
[16539] | 139 | count++;
|
---|
| 140 |
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | else if (M==(iomodel->numberofvertices+1)){
|
---|
| 146 | /*transient: create transient SpcTransient objects. Same logic, except we need to retrieve
|
---|
| 147 | * various times and values to initialize an SpcTransient object: */
|
---|
| 148 | count=0;
|
---|
| 149 |
|
---|
| 150 | /*figure out times: */
|
---|
| 151 | times=xNew<IssmDouble>(N);
|
---|
| 152 | for(int j=0;j<N;j++){
|
---|
| 153 | times[j]=spcvector[(M-1)*N+j];
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | /*Create constraints from x,y,z: */
|
---|
| 157 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
| 158 |
|
---|
| 159 | /*keep only this partition's nodes:*/
|
---|
| 160 | if((iomodel->my_vertices[i])){
|
---|
| 161 |
|
---|
| 162 | /*figure out times and values: */
|
---|
| 163 | values=xNew<IssmDouble>(N);
|
---|
| 164 | spcpresent=false;
|
---|
| 165 | for(int j=0;j<N;j++){
|
---|
| 166 | values[j]=heatcapacity*(spcvector[i*N+j]-referencetemperature);
|
---|
| 167 | if(!xIsNan<IssmDouble>(values[j]))spcpresent=true; //NaN means no spc by default
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | if(spcpresent){
|
---|
[17600] | 171 | constraints->AddObject(new SpcTransient(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,0,N,times,values,EnthalpyAnalysisEnum));
|
---|
[16539] | 172 | count++;
|
---|
| 173 | }
|
---|
| 174 | xDelete<IssmDouble>(values);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | else{
|
---|
| 179 | _error_("Size of field " << EnumToStringx(ThermalSpctemperatureEnum) << " not supported");
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | /*Free ressources:*/
|
---|
| 183 | iomodel->DeleteData(spcvector,ThermalSpctemperatureEnum);
|
---|
| 184 | xDelete<IssmDouble>(times);
|
---|
| 185 | xDelete<IssmDouble>(values);
|
---|
| 186 | }/*}}}*/
|
---|
[16542] | 187 | void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
[16539] | 188 |
|
---|
| 189 | /*No loads */
|
---|
| 190 | }/*}}}*/
|
---|
[16675] | 191 |
|
---|
[16782] | 192 | /*Finite Element Analysis*/
|
---|
[17029] | 193 | void EnthalpyAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
[17005] | 194 | _error_("not implemented");
|
---|
| 195 | }/*}}}*/
|
---|
[17000] | 196 | ElementVector* EnthalpyAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
| 197 | /*Default, return NULL*/
|
---|
| 198 | return NULL;
|
---|
| 199 | }/*}}}*/
|
---|
[16992] | 200 | ElementMatrix* EnthalpyAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
| 201 | _error_("Not implemented");
|
---|
| 202 | }/*}}}*/
|
---|
[16782] | 203 | ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
[16888] | 204 |
|
---|
[17434] | 205 | /* Check if ice in element */
|
---|
| 206 | if(!element->IsIceInElement()) return NULL;
|
---|
| 207 |
|
---|
[16888] | 208 | /*compute all stiffness matrices for this element*/
|
---|
| 209 | ElementMatrix* Ke1=CreateKMatrixVolume(element);
|
---|
| 210 | ElementMatrix* Ke2=CreateKMatrixShelf(element);
|
---|
| 211 | ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
|
---|
| 212 |
|
---|
| 213 | /*clean-up and return*/
|
---|
| 214 | delete Ke1;
|
---|
| 215 | delete Ke2;
|
---|
| 216 | return Ke;
|
---|
[16782] | 217 | }/*}}}*/
|
---|
[16888] | 218 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
|
---|
| 219 |
|
---|
[17434] | 220 | /* Check if ice in element */
|
---|
| 221 | if(!element->IsIceInElement()) return NULL;
|
---|
| 222 |
|
---|
[16888] | 223 | /*Intermediaries */
|
---|
| 224 | int stabilization;
|
---|
| 225 | IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
|
---|
| 226 | IssmDouble h,hx,hy,hz,vx,vy,vz;
|
---|
| 227 | IssmDouble tau_parameter,diameter;
|
---|
| 228 | IssmDouble D_scalar;
|
---|
| 229 | IssmDouble* xyz_list = NULL;
|
---|
| 230 |
|
---|
| 231 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 232 | int numnodes = element->GetNumberOfNodes();
|
---|
| 233 |
|
---|
| 234 | /*Initialize Element vector and other vectors*/
|
---|
| 235 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 236 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 237 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
| 238 | IssmDouble* B = xNew<IssmDouble>(3*numnodes);
|
---|
| 239 | IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
|
---|
| 240 | IssmDouble D[3][3] = {0.};
|
---|
| 241 | IssmDouble K[3][3];
|
---|
| 242 |
|
---|
| 243 | /*Retrieve all inputs and parameters*/
|
---|
| 244 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 245 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 246 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
[17946] | 247 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[16888] | 248 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 249 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
| 250 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 251 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 252 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 253 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 254 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 255 | Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
|
---|
| 256 | Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
|
---|
| 257 | Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
|
---|
| 258 | if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
|
---|
| 259 |
|
---|
| 260 | /*Enthalpy diffusion parameter*/
|
---|
[17027] | 261 | IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
[16888] | 262 |
|
---|
| 263 | /* Start looping on the number of gaussian points: */
|
---|
| 264 | Gauss* gauss=element->NewGauss(2);
|
---|
| 265 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 266 | gauss->GaussPoint(ig);
|
---|
| 267 |
|
---|
| 268 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 269 | D_scalar=gauss->weight*Jdet;
|
---|
| 270 | if(dt!=0.) D_scalar=D_scalar*dt;
|
---|
| 271 |
|
---|
| 272 | /*Conduction: */
|
---|
| 273 | GetBConduct(B,element,xyz_list,gauss);
|
---|
| 274 | D[0][0]=D_scalar*kappa/rho_ice;
|
---|
| 275 | D[1][1]=D_scalar*kappa/rho_ice;
|
---|
| 276 | D[2][2]=D_scalar*kappa/rho_ice;
|
---|
| 277 | TripleMultiply(B,3,numnodes,1,
|
---|
| 278 | &D[0][0],3,3,0,
|
---|
| 279 | B,3,numnodes,0,
|
---|
| 280 | &Ke->values[0],1);
|
---|
| 281 |
|
---|
| 282 | /*Advection: */
|
---|
| 283 | GetBAdvec(B,element,xyz_list,gauss);
|
---|
| 284 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
| 285 | vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
|
---|
| 286 | vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
|
---|
| 287 | vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
|
---|
| 288 | D[0][0]=D_scalar*vx;
|
---|
| 289 | D[1][1]=D_scalar*vy;
|
---|
| 290 | D[2][2]=D_scalar*vz;
|
---|
| 291 | TripleMultiply(B,3,numnodes,1,
|
---|
| 292 | &D[0][0],3,3,0,
|
---|
| 293 | Bprime,3,numnodes,0,
|
---|
| 294 | &Ke->values[0],1);
|
---|
| 295 |
|
---|
| 296 | /*Transient: */
|
---|
| 297 | if(dt!=0.){
|
---|
| 298 | D_scalar=gauss->weight*Jdet;
|
---|
| 299 | element->NodalFunctions(basis,gauss);
|
---|
| 300 | TripleMultiply(basis,numnodes,1,0,
|
---|
| 301 | &D_scalar,1,1,0,
|
---|
| 302 | basis,1,numnodes,0,
|
---|
| 303 | &Ke->values[0],1);
|
---|
| 304 | D_scalar=D_scalar*dt;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | /*Artifficial diffusivity*/
|
---|
| 308 | if(stabilization==1){
|
---|
| 309 | element->ElementSizes(&hx,&hy,&hz);
|
---|
| 310 | vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
|
---|
| 311 | h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
|
---|
[16894] | 312 | K[0][0]=h/(2.*vel)*vx*vx; K[0][1]=h/(2.*vel)*vx*vy; K[0][2]=h/(2.*vel)*vx*vz;
|
---|
| 313 | K[1][0]=h/(2.*vel)*vy*vx; K[1][1]=h/(2.*vel)*vy*vy; K[1][2]=h/(2.*vel)*vy*vz;
|
---|
| 314 | K[2][0]=h/(2.*vel)*vz*vx; K[2][1]=h/(2.*vel)*vz*vy; K[2][2]=h/(2.*vel)*vz*vz;
|
---|
[16888] | 315 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
|
---|
| 316 |
|
---|
| 317 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
| 318 | TripleMultiply(Bprime,3,numnodes,1,
|
---|
| 319 | &K[0][0],3,3,0,
|
---|
| 320 | Bprime,3,numnodes,0,
|
---|
| 321 | &Ke->values[0],1);
|
---|
| 322 | }
|
---|
| 323 | else if(stabilization==2){
|
---|
| 324 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 325 | tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
|
---|
| 326 | for(int i=0;i<numnodes;i++){
|
---|
| 327 | for(int j=0;j<numnodes;j++){
|
---|
| 328 | Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
|
---|
[16895] | 329 | ((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] | 330 | }
|
---|
| 331 | }
|
---|
| 332 | if(dt!=0.){
|
---|
[16896] | 333 | D_scalar=gauss->weight*Jdet;
|
---|
[16888] | 334 | for(int i=0;i<numnodes;i++){
|
---|
| 335 | for(int j=0;j<numnodes;j++){
|
---|
[16895] | 336 | 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] | 337 | }
|
---|
| 338 | }
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | /*Clean up and return*/
|
---|
| 344 | xDelete<IssmDouble>(xyz_list);
|
---|
| 345 | xDelete<IssmDouble>(basis);
|
---|
| 346 | xDelete<IssmDouble>(dbasis);
|
---|
| 347 | xDelete<IssmDouble>(B);
|
---|
| 348 | xDelete<IssmDouble>(Bprime);
|
---|
| 349 | delete gauss;
|
---|
| 350 | return Ke;
|
---|
| 351 | }/*}}}*/
|
---|
| 352 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
|
---|
| 353 |
|
---|
[17434] | 354 | /* Check if ice in element */
|
---|
| 355 | if(!element->IsIceInElement()) return NULL;
|
---|
| 356 |
|
---|
[16888] | 357 | /*Initialize Element matrix and return if necessary*/
|
---|
[17585] | 358 | if(!element->IsOnBase() || !element->IsFloating()) return NULL;
|
---|
[16888] | 359 |
|
---|
[16986] | 360 | /*Intermediaries*/
|
---|
[16888] | 361 | IssmDouble dt,Jdet,D;
|
---|
| 362 | IssmDouble *xyz_list_base = NULL;
|
---|
| 363 |
|
---|
| 364 | /*Fetch number of nodes for this finite element*/
|
---|
| 365 | int numnodes = element->GetNumberOfNodes();
|
---|
| 366 |
|
---|
| 367 | /*Initialize vectors*/
|
---|
| 368 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 369 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 370 |
|
---|
| 371 | /*Retrieve all inputs and parameters*/
|
---|
| 372 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 373 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 374 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
[17946] | 375 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[16888] | 376 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 377 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 378 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
| 379 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
| 380 |
|
---|
| 381 | /* Start looping on the number of gaussian points: */
|
---|
| 382 | Gauss* gauss=element->NewGaussBase(2);
|
---|
| 383 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 384 | gauss->GaussPoint(ig);
|
---|
| 385 |
|
---|
| 386 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 387 | element->NodalFunctions(basis,gauss);
|
---|
| 388 |
|
---|
| 389 | D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
|
---|
| 390 | if(reCast<bool,IssmDouble>(dt)) D=dt*D;
|
---|
| 391 | TripleMultiply(basis,numnodes,1,0,
|
---|
| 392 | &D,1,1,0,
|
---|
| 393 | basis,1,numnodes,0,
|
---|
| 394 | &Ke->values[0],1);
|
---|
| 395 |
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | /*Clean up and return*/
|
---|
| 399 | delete gauss;
|
---|
| 400 | xDelete<IssmDouble>(basis);
|
---|
| 401 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 402 | return Ke;
|
---|
| 403 | }/*}}}*/
|
---|
[16782] | 404 | ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
[16812] | 405 |
|
---|
[17434] | 406 | /* Check if ice in element */
|
---|
| 407 | if(!element->IsIceInElement()) return NULL;
|
---|
| 408 |
|
---|
[16812] | 409 | /*compute all load vectors for this element*/
|
---|
| 410 | ElementVector* pe1=CreatePVectorVolume(element);
|
---|
| 411 | ElementVector* pe2=CreatePVectorSheet(element);
|
---|
| 412 | ElementVector* pe3=CreatePVectorShelf(element);
|
---|
| 413 | ElementVector* pe =new ElementVector(pe1,pe2,pe3);
|
---|
| 414 |
|
---|
| 415 | /*clean-up and return*/
|
---|
| 416 | delete pe1;
|
---|
| 417 | delete pe2;
|
---|
| 418 | delete pe3;
|
---|
| 419 | return pe;
|
---|
[16782] | 420 | }/*}}}*/
|
---|
[16812] | 421 | ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
|
---|
| 422 |
|
---|
[17434] | 423 | /* Check if ice in element */
|
---|
| 424 | if(!element->IsIceInElement()) return NULL;
|
---|
| 425 |
|
---|
[16812] | 426 | /*Intermediaries*/
|
---|
[17014] | 427 | int i, stabilization;
|
---|
[16812] | 428 | IssmDouble Jdet,phi,dt;
|
---|
[17014] | 429 | IssmDouble enthalpy, Hpmp;
|
---|
| 430 | IssmDouble enthalpypicard, d1enthalpypicard[3];
|
---|
| 431 | IssmDouble pressure, d1pressure[3], d2pressure;
|
---|
| 432 | IssmDouble waterfractionpicard;
|
---|
| 433 | IssmDouble kappa,tau_parameter,diameter,kappa_w;
|
---|
[16812] | 434 | IssmDouble u,v,w;
|
---|
[17014] | 435 | IssmDouble scalar_def, scalar_sens ,scalar_transient;
|
---|
[16812] | 436 | IssmDouble* xyz_list = NULL;
|
---|
[17014] | 437 | IssmDouble d1H_d1P, d1P2;
|
---|
[16812] | 438 |
|
---|
| 439 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 440 | int numnodes = element->GetNumberOfNodes();
|
---|
| 441 | int numvertices = element->GetNumberOfVertices();
|
---|
| 442 |
|
---|
| 443 | /*Initialize Element vector*/
|
---|
| 444 | ElementVector* pe = element->NewElementVector();
|
---|
| 445 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 446 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
| 447 |
|
---|
| 448 | /*Retrieve all inputs and parameters*/
|
---|
| 449 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 450 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
[17014] | 451 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
[16812] | 452 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
[17014] | 453 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
| 454 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
| 455 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
[16812] | 456 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 457 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
| 458 | Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 459 | Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 460 | Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
|
---|
[17014] | 461 | Input* enthalpypicard_input=element->GetInput(EnthalpyPicardEnum); _assert_(enthalpypicard_input);
|
---|
| 462 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 463 | Input* enthalpy_input=NULL;
|
---|
[16812] | 464 | if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
|
---|
| 465 | if(stabilization==2){
|
---|
| 466 | diameter=element->MinEdgeLength(xyz_list);
|
---|
[17027] | 467 | kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>=0.);
|
---|
[16812] | 468 | }
|
---|
| 469 |
|
---|
| 470 | /* Start looping on the number of gaussian points: */
|
---|
[16975] | 471 | Gauss* gauss=element->NewGauss(3);
|
---|
[16812] | 472 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 473 | gauss->GaussPoint(ig);
|
---|
| 474 |
|
---|
| 475 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 476 | element->NodalFunctions(basis,gauss);
|
---|
[17014] | 477 |
|
---|
| 478 | /*viscous dissipation*/
|
---|
[16812] | 479 | element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
|
---|
| 480 |
|
---|
| 481 | scalar_def=phi/rho_ice*Jdet*gauss->weight;
|
---|
[16895] | 482 | if(dt!=0.) scalar_def=scalar_def*dt;
|
---|
[16812] | 483 |
|
---|
[17014] | 484 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
|
---|
[16812] | 485 |
|
---|
[17014] | 486 | /*sensible heat flux in temperate ice*/
|
---|
| 487 | enthalpypicard_input->GetInputValue(&enthalpypicard,gauss);
|
---|
| 488 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 489 | Hpmp=this->PureIceEnthalpy(element, pressure);
|
---|
| 490 |
|
---|
| 491 | if(enthalpypicard>=Hpmp){
|
---|
| 492 | enthalpypicard_input->GetInputDerivativeValue(&d1enthalpypicard[0],xyz_list,gauss);
|
---|
| 493 | pressure_input->GetInputDerivativeValue(&d1pressure[0],xyz_list,gauss);
|
---|
| 494 | d2pressure=0.; // for linear elements, 2nd derivative is zero
|
---|
| 495 |
|
---|
| 496 | d1H_d1P=0.;
|
---|
| 497 | for(i=0;i<3;i++) d1H_d1P+=d1enthalpypicard[i]*d1pressure[i];
|
---|
| 498 | d1P2=0.;
|
---|
| 499 | for(i=0;i<3;i++) d1P2+=pow(d1pressure[i],2.);
|
---|
| 500 |
|
---|
| 501 | scalar_sens=-beta*((temperateiceconductivity - thermalconductivity)/latentheat*(d1H_d1P + beta*heatcapacity*d1P2))/rho_ice;
|
---|
| 502 | if(dt!=0.) scalar_sens=scalar_sens*dt;
|
---|
| 503 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_sens*basis[i];
|
---|
| 504 | }
|
---|
| 505 |
|
---|
[16812] | 506 | /* Build transient now */
|
---|
| 507 | if(reCast<bool,IssmDouble>(dt)){
|
---|
| 508 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
| 509 | scalar_transient=enthalpy*Jdet*gauss->weight;
|
---|
[17014] | 510 | for(i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
|
---|
[16812] | 511 | }
|
---|
| 512 |
|
---|
| 513 | if(stabilization==2){
|
---|
| 514 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 515 |
|
---|
| 516 | vx_input->GetInputValue(&u,gauss);
|
---|
| 517 | vy_input->GetInputValue(&v,gauss);
|
---|
| 518 | vz_input->GetInputValue(&w,gauss);
|
---|
[16895] | 519 | tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
|
---|
[16812] | 520 |
|
---|
[17014] | 521 | 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] | 522 |
|
---|
| 523 | if(dt!=0.){
|
---|
[17014] | 524 | 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] | 525 | }
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | /*Clean up and return*/
|
---|
| 530 | xDelete<IssmDouble>(basis);
|
---|
| 531 | xDelete<IssmDouble>(dbasis);
|
---|
| 532 | xDelete<IssmDouble>(xyz_list);
|
---|
| 533 | delete gauss;
|
---|
| 534 | return pe;
|
---|
| 535 |
|
---|
| 536 | }/*}}}*/
|
---|
| 537 | ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
|
---|
[16888] | 538 |
|
---|
[17434] | 539 | /* Check if ice in element */
|
---|
| 540 | if(!element->IsIceInElement()) return NULL;
|
---|
| 541 |
|
---|
[17014] | 542 | /* implementation of the basal condition decision chart of Aschwanden 2012, Fig.5 */
|
---|
[17585] | 543 | if(!element->IsOnBase() || element->IsFloating()) return NULL;
|
---|
[16888] | 544 |
|
---|
| 545 | IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
|
---|
| 546 | IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
|
---|
| 547 | IssmDouble *xyz_list_base = NULL;
|
---|
| 548 |
|
---|
| 549 | /*Fetch number of nodes for this finite element*/
|
---|
| 550 | int numnodes = element->GetNumberOfNodes();
|
---|
| 551 |
|
---|
| 552 | /*Initialize vectors*/
|
---|
| 553 | ElementVector* pe = element->NewElementVector();
|
---|
| 554 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 555 |
|
---|
| 556 | /*Retrieve all inputs and parameters*/
|
---|
| 557 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 558 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 559 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 560 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 561 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 562 | Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
|
---|
| 563 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 564 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
| 565 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
| 566 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 567 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 568 |
|
---|
| 569 | /*Build friction element, needed later: */
|
---|
| 570 | Friction* friction=new Friction(element,3);
|
---|
| 571 |
|
---|
| 572 | /* Start looping on the number of gaussian points: */
|
---|
| 573 | Gauss* gauss = element->NewGaussBase(2);
|
---|
| 574 | Gauss* gaussup = element->NewGaussTop(2);
|
---|
| 575 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 576 | gauss->GaussPoint(ig);
|
---|
| 577 |
|
---|
| 578 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 579 | element->NodalFunctions(basis,gauss);
|
---|
| 580 |
|
---|
| 581 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
| 582 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 583 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
| 584 |
|
---|
[17014] | 585 | if((watercolumn<=0.) && (enthalpy<PureIceEnthalpy(element,pressure))){
|
---|
[16888] | 586 | /* the above check is equivalent to
|
---|
[17014] | 587 | NOT [(watercolumn>0.) AND (enthalpy<PIE)] AND (enthalpy<PIE)*/
|
---|
[16888] | 588 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
| 589 |
|
---|
[17943] | 590 | friction->GetAlpha2(&alpha2,gauss);
|
---|
[16888] | 591 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 592 | vy_input->GetInputValue(&vy,gauss);
|
---|
| 593 | vz_input->GetInputValue(&vz,gauss);
|
---|
| 594 | basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
| 595 | heatflux = (basalfriction+geothermalflux)/(rho_ice);
|
---|
| 596 |
|
---|
| 597 | scalar = gauss->weight*Jdet*heatflux;
|
---|
| 598 | if(dt!=0.) scalar=dt*scalar;
|
---|
| 599 |
|
---|
| 600 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
|
---|
| 601 | }
|
---|
| 602 | else if(enthalpy >= PureIceEnthalpy(element,pressure)){
|
---|
| 603 | /* check positive thickness of temperate basal ice layer */
|
---|
| 604 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
| 605 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
| 606 | if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
|
---|
[17014] | 607 | // do nothing, set grad enthalpy*n=0.
|
---|
[16888] | 608 | }
|
---|
| 609 | else{
|
---|
| 610 | // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
|
---|
| 611 | }
|
---|
| 612 | }
|
---|
| 613 | else{
|
---|
[17014] | 614 | // base cold, but watercolumn positive. Set base to pressure melting point enthalpy
|
---|
[16888] | 615 | }
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | /*Clean up and return*/
|
---|
| 619 | delete gauss;
|
---|
| 620 | delete gaussup;
|
---|
| 621 | delete friction;
|
---|
| 622 | xDelete<IssmDouble>(basis);
|
---|
| 623 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 624 | return pe;
|
---|
| 625 |
|
---|
[16812] | 626 | }/*}}}*/
|
---|
| 627 | ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
|
---|
| 628 |
|
---|
[17434] | 629 | /* Check if ice in element */
|
---|
| 630 | if(!element->IsIceInElement()) return NULL;
|
---|
| 631 |
|
---|
[16888] | 632 | /*Get basal element*/
|
---|
[17585] | 633 | if(!element->IsOnBase() || !element->IsFloating()) return NULL;
|
---|
[16888] | 634 |
|
---|
[16813] | 635 | IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
|
---|
[16812] | 636 | IssmDouble *xyz_list_base = NULL;
|
---|
| 637 |
|
---|
| 638 | /*Fetch number of nodes for this finite element*/
|
---|
| 639 | int numnodes = element->GetNumberOfNodes();
|
---|
| 640 |
|
---|
| 641 | /*Initialize vectors*/
|
---|
| 642 | ElementVector* pe = element->NewElementVector();
|
---|
| 643 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 644 |
|
---|
| 645 | /*Retrieve all inputs and parameters*/
|
---|
| 646 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 647 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 648 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 649 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
[17946] | 650 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[16812] | 651 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 652 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 653 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
| 654 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
| 655 |
|
---|
| 656 | /* Start looping on the number of gaussian points: */
|
---|
| 657 | Gauss* gauss=element->NewGaussBase(2);
|
---|
| 658 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 659 | gauss->GaussPoint(ig);
|
---|
| 660 |
|
---|
| 661 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 662 | element->NodalFunctions(basis,gauss);
|
---|
| 663 |
|
---|
| 664 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
[16813] | 665 | h_pmp=element->PureIceEnthalpy(pressure);
|
---|
[16812] | 666 |
|
---|
[16813] | 667 | scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
|
---|
[16812] | 668 | if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
|
---|
| 669 |
|
---|
| 670 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
|
---|
| 671 | }
|
---|
| 672 |
|
---|
| 673 | /*Clean up and return*/
|
---|
| 674 | delete gauss;
|
---|
| 675 | xDelete<IssmDouble>(basis);
|
---|
| 676 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 677 | return pe;
|
---|
| 678 | }/*}}}*/
|
---|
[16888] | 679 | void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 680 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 681 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 682 | * by:
|
---|
| 683 | * Bi_conduct=[ dh/dx ]
|
---|
| 684 | * [ dh/dy ]
|
---|
| 685 | * [ dh/dz ]
|
---|
| 686 | * where h is the interpolation function for node i.
|
---|
| 687 | *
|
---|
| 688 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
| 689 | */
|
---|
| 690 |
|
---|
| 691 | /*Fetch number of nodes for this finite element*/
|
---|
| 692 | int numnodes = element->GetNumberOfNodes();
|
---|
| 693 |
|
---|
| 694 | /*Get nodal functions derivatives*/
|
---|
| 695 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
| 696 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 697 |
|
---|
| 698 | /*Build B: */
|
---|
| 699 | for(int i=0;i<numnodes;i++){
|
---|
| 700 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
| 701 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
| 702 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | /*Clean-up*/
|
---|
| 706 | xDelete<IssmDouble>(dbasis);
|
---|
| 707 | }/*}}}*/
|
---|
| 708 | void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 709 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 710 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 711 | * by:
|
---|
| 712 | * Bi_advec =[ h ]
|
---|
| 713 | * [ h ]
|
---|
| 714 | * [ h ]
|
---|
| 715 | * where h is the interpolation function for node i.
|
---|
| 716 | *
|
---|
| 717 | * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
|
---|
| 718 | */
|
---|
| 719 |
|
---|
| 720 | /*Fetch number of nodes for this finite element*/
|
---|
| 721 | int numnodes = element->GetNumberOfNodes();
|
---|
| 722 |
|
---|
| 723 | /*Get nodal functions*/
|
---|
| 724 | IssmDouble* basis=xNew<IssmDouble>(numnodes);
|
---|
| 725 | element->NodalFunctions(basis,gauss);
|
---|
| 726 |
|
---|
| 727 | /*Build B: */
|
---|
| 728 | for(int i=0;i<numnodes;i++){
|
---|
| 729 | B[numnodes*0+i] = basis[i];
|
---|
| 730 | B[numnodes*1+i] = basis[i];
|
---|
| 731 | B[numnodes*2+i] = basis[i];
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | /*Clean-up*/
|
---|
| 735 | xDelete<IssmDouble>(basis);
|
---|
| 736 | }/*}}}*/
|
---|
| 737 | void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 738 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 739 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 740 | * by:
|
---|
| 741 | * Biprime_advec=[ dh/dx ]
|
---|
| 742 | * [ dh/dy ]
|
---|
| 743 | * [ dh/dz ]
|
---|
| 744 | * where h is the interpolation function for node i.
|
---|
| 745 | *
|
---|
| 746 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
| 747 | */
|
---|
| 748 |
|
---|
| 749 | /*Fetch number of nodes for this finite element*/
|
---|
| 750 | int numnodes = element->GetNumberOfNodes();
|
---|
| 751 |
|
---|
| 752 | /*Get nodal functions derivatives*/
|
---|
| 753 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
| 754 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 755 |
|
---|
| 756 | /*Build B: */
|
---|
| 757 | for(int i=0;i<numnodes;i++){
|
---|
| 758 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
| 759 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
| 760 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
| 761 | }
|
---|
| 762 |
|
---|
| 763 | /*Clean-up*/
|
---|
| 764 | xDelete<IssmDouble>(dbasis);
|
---|
| 765 | }/*}}}*/
|
---|
[16675] | 766 | void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
| 767 | element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
|
---|
| 768 | }/*}}}*/
|
---|
[16684] | 769 | void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[16734] | 770 |
|
---|
| 771 | bool converged;
|
---|
| 772 | int i,rheology_law;
|
---|
| 773 | IssmDouble B_average,s_average,T_average=0.,P_average=0.;
|
---|
| 774 | int *doflist = NULL;
|
---|
| 775 | IssmDouble *xyz_list = NULL;
|
---|
| 776 |
|
---|
| 777 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 778 | int numnodes = element->GetNumberOfNodes();
|
---|
| 779 |
|
---|
| 780 | /*Fetch dof list and allocate solution vector*/
|
---|
| 781 | element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
| 782 | IssmDouble* values = xNew<IssmDouble>(numnodes);
|
---|
| 783 | IssmDouble* pressure = xNew<IssmDouble>(numnodes);
|
---|
[16745] | 784 | IssmDouble* surface = xNew<IssmDouble>(numnodes);
|
---|
| 785 | IssmDouble* B = xNew<IssmDouble>(numnodes);
|
---|
[16734] | 786 | IssmDouble* temperature = xNew<IssmDouble>(numnodes);
|
---|
| 787 | IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
|
---|
| 788 |
|
---|
| 789 | /*Use the dof list to index into the solution vector: */
|
---|
| 790 | for(i=0;i<numnodes;i++){
|
---|
| 791 | values[i]=solution[doflist[i]];
|
---|
| 792 |
|
---|
| 793 | /*Check solution*/
|
---|
| 794 | if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
|
---|
| 795 | }
|
---|
| 796 |
|
---|
| 797 | /*Get all inputs and parameters*/
|
---|
| 798 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
[16745] | 799 | element->GetInputListOnNodes(&pressure[0],PressureEnum);
|
---|
[16734] | 800 | if(converged){
|
---|
| 801 | for(i=0;i<numnodes;i++){
|
---|
| 802 | element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
|
---|
| 803 | if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
|
---|
[17045] | 804 | //if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
|
---|
[16734] | 805 | }
|
---|
[17609] | 806 | element->AddInput(EnthalpyEnum,values,element->GetElementType());
|
---|
| 807 | element->AddInput(WaterfractionEnum,waterfraction,element->GetElementType());
|
---|
| 808 | element->AddInput(TemperatureEnum,temperature,element->GetElementType());
|
---|
[16734] | 809 |
|
---|
| 810 | /*Update Rheology only if converged (we must make sure that the temperature is below melting point
|
---|
| 811 | * otherwise the rheology could be negative*/
|
---|
| 812 | element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
|
---|
[16745] | 813 | element->GetInputListOnNodes(&surface[0],SurfaceEnum);
|
---|
[16734] | 814 | switch(rheology_law){
|
---|
| 815 | case NoneEnum:
|
---|
| 816 | /*Do nothing: B is not temperature dependent*/
|
---|
| 817 | break;
|
---|
[17459] | 818 | case CuffeyEnum:
|
---|
| 819 | for(i=0;i<numnodes;i++) B[i]=Cuffey(temperature[i]);
|
---|
[17609] | 820 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
[17459] | 821 | break;
|
---|
[16734] | 822 | case PatersonEnum:
|
---|
[16748] | 823 | for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
|
---|
[17609] | 824 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
[16734] | 825 | break;
|
---|
[16745] | 826 | case ArrheniusEnum:
|
---|
[16734] | 827 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[16748] | 828 | for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
|
---|
[17609] | 829 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
[16734] | 830 | break;
|
---|
| 831 | case LliboutryDuvalEnum:
|
---|
[16750] | 832 | 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));
|
---|
[17609] | 833 | element->AddInput(MaterialsRheologyBEnum,&B[0],element->GetElementType());
|
---|
[16745] | 834 | break;
|
---|
| 835 | default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
|
---|
[16734] | 836 | }
|
---|
| 837 | }
|
---|
| 838 | else{
|
---|
[17609] | 839 | element->AddInput(EnthalpyPicardEnum,values,element->GetElementType());
|
---|
[16734] | 840 | }
|
---|
| 841 |
|
---|
| 842 | /*Free ressources:*/
|
---|
| 843 | xDelete<IssmDouble>(values);
|
---|
| 844 | xDelete<IssmDouble>(pressure);
|
---|
[16745] | 845 | xDelete<IssmDouble>(surface);
|
---|
| 846 | xDelete<IssmDouble>(B);
|
---|
[16734] | 847 | xDelete<IssmDouble>(temperature);
|
---|
| 848 | xDelete<IssmDouble>(waterfraction);
|
---|
| 849 | xDelete<IssmDouble>(xyz_list);
|
---|
| 850 | xDelete<int>(doflist);
|
---|
[16684] | 851 | }/*}}}*/
|
---|
[17212] | 852 | void EnthalpyAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
[17434] | 853 |
|
---|
| 854 | bool islevelset;
|
---|
| 855 | femmodel->parameters->FindParam(&islevelset,TransientIslevelsetEnum);
|
---|
| 856 | if(islevelset){
|
---|
| 857 | SetActiveNodesLSMx(femmodel);
|
---|
| 858 | }
|
---|
[17212] | 859 | return;
|
---|
| 860 | }/*}}}*/
|
---|
[16888] | 861 |
|
---|
[17002] | 862 | /*Modules*/
|
---|
[17166] | 863 | void EnthalpyAnalysis::PostProcessing(FemModel* femmodel){/*{{{*/
|
---|
| 864 |
|
---|
[17029] | 865 | /*Intermediaries*/
|
---|
[17166] | 866 | int solution_type, i;
|
---|
| 867 | bool computebasalmeltingrates=true;
|
---|
[17436] | 868 | bool isdrainage=true;
|
---|
[17166] | 869 | bool updatebasalconstraints=true;
|
---|
[17002] | 870 |
|
---|
[17166] | 871 | if(isdrainage){
|
---|
| 872 | /*Drain excess water fraction in ice column: */
|
---|
| 873 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
| 874 | Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 875 | DrainWaterfractionIcecolumn(element);
|
---|
| 876 | }
|
---|
[17002] | 877 | }
|
---|
| 878 |
|
---|
[17166] | 879 | if(computebasalmeltingrates){
|
---|
| 880 | /*Compute basal melting rates: */
|
---|
| 881 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
[17029] | 882 | Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
[17166] | 883 | ComputeBasalMeltingrate(element);
|
---|
[17029] | 884 | }
|
---|
[17002] | 885 | }
|
---|
[17166] | 886 |
|
---|
| 887 | if(updatebasalconstraints){
|
---|
| 888 | /*Update basal dirichlet BCs for enthalpy in transient runs: */
|
---|
| 889 | femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
|
---|
| 890 | if(solution_type==TransientSolutionEnum){
|
---|
| 891 | for(i=0;i<femmodel->elements->Size();i++){
|
---|
| 892 | Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
|
---|
| 893 | UpdateBasalConstraints(element);
|
---|
| 894 | }
|
---|
| 895 | }
|
---|
| 896 | }
|
---|
[17002] | 897 | }/*}}}*/
|
---|
| 898 | void EnthalpyAnalysis::ComputeBasalMeltingrate(Element* element){/*{{{*/
|
---|
[17014] | 899 | /*Calculate the basal melt rates of the enthalpy model after Aschwanden 2012*/
|
---|
| 900 | /* melting rate is positive when melting, negative when refreezing*/
|
---|
[17002] | 901 |
|
---|
[17434] | 902 | /* Check if ice in element */
|
---|
| 903 | if(!element->IsIceInElement()) return;
|
---|
| 904 |
|
---|
| 905 | /* Only compute melt rates at the base of grounded ice*/
|
---|
[17585] | 906 | if(!element->IsOnBase() || element->IsFloating()) return;
|
---|
[17434] | 907 |
|
---|
[17014] | 908 | /* Intermediaries */
|
---|
[17046] | 909 | const int dim=3;
|
---|
| 910 | int i,is,vertexdown,vertexup,numvertices,numsegments;
|
---|
[17014] | 911 | IssmDouble heatflux;
|
---|
| 912 | IssmDouble vec_heatflux[dim],normal_base[dim],d1enthalpy[dim];
|
---|
| 913 | IssmDouble basalfriction,alpha2;
|
---|
| 914 | IssmDouble dt,yts;
|
---|
| 915 | IssmDouble melting_overshoot,lambda;
|
---|
| 916 | IssmDouble geothermalflux;
|
---|
| 917 | IssmDouble vx,vy,vz;
|
---|
| 918 | IssmDouble *xyz_list = NULL;
|
---|
| 919 | IssmDouble *xyz_list_base = NULL;
|
---|
| 920 | int *pairindices = NULL;
|
---|
| 921 |
|
---|
| 922 | /*Fetch parameters and inputs */
|
---|
| 923 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 924 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 925 | IssmDouble latentheat = element->GetMaterialParameter(MaterialsLatentheatEnum);
|
---|
| 926 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
[17944] | 927 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoFreshwaterEnum);
|
---|
[17014] | 928 | Input* enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
|
---|
| 929 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
| 930 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 931 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 932 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
[17027] | 933 | IssmDouble kappa=EnthalpyDiffusionParameterVolume(element,EnthalpyEnum); _assert_(kappa>=0.);
|
---|
[17014] | 934 | element->NormalBase(&normal_base[0],xyz_list_base);
|
---|
| 935 | element->VerticalSegmentIndices(&pairindices,&numsegments);
|
---|
| 936 | IssmDouble* meltingrate_enthalpy = xNew<IssmDouble>(numsegments);
|
---|
| 937 | IssmDouble* heating = xNew<IssmDouble>(numsegments);
|
---|
| 938 |
|
---|
| 939 | /*Build friction element, needed later: */
|
---|
| 940 | Friction* friction=new Friction(element,dim);
|
---|
| 941 |
|
---|
| 942 | /******** MELTING RATES ************************************/
|
---|
| 943 | numvertices=element->GetNumberOfVertices();
|
---|
| 944 | IssmDouble* enthalpy = xNew<IssmDouble>(numvertices);
|
---|
| 945 | IssmDouble* pressure = xNew<IssmDouble>(numvertices);
|
---|
| 946 | IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
|
---|
| 947 | IssmDouble* basalmeltingrate = xNew<IssmDouble>(numvertices);
|
---|
| 948 | element->GetInputListOnVertices(enthalpy,EnthalpyEnum);
|
---|
| 949 | element->GetInputListOnVertices(pressure,PressureEnum);
|
---|
| 950 | element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
|
---|
| 951 | element->GetInputListOnVertices(basalmeltingrate,BasalforcingsMeltingRateEnum);
|
---|
| 952 |
|
---|
| 953 | Gauss* gauss=element->NewGauss();
|
---|
| 954 |
|
---|
| 955 | for(int is=0;is<numsegments;is++){
|
---|
| 956 | vertexdown = pairindices[is*2+0];
|
---|
| 957 | vertexup = pairindices[is*2+1];
|
---|
| 958 | gauss->GaussVertex(vertexdown);
|
---|
| 959 |
|
---|
| 960 | bool checkpositivethickness=true;
|
---|
[17015] | 961 | _assert_(watercolumn[vertexdown]>=0.);
|
---|
[17014] | 962 |
|
---|
| 963 | /*Calculate basal meltingrate after Fig.5 of A.Aschwanden 2012*/
|
---|
| 964 | meltingrate_enthalpy[is]=0.;
|
---|
| 965 | heating[is]=0.;
|
---|
| 966 | if((watercolumn[vertexdown]>0.) && (enthalpy[vertexdown]<PureIceEnthalpy(element,pressure[vertexdown]))){
|
---|
| 967 | /*ensure that no ice is at T<Tm(p), if water layer present*/
|
---|
| 968 | enthalpy[vertexdown]=element->PureIceEnthalpy(pressure[vertexdown]);
|
---|
| 969 | }
|
---|
| 970 | else if(enthalpy[vertexdown]<element->PureIceEnthalpy(pressure[vertexdown])){
|
---|
| 971 | /*cold base: set q*n=q_geo*n+frictionheating as Neumann BC in Penta::CreatePVectorEnthalpySheet*/
|
---|
| 972 | checkpositivethickness=false; // cold base, skip next test
|
---|
| 973 | }
|
---|
| 974 | else{/*we have a temperate base, go to next test*/}
|
---|
| 975 |
|
---|
| 976 | if(checkpositivethickness){
|
---|
| 977 | /*From here on all basal ice is temperate. Check for positive thickness of layer of temperate ice. */
|
---|
| 978 | bool istemperatelayer=false;
|
---|
| 979 | if(enthalpy[vertexup]>=element->PureIceEnthalpy(pressure[vertexup])) istemperatelayer=true;
|
---|
| 980 | if(istemperatelayer) for(i=0;i<dim;i++) vec_heatflux[i]=0.; // TODO: add -k*nabla T_pmp
|
---|
| 981 | else{
|
---|
| 982 | enthalpy_input->GetInputDerivativeValue(&d1enthalpy[0],xyz_list,gauss);
|
---|
| 983 | for(i=0;i<3;i++) vec_heatflux[i]=-kappa*d1enthalpy[i];
|
---|
| 984 | }
|
---|
| 985 |
|
---|
| 986 | /*heat flux along normal*/
|
---|
| 987 | heatflux=0.;
|
---|
| 988 | for(i=0;i<3;i++) heatflux+=(vec_heatflux[i])*normal_base[i];
|
---|
| 989 |
|
---|
| 990 | /*basal friction*/
|
---|
[17943] | 991 | friction->GetAlpha2(&alpha2,gauss);
|
---|
[17014] | 992 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 993 | vy_input->GetInputValue(&vy,gauss);
|
---|
| 994 | vz_input->GetInputValue(&vz,gauss);
|
---|
| 995 | basalfriction=alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
| 996 |
|
---|
| 997 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
[17944] | 998 | /* -Mb= Fb-(q-q_geo)/((1-w)*L*rho), and (1-w)*rho=rho_ice, cf Aschwanden 2012, eqs.1, 2, 66*/
|
---|
[17014] | 999 | heating[is]=(heatflux+basalfriction+geothermalflux);
|
---|
[17944] | 1000 | meltingrate_enthalpy[is]=heating[is]/(latentheat*rho_ice); // m/s water equivalent
|
---|
[17014] | 1001 | }
|
---|
| 1002 | }
|
---|
| 1003 | /******** UPDATE MELTINGRATES AND WATERCOLUMN **************/
|
---|
| 1004 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 1005 | for(is=0;is<numsegments;is++){
|
---|
| 1006 | vertexdown = pairindices[is*2+0];
|
---|
| 1007 | vertexup = pairindices[is*2+1];
|
---|
[17015] | 1008 | if(dt!=0.){
|
---|
[17014] | 1009 | if(watercolumn[vertexdown]+meltingrate_enthalpy[is]*dt<0.){ // prevent too much freeze on
|
---|
[17166] | 1010 | lambda = -watercolumn[vertexdown]/(dt*meltingrate_enthalpy[is]); _assert_(lambda>=0.); _assert_(lambda<1.);
|
---|
[17014] | 1011 | watercolumn[vertexdown]=0.;
|
---|
[17166] | 1012 | basalmeltingrate[vertexdown]=lambda*meltingrate_enthalpy[is]; // restrict freeze on only to size of watercolumn
|
---|
| 1013 | enthalpy[vertexdown]+=(1.-lambda)*meltingrate_enthalpy[is]*dt*latentheat; // use rest of energy to cool down base
|
---|
[17014] | 1014 | }
|
---|
| 1015 | else{
|
---|
| 1016 | basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
|
---|
| 1017 | watercolumn[vertexdown]+=dt*meltingrate_enthalpy[is];
|
---|
| 1018 | }
|
---|
| 1019 | }
|
---|
| 1020 | else{
|
---|
| 1021 | basalmeltingrate[vertexdown]=meltingrate_enthalpy[is];
|
---|
| 1022 | watercolumn[vertexdown]+=meltingrate_enthalpy[is];
|
---|
[17027] | 1023 | }
|
---|
[17157] | 1024 | basalmeltingrate[vertexdown]*=rho_water/rho_ice; // convert meltingrate from water to ice equivalent
|
---|
[17014] | 1025 | _assert_(watercolumn[vertexdown]>=0.);
|
---|
| 1026 | }
|
---|
| 1027 |
|
---|
| 1028 | /*feed updated variables back into model*/
|
---|
| 1029 | element->AddInput(EnthalpyEnum,enthalpy,P1Enum);
|
---|
| 1030 | element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
|
---|
| 1031 | element->AddInput(BasalforcingsMeltingRateEnum,basalmeltingrate,P1Enum);
|
---|
| 1032 |
|
---|
| 1033 | /*Clean up and return*/
|
---|
| 1034 | delete gauss;
|
---|
| 1035 | delete friction;
|
---|
[17027] | 1036 | xDelete<IssmDouble>(enthalpy);
|
---|
| 1037 | xDelete<IssmDouble>(pressure);
|
---|
| 1038 | xDelete<IssmDouble>(watercolumn);
|
---|
| 1039 | xDelete<IssmDouble>(basalmeltingrate);
|
---|
[17014] | 1040 | xDelete<IssmDouble>(meltingrate_enthalpy);
|
---|
| 1041 | xDelete<IssmDouble>(heating);
|
---|
[17166] | 1042 | xDelete<IssmDouble>(xyz_list);
|
---|
| 1043 | }/*}}}*/
|
---|
| 1044 | void EnthalpyAnalysis::DrainWaterfractionIcecolumn(Element* element){/*{{{*/
|
---|
| 1045 |
|
---|
[17434] | 1046 | /* Check if ice in element */
|
---|
| 1047 | if(!element->IsIceInElement()) return;
|
---|
| 1048 |
|
---|
[17166] | 1049 | /* Only drain waterfraction of ice column from element at base*/
|
---|
[17585] | 1050 | if(!element->IsOnBase()) return; //FIXME: allow freeze on for floating elements
|
---|
[17166] | 1051 |
|
---|
| 1052 | /* Intermediaries*/
|
---|
| 1053 | int is, numvertices, numsegments;
|
---|
| 1054 | int *pairindices = NULL;
|
---|
| 1055 |
|
---|
| 1056 | numvertices=element->GetNumberOfVertices();
|
---|
| 1057 | element->VerticalSegmentIndices(&pairindices,&numsegments);
|
---|
| 1058 |
|
---|
| 1059 | IssmDouble* watercolumn = xNew<IssmDouble>(numvertices);
|
---|
| 1060 | IssmDouble* drainrate_column = xNew<IssmDouble>(numsegments);
|
---|
| 1061 | IssmDouble* drainrate_element = xNew<IssmDouble>(numsegments);
|
---|
| 1062 |
|
---|
| 1063 | element->GetInputListOnVertices(watercolumn,WatercolumnEnum);
|
---|
| 1064 |
|
---|
| 1065 | for(is=0;is<numsegments;is++) drainrate_column[is]=0.;
|
---|
| 1066 | Element* elementi = element;
|
---|
| 1067 | for(;;){
|
---|
| 1068 | for(is=0;is<numsegments;is++) drainrate_element[is]=0.;
|
---|
| 1069 | DrainWaterfraction(elementi,drainrate_element); // TODO: make sure every vertex is only drained once
|
---|
| 1070 | for(is=0;is<numsegments;is++) drainrate_column[is]+=drainrate_element[is];
|
---|
| 1071 |
|
---|
| 1072 | if(elementi->IsOnSurface()) break;
|
---|
| 1073 | elementi=elementi->GetUpperElement();
|
---|
| 1074 | }
|
---|
| 1075 | /* add drained water to water column*/
|
---|
| 1076 | for(is=0;is<numsegments;is++) watercolumn[is]+=drainrate_column[is];
|
---|
| 1077 | /* Feed updated water column back into model */
|
---|
| 1078 | element->AddInput(WatercolumnEnum,watercolumn,P1Enum);
|
---|
| 1079 |
|
---|
[17608] | 1080 | xDelete<int>(pairindices);
|
---|
[17014] | 1081 | xDelete<IssmDouble>(drainrate_column);
|
---|
| 1082 | xDelete<IssmDouble>(drainrate_element);
|
---|
[17166] | 1083 | xDelete<IssmDouble>(watercolumn);
|
---|
[17002] | 1084 | }/*}}}*/
|
---|
[17014] | 1085 | void EnthalpyAnalysis::DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element){/*{{{*/
|
---|
| 1086 |
|
---|
[17434] | 1087 | /* Check if ice in element */
|
---|
| 1088 | if(!element->IsIceInElement()) return;
|
---|
| 1089 |
|
---|
[17014] | 1090 | /*Intermediaries*/
|
---|
| 1091 | int iv,is,vertexdown,vertexup,numsegments;
|
---|
| 1092 | IssmDouble dt, height_element;
|
---|
| 1093 | IssmDouble rho_water, rho_ice;
|
---|
| 1094 | int numvertices = element->GetNumberOfVertices();
|
---|
| 1095 |
|
---|
| 1096 | IssmDouble* xyz_list = NULL;
|
---|
| 1097 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
| 1098 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
| 1099 | IssmDouble* temperatures = xNew<IssmDouble>(numvertices);
|
---|
| 1100 | IssmDouble* waterfractions = xNew<IssmDouble>(numvertices);
|
---|
| 1101 | IssmDouble* deltawaterfractions = xNew<IssmDouble>(numvertices);
|
---|
| 1102 | int *pairindices = NULL;
|
---|
| 1103 |
|
---|
| 1104 | rho_ice=element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
[17946] | 1105 | rho_water=element->GetMaterialParameter(MaterialsRhoSeawaterEnum);
|
---|
[17014] | 1106 |
|
---|
| 1107 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 1108 | element->GetInputListOnVertices(enthalpies,EnthalpyEnum);
|
---|
| 1109 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
| 1110 |
|
---|
| 1111 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 1112 | for(iv=0;iv<numvertices;iv++){
|
---|
| 1113 | element->EnthalpyToThermal(&temperatures[iv],&waterfractions[iv], enthalpies[iv],pressures[iv]);
|
---|
| 1114 | deltawaterfractions[iv]=DrainageFunctionWaterfraction(waterfractions[iv], dt);
|
---|
| 1115 | }
|
---|
| 1116 |
|
---|
| 1117 | /*drain waterfraction, feed updated variables back into model*/
|
---|
| 1118 | for(iv=0;iv<numvertices;iv++){
|
---|
| 1119 | if(reCast<bool,IssmDouble>(dt))
|
---|
| 1120 | waterfractions[iv]-=deltawaterfractions[iv]*dt;
|
---|
| 1121 | else
|
---|
| 1122 | waterfractions[iv]-=deltawaterfractions[iv];
|
---|
| 1123 | element->ThermalToEnthalpy(&enthalpies[iv], temperatures[iv], waterfractions[iv], pressures[iv]);
|
---|
| 1124 | }
|
---|
| 1125 | element->AddInput(EnthalpyEnum,enthalpies,P1Enum);
|
---|
| 1126 | element->AddInput(WaterfractionEnum,waterfractions,P1Enum);
|
---|
| 1127 |
|
---|
| 1128 | /*return meltwater column equivalent to drained water*/
|
---|
| 1129 | element->VerticalSegmentIndices(&pairindices,&numsegments);
|
---|
| 1130 | for(is=0;is<numsegments;is++){
|
---|
| 1131 | vertexdown = pairindices[is*2+0];
|
---|
| 1132 | vertexup = pairindices[is*2+1];
|
---|
| 1133 | height_element=fabs(xyz_list[vertexup*3+2]-xyz_list[vertexdown*3+2]);
|
---|
[17157] | 1134 | pdrainrate_element[is]=(deltawaterfractions[vertexdown]+deltawaterfractions[vertexup])/2.*height_element; // return water equivalent of drainage
|
---|
[17166] | 1135 | _assert_(pdrainrate_element[is]>=0.);
|
---|
[17014] | 1136 | }
|
---|
| 1137 |
|
---|
| 1138 | /*Clean up and return*/
|
---|
[17608] | 1139 | xDelete<int>(pairindices);
|
---|
[17014] | 1140 | xDelete<IssmDouble>(xyz_list);
|
---|
| 1141 | xDelete<IssmDouble>(enthalpies);
|
---|
| 1142 | xDelete<IssmDouble>(pressures);
|
---|
| 1143 | xDelete<IssmDouble>(temperatures);
|
---|
| 1144 | xDelete<IssmDouble>(waterfractions);
|
---|
| 1145 | xDelete<IssmDouble>(deltawaterfractions);
|
---|
[17002] | 1146 | }/*}}}*/
|
---|
| 1147 | void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
|
---|
| 1148 |
|
---|
[17434] | 1149 | /* Check if ice in element */
|
---|
| 1150 | if(!element->IsIceInElement()) return;
|
---|
| 1151 |
|
---|
| 1152 | /* Only update Constraints at the base of grounded ice*/
|
---|
[17585] | 1153 | if(!(element->IsOnBase()) || element->IsFloating()) return;
|
---|
[17434] | 1154 |
|
---|
[17027] | 1155 | /*Intermediary*/
|
---|
| 1156 | bool isdynamicbasalspc,setspc;
|
---|
| 1157 | int numindices, numindicesup;
|
---|
| 1158 | IssmDouble pressure, pressureup;
|
---|
| 1159 | IssmDouble h_pmp, enthalpy, enthalpyup;
|
---|
| 1160 | IssmDouble watercolumn;
|
---|
| 1161 | int *indices = NULL, *indicesup = NULL;
|
---|
| 1162 | Node* node = NULL;
|
---|
[17014] | 1163 |
|
---|
[17027] | 1164 | /*Check wether dynamic basal boundary conditions are activated */
|
---|
| 1165 | element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
|
---|
| 1166 | if(!isdynamicbasalspc) return;
|
---|
[17014] | 1167 |
|
---|
[17027] | 1168 | /*Fetch indices of basal & surface nodes for this finite element*/
|
---|
| 1169 | Penta *penta = (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
|
---|
| 1170 | penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
|
---|
| 1171 | penta->SurfaceNodeIndices(&numindicesup,&indicesup,element->GetElementType());
|
---|
| 1172 | _assert_(numindices==numindicesup);
|
---|
[17014] | 1173 |
|
---|
[17027] | 1174 | /*Get parameters and inputs: */
|
---|
| 1175 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 1176 | Input* enthalpy_input=element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);
|
---|
| 1177 | Input* watercolumn_input=element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
[17014] | 1178 |
|
---|
[17027] | 1179 | /*if there is a temperate layer of zero thickness, set spc enthalpy=h_pmp at that node*/
|
---|
| 1180 | GaussPenta* gauss=new GaussPenta();
|
---|
| 1181 | GaussPenta* gaussup=new GaussPenta();
|
---|
| 1182 | for(int i=0;i<numindices;i++){
|
---|
| 1183 | gauss->GaussNode(element->GetElementType(),indices[i]);
|
---|
| 1184 | gaussup->GaussNode(element->GetElementType(),indicesup[i]);
|
---|
[17014] | 1185 |
|
---|
[17027] | 1186 | /*Check wether there is a temperate layer at the base or not */
|
---|
| 1187 | /*check if node is temperate, else continue*/
|
---|
| 1188 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
| 1189 | pressure_input->GetInputValue(&pressure, gauss);
|
---|
| 1190 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
| 1191 | h_pmp=PureIceEnthalpy(element,pressure);
|
---|
| 1192 | if (enthalpy>=h_pmp){
|
---|
| 1193 | /*check if upper node is temperate, too.
|
---|
| 1194 | if yes, then we have a temperate layer of positive thickness and reset the spc.
|
---|
| 1195 | if not, apply dirichlet BC.*/
|
---|
| 1196 | enthalpy_input->GetInputValue(&enthalpyup, gaussup);
|
---|
| 1197 | pressure_input->GetInputValue(&pressureup, gaussup);
|
---|
| 1198 | setspc=((enthalpyup<PureIceEnthalpy(element,pressureup)) && (watercolumn>=0.))?true:false;
|
---|
| 1199 | }
|
---|
| 1200 | else
|
---|
| 1201 | setspc = false;
|
---|
[17014] | 1202 |
|
---|
[17027] | 1203 | node=element->GetNode(indices[i]);
|
---|
[17600] | 1204 | if(setspc)
|
---|
| 1205 | node->ApplyConstraint(0,h_pmp); /*apply spc*/
|
---|
[17027] | 1206 | else
|
---|
[17166] | 1207 | node->DofInFSet(0); /*remove spc*/
|
---|
[17027] | 1208 | }
|
---|
[17014] | 1209 |
|
---|
[17027] | 1210 | /*Free ressources:*/
|
---|
| 1211 | xDelete<int>(indices);
|
---|
| 1212 | xDelete<int>(indicesup);
|
---|
| 1213 | delete gauss;
|
---|
| 1214 | delete gaussup;
|
---|
[17002] | 1215 | }/*}}}*/
|
---|
| 1216 |
|
---|
[16888] | 1217 | /*Intermediaries*/
|
---|
| 1218 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
|
---|
| 1219 |
|
---|
| 1220 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 1221 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
| 1222 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 1223 |
|
---|
| 1224 | if(enthalpy < PureIceEnthalpy(element,pressure)){
|
---|
| 1225 | return thermalconductivity/heatcapacity;
|
---|
| 1226 | }
|
---|
| 1227 | else{
|
---|
| 1228 | return temperateiceconductivity/heatcapacity;
|
---|
| 1229 | }
|
---|
| 1230 | }/*}}}*/
|
---|
[16895] | 1231 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
|
---|
[16888] | 1232 |
|
---|
| 1233 | int iv;
|
---|
| 1234 | IssmDouble lambda; /* fraction of cold ice */
|
---|
[17027] | 1235 | IssmDouble kappa,kappa_c,kappa_t; /* enthalpy conductivities */
|
---|
[16888] | 1236 | IssmDouble Hc,Ht;
|
---|
| 1237 |
|
---|
| 1238 | /*Get pressures and enthalpies on vertices*/
|
---|
| 1239 | int numvertices = element->GetNumberOfVertices();
|
---|
| 1240 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
| 1241 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
| 1242 | IssmDouble* PIE = xNew<IssmDouble>(numvertices);
|
---|
| 1243 | IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
|
---|
| 1244 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
[16895] | 1245 | element->GetInputListOnVertices(enthalpies,enthalpy_enum);
|
---|
[16888] | 1246 | for(iv=0;iv<numvertices;iv++){
|
---|
| 1247 | PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
|
---|
| 1248 | dHpmp[iv] = enthalpies[iv]-PIE[iv];
|
---|
| 1249 | }
|
---|
| 1250 |
|
---|
| 1251 | bool allequalsign = true;
|
---|
| 1252 | if(dHpmp[0]<0.){
|
---|
| 1253 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
|
---|
| 1254 | }
|
---|
| 1255 | else{
|
---|
| 1256 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
|
---|
| 1257 | }
|
---|
| 1258 |
|
---|
| 1259 | if(allequalsign){
|
---|
| 1260 | kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
|
---|
| 1261 | }
|
---|
| 1262 | else{
|
---|
| 1263 | /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
|
---|
| 1264 | cf Patankar 1980, pp44 */
|
---|
| 1265 | kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
|
---|
| 1266 | kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
|
---|
| 1267 | Hc=0.; Ht=0.;
|
---|
| 1268 | for(iv=0; iv<numvertices;iv++){
|
---|
| 1269 | if(enthalpies[iv]<PIE[iv])
|
---|
| 1270 | Hc+=(PIE[iv]-enthalpies[iv]);
|
---|
| 1271 | else
|
---|
| 1272 | Ht+=(enthalpies[iv]-PIE[iv]);
|
---|
| 1273 | }
|
---|
| 1274 | _assert_((Hc+Ht)>0.);
|
---|
| 1275 | lambda = Hc/(Hc+Ht);
|
---|
[17027] | 1276 | kappa = kappa_c*kappa_t/(lambda*kappa_t+(1.-lambda)*kappa_c); // ==(lambda/kappa_c + (1.-lambda)/kappa_t)^-1
|
---|
| 1277 | }
|
---|
[16888] | 1278 |
|
---|
| 1279 | /*Clean up and return*/
|
---|
| 1280 | xDelete<IssmDouble>(PIE);
|
---|
| 1281 | xDelete<IssmDouble>(dHpmp);
|
---|
| 1282 | xDelete<IssmDouble>(pressures);
|
---|
| 1283 | xDelete<IssmDouble>(enthalpies);
|
---|
| 1284 | return kappa;
|
---|
[17027] | 1285 | }/*}}}*/
|
---|
[16888] | 1286 | IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
|
---|
| 1287 |
|
---|
| 1288 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 1289 | IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
|
---|
| 1290 |
|
---|
| 1291 | return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
|
---|
| 1292 | }/*}}}*/
|
---|
| 1293 | IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
|
---|
| 1294 |
|
---|
| 1295 | IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
|
---|
| 1296 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
| 1297 |
|
---|
| 1298 | return meltingpoint-beta*pressure;
|
---|
| 1299 | }/*}}}*/
|
---|