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