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