[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*/
|
---|
[16539] | 8 | int EnthalpyAnalysis::DofsPerNode(int** doflist,int meshtype,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 |
|
---|
| 27 | bool dakota_analysis;
|
---|
| 28 | bool isenthalpy;
|
---|
| 29 |
|
---|
| 30 | /*Now, is the model 3d? otherwise, do nothing: */
|
---|
| 31 | if(iomodel->meshtype==Mesh2DhorizontalEnum)return;
|
---|
| 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);
|
---|
| 51 |
|
---|
| 52 | iomodel->FetchDataToInput(elements,ThicknessEnum);
|
---|
| 53 | iomodel->FetchDataToInput(elements,SurfaceEnum);
|
---|
| 54 | iomodel->FetchDataToInput(elements,BedEnum);
|
---|
| 55 | iomodel->FetchDataToInput(elements,FrictionCoefficientEnum);
|
---|
| 56 | iomodel->FetchDataToInput(elements,FrictionPEnum);
|
---|
| 57 | iomodel->FetchDataToInput(elements,FrictionQEnum);
|
---|
| 58 | iomodel->FetchDataToInput(elements,MaskIceLevelsetEnum);
|
---|
| 59 | iomodel->FetchDataToInput(elements,MaskGroundediceLevelsetEnum);
|
---|
| 60 | iomodel->FetchDataToInput(elements,MeshElementonbedEnum);
|
---|
| 61 | iomodel->FetchDataToInput(elements,MeshElementonsurfaceEnum);
|
---|
| 62 | iomodel->FetchDataToInput(elements,FlowequationElementEquationEnum);
|
---|
| 63 | iomodel->FetchDataToInput(elements,MaterialsRheologyBEnum);
|
---|
| 64 | iomodel->FetchDataToInput(elements,MaterialsRheologyNEnum);
|
---|
| 65 | iomodel->FetchDataToInput(elements,PressureEnum);
|
---|
| 66 | iomodel->FetchDataToInput(elements,TemperatureEnum);
|
---|
| 67 | iomodel->FetchDataToInput(elements,WaterfractionEnum);
|
---|
| 68 | iomodel->FetchDataToInput(elements,EnthalpyEnum);
|
---|
| 69 | iomodel->FetchDataToInput(elements,BasalforcingsGeothermalfluxEnum);
|
---|
| 70 | iomodel->FetchDataToInput(elements,WatercolumnEnum);
|
---|
| 71 | iomodel->FetchDataToInput(elements,BasalforcingsMeltingRateEnum);
|
---|
| 72 | iomodel->FetchDataToInput(elements,VxEnum);
|
---|
| 73 | iomodel->FetchDataToInput(elements,VyEnum);
|
---|
| 74 | iomodel->FetchDataToInput(elements,VzEnum);
|
---|
| 75 | InputUpdateFromConstantx(elements,0.,VxMeshEnum);
|
---|
| 76 | InputUpdateFromConstantx(elements,0.,VyMeshEnum);
|
---|
| 77 | InputUpdateFromConstantx(elements,0.,VzMeshEnum);
|
---|
| 78 | if(dakota_analysis){
|
---|
| 79 | elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
|
---|
| 80 | elements->InputDuplicate(BasalforcingsMeltingRateEnum,QmuMeltingEnum);
|
---|
| 81 | elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
|
---|
| 82 | elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
|
---|
| 83 | elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /*Free data: */
|
---|
| 87 | iomodel->DeleteData(3,TemperatureEnum,WaterfractionEnum,PressureEnum);
|
---|
| 88 | }/*}}}*/
|
---|
[16542] | 89 | void EnthalpyAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
|
---|
[16539] | 90 |
|
---|
| 91 | if(iomodel->meshtype==Mesh3DEnum) iomodel->FetchData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
|
---|
[16542] | 92 | ::CreateNodes(nodes,iomodel,EnthalpyAnalysisEnum,P1Enum);
|
---|
[16539] | 93 | iomodel->DeleteData(2,MeshVertexonbedEnum,MeshVertexonsurfaceEnum);
|
---|
| 94 | }/*}}}*/
|
---|
[16542] | 95 | void EnthalpyAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
[16539] | 96 |
|
---|
| 97 | /*Intermediary*/
|
---|
| 98 | int count;
|
---|
| 99 | int M,N;
|
---|
| 100 | bool spcpresent = false;
|
---|
| 101 | IssmDouble heatcapacity;
|
---|
| 102 | IssmDouble referencetemperature;
|
---|
| 103 |
|
---|
| 104 | /*Output*/
|
---|
| 105 | IssmDouble *spcvector = NULL;
|
---|
| 106 | IssmDouble* times=NULL;
|
---|
| 107 | IssmDouble* values=NULL;
|
---|
| 108 |
|
---|
| 109 | /*Fetch parameters: */
|
---|
| 110 | iomodel->Constant(&heatcapacity,MaterialsHeatcapacityEnum);
|
---|
| 111 | iomodel->Constant(&referencetemperature,ConstantsReferencetemperatureEnum);
|
---|
| 112 |
|
---|
| 113 | /*return if 2d mesh*/
|
---|
| 114 | if(iomodel->meshtype==Mesh2DhorizontalEnum) return;
|
---|
| 115 |
|
---|
| 116 | /*Fetch data: */
|
---|
| 117 | iomodel->FetchData(&spcvector,&M,&N,ThermalSpctemperatureEnum);
|
---|
| 118 |
|
---|
| 119 | //FIX ME: SHOULD USE IOMODELCREATECONSTRAINTS
|
---|
| 120 | /*Transient or static?:*/
|
---|
| 121 | if(M==iomodel->numberofvertices){
|
---|
| 122 | /*static: just create Constraints objects*/
|
---|
| 123 | count=0;
|
---|
| 124 |
|
---|
| 125 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
| 126 | /*keep only this partition's nodes:*/
|
---|
| 127 | if((iomodel->my_vertices[i])){
|
---|
| 128 |
|
---|
| 129 | if (!xIsNan<IssmDouble>(spcvector[i])){
|
---|
| 130 |
|
---|
| 131 | constraints->AddObject(new SpcStatic(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,heatcapacity*(spcvector[i]-referencetemperature),EnthalpyAnalysisEnum));
|
---|
| 132 | count++;
|
---|
| 133 |
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | else if (M==(iomodel->numberofvertices+1)){
|
---|
| 139 | /*transient: create transient SpcTransient objects. Same logic, except we need to retrieve
|
---|
| 140 | * various times and values to initialize an SpcTransient object: */
|
---|
| 141 | count=0;
|
---|
| 142 |
|
---|
| 143 | /*figure out times: */
|
---|
| 144 | times=xNew<IssmDouble>(N);
|
---|
| 145 | for(int j=0;j<N;j++){
|
---|
| 146 | times[j]=spcvector[(M-1)*N+j];
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /*Create constraints from x,y,z: */
|
---|
| 150 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
| 151 |
|
---|
| 152 | /*keep only this partition's nodes:*/
|
---|
| 153 | if((iomodel->my_vertices[i])){
|
---|
| 154 |
|
---|
| 155 | /*figure out times and values: */
|
---|
| 156 | values=xNew<IssmDouble>(N);
|
---|
| 157 | spcpresent=false;
|
---|
| 158 | for(int j=0;j<N;j++){
|
---|
| 159 | values[j]=heatcapacity*(spcvector[i*N+j]-referencetemperature);
|
---|
| 160 | if(!xIsNan<IssmDouble>(values[j]))spcpresent=true; //NaN means no spc by default
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | if(spcpresent){
|
---|
| 164 | constraints->AddObject(new SpcTransient(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,N,times,values,EnthalpyAnalysisEnum));
|
---|
| 165 | count++;
|
---|
| 166 | }
|
---|
| 167 | xDelete<IssmDouble>(values);
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 | else{
|
---|
| 172 | _error_("Size of field " << EnumToStringx(ThermalSpctemperatureEnum) << " not supported");
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /*Free ressources:*/
|
---|
| 176 | iomodel->DeleteData(spcvector,ThermalSpctemperatureEnum);
|
---|
| 177 | xDelete<IssmDouble>(times);
|
---|
| 178 | xDelete<IssmDouble>(values);
|
---|
| 179 | }/*}}}*/
|
---|
[16542] | 180 | void EnthalpyAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
[16539] | 181 |
|
---|
| 182 | /*No loads */
|
---|
| 183 | }/*}}}*/
|
---|
[16675] | 184 |
|
---|
[16782] | 185 | /*Finite Element Analysis*/
|
---|
| 186 | ElementMatrix* EnthalpyAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
[16888] | 187 |
|
---|
| 188 | /*compute all stiffness matrices for this element*/
|
---|
| 189 | ElementMatrix* Ke1=CreateKMatrixVolume(element);
|
---|
| 190 | ElementMatrix* Ke2=CreateKMatrixShelf(element);
|
---|
| 191 | ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
|
---|
| 192 |
|
---|
| 193 | /*clean-up and return*/
|
---|
| 194 | delete Ke1;
|
---|
| 195 | delete Ke2;
|
---|
| 196 | return Ke;
|
---|
[16782] | 197 | }/*}}}*/
|
---|
[16888] | 198 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixVolume(Element* element){/*{{{*/
|
---|
| 199 |
|
---|
| 200 | /*Intermediaries */
|
---|
| 201 | int stabilization;
|
---|
| 202 | IssmDouble Jdet,dt,u,v,w,um,vm,wm,vel;
|
---|
| 203 | IssmDouble h,hx,hy,hz,vx,vy,vz;
|
---|
| 204 | IssmDouble tau_parameter,diameter;
|
---|
| 205 | IssmDouble D_scalar;
|
---|
| 206 | IssmDouble* xyz_list = NULL;
|
---|
| 207 |
|
---|
| 208 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 209 | int numnodes = element->GetNumberOfNodes();
|
---|
| 210 |
|
---|
| 211 | /*Initialize Element vector and other vectors*/
|
---|
| 212 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 213 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 214 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
| 215 | IssmDouble* B = xNew<IssmDouble>(3*numnodes);
|
---|
| 216 | IssmDouble* Bprime = xNew<IssmDouble>(3*numnodes);
|
---|
| 217 | IssmDouble D[3][3] = {0.};
|
---|
| 218 | IssmDouble K[3][3];
|
---|
| 219 |
|
---|
| 220 | /*Retrieve all inputs and parameters*/
|
---|
| 221 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 222 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 223 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
| 224 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
| 225 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 226 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
| 227 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 228 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 229 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 230 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 231 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 232 | Input* vxm_input = element->GetInput(VxMeshEnum); _assert_(vxm_input);
|
---|
| 233 | Input* vym_input = element->GetInput(VyMeshEnum); _assert_(vym_input);
|
---|
| 234 | Input* vzm_input = element->GetInput(VzMeshEnum); _assert_(vzm_input);
|
---|
| 235 | if(stabilization==2) diameter=element->MinEdgeLength(xyz_list);
|
---|
| 236 |
|
---|
| 237 | /*Enthalpy diffusion parameter*/
|
---|
[16986] | 238 | IssmDouble kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>0.);
|
---|
[16888] | 239 |
|
---|
| 240 | /* Start looping on the number of gaussian points: */
|
---|
| 241 | Gauss* gauss=element->NewGauss(2);
|
---|
| 242 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 243 | gauss->GaussPoint(ig);
|
---|
| 244 |
|
---|
| 245 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 246 | D_scalar=gauss->weight*Jdet;
|
---|
| 247 | if(dt!=0.) D_scalar=D_scalar*dt;
|
---|
| 248 |
|
---|
| 249 | /*Conduction: */
|
---|
| 250 | GetBConduct(B,element,xyz_list,gauss);
|
---|
| 251 | D[0][0]=D_scalar*kappa/rho_ice;
|
---|
| 252 | D[1][1]=D_scalar*kappa/rho_ice;
|
---|
| 253 | D[2][2]=D_scalar*kappa/rho_ice;
|
---|
| 254 | TripleMultiply(B,3,numnodes,1,
|
---|
| 255 | &D[0][0],3,3,0,
|
---|
| 256 | B,3,numnodes,0,
|
---|
| 257 | &Ke->values[0],1);
|
---|
| 258 |
|
---|
| 259 | /*Advection: */
|
---|
| 260 | GetBAdvec(B,element,xyz_list,gauss);
|
---|
| 261 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
| 262 | vx_input->GetInputValue(&u,gauss); vxm_input->GetInputValue(&um,gauss); vx=u-um;
|
---|
| 263 | vy_input->GetInputValue(&v,gauss); vym_input->GetInputValue(&vm,gauss); vy=v-vm;
|
---|
| 264 | vz_input->GetInputValue(&w,gauss); vzm_input->GetInputValue(&wm,gauss); vz=w-wm;
|
---|
| 265 | D[0][0]=D_scalar*vx;
|
---|
| 266 | D[1][1]=D_scalar*vy;
|
---|
| 267 | D[2][2]=D_scalar*vz;
|
---|
| 268 | TripleMultiply(B,3,numnodes,1,
|
---|
| 269 | &D[0][0],3,3,0,
|
---|
| 270 | Bprime,3,numnodes,0,
|
---|
| 271 | &Ke->values[0],1);
|
---|
| 272 |
|
---|
| 273 | /*Transient: */
|
---|
| 274 | if(dt!=0.){
|
---|
| 275 | D_scalar=gauss->weight*Jdet;
|
---|
| 276 | element->NodalFunctions(basis,gauss);
|
---|
| 277 | TripleMultiply(basis,numnodes,1,0,
|
---|
| 278 | &D_scalar,1,1,0,
|
---|
| 279 | basis,1,numnodes,0,
|
---|
| 280 | &Ke->values[0],1);
|
---|
| 281 | D_scalar=D_scalar*dt;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | /*Artifficial diffusivity*/
|
---|
| 285 | if(stabilization==1){
|
---|
| 286 | element->ElementSizes(&hx,&hy,&hz);
|
---|
| 287 | vel=sqrt(vx*vx + vy*vy + vz*vz)+1.e-14;
|
---|
| 288 | h=sqrt( pow(hx*vx/vel,2) + pow(hy*vy/vel,2) + pow(hz*vz/vel,2));
|
---|
[16894] | 289 | K[0][0]=h/(2.*vel)*vx*vx; K[0][1]=h/(2.*vel)*vx*vy; K[0][2]=h/(2.*vel)*vx*vz;
|
---|
| 290 | K[1][0]=h/(2.*vel)*vy*vx; K[1][1]=h/(2.*vel)*vy*vy; K[1][2]=h/(2.*vel)*vy*vz;
|
---|
| 291 | 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] | 292 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) K[i][j] = D_scalar*K[i][j];
|
---|
| 293 |
|
---|
| 294 | GetBAdvecprime(Bprime,element,xyz_list,gauss);
|
---|
| 295 | TripleMultiply(Bprime,3,numnodes,1,
|
---|
| 296 | &K[0][0],3,3,0,
|
---|
| 297 | Bprime,3,numnodes,0,
|
---|
| 298 | &Ke->values[0],1);
|
---|
| 299 | }
|
---|
| 300 | else if(stabilization==2){
|
---|
| 301 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 302 | tau_parameter=element->StabilizationParameter(u-um,v-vm,w-wm,diameter,kappa/rho_ice);
|
---|
| 303 | for(int i=0;i<numnodes;i++){
|
---|
| 304 | for(int j=0;j<numnodes;j++){
|
---|
| 305 | Ke->values[i*numnodes+j]+=tau_parameter*D_scalar*
|
---|
[16895] | 306 | ((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] | 307 | }
|
---|
| 308 | }
|
---|
| 309 | if(dt!=0.){
|
---|
[16896] | 310 | D_scalar=gauss->weight*Jdet;
|
---|
[16888] | 311 | for(int i=0;i<numnodes;i++){
|
---|
| 312 | for(int j=0;j<numnodes;j++){
|
---|
[16895] | 313 | 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] | 314 | }
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | /*Clean up and return*/
|
---|
| 321 | xDelete<IssmDouble>(xyz_list);
|
---|
| 322 | xDelete<IssmDouble>(basis);
|
---|
| 323 | xDelete<IssmDouble>(dbasis);
|
---|
| 324 | xDelete<IssmDouble>(B);
|
---|
| 325 | xDelete<IssmDouble>(Bprime);
|
---|
| 326 | delete gauss;
|
---|
| 327 | return Ke;
|
---|
| 328 | }/*}}}*/
|
---|
| 329 | ElementMatrix* EnthalpyAnalysis::CreateKMatrixShelf(Element* element){/*{{{*/
|
---|
| 330 |
|
---|
| 331 | /*Initialize Element matrix and return if necessary*/
|
---|
| 332 | if(!element->IsOnBed() || !element->IsFloating()) return NULL;
|
---|
| 333 |
|
---|
[16986] | 334 | /*Intermediaries*/
|
---|
[16888] | 335 | IssmDouble dt,Jdet,D;
|
---|
| 336 | IssmDouble *xyz_list_base = NULL;
|
---|
| 337 |
|
---|
| 338 | /*Fetch number of nodes for this finite element*/
|
---|
| 339 | int numnodes = element->GetNumberOfNodes();
|
---|
| 340 |
|
---|
| 341 | /*Initialize vectors*/
|
---|
| 342 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 343 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 344 |
|
---|
| 345 | /*Retrieve all inputs and parameters*/
|
---|
| 346 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 347 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 348 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
| 349 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
| 350 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 351 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 352 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
| 353 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
| 354 |
|
---|
| 355 | /* Start looping on the number of gaussian points: */
|
---|
| 356 | Gauss* gauss=element->NewGaussBase(2);
|
---|
| 357 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 358 | gauss->GaussPoint(ig);
|
---|
| 359 |
|
---|
| 360 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 361 | element->NodalFunctions(basis,gauss);
|
---|
| 362 |
|
---|
| 363 | D=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel/(heatcapacity*rho_ice);
|
---|
| 364 | if(reCast<bool,IssmDouble>(dt)) D=dt*D;
|
---|
| 365 | TripleMultiply(basis,numnodes,1,0,
|
---|
| 366 | &D,1,1,0,
|
---|
| 367 | basis,1,numnodes,0,
|
---|
| 368 | &Ke->values[0],1);
|
---|
| 369 |
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | /*Clean up and return*/
|
---|
| 373 | delete gauss;
|
---|
| 374 | xDelete<IssmDouble>(basis);
|
---|
| 375 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 376 | return Ke;
|
---|
| 377 | }/*}}}*/
|
---|
[16782] | 378 | ElementVector* EnthalpyAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
[16812] | 379 |
|
---|
| 380 | /*compute all load vectors for this element*/
|
---|
| 381 | ElementVector* pe1=CreatePVectorVolume(element);
|
---|
| 382 | ElementVector* pe2=CreatePVectorSheet(element);
|
---|
| 383 | ElementVector* pe3=CreatePVectorShelf(element);
|
---|
| 384 | ElementVector* pe =new ElementVector(pe1,pe2,pe3);
|
---|
| 385 |
|
---|
| 386 | /*clean-up and return*/
|
---|
| 387 | delete pe1;
|
---|
| 388 | delete pe2;
|
---|
| 389 | delete pe3;
|
---|
| 390 | return pe;
|
---|
[16782] | 391 | }/*}}}*/
|
---|
[16812] | 392 | ElementVector* EnthalpyAnalysis::CreatePVectorVolume(Element* element){/*{{{*/
|
---|
| 393 |
|
---|
| 394 | /*Intermediaries*/
|
---|
| 395 | int stabilization;
|
---|
| 396 | IssmDouble Jdet,phi,dt;
|
---|
| 397 | IssmDouble enthalpy;
|
---|
| 398 | IssmDouble kappa,tau_parameter,diameter;
|
---|
| 399 | IssmDouble u,v,w;
|
---|
| 400 | IssmDouble scalar_def,scalar_transient;
|
---|
| 401 | IssmDouble* xyz_list = NULL;
|
---|
| 402 |
|
---|
| 403 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 404 | int numnodes = element->GetNumberOfNodes();
|
---|
| 405 | int numvertices = element->GetNumberOfVertices();
|
---|
| 406 |
|
---|
| 407 | /*Initialize Element vector*/
|
---|
| 408 | ElementVector* pe = element->NewElementVector();
|
---|
| 409 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 410 | IssmDouble* dbasis = xNew<IssmDouble>(3*numnodes);
|
---|
| 411 |
|
---|
| 412 | /*Retrieve all inputs and parameters*/
|
---|
| 413 | element->GetVerticesCoordinates(&xyz_list);
|
---|
| 414 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 415 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 416 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 417 | element->FindParam(&stabilization,ThermalStabilizationEnum);
|
---|
| 418 | Input* vx_input=element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 419 | Input* vy_input=element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 420 | Input* vz_input=element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 421 | Input* enthalpy_input = NULL;
|
---|
| 422 | if(reCast<bool,IssmDouble>(dt)){enthalpy_input = element->GetInput(EnthalpyEnum); _assert_(enthalpy_input);}
|
---|
| 423 | if(stabilization==2){
|
---|
| 424 | diameter=element->MinEdgeLength(xyz_list);
|
---|
[16895] | 425 | kappa=this->EnthalpyDiffusionParameterVolume(element,EnthalpyPicardEnum); _assert_(kappa>0.);
|
---|
[16812] | 426 | }
|
---|
| 427 |
|
---|
| 428 | /* Start looping on the number of gaussian points: */
|
---|
[16975] | 429 | Gauss* gauss=element->NewGauss(3);
|
---|
[16812] | 430 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 431 | gauss->GaussPoint(ig);
|
---|
| 432 |
|
---|
| 433 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 434 | element->NodalFunctions(basis,gauss);
|
---|
| 435 | element->ViscousHeating(&phi,xyz_list,gauss,vx_input,vy_input,vz_input);
|
---|
| 436 |
|
---|
| 437 | scalar_def=phi/rho_ice*Jdet*gauss->weight;
|
---|
[16895] | 438 | if(dt!=0.) scalar_def=scalar_def*dt;
|
---|
[16812] | 439 |
|
---|
| 440 | /*TODO: add -beta*laplace T_m(p)*/
|
---|
| 441 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_def*basis[i];
|
---|
| 442 |
|
---|
| 443 | /* Build transient now */
|
---|
| 444 | if(reCast<bool,IssmDouble>(dt)){
|
---|
| 445 | enthalpy_input->GetInputValue(&enthalpy, gauss);
|
---|
| 446 | scalar_transient=enthalpy*Jdet*gauss->weight;
|
---|
| 447 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_transient*basis[i];
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | if(stabilization==2){
|
---|
| 451 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 452 |
|
---|
| 453 | vx_input->GetInputValue(&u,gauss);
|
---|
| 454 | vy_input->GetInputValue(&v,gauss);
|
---|
| 455 | vz_input->GetInputValue(&w,gauss);
|
---|
[16895] | 456 | tau_parameter=element->StabilizationParameter(u,v,w,diameter,kappa/rho_ice);
|
---|
[16812] | 457 |
|
---|
[16895] | 458 | for(int 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]);
|
---|
| 459 |
|
---|
| 460 | if(dt!=0.){
|
---|
| 461 | for(int 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] | 462 | }
|
---|
| 463 | }
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | /*Clean up and return*/
|
---|
| 467 | xDelete<IssmDouble>(basis);
|
---|
| 468 | xDelete<IssmDouble>(dbasis);
|
---|
| 469 | xDelete<IssmDouble>(xyz_list);
|
---|
| 470 | delete gauss;
|
---|
| 471 | return pe;
|
---|
| 472 |
|
---|
| 473 | }/*}}}*/
|
---|
| 474 | ElementVector* EnthalpyAnalysis::CreatePVectorSheet(Element* element){/*{{{*/
|
---|
[16888] | 475 |
|
---|
| 476 | /* Geothermal flux on ice sheet base and basal friction */
|
---|
| 477 | if(!element->IsOnBed() || element->IsFloating()) return NULL;
|
---|
| 478 |
|
---|
| 479 | IssmDouble dt,Jdet,enthalpy,pressure,watercolumn,geothermalflux,vx,vy,vz;
|
---|
| 480 | IssmDouble enthalpyup,pressureup,alpha2,scalar,basalfriction,heatflux;
|
---|
| 481 | IssmDouble *xyz_list_base = NULL;
|
---|
| 482 |
|
---|
| 483 | /*Fetch number of nodes for this finite element*/
|
---|
| 484 | int numnodes = element->GetNumberOfNodes();
|
---|
| 485 |
|
---|
| 486 | /*Initialize vectors*/
|
---|
| 487 | ElementVector* pe = element->NewElementVector();
|
---|
| 488 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 489 |
|
---|
| 490 | /*Retrieve all inputs and parameters*/
|
---|
| 491 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 492 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 493 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 494 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
| 495 | Input* vz_input = element->GetInput(VzEnum); _assert_(vz_input);
|
---|
| 496 | Input* enthalpy_input = element->GetInput(EnthalpyPicardEnum); _assert_(enthalpy_input);
|
---|
| 497 | Input* pressure_input = element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 498 | Input* geothermalflux_input = element->GetInput(BasalforcingsGeothermalfluxEnum); _assert_(geothermalflux_input);
|
---|
| 499 | Input* watercolumn_input = element->GetInput(WatercolumnEnum); _assert_(watercolumn_input);
|
---|
| 500 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 501 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 502 |
|
---|
| 503 | /*Build friction element, needed later: */
|
---|
| 504 | Friction* friction=new Friction(element,3);
|
---|
| 505 |
|
---|
| 506 | /* Start looping on the number of gaussian points: */
|
---|
| 507 | Gauss* gauss = element->NewGaussBase(2);
|
---|
| 508 | Gauss* gaussup = element->NewGaussTop(2);
|
---|
| 509 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 510 | gauss->GaussPoint(ig);
|
---|
| 511 |
|
---|
| 512 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 513 | element->NodalFunctions(basis,gauss);
|
---|
| 514 |
|
---|
| 515 | enthalpy_input->GetInputValue(&enthalpy,gauss);
|
---|
| 516 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
| 517 | watercolumn_input->GetInputValue(&watercolumn,gauss);
|
---|
| 518 |
|
---|
| 519 | if((watercolumn<=0.) && (enthalpy < PureIceEnthalpy(element,pressure))){
|
---|
| 520 | /* the above check is equivalent to
|
---|
| 521 | NOT ((watercolumn>0.) AND (enthalpy<PIE)) AND (enthalpy<PIE)*/
|
---|
| 522 | geothermalflux_input->GetInputValue(&geothermalflux,gauss);
|
---|
| 523 |
|
---|
| 524 | friction->GetAlpha2(&alpha2,gauss,vx_input,vy_input,vz_input);
|
---|
| 525 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 526 | vy_input->GetInputValue(&vy,gauss);
|
---|
| 527 | vz_input->GetInputValue(&vz,gauss);
|
---|
| 528 | basalfriction = alpha2*(vx*vx + vy*vy + vz*vz);
|
---|
| 529 | heatflux = (basalfriction+geothermalflux)/(rho_ice);
|
---|
| 530 |
|
---|
| 531 | scalar = gauss->weight*Jdet*heatflux;
|
---|
| 532 | if(dt!=0.) scalar=dt*scalar;
|
---|
| 533 |
|
---|
| 534 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar*basis[i];
|
---|
| 535 | }
|
---|
| 536 | else if(enthalpy >= PureIceEnthalpy(element,pressure)){
|
---|
| 537 | /* check positive thickness of temperate basal ice layer */
|
---|
| 538 | enthalpy_input->GetInputValue(&enthalpyup,gaussup);
|
---|
| 539 | pressure_input->GetInputValue(&pressureup,gaussup);
|
---|
| 540 | if(enthalpyup >= PureIceEnthalpy(element,pressureup)){
|
---|
| 541 | // TODO: temperate ice has positive thickness: grad enthalpy*n=0.
|
---|
| 542 | }
|
---|
| 543 | else{
|
---|
| 544 | // only base temperate, set Dirichlet BCs in Penta::UpdateBasalConstraintsEnthalpy()
|
---|
| 545 | }
|
---|
| 546 | }
|
---|
| 547 | else{
|
---|
| 548 | // base cold, but watercolumn positive. Set base to h_pmp.
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | /*Clean up and return*/
|
---|
| 553 | delete gauss;
|
---|
| 554 | delete gaussup;
|
---|
| 555 | delete friction;
|
---|
| 556 | xDelete<IssmDouble>(basis);
|
---|
| 557 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 558 | return pe;
|
---|
| 559 |
|
---|
[16812] | 560 | }/*}}}*/
|
---|
| 561 | ElementVector* EnthalpyAnalysis::CreatePVectorShelf(Element* element){/*{{{*/
|
---|
| 562 |
|
---|
[16888] | 563 | /*Get basal element*/
|
---|
| 564 | if(!element->IsOnBed() || !element->IsFloating()) return NULL;
|
---|
| 565 |
|
---|
[16813] | 566 | IssmDouble h_pmp,dt,Jdet,scalar_ocean,pressure;
|
---|
[16812] | 567 | IssmDouble *xyz_list_base = NULL;
|
---|
| 568 |
|
---|
| 569 | /*Fetch number of nodes for this finite element*/
|
---|
| 570 | int numnodes = element->GetNumberOfNodes();
|
---|
| 571 |
|
---|
| 572 | /*Initialize vectors*/
|
---|
| 573 | ElementVector* pe = element->NewElementVector();
|
---|
| 574 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 575 |
|
---|
| 576 | /*Retrieve all inputs and parameters*/
|
---|
| 577 | element->GetVerticesCoordinatesBase(&xyz_list_base);
|
---|
| 578 | element->FindParam(&dt,TimesteppingTimeStepEnum);
|
---|
| 579 | Input* pressure_input=element->GetInput(PressureEnum); _assert_(pressure_input);
|
---|
| 580 | IssmDouble gravity = element->GetMaterialParameter(ConstantsGEnum);
|
---|
| 581 | IssmDouble rho_water = element->GetMaterialParameter(MaterialsRhoWaterEnum);
|
---|
| 582 | IssmDouble rho_ice = element->GetMaterialParameter(MaterialsRhoIceEnum);
|
---|
| 583 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 584 | IssmDouble mixed_layer_capacity= element->GetMaterialParameter(MaterialsMixedLayerCapacityEnum);
|
---|
| 585 | IssmDouble thermal_exchange_vel= element->GetMaterialParameter(MaterialsThermalExchangeVelocityEnum);
|
---|
| 586 |
|
---|
| 587 | /* Start looping on the number of gaussian points: */
|
---|
| 588 | Gauss* gauss=element->NewGaussBase(2);
|
---|
| 589 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 590 | gauss->GaussPoint(ig);
|
---|
| 591 |
|
---|
| 592 | element->JacobianDeterminantBase(&Jdet,xyz_list_base,gauss);
|
---|
| 593 | element->NodalFunctions(basis,gauss);
|
---|
| 594 |
|
---|
| 595 | pressure_input->GetInputValue(&pressure,gauss);
|
---|
[16813] | 596 | h_pmp=element->PureIceEnthalpy(pressure);
|
---|
[16812] | 597 |
|
---|
[16813] | 598 | scalar_ocean=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_vel*h_pmp/(heatcapacity*rho_ice);
|
---|
[16812] | 599 | if(reCast<bool,IssmDouble>(dt)) scalar_ocean=dt*scalar_ocean;
|
---|
| 600 |
|
---|
| 601 | for(int i=0;i<numnodes;i++) pe->values[i]+=scalar_ocean*basis[i];
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | /*Clean up and return*/
|
---|
| 605 | delete gauss;
|
---|
| 606 | xDelete<IssmDouble>(basis);
|
---|
| 607 | xDelete<IssmDouble>(xyz_list_base);
|
---|
| 608 | return pe;
|
---|
| 609 | }/*}}}*/
|
---|
[16888] | 610 | void EnthalpyAnalysis::GetBConduct(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 611 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 612 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 613 | * by:
|
---|
| 614 | * Bi_conduct=[ dh/dx ]
|
---|
| 615 | * [ dh/dy ]
|
---|
| 616 | * [ dh/dz ]
|
---|
| 617 | * where h is the interpolation function for node i.
|
---|
| 618 | *
|
---|
| 619 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
| 620 | */
|
---|
| 621 |
|
---|
| 622 | /*Fetch number of nodes for this finite element*/
|
---|
| 623 | int numnodes = element->GetNumberOfNodes();
|
---|
| 624 |
|
---|
| 625 | /*Get nodal functions derivatives*/
|
---|
| 626 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
| 627 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 628 |
|
---|
| 629 | /*Build B: */
|
---|
| 630 | for(int i=0;i<numnodes;i++){
|
---|
| 631 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
| 632 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
| 633 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | /*Clean-up*/
|
---|
| 637 | xDelete<IssmDouble>(dbasis);
|
---|
| 638 | }/*}}}*/
|
---|
| 639 | void EnthalpyAnalysis::GetBAdvec(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 640 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 641 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 642 | * by:
|
---|
| 643 | * Bi_advec =[ h ]
|
---|
| 644 | * [ h ]
|
---|
| 645 | * [ h ]
|
---|
| 646 | * where h is the interpolation function for node i.
|
---|
| 647 | *
|
---|
| 648 | * We assume B has been allocated already, of size: 3x(NDOF1*NUMNODESP1)
|
---|
| 649 | */
|
---|
| 650 |
|
---|
| 651 | /*Fetch number of nodes for this finite element*/
|
---|
| 652 | int numnodes = element->GetNumberOfNodes();
|
---|
| 653 |
|
---|
| 654 | /*Get nodal functions*/
|
---|
| 655 | IssmDouble* basis=xNew<IssmDouble>(numnodes);
|
---|
| 656 | element->NodalFunctions(basis,gauss);
|
---|
| 657 |
|
---|
| 658 | /*Build B: */
|
---|
| 659 | for(int i=0;i<numnodes;i++){
|
---|
| 660 | B[numnodes*0+i] = basis[i];
|
---|
| 661 | B[numnodes*1+i] = basis[i];
|
---|
| 662 | B[numnodes*2+i] = basis[i];
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | /*Clean-up*/
|
---|
| 666 | xDelete<IssmDouble>(basis);
|
---|
| 667 | }/*}}}*/
|
---|
| 668 | void EnthalpyAnalysis::GetBAdvecprime(IssmDouble* B,Element* element,IssmDouble* xyz_list,Gauss* gauss){/*{{{*/
|
---|
| 669 | /*Compute B matrix. B=[B1 B2 B3 B4 B5 B6] where Bi is of size 5*NDOF1.
|
---|
| 670 | * For node i, Bi' can be expressed in the actual coordinate system
|
---|
| 671 | * by:
|
---|
| 672 | * Biprime_advec=[ dh/dx ]
|
---|
| 673 | * [ dh/dy ]
|
---|
| 674 | * [ dh/dz ]
|
---|
| 675 | * where h is the interpolation function for node i.
|
---|
| 676 | *
|
---|
| 677 | * We assume B has been allocated already, of size: 3x(NDOF1*numnodes)
|
---|
| 678 | */
|
---|
| 679 |
|
---|
| 680 | /*Fetch number of nodes for this finite element*/
|
---|
| 681 | int numnodes = element->GetNumberOfNodes();
|
---|
| 682 |
|
---|
| 683 | /*Get nodal functions derivatives*/
|
---|
| 684 | IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
|
---|
| 685 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
| 686 |
|
---|
| 687 | /*Build B: */
|
---|
| 688 | for(int i=0;i<numnodes;i++){
|
---|
| 689 | B[numnodes*0+i] = dbasis[0*numnodes+i];
|
---|
| 690 | B[numnodes*1+i] = dbasis[1*numnodes+i];
|
---|
| 691 | B[numnodes*2+i] = dbasis[2*numnodes+i];
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | /*Clean-up*/
|
---|
| 695 | xDelete<IssmDouble>(dbasis);
|
---|
| 696 | }/*}}}*/
|
---|
[16675] | 697 | void EnthalpyAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
| 698 | element->GetSolutionFromInputsOneDof(solution,EnthalpyEnum);
|
---|
| 699 | }/*}}}*/
|
---|
[16684] | 700 | void EnthalpyAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[16734] | 701 |
|
---|
| 702 | bool converged;
|
---|
| 703 | int i,rheology_law;
|
---|
| 704 | IssmDouble B_average,s_average,T_average=0.,P_average=0.;
|
---|
| 705 | int *doflist = NULL;
|
---|
| 706 | IssmDouble *xyz_list = NULL;
|
---|
| 707 |
|
---|
| 708 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 709 | int numnodes = element->GetNumberOfNodes();
|
---|
| 710 |
|
---|
| 711 | /*Fetch dof list and allocate solution vector*/
|
---|
| 712 | element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
| 713 | IssmDouble* values = xNew<IssmDouble>(numnodes);
|
---|
| 714 | IssmDouble* pressure = xNew<IssmDouble>(numnodes);
|
---|
[16745] | 715 | IssmDouble* surface = xNew<IssmDouble>(numnodes);
|
---|
| 716 | IssmDouble* B = xNew<IssmDouble>(numnodes);
|
---|
[16734] | 717 | IssmDouble* temperature = xNew<IssmDouble>(numnodes);
|
---|
| 718 | IssmDouble* waterfraction = xNew<IssmDouble>(numnodes);
|
---|
| 719 |
|
---|
| 720 | /*Use the dof list to index into the solution vector: */
|
---|
| 721 | for(i=0;i<numnodes;i++){
|
---|
| 722 | values[i]=solution[doflist[i]];
|
---|
| 723 |
|
---|
| 724 | /*Check solution*/
|
---|
| 725 | if(xIsNan<IssmDouble>(values[i])) _error_("NaN found in solution vector");
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | /*Get all inputs and parameters*/
|
---|
| 729 | element->GetInputValue(&converged,ConvergedEnum);
|
---|
[16745] | 730 | element->GetInputListOnNodes(&pressure[0],PressureEnum);
|
---|
[16734] | 731 | if(converged){
|
---|
| 732 | for(i=0;i<numnodes;i++){
|
---|
| 733 | element->EnthalpyToThermal(&temperature[i],&waterfraction[i],values[i],pressure[i]);
|
---|
| 734 | if(waterfraction[i]<0.) _error_("Negative water fraction found in solution vector");
|
---|
[16837] | 735 | if(waterfraction[i]>1.) _error_("Water fraction >1 found in solution vector");
|
---|
[16734] | 736 | }
|
---|
| 737 | element->AddInput(EnthalpyEnum,values,P1Enum);
|
---|
| 738 | element->AddInput(WaterfractionEnum,waterfraction,P1Enum);
|
---|
| 739 | element->AddInput(TemperatureEnum,temperature,P1Enum);
|
---|
| 740 |
|
---|
| 741 | /*Update Rheology only if converged (we must make sure that the temperature is below melting point
|
---|
| 742 | * otherwise the rheology could be negative*/
|
---|
| 743 | element->FindParam(&rheology_law,MaterialsRheologyLawEnum);
|
---|
[16745] | 744 | element->GetInputListOnNodes(&surface[0],SurfaceEnum);
|
---|
[16734] | 745 | switch(rheology_law){
|
---|
| 746 | case NoneEnum:
|
---|
| 747 | /*Do nothing: B is not temperature dependent*/
|
---|
| 748 | break;
|
---|
| 749 | case PatersonEnum:
|
---|
[16748] | 750 | for(i=0;i<numnodes;i++) B[i]=Paterson(temperature[i]);
|
---|
[16745] | 751 | element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
[16734] | 752 | break;
|
---|
[16745] | 753 | case ArrheniusEnum:
|
---|
[16734] | 754 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[16748] | 755 | for(i=0;i<numnodes;i++) B[i]=Arrhenius(temperature[i],surface[i]-xyz_list[i*3+2],element->GetMaterialParameter(MaterialsRheologyNEnum));
|
---|
[16745] | 756 | element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
[16734] | 757 | break;
|
---|
| 758 | case LliboutryDuvalEnum:
|
---|
[16750] | 759 | 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));
|
---|
[16745] | 760 | element->AddMaterialInput(MaterialsRheologyBEnum,&B[0],P1Enum);
|
---|
| 761 | break;
|
---|
| 762 | default: _error_("Rheology law " << EnumToStringx(rheology_law) << " not supported yet");
|
---|
[16734] | 763 | }
|
---|
| 764 | }
|
---|
| 765 | else{
|
---|
| 766 | element->AddInput(EnthalpyPicardEnum,values,P1Enum);
|
---|
| 767 | }
|
---|
| 768 |
|
---|
| 769 | /*Free ressources:*/
|
---|
| 770 | xDelete<IssmDouble>(values);
|
---|
| 771 | xDelete<IssmDouble>(pressure);
|
---|
[16745] | 772 | xDelete<IssmDouble>(surface);
|
---|
| 773 | xDelete<IssmDouble>(B);
|
---|
[16734] | 774 | xDelete<IssmDouble>(temperature);
|
---|
| 775 | xDelete<IssmDouble>(waterfraction);
|
---|
| 776 | xDelete<IssmDouble>(xyz_list);
|
---|
| 777 | xDelete<int>(doflist);
|
---|
[16684] | 778 | }/*}}}*/
|
---|
[16888] | 779 |
|
---|
| 780 | /*Intermediaries*/
|
---|
| 781 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameter(Element* element,IssmDouble enthalpy,IssmDouble pressure){/*{{{*/
|
---|
| 782 |
|
---|
| 783 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 784 | IssmDouble temperateiceconductivity = element->GetMaterialParameter(MaterialsTemperateiceconductivityEnum);
|
---|
| 785 | IssmDouble thermalconductivity = element->GetMaterialParameter(MaterialsThermalconductivityEnum);
|
---|
| 786 |
|
---|
| 787 | if(enthalpy < PureIceEnthalpy(element,pressure)){
|
---|
| 788 | return thermalconductivity/heatcapacity;
|
---|
| 789 | }
|
---|
| 790 | else{
|
---|
| 791 | return temperateiceconductivity/heatcapacity;
|
---|
| 792 | }
|
---|
| 793 | }/*}}}*/
|
---|
[16895] | 794 | IssmDouble EnthalpyAnalysis::EnthalpyDiffusionParameterVolume(Element* element,int enthalpy_enum){/*{{{*/
|
---|
[16888] | 795 |
|
---|
| 796 | int iv;
|
---|
| 797 | IssmDouble lambda; /* fraction of cold ice */
|
---|
| 798 | IssmDouble kappa ,kappa_c,kappa_t; /* enthalpy conductivities */
|
---|
| 799 | IssmDouble Hc,Ht;
|
---|
| 800 |
|
---|
| 801 |
|
---|
| 802 | /*Get pressures and enthalpies on vertices*/
|
---|
| 803 | int numvertices = element->GetNumberOfVertices();
|
---|
| 804 | IssmDouble* pressures = xNew<IssmDouble>(numvertices);
|
---|
| 805 | IssmDouble* enthalpies = xNew<IssmDouble>(numvertices);
|
---|
| 806 | IssmDouble* PIE = xNew<IssmDouble>(numvertices);
|
---|
| 807 | IssmDouble* dHpmp = xNew<IssmDouble>(numvertices);
|
---|
| 808 | element->GetInputListOnVertices(pressures,PressureEnum);
|
---|
[16895] | 809 | element->GetInputListOnVertices(enthalpies,enthalpy_enum);
|
---|
[16888] | 810 | for(iv=0;iv<numvertices;iv++){
|
---|
| 811 | PIE[iv] = PureIceEnthalpy(element,pressures[iv]);
|
---|
| 812 | dHpmp[iv] = enthalpies[iv]-PIE[iv];
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 | bool allequalsign = true;
|
---|
| 816 | if(dHpmp[0]<0.){
|
---|
| 817 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]<0.));
|
---|
| 818 | }
|
---|
| 819 | else{
|
---|
| 820 | for(iv=1; iv<numvertices;iv++) allequalsign=(allequalsign && (dHpmp[iv]>=0.));
|
---|
| 821 | }
|
---|
| 822 |
|
---|
| 823 | if(allequalsign){
|
---|
| 824 | kappa = EnthalpyDiffusionParameter(element,enthalpies[0],pressures[0]);
|
---|
| 825 | }
|
---|
| 826 | else{
|
---|
| 827 | /* return harmonic mean of thermal conductivities, weighted by fraction of cold/temperate ice,
|
---|
| 828 | cf Patankar 1980, pp44 */
|
---|
| 829 | kappa_c = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)-1.,0.);
|
---|
| 830 | kappa_t = EnthalpyDiffusionParameter(element,PureIceEnthalpy(element,0.)+1.,0.);
|
---|
| 831 | Hc=0.; Ht=0.;
|
---|
| 832 | for(iv=0; iv<numvertices;iv++){
|
---|
| 833 | if(enthalpies[iv]<PIE[iv])
|
---|
| 834 | Hc+=(PIE[iv]-enthalpies[iv]);
|
---|
| 835 | else
|
---|
| 836 | Ht+=(enthalpies[iv]-PIE[iv]);
|
---|
| 837 | }
|
---|
| 838 | _assert_((Hc+Ht)>0.);
|
---|
| 839 | lambda = Hc/(Hc+Ht);
|
---|
| 840 | kappa = 1./(lambda/kappa_c + (1.-lambda)/kappa_t);
|
---|
| 841 | }
|
---|
| 842 |
|
---|
| 843 | /*Clean up and return*/
|
---|
| 844 | xDelete<IssmDouble>(PIE);
|
---|
| 845 | xDelete<IssmDouble>(dHpmp);
|
---|
| 846 | xDelete<IssmDouble>(pressures);
|
---|
| 847 | xDelete<IssmDouble>(enthalpies);
|
---|
| 848 | return kappa;
|
---|
| 849 | }
|
---|
| 850 | /*}}}*/
|
---|
| 851 | IssmDouble EnthalpyAnalysis::PureIceEnthalpy(Element* element,IssmDouble pressure){/*{{{*/
|
---|
| 852 |
|
---|
| 853 | IssmDouble heatcapacity = element->GetMaterialParameter(MaterialsHeatcapacityEnum);
|
---|
| 854 | IssmDouble referencetemperature = element->GetMaterialParameter(ConstantsReferencetemperatureEnum);
|
---|
| 855 |
|
---|
| 856 | return heatcapacity*(TMeltingPoint(element,pressure)-referencetemperature);
|
---|
| 857 | }/*}}}*/
|
---|
| 858 | IssmDouble EnthalpyAnalysis::TMeltingPoint(Element* element,IssmDouble pressure){/*{{{*/
|
---|
| 859 |
|
---|
| 860 | IssmDouble meltingpoint = element->GetMaterialParameter(MaterialsMeltingpointEnum);
|
---|
| 861 | IssmDouble beta = element->GetMaterialParameter(MaterialsBetaEnum);
|
---|
| 862 |
|
---|
| 863 | return meltingpoint-beta*pressure;
|
---|
| 864 | }/*}}}*/
|
---|