28#ifndef DUMUX_TABULATED_COMPONENT_HH
29#define DUMUX_TABULATED_COMPONENT_HH
39#include <dune/common/std/type_traits.hh>
49template<
class RawComponent,
bool useVaporPressure>
50class TabulatedComponent;
56template<
class RawComponent,
bool useVaporPressure>
57struct ComponentTraits<Components::TabulatedComponent<RawComponent, useVaporPressure>>
59 using Scalar =
typename RawComponent::Scalar;
62 static constexpr bool hasSolidState = std::is_base_of<Components::Solid<Scalar, RawComponent>, RawComponent>::value;
65 static constexpr bool hasLiquidState = std::is_base_of<Components::Liquid<Scalar, RawComponent>, RawComponent>::value;
68 static constexpr bool hasGasState = std::is_base_of<Components::Gas<Scalar, RawComponent>, RawComponent>::value;
77template<>
struct AlwaysFalse<Components::Detail::DisableStaticAssert> :
public std::true_type {};
89template<
class C>
using CompHasNoGasEnthalpy =
decltype(C::template gasEnthalpy<DisableStaticAssert>(0.0, 0.0));
90template<
class C>
using CompHasNoGasDensity =
decltype(C::template gasDensity<DisableStaticAssert>(0.0, 0.0));
91template<
class C>
using CompHasNoGasThermalCond =
decltype(C::template gasThermalConductivity<DisableStaticAssert>(0.0, 0.0));
93template<
class C>
using CompHasNoGasViscosity =
decltype(C::template gasViscosity<DisableStaticAssert>(0.0, 0.0));
122template<
class RawComponent,
bool useVaporPressure = true>
125 using Scalar =
typename RawComponent::Scalar;
130 Scalar minP(std::size_t iT)
const {
return table.minGasPressure(iT); }
131 Scalar maxP(std::size_t iT)
const {
return table.maxGasPressure(iT); }
138 Scalar maxP(std::size_t iT)
const {
return table.maxLiquidPressure(iT); }
143 Scalar pressMin, Scalar pressMax, std::size_t
nPress)
148 pressMin_ = pressMin;
149 pressMax_ = pressMax;
154 assert(std::numeric_limits<Scalar>::has_quiet_NaN);
155 const auto NaN = std::numeric_limits<Scalar>::quiet_NaN();
158 vaporPressure_.resize(nTemp_, NaN);
159 tabularizeVaporPressure_();
163 minGasDensity_.resize(nTemp_, NaN);
164 maxGasDensity_.resize(nTemp_, NaN);
165 const std::size_t numEntriesTp = nTemp_*nPress_;
166 gasEnthalpy_.resize(numEntriesTp, NaN);
167 gasHeatCapacity_.resize(numEntriesTp, NaN);
168 gasDensity_.resize(numEntriesTp, NaN);
169 gasViscosity_.resize(numEntriesTp, NaN);
170 gasThermalConductivity_.resize(numEntriesTp, NaN);
172 if constexpr (RawComponent::gasIsCompressible())
173 gasPressure_.resize(numEntriesTp, NaN);
175 minMaxGasDensityInitialized_ = tabularizeMinMaxGasDensity_();
176 gasPressureInitialized_ = tabularizeGasPressure_();
177 gasEnthalpyInitialized_ = tabularizeGasEnthalpy_();
178 gasHeatCapacityInitialized_ = tabularizeGasHeatCapacity_();
179 gasDensityInitialized_ = tabularizeGasDensity_();
180 gasViscosityInitialized_ = tabularizeGasViscosity_();
181 gasThermalConductivityInitialized_ = tabularizeGasThermalConductivity_();
186 minLiquidDensity_.resize(nTemp_, NaN);
187 maxLiquidDensity_.resize(nTemp_, NaN);
189 const std::size_t numEntriesTp = nTemp_*nPress_;
190 liquidEnthalpy_.resize(numEntriesTp, NaN);
191 liquidHeatCapacity_.resize(numEntriesTp, NaN);
192 liquidDensity_.resize(numEntriesTp, NaN);
193 liquidViscosity_.resize(numEntriesTp, NaN);
194 liquidThermalConductivity_.resize(numEntriesTp, NaN);
196 if constexpr (RawComponent::liquidIsCompressible())
197 liquidPressure_.resize(numEntriesTp, NaN);
199 minMaxLiquidDensityInitialized_ = tabularizeMinMaxLiquidDensity_();
200 liquidPressureInitialized_ = tabularizeLiquidPressure_();
201 liquidEnthalpyInitialized_ = tabularizeLiquidEnthalpy_();
202 liquidHeatCapacityInitialized_ = tabularizeLiquidHeatCapacity_();
203 liquidDensityInitialized_ = tabularizeLiquidDensity_();
204 liquidViscosityInitialized_ = tabularizeLiquidViscosity_();
205 liquidThermalConductivityInitialized_ = tabularizeLiquidThermalConductivity_();
212 return (nTemp_ - 1)*(
temperature - tempMin_)/(tempMax_ - tempMin_);
220 return (nPress_ - 1)*(
pressure - plMin)/(plMax - plMin);
228 return (nPress_ - 1)*(
pressure - pgMin)/(pgMax - pgMin);
234 const Scalar densityMin = minLiquidDensity_[
tempIdx];
235 const Scalar densityMax = maxLiquidDensity_[
tempIdx];
236 return (nDensity_ - 1) * (
density - densityMin)/(densityMax - densityMin);
242 const Scalar densityMin = minGasDensity_[
tempIdx];
243 const Scalar densityMax = maxGasDensity_[
tempIdx];
244 return (nDensity_ - 1) * (
density - densityMin)/(densityMax - densityMin);
251 if (!useVaporPressure)
254 return max(pressMin_, vaporPressure_[
tempIdx] / 1.1);
261 if (!useVaporPressure)
264 return max(pressMax_, vaporPressure_[
tempIdx] * 1.1);
271 if (!useVaporPressure)
274 return min(pressMin_, vaporPressure_[
tempIdx] / 1.1 );
281 if (!useVaporPressure)
284 return min(pressMax_, vaporPressure_[
tempIdx] * 1.1);
289 {
return minLiquidDensity_[
tempIdx]; }
293 {
return maxLiquidDensity_[
tempIdx]; }
297 {
return minGasDensity_[
tempIdx]; }
301 {
return maxGasDensity_[
tempIdx]; }
303 inline std::size_t
nTemp()
const {
return nTemp_; }
304 inline std::size_t
nPress()
const {
return nPress_; }
305 inline std::size_t
nDensity()
const {
return nDensity_; }
307 inline Scalar
tempMax()
const {
return tempMax_; }
308 inline Scalar
tempMin()
const {
return tempMin_; }
313 template<
bool useVP = useVaporPressure, std::enable_if_t<useVP,
int> = 0 >
314 void tabularizeVaporPressure_()
319 Scalar
temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
320 vaporPressure_[iT] = RawComponent::vaporPressure(
temperature);
325 template<
bool useVP = useVaporPressure, std::enable_if_t<!useVP,
int> = 0 >
326 void tabularizeVaporPressure_() {}
342 template<
class PropFunc,
class Policy>
343 void tabularizeTPArray_(
const PropFunc& f, Policy policy, std::vector<typename RawComponent::Scalar>& values)
const
347 Scalar
temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
349 Scalar pMax = policy.maxP(iT);
350 Scalar pMin = policy.minP(iT);
351 for (std::size_t iP = 0; iP < nPress_; ++ iP)
353 Scalar
pressure = iP * (pMax - pMin)/(nPress_ - 1) + pMin;
374 template<
class RhoFunc,
class Policy>
375 void tabularizeMinMaxRhoArray_(
const RhoFunc& rho, Policy policy,
376 std::vector<typename RawComponent::Scalar>& rhoMin,
377 std::vector<typename RawComponent::Scalar>& rhoMax)
const
381 Scalar
temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
385 rhoMax[iT] = rho(
temperature, policy.maxP(min(iT + 1, nTemp_ - 1)));
399 template<
class PFunc>
400 void tabularizePressureArray_(std::vector<typename RawComponent::Scalar>&
pressure,
402 const std::vector<typename RawComponent::Scalar>& rhoMin,
403 const std::vector<typename RawComponent::Scalar>& rhoMax)
const
407 Scalar
temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
409 for (std::size_t iRho = 0; iRho < nDensity_; ++ iRho)
411 Scalar
density = Scalar(iRho)/(nDensity_ - 1)
412 * (rhoMax[iT] - rhoMin[iT])
419 template<
class RC = RawComponent>
420 bool tabularizeGasEnthalpy_()
422 if constexpr (Detail::hasGasEnthalpy<RC>())
424 const auto gasEnth = [] (
auto T,
auto p) {
return RC::gasEnthalpy(T, p); };
425 tabularizeTPArray_(gasEnth, GasPolicy{ *
this }, gasEnthalpy_);
432 template<
class RC = RawComponent>
433 bool tabularizeLiquidEnthalpy_()
435 if constexpr (Detail::hasLiquidEnthalpy<RC>())
437 const auto liqEnth = [] (
auto T,
auto p) {
return RC::liquidEnthalpy(T, p); };
438 tabularizeTPArray_(liqEnth, LiquidPolicy{ *
this }, liquidEnthalpy_);
445 template<
class RC = RawComponent>
446 bool tabularizeGasHeatCapacity_()
448 if constexpr (Detail::hasGasHeatCapacity<RC>())
450 const auto gasHC = [] (
auto T,
auto p) {
return RC::gasHeatCapacity(T, p); };
451 tabularizeTPArray_(gasHC, GasPolicy{ *
this }, gasHeatCapacity_);
458 template<
class RC = RawComponent>
459 bool tabularizeLiquidHeatCapacity_()
461 if constexpr (Detail::hasLiquidHeatCapacity<RC>())
463 const auto liqHC = [] (
auto T,
auto p) {
return RC::liquidHeatCapacity(T, p); };
464 tabularizeTPArray_(liqHC, LiquidPolicy{ *
this }, liquidHeatCapacity_);
471 template<
class RC = RawComponent>
472 bool tabularizeMinMaxGasDensity_()
474 if constexpr (Detail::hasGasDensity<RC>())
476 const auto gasRho = [] (
auto T,
auto p) {
return RC::gasDensity(T, p); };
477 tabularizeMinMaxRhoArray_(gasRho, GasPolicy{ *
this }, minGasDensity_, maxGasDensity_);
484 template<
class RC = RawComponent>
485 bool tabularizeMinMaxLiquidDensity_()
487 if constexpr (Detail::hasGasEnthalpy<RC>())
489 const auto liqRho = [] (
auto T,
auto p) {
return RC::liquidDensity(T, p); };
490 tabularizeMinMaxRhoArray_(liqRho, LiquidPolicy{ *
this }, minLiquidDensity_, maxLiquidDensity_);
497 template<
class RC = RawComponent>
498 bool tabularizeGasPressure_()
501 if constexpr (Detail::hasGasPressure<RC>() && RC::gasIsCompressible())
503 const auto gasPFunc = [] (
auto T,
auto rho) {
return RC::gasPressure(T, rho); };
504 tabularizePressureArray_(gasPressure_, gasPFunc, minGasDensity_, maxGasDensity_);
511 template<
class RC = RawComponent>
512 bool tabularizeLiquidPressure_()
515 if constexpr (Detail::hasLiquidPressure<RC>() && RC::liquidIsCompressible())
517 const auto liqPFunc = [] (
auto T,
auto rho) {
return RC::liquidPressure(T, rho); };
518 tabularizePressureArray_(liquidPressure_, liqPFunc, minLiquidDensity_, maxLiquidDensity_);
525 template<
class RC = RawComponent>
526 bool tabularizeGasDensity_()
528 if constexpr (Detail::hasGasDensity<RC>())
530 const auto gasRho = [] (
auto T,
auto p) {
return RC::gasDensity(T, p); };
531 tabularizeTPArray_(gasRho, GasPolicy{ *
this }, gasDensity_);
538 template<
class RC = RawComponent>
539 bool tabularizeLiquidDensity_()
541 if constexpr (Detail::hasLiquidDensity<RC>())
547 const auto liqRho = [] (
auto T,
auto p) {
return RC::liquidDensity(T, p); };
548 tabularizeTPArray_(liqRho, LiquidPolicy{ *
this }, liquidDensity_);
555 template<
class RC = RawComponent>
556 bool tabularizeGasViscosity_()
558 if constexpr (Detail::hasGasViscosity<RC>())
560 const auto gasVisc = [] (
auto T,
auto p) {
return RC::gasViscosity(T, p); };
561 tabularizeTPArray_(gasVisc, GasPolicy{ *
this }, gasViscosity_);
568 template<
class RC = RawComponent>
569 bool tabularizeLiquidViscosity_()
571 if constexpr (Detail::hasLiquidViscosity<RC>())
573 const auto liqVisc = [] (
auto T,
auto p) {
return RC::liquidViscosity(T, p); };
574 tabularizeTPArray_(liqVisc, LiquidPolicy{ *
this }, liquidViscosity_);
581 template<
class RC = RawComponent>
582 bool tabularizeGasThermalConductivity_()
584 if constexpr (Detail::hasGasThermalConductivity<RC>())
586 const auto gasTC = [] (
auto T,
auto p) {
return RC::gasThermalConductivity(T, p); };
587 tabularizeTPArray_(gasTC, GasPolicy{ *
this }, gasThermalConductivity_);
594 template<
class RC = RawComponent>
595 bool tabularizeLiquidThermalConductivity_()
597 if constexpr (Detail::hasLiquidThermalConductivity<RC>())
599 const auto liqTC = [] (
auto T,
auto p) {
return RC::liquidThermalConductivity(T, p); };
600 tabularizeTPArray_(liqTC, LiquidPolicy{ *
this }, liquidThermalConductivity_);
609 std::vector<Scalar> vaporPressure_;
611 std::vector<Scalar> minLiquidDensity_;
612 std::vector<Scalar> maxLiquidDensity_;
613 bool minMaxLiquidDensityInitialized_;
615 std::vector<Scalar> minGasDensity_;
616 std::vector<Scalar> maxGasDensity_;
617 bool minMaxGasDensityInitialized_;
620 std::vector<Scalar> gasEnthalpy_;
621 std::vector<Scalar> liquidEnthalpy_;
622 bool gasEnthalpyInitialized_;
623 bool liquidEnthalpyInitialized_;
625 std::vector<Scalar> gasHeatCapacity_;
626 std::vector<Scalar> liquidHeatCapacity_;
627 bool gasHeatCapacityInitialized_;
628 bool liquidHeatCapacityInitialized_;
630 std::vector<Scalar> gasDensity_;
631 std::vector<Scalar> liquidDensity_;
632 bool gasDensityInitialized_;
633 bool liquidDensityInitialized_;
635 std::vector<Scalar> gasViscosity_;
636 std::vector<Scalar> liquidViscosity_;
637 bool gasViscosityInitialized_;
638 bool liquidViscosityInitialized_;
640 std::vector<Scalar> gasThermalConductivity_;
641 std::vector<Scalar> liquidThermalConductivity_;
642 bool gasThermalConductivityInitialized_;
643 bool liquidThermalConductivityInitialized_;
646 std::vector<Scalar> gasPressure_;
647 std::vector<Scalar> liquidPressure_;
648 bool gasPressureInitialized_;
649 bool liquidPressureInitialized_;
662 std::size_t nDensity_;
682template <
class RawComponent,
bool useVaporPressure=true>
688 struct InterpolatePolicy
690 using Scalar =
typename RawComponent::Scalar;
697 std::size_t nTemp()
const {
return table.
nTemp(); }
698 std::size_t nPress()
const {
return table.
nPress(); }
699 std::size_t nDensity()
const {
return table.
nDensity(); }
702 struct InterpolateGasPolicy :
public InterpolatePolicy
704 using Scalar =
typename RawComponent::Scalar;
705 Scalar pressIdx(
Scalar p, std::size_t tempIdx)
const {
return this->table.pressGasIdx(p, tempIdx); }
706 Scalar rhoIdx(
Scalar rho, std::size_t tempIdx)
const {
return this->table.densityGasIdx(rho, tempIdx); }
707 Scalar minP(
int tempIdx)
const {
return this->table.minGasPressure(tempIdx); }
708 Scalar maxP(
int tempIdx)
const {
return this->table.maxGasPressure(tempIdx); }
709 Scalar minRho(
int tempIdx)
const {
return this->table.minGasDensity(tempIdx); }
710 Scalar maxRho(
int tempIdx)
const {
return this->table.maxGasDensity(tempIdx); }
713 struct InterpolateLiquidPolicy :
public InterpolatePolicy
715 using Scalar =
typename RawComponent::Scalar;
716 Scalar pressIdx(
Scalar p, std::size_t tempIdx)
const {
return this->table.pressLiquidIdx(p, tempIdx); }
717 Scalar rhoIdx(
Scalar rho, std::size_t tempIdx)
const {
return this->table.densityLiquidIdx(rho, tempIdx); }
718 Scalar minP(
int tempIdx)
const {
return this->table.minLiquidPressure(tempIdx); }
719 Scalar maxP(
int tempIdx)
const {
return this->table.maxLiquidPressure(tempIdx); }
720 Scalar minRho(
int tempIdx)
const {
return this->table.minLiquidDensity(tempIdx); }
721 Scalar maxRho(
int tempIdx)
const {
return this->table.maxLiquidDensity(tempIdx); }
725 using Scalar =
typename RawComponent::Scalar;
744 warningPrinted_ =
false;
746 std::cout <<
"-------------------------------------------------------------------------\n"
747 <<
"Initializing tables for the " << RawComponent::name()
748 <<
" fluid properties (" << nTemp*nPress <<
" entries).\n"
749 <<
"Temperature -> min: " << std::scientific << std::setprecision(3)
750 << tempMin <<
", max: " << tempMax <<
", n: " << nTemp <<
'\n'
751 <<
"Pressure -> min: " << std::scientific << std::setprecision(3)
752 << pressMin <<
", max: " << pressMax <<
", n: " << nPress <<
'\n'
753 <<
"-------------------------------------------------------------------------" << std::endl;
755 table().
init(tempMin, tempMax, nTemp, pressMin, pressMax, nPress);
764 {
return RawComponent::name(); }
770 {
return RawComponent::molarMass(); }
776 {
return RawComponent::criticalTemperature(); }
782 {
return RawComponent::criticalPressure(); }
788 {
return RawComponent::tripleTemperature(); }
794 {
return RawComponent::triplePressure(); }
805 Scalar result = interpolateT_(table().vaporPressure_, T, InterpolatePolicy{{ table() }});
807 return RawComponent::vaporPressure(T);
820 return RawComponent::vaporTemperature(
pressure);
853 printWarningTP_(
"liquidEnthalpy",
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
871 printWarningTP_(
"gasHeatCapacity",
temperature,
pressure, InterpolateGasPolicy{{ table() }});
885 Scalar result = interpolateTP_(table().liquidHeatCapacity_,
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
889 printWarningTP_(
"liquidHeatCapacity",
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
929 printWarningTRho_(
"gasPressure",
temperature,
density, InterpolateGasPolicy{{ table() }});
943 Scalar result = interpolateTRho_(table().liquidPressure_,
temperature,
density, InterpolateLiquidPolicy{{ table() }});
947 printWarningTRho_(
"liquidPressure",
temperature,
density, InterpolateLiquidPolicy{{ table() }});
957 {
return RawComponent::gasIsCompressible(); }
963 {
return RawComponent::liquidIsCompressible(); }
969 {
return RawComponent::gasIsIdeal(); }
1015 printWarningTP_(
"liquidDensity",
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
1045 printWarningTP_(
"gasViscosity",
temperature,
pressure, InterpolateGasPolicy{{ table() }});
1063 printWarningTP_(
"liquidViscosity",
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
1077 Scalar result = interpolateTP_(table().gasThermalConductivity_,
temperature,
pressure, InterpolateGasPolicy{{ table() }});
1081 printWarningTP_(
"gasThermalConductivity",
temperature,
pressure, InterpolateGasPolicy{{ table() }});
1095 Scalar result = interpolateTP_(table().liquidThermalConductivity_,
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
1099 printWarningTP_(
"liquidThermalConductivity",
temperature,
pressure, InterpolateLiquidPolicy{{ table() }});
1108 template<
class Policy>
1109 static void printWarningTP_(
const std::string& quantity,
Scalar T,
Scalar p, Policy policy)
1112 if (warningPrinted_)
1116 std::cerr <<
"Warning: tabulated component '" <<
name()
1117 <<
"' has not been initialized. "
1118 <<
"Call FluidSystem::init() to use the tabulation in order to reduce runtime. \n";
1120 std::cerr <<
"Warning: "<<quantity<<
"(T="<<T<<
", p="<<p<<
") of component '"<<
name()
1121 <<
"' is outside tabulation range: ("<< policy.tempMin() <<
"<=T<="<< policy.tempMax() <<
"), ("
1122 << policy.minP(0) <<
"<=p<=" << policy.maxP(policy.nTemp()-1) <<
"). "
1123 <<
"Forwarded to FluidSystem for direct evaluation of "<<quantity<<
". \n";
1124 warningPrinted_ =
true;
1129 template<
class Policy>
1130 static void printWarningTRho_(
const std::string& quantity,
Scalar T,
Scalar rho, Policy policy)
1133 if (warningPrinted_)
1137 std::cerr <<
"Warning: tabulated component '" <<
name()
1138 <<
"' has not been initialized. "
1139 <<
"Call FluidSystem::init() to use the tabulation in order to reduce runtime. \n";
1142 const auto [densityMin, densityMax] = [&]
1144 const Scalar alphaT = policy.tempIdx(T);
1146 const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, policy.nTemp() - 2);
1147 return std::make_pair( policy.minRho(iT), policy.maxRho(iT) );
1150 std::cerr <<
"Warning: "<<quantity<<
"(T="<<T<<
", density="<<rho<<
") of component '"<<
name()
1151 <<
"' is outside tabulation range: ("<< policy.tempMin() <<
"<=T<="<< policy.tempMax() <<
"), ("
1152 << densityMin <<
"<=density<=" << densityMax <<
"). "
1153 <<
"Forwarded to FluidSystem for direct evaluation of "<<quantity<<
". \n";
1155 warningPrinted_ =
true;
1160 template<
class Policy>
1161 static Scalar interpolateT_(
const std::vector<Scalar>& values,
Scalar T, Policy policy)
1163 Scalar alphaT = policy.tempIdx(T);
1164 const auto nTemp = policy.nTemp();
1165 if (alphaT < 0 - 1e-7*nTemp || alphaT >= nTemp - 1 + 1e-7*nTemp)
1166 return std::numeric_limits<Scalar>::quiet_NaN();
1169 const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, nTemp - 2);
1172 return values[iT ]*(1 - alphaT) +
1173 values[iT + 1]*( alphaT);
1177 template<
class Policy>
1178 static Scalar interpolateTP_(
const std::vector<Scalar>& values,
const Scalar T,
const Scalar p, Policy policy)
1180 const auto nTemp = policy.nTemp();
1181 const auto nPress = policy.nPress();
1183 Scalar alphaT = policy.tempIdx(T);
1184 if (alphaT < 0 - 1e-7*nTemp || alphaT >= nTemp - 1 + 1e-7*nTemp)
1185 return std::numeric_limits<Scalar>::quiet_NaN();
1188 const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, nTemp - 2);
1191 Scalar alphaP1 = policy.pressIdx(p, iT);
1192 Scalar alphaP2 = policy.pressIdx(p, iT + 1);
1194 const auto iP1 = clamp<int>(
static_cast<int>(alphaP1), 0, nPress - 2);
1195 const auto iP2 = clamp<int>(
static_cast<int>(alphaP2), 0, nPress - 2);
1199#if 0 && !defined NDEBUG
1200 const auto tempMin = policy.tempMin();
1201 const auto tempMin = policy.tempMax();
1202 if(!(0 <= alphaT && alphaT <= 1.0))
1203 DUNE_THROW(NumericalProblem,
"Temperature out of range: "
1204 <<
"T=" << T <<
" range: [" << tempMin_ <<
", " << tempMax_ <<
"]");
1205 if(!(0 <= alphaP1 && alphaP1 <= 1.0))
1206 DUNE_THROW(NumericalProblem,
"First pressure out of range: "
1207 <<
"p=" << p <<
" range: [" << policy.minP(policy.tempIdx(T)) <<
", " << policy.maxP(policy.tempIdx(T)) <<
"]");
1208 if(!(0 <= alphaP2 && alphaP2 <= 1.0))
1209 DUNE_THROW(NumericalProblem,
"Second pressure out of range: "
1210 <<
"p=" << p <<
" range: [" << policy.minP(policy.tempIdx(T) + 1) <<
", " << policy.maxP(policy.tempIdx(T) + 1) <<
"]");
1212 return values[(iT ) + (iP1 )*nTemp]*(1 - alphaT)*(1 - alphaP1) +
1213 values[(iT ) + (iP1 + 1)*nTemp]*(1 - alphaT)*( alphaP1) +
1214 values[(iT + 1) + (iP2 )*nTemp]*( alphaT)*(1 - alphaP2) +
1215 values[(iT + 1) + (iP2 + 1)*nTemp]*( alphaT)*( alphaP2);
1219 template<
class Policy>
1220 static Scalar interpolateTRho_(
const std::vector<Scalar>& values,
const Scalar T,
const Scalar rho, Policy policy)
1222 const auto nTemp = policy.nTemp();
1223 const auto nDensity = policy.nDensity();
1226 Scalar alphaT = policy.tempIdx(T);
1227 if (alphaT < 0 - 1e-7*nTemp || alphaT >= nTemp - 1 + 1e-7*nTemp)
1228 return std::numeric_limits<Scalar>::quiet_NaN();
1230 const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, nTemp - 2);
1233 Scalar alphaP1 = policy.rhoIdx(rho, iT);
1234 Scalar alphaP2 = policy.rhoIdx(rho, iT + 1);
1235 const auto iP1 = clamp<int>(
static_cast<int>(alphaP1), 0, nDensity - 2);
1236 const auto iP2 = clamp<int>(
static_cast<int>(alphaP2), 0, nDensity - 2);
1240 return values[(iT ) + (iP1 )*nTemp]*(1 - alphaT)*(1 - alphaP1) +
1241 values[(iT ) + (iP1 + 1)*nTemp]*(1 - alphaT)*( alphaP1) +
1242 values[(iT + 1) + (iP2 )*nTemp]*( alphaT)*(1 - alphaP2) +
1243 values[(iT + 1) + (iP2 + 1)*nTemp]*( alphaT)*( alphaP2);
1247 static bool initialized_;
1251 static bool warningPrinted_;
1254 static Table& table()
1261template <
class RawComponent,
bool useVaporPressure>
1262bool TabulatedComponent<RawComponent, useVaporPressure>::initialized_ =
false;
1265template <
class RawComponent,
bool useVaporPressure>
1266bool TabulatedComponent<RawComponent, useVaporPressure>::warningPrinted_ =
false;
1270template <
class Component>
1274template <
class RawComponent,
bool useVaporPressure>
Some exceptions thrown in DuMux
Component traits, i.e. information extracted from components.
Parallel for loop (multithreading)
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:172
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
Definition: tabulatedcomponent.hh:72
decltype(C::template gasThermalConductivity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasThermalCond
Definition: tabulatedcomponent.hh:91
constexpr bool hasGasEnthalpy()
Definition: tabulatedcomponent.hh:109
constexpr bool hasGasHeatCapacity()
Definition: tabulatedcomponent.hh:115
decltype(C::template liquidEnthalpy< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidEnthalpy
Definition: tabulatedcomponent.hh:82
decltype(C::template gasViscosity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasViscosity
Definition: tabulatedcomponent.hh:93
decltype(C::template gasDensity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasDensity
Definition: tabulatedcomponent.hh:90
decltype(C::template liquidHeatCapacity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidHeatCapacity
Definition: tabulatedcomponent.hh:85
decltype(C::gasPressure(0.0, 0.0)) CompHasGasPressure
Definition: tabulatedcomponent.hh:94
constexpr bool hasLiquidThermalConductivity()
Definition: tabulatedcomponent.hh:100
constexpr bool hasGasViscosity()
Definition: tabulatedcomponent.hh:117
constexpr bool hasLiquidPressure()
Definition: tabulatedcomponent.hh:106
constexpr bool hasLiquidEnthalpy()
Definition: tabulatedcomponent.hh:96
decltype(C::template gasEnthalpy< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasEnthalpy
Definition: tabulatedcomponent.hh:89
constexpr bool hasGasDensity()
Definition: tabulatedcomponent.hh:111
decltype(C::liquidPressure(0.0, 0.0)) CompHasLiquidPressure
Definition: tabulatedcomponent.hh:87
constexpr bool hasGasThermalConductivity()
Definition: tabulatedcomponent.hh:113
constexpr bool hasLiquidViscosity()
Definition: tabulatedcomponent.hh:104
constexpr bool hasGasPressure()
Definition: tabulatedcomponent.hh:119
decltype(C::template liquidThermalConductivity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidThermalCond
Definition: tabulatedcomponent.hh:84
constexpr bool hasLiquidHeatCapacity()
Definition: tabulatedcomponent.hh:102
constexpr bool hasLiquidDensity()
Definition: tabulatedcomponent.hh:98
decltype(C::template gasHeatCapacity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasHeatCapacity
Definition: tabulatedcomponent.hh:92
decltype(C::template liquidDensity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidDensity
Definition: tabulatedcomponent.hh:83
decltype(C::template liquidViscosity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidViscosity
Definition: tabulatedcomponent.hh:86
Template which always yields a false value.
Definition: typetraits.hh:35
IsAqueous struct.
Definition: components/base.hh:47
Component traits, i.e. information extracted from components.
Definition: componenttraits.hh:43
static constexpr bool hasLiquidState
if the component implements a liquid state
Definition: componenttraits.hh:50
static constexpr bool hasSolidState
if the component implements a solid state
Definition: componenttraits.hh:47
static constexpr bool hasGasState
if the component implements a gaseous state
Definition: componenttraits.hh:53
Tabulates all thermodynamic properties of a given component.
Definition: tabulatedcomponent.hh:684
static const Scalar gasEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of the gas .
Definition: tabulatedcomponent.hh:829
static Scalar gasPressure(Scalar temperature, Scalar density)
The pressure of gas in at a given density and temperature.
Definition: tabulatedcomponent.hh:923
static Scalar criticalTemperature()
Returns the critical temperature in of the component.
Definition: tabulatedcomponent.hh:775
static Scalar liquidPressure(Scalar temperature, Scalar density)
The pressure of liquid in at a given density and temperature.
Definition: tabulatedcomponent.hh:941
static const Scalar gasHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of the gas .
Definition: tabulatedcomponent.hh:865
static std::string name()
A human readable name for the component.
Definition: tabulatedcomponent.hh:763
static Scalar vaporTemperature(Scalar pressure)
The vapor pressure in of the component at a given temperature.
Definition: tabulatedcomponent.hh:818
static Scalar liquidThermalConductivity(Scalar temperature, Scalar pressure)
The thermal conductivity of liquid water .
Definition: tabulatedcomponent.hh:1093
static Scalar gasDensity(Scalar temperature, Scalar pressure)
The density of gas at a given pressure and temperature .
Definition: tabulatedcomponent.hh:979
static const Scalar liquidEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of the liquid .
Definition: tabulatedcomponent.hh:847
static Scalar triplePressure()
Returns the pressure in at the component's triple point.
Definition: tabulatedcomponent.hh:793
static Scalar criticalPressure()
Returns the critical pressure in of the component.
Definition: tabulatedcomponent.hh:781
static const Scalar gasInternalEnergy(Scalar temperature, Scalar pressure)
Specific internal energy of the gas .
Definition: tabulatedcomponent.hh:901
static Scalar liquidMolarDensity(Scalar temperature, Scalar pressure)
The molar density of liquid in at a given pressure and temperature.
Definition: tabulatedcomponent.hh:1030
static constexpr Scalar molarMass()
The molar mass in of the component.
Definition: tabulatedcomponent.hh:769
static Scalar liquidViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of liquid.
Definition: tabulatedcomponent.hh:1057
static Scalar gasViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of gas.
Definition: tabulatedcomponent.hh:1039
static Scalar tripleTemperature()
Returns the temperature in at the component's triple point.
Definition: tabulatedcomponent.hh:787
static constexpr bool liquidIsCompressible()
Returns true if the liquid phase is assumed to be compressible.
Definition: tabulatedcomponent.hh:962
static Scalar liquidDensity(Scalar temperature, Scalar pressure)
The density of liquid at a given pressure and temperature .
Definition: tabulatedcomponent.hh:1009
static Scalar gasThermalConductivity(Scalar temperature, Scalar pressure)
The thermal conductivity of gaseous water .
Definition: tabulatedcomponent.hh:1075
static Scalar gasMolarDensity(Scalar temperature, Scalar pressure)
The molar density of gas in at a given pressure and temperature.
Definition: tabulatedcomponent.hh:999
static constexpr bool isTabulated
state that we are tabulated
Definition: tabulatedcomponent.hh:728
static const Scalar liquidInternalEnergy(Scalar temperature, Scalar pressure)
Specific internal energy of the liquid .
Definition: tabulatedcomponent.hh:912
static Scalar vaporPressure(Scalar T)
The vapor pressure in of the component at a given temperature.
Definition: tabulatedcomponent.hh:802
static constexpr bool gasIsCompressible()
Returns true if the gas phase is assumed to be compressible.
Definition: tabulatedcomponent.hh:956
static void init(Scalar tempMin, Scalar tempMax, std::size_t nTemp, Scalar pressMin, Scalar pressMax, std::size_t nPress)
Initialize the tables.
Definition: tabulatedcomponent.hh:740
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition: tabulatedcomponent.hh:968
static const Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of the liquid .
Definition: tabulatedcomponent.hh:883
typename RawComponent::Scalar Scalar
export scalar type
Definition: tabulatedcomponent.hh:725
typename RawComponent::Scalar Scalar
Definition: tabulatedcomponent.hh:59
Definition: tabulatedcomponent.hh:73
Definition: tabulatedcomponent.hh:124
std::size_t nPress() const
Definition: tabulatedcomponent.hh:304
Scalar tempIdx(Scalar temperature) const
returns the index of an entry in a temperature field
Definition: tabulatedcomponent.hh:210
Scalar densityLiquidIdx(Scalar density, std::size_t tempIdx) const
returns the index of an entry in a density field
Definition: tabulatedcomponent.hh:232
void init(Scalar tempMin, Scalar tempMax, std::size_t nTemp, Scalar pressMin, Scalar pressMax, std::size_t nPress)
Definition: tabulatedcomponent.hh:142
Scalar pressGasIdx(Scalar pressure, std::size_t tempIdx) const
returns the index of an entry in a temperature field
Definition: tabulatedcomponent.hh:224
Scalar minLiquidPressure(int tempIdx) const
returns the minimum tabularized liquid pressure at a given temperature index
Definition: tabulatedcomponent.hh:248
Scalar densityGasIdx(Scalar density, std::size_t tempIdx) const
returns the index of an entry in a density field
Definition: tabulatedcomponent.hh:240
Scalar maxGasPressure(int tempIdx) const
returns the maximum tabularized gas pressure at a given temperature index
Definition: tabulatedcomponent.hh:278
Scalar minGasDensity(int tempIdx) const
returns the minimum tabularized gas density at a given temperature index
Definition: tabulatedcomponent.hh:296
Scalar maxLiquidDensity(int tempIdx) const
returns the maximum tabularized liquid density at a given temperature index
Definition: tabulatedcomponent.hh:292
Scalar maxGasDensity(int tempIdx) const
returns the maximum tabularized gas density at a given temperature index
Definition: tabulatedcomponent.hh:300
Scalar tempMin() const
Definition: tabulatedcomponent.hh:308
Scalar maxLiquidPressure(int tempIdx) const
returns the maximum tabularized liquid pressure at a given temperature index
Definition: tabulatedcomponent.hh:258
Scalar pressLiquidIdx(Scalar pressure, std::size_t tempIdx) const
returns the index of an entry in a pressure field
Definition: tabulatedcomponent.hh:216
Scalar tempMax() const
Definition: tabulatedcomponent.hh:307
std::size_t nDensity() const
Definition: tabulatedcomponent.hh:305
Scalar minLiquidDensity(int tempIdx) const
returns the minimum tabularized liquid density at a given temperature index
Definition: tabulatedcomponent.hh:288
std::size_t nTemp() const
Definition: tabulatedcomponent.hh:303
Scalar minGasPressure(int tempIdx) const
returns the minimum tabularized gas pressure at a given temperature index
Definition: tabulatedcomponent.hh:268