16#ifndef DUMUX_TABULATED_COMPONENT_HH 
   17#define DUMUX_TABULATED_COMPONENT_HH 
   27#include <dune/common/std/type_traits.hh> 
   37template<
class RawComponent, 
bool useVaporPressure>
 
   44template<
class RawComponent, 
bool useVaporPressure>
 
   47    using Scalar = 
typename RawComponent::Scalar;
 
   50    static constexpr bool hasSolidState = std::is_base_of<Components::Solid<Scalar, RawComponent>, RawComponent>::value;
 
   53    static constexpr bool hasLiquidState = std::is_base_of<Components::Liquid<Scalar, RawComponent>, RawComponent>::value;
 
   56    static constexpr bool hasGasState = std::is_base_of<Components::Gas<Scalar, RawComponent>, RawComponent>::value;
 
 
   77template<
class C> 
using CompHasNoGasEnthalpy = 
decltype(C::template gasEnthalpy<DisableStaticAssert>(0.0, 0.0));
 
   78template<
class C> 
using CompHasNoGasDensity = 
decltype(C::template gasDensity<DisableStaticAssert>(0.0, 0.0));
 
   79template<
class C> 
using CompHasNoGasThermalCond = 
decltype(C::template gasThermalConductivity<DisableStaticAssert>(0.0, 0.0));
 
   81template<
class C> 
using CompHasNoGasViscosity = 
decltype(C::template gasViscosity<DisableStaticAssert>(0.0, 0.0));
 
  110template<
class RawComponent, 
bool useVaporPressure = true>
 
  113    using Scalar = 
typename RawComponent::Scalar;
 
  118        Scalar minP(std::size_t iT)
 const { 
return table.
minGasPressure(iT); }
 
  119        Scalar maxP(std::size_t iT)
 const { 
return table.
maxGasPressure(iT); }
 
  131              Scalar pressMin, Scalar pressMax, std::size_t 
nPress)
 
  136        pressMin_ = pressMin;
 
  137        pressMax_ = pressMax;
 
  142        assert(std::numeric_limits<Scalar>::has_quiet_NaN);
 
  143        const auto NaN = std::numeric_limits<Scalar>::quiet_NaN();
 
  146        vaporPressure_.resize(nTemp_, NaN);
 
  147        tabularizeVaporPressure_();
 
  151            minGasDensity_.resize(nTemp_, NaN);
 
  152            maxGasDensity_.resize(nTemp_, NaN);
 
  153            const std::size_t numEntriesTp = nTemp_*nPress_;
 
  154            gasEnthalpy_.resize(numEntriesTp, NaN);
 
  155            gasHeatCapacity_.resize(numEntriesTp, NaN);
 
  156            gasDensity_.resize(numEntriesTp, NaN);
 
  157            gasViscosity_.resize(numEntriesTp, NaN);
 
  158            gasThermalConductivity_.resize(numEntriesTp, NaN);
 
  160            if constexpr (RawComponent::gasIsCompressible())
 
  161                gasPressure_.resize(numEntriesTp, NaN);
 
  163            minMaxGasDensityInitialized_ = tabularizeMinMaxGasDensity_();
 
  164            gasPressureInitialized_ = tabularizeGasPressure_();
 
  165            gasEnthalpyInitialized_ = tabularizeGasEnthalpy_();
 
  166            gasHeatCapacityInitialized_ = tabularizeGasHeatCapacity_();
 
  167            gasDensityInitialized_ = tabularizeGasDensity_();
 
  168            gasViscosityInitialized_ = tabularizeGasViscosity_();
 
  169            gasThermalConductivityInitialized_ = tabularizeGasThermalConductivity_();
 
  174            minLiquidDensity_.resize(nTemp_, NaN);
 
  175            maxLiquidDensity_.resize(nTemp_, NaN);
 
  177            const std::size_t numEntriesTp = nTemp_*nPress_;
 
  178            liquidEnthalpy_.resize(numEntriesTp, NaN);
 
  179            liquidHeatCapacity_.resize(numEntriesTp, NaN);
 
  180            liquidDensity_.resize(numEntriesTp, NaN);
 
  181            liquidViscosity_.resize(numEntriesTp, NaN);
 
  182            liquidThermalConductivity_.resize(numEntriesTp, NaN);
 
  184            if constexpr (RawComponent::liquidIsCompressible())
 
  185                liquidPressure_.resize(numEntriesTp, NaN);
 
  187            minMaxLiquidDensityInitialized_ = tabularizeMinMaxLiquidDensity_();
 
  188            liquidPressureInitialized_ = tabularizeLiquidPressure_();
 
  189            liquidEnthalpyInitialized_ = tabularizeLiquidEnthalpy_();
 
  190            liquidHeatCapacityInitialized_ = tabularizeLiquidHeatCapacity_();
 
  191            liquidDensityInitialized_ = tabularizeLiquidDensity_();
 
  192            liquidViscosityInitialized_ = tabularizeLiquidViscosity_();
 
  193            liquidThermalConductivityInitialized_ = tabularizeLiquidThermalConductivity_();
 
 
  198    inline Scalar 
tempIdx(Scalar temperature)
 const 
  200        return (nTemp_ - 1)*(temperature - tempMin_)/(tempMax_ - tempMin_);
 
 
  208        return (nPress_ - 1)*(pressure - plMin)/(plMax - plMin);
 
 
  216        return (nPress_ - 1)*(pressure - pgMin)/(pgMax - pgMin);
 
 
  222        const Scalar densityMin = minLiquidDensity_[
tempIdx];
 
  223        const Scalar densityMax = maxLiquidDensity_[
tempIdx];
 
  224        return (nDensity_ - 1) * (density - densityMin)/(densityMax - densityMin);
 
 
  230        const Scalar densityMin = minGasDensity_[
tempIdx];
 
  231        const Scalar densityMax = maxGasDensity_[
tempIdx];
 
  232        return (nDensity_ - 1) * (density - densityMin)/(densityMax - densityMin);
 
 
  239        if (!useVaporPressure)
 
  242            return max(pressMin_, vaporPressure_[
tempIdx] / 1.1);
 
 
  249        if (!useVaporPressure)
 
  252            return max(pressMax_, vaporPressure_[
tempIdx] * 1.1);
 
 
  259        if (!useVaporPressure)
 
  262            return min(pressMin_, vaporPressure_[
tempIdx] / 1.1 );
 
 
  269        if (!useVaporPressure)
 
  272            return min(pressMax_, vaporPressure_[
tempIdx] * 1.1);
 
 
  277    { 
return minLiquidDensity_[
tempIdx]; }
 
 
  281    { 
return maxLiquidDensity_[
tempIdx]; }
 
 
  285    { 
return minGasDensity_[
tempIdx]; }
 
 
  289    { 
return maxGasDensity_[
tempIdx]; }
 
 
  291    inline std::size_t 
nTemp()
 const { 
return nTemp_; }
 
  292    inline std::size_t 
nPress()
 const { 
return nPress_; }
 
  293    inline std::size_t 
nDensity()
 const { 
return nDensity_; }
 
  295    inline Scalar 
tempMax()
 const { 
return tempMax_; }
 
  296    inline Scalar 
tempMin()
 const { 
return tempMin_; }
 
  301    template< 
bool useVP = useVaporPressure, std::enable_if_t<useVP, 
int> = 0 >
 
  302    void tabularizeVaporPressure_()
 
  307            Scalar temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
 
  308            vaporPressure_[iT] = RawComponent::vaporPressure(temperature);
 
  313    template< 
bool useVP = useVaporPressure, std::enable_if_t<!useVP, 
int> = 0 >
 
  314    void tabularizeVaporPressure_() {}
 
  330    template<
class PropFunc, 
class Policy>
 
  331    void tabularizeTPArray_(
const PropFunc& f, Policy policy, std::vector<typename RawComponent::Scalar>& values)
 const 
  335            Scalar temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
 
  337            Scalar pMax = policy.maxP(iT);
 
  338            Scalar pMin = policy.minP(iT);
 
  339            for (std::size_t iP = 0; iP < nPress_; ++ iP)
 
  341                Scalar pressure = iP * (pMax - pMin)/(nPress_ - 1) + pMin;
 
  342                values[iT + iP*nTemp_] = f(temperature, pressure);
 
  362    template<
class RhoFunc, 
class Policy>
 
  363    void tabularizeMinMaxRhoArray_(
const RhoFunc& rho, Policy policy,
 
  364                                   std::vector<typename RawComponent::Scalar>& rhoMin,
 
  365                                   std::vector<typename RawComponent::Scalar>& rhoMax)
 const 
  369            Scalar 
temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
 
  372            rhoMin[iT] = rho(temperature, policy.minP(iT));
 
  373            rhoMax[iT] = rho(temperature, policy.maxP(min(iT + 1, nTemp_ - 1)));
 
  387    template<
class PFunc>
 
  388    void tabularizePressureArray_(std::vector<typename RawComponent::Scalar>& pressure,
 
  390                                  const std::vector<typename RawComponent::Scalar>& rhoMin,
 
  391                                  const std::vector<typename RawComponent::Scalar>& rhoMax)
 const 
  395            Scalar 
temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
 
  397            for (std::size_t iRho = 0; iRho < nDensity_; ++ iRho)
 
  399                Scalar 
density = Scalar(iRho)/(nDensity_ - 1)
 
  400                                 * (rhoMax[iT] - rhoMin[iT])
 
  402                pressure[iT + iRho*nTemp_] = p(temperature, density);
 
  407    template<
class RC = RawComponent>
 
  408    bool tabularizeGasEnthalpy_()
 
  412            const auto gasEnth = [] (
auto T, 
auto p) { 
return RC::gasEnthalpy(T, p); };
 
  413            tabularizeTPArray_(gasEnth, GasPolicy{ *
this }, gasEnthalpy_);
 
  420    template<
class RC = RawComponent>
 
  421    bool tabularizeLiquidEnthalpy_()
 
  425            const auto liqEnth = [] (
auto T, 
auto p) { 
return RC::liquidEnthalpy(T, p); };
 
  426            tabularizeTPArray_(liqEnth, LiquidPolicy{ *
this }, liquidEnthalpy_);
 
  433    template<
class RC = RawComponent>
 
  434    bool tabularizeGasHeatCapacity_()
 
  438            const auto gasHC = [] (
auto T, 
auto p) { 
return RC::gasHeatCapacity(T, p); };
 
  439            tabularizeTPArray_(gasHC, GasPolicy{ *
this }, gasHeatCapacity_);
 
  446    template<
class RC = RawComponent>
 
  447    bool tabularizeLiquidHeatCapacity_()
 
  451            const auto liqHC = [] (
auto T, 
auto p) { 
return RC::liquidHeatCapacity(T, p); };
 
  452            tabularizeTPArray_(liqHC, LiquidPolicy{ *
this }, liquidHeatCapacity_);
 
  459    template<
class RC = RawComponent>
 
  460    bool tabularizeMinMaxGasDensity_()
 
  464            const auto gasRho = [] (
auto T, 
auto p) { 
return RC::gasDensity(T, p); };
 
  465            tabularizeMinMaxRhoArray_(gasRho, GasPolicy{ *
this }, minGasDensity_, maxGasDensity_);
 
  472    template<
class RC = RawComponent>
 
  473    bool tabularizeMinMaxLiquidDensity_()
 
  477            const auto liqRho = [] (
auto T, 
auto p) { 
return RC::liquidDensity(T, p); };
 
  478            tabularizeMinMaxRhoArray_(liqRho, LiquidPolicy{ *
this }, minLiquidDensity_, maxLiquidDensity_);
 
  485    template<
class RC = RawComponent>
 
  486    bool tabularizeGasPressure_()
 
  491            const auto gasPFunc = [] (
auto T, 
auto rho) { 
return RC::gasPressure(T, rho); };
 
  492            tabularizePressureArray_(gasPressure_, gasPFunc, minGasDensity_, maxGasDensity_);
 
  499    template<
class RC = RawComponent>
 
  500    bool tabularizeLiquidPressure_()
 
  505            const auto liqPFunc = [] (
auto T, 
auto rho) { 
return RC::liquidPressure(T, rho); };
 
  506            tabularizePressureArray_(liquidPressure_, liqPFunc, minLiquidDensity_, maxLiquidDensity_);
 
  513    template<
class RC = RawComponent>
 
  514    bool tabularizeGasDensity_()
 
  518            const auto gasRho = [] (
auto T, 
auto p) { 
return RC::gasDensity(T, p); };
 
  519            tabularizeTPArray_(gasRho, GasPolicy{ *
this }, gasDensity_);
 
  526    template<
class RC = RawComponent>
 
  527    bool tabularizeLiquidDensity_()
 
  535            const auto liqRho = [] (
auto T, 
auto p) { 
return RC::liquidDensity(T, p); };
 
  536            tabularizeTPArray_(liqRho, LiquidPolicy{ *
this }, liquidDensity_);
 
  543    template<
class RC = RawComponent>
 
  544    bool tabularizeGasViscosity_()
 
  548            const auto gasVisc = [] (
auto T, 
auto p) { 
return RC::gasViscosity(T, p); };
 
  549            tabularizeTPArray_(gasVisc, GasPolicy{ *
this }, gasViscosity_);
 
  556    template<
class RC = RawComponent>
 
  557    bool tabularizeLiquidViscosity_()
 
  561            const auto liqVisc = [] (
auto T, 
auto p) { 
return RC::liquidViscosity(T, p); };
 
  562            tabularizeTPArray_(liqVisc, LiquidPolicy{ *
this }, liquidViscosity_);
 
  569    template<
class RC = RawComponent>
 
  570    bool tabularizeGasThermalConductivity_()
 
  574            const auto gasTC = [] (
auto T, 
auto p) { 
return RC::gasThermalConductivity(T, p); };
 
  575            tabularizeTPArray_(gasTC, GasPolicy{ *
this }, gasThermalConductivity_);
 
  582    template<
class RC = RawComponent>
 
  583    bool tabularizeLiquidThermalConductivity_()
 
  587            const auto liqTC = [] (
auto T, 
auto p) { 
return RC::liquidThermalConductivity(T, p); };
 
  588            tabularizeTPArray_(liqTC, LiquidPolicy{ *
this }, liquidThermalConductivity_);
 
  597    std::vector<Scalar> vaporPressure_;
 
  599    std::vector<Scalar> minLiquidDensity_;
 
  600    std::vector<Scalar> maxLiquidDensity_;
 
  601    bool minMaxLiquidDensityInitialized_;
 
  603    std::vector<Scalar> minGasDensity_;
 
  604    std::vector<Scalar> maxGasDensity_;
 
  605    bool minMaxGasDensityInitialized_;
 
  608    std::vector<Scalar> gasEnthalpy_;
 
  609    std::vector<Scalar> liquidEnthalpy_;
 
  610    bool gasEnthalpyInitialized_;
 
  611    bool liquidEnthalpyInitialized_;
 
  613    std::vector<Scalar> gasHeatCapacity_;
 
  614    std::vector<Scalar> liquidHeatCapacity_;
 
  615    bool gasHeatCapacityInitialized_;
 
  616    bool liquidHeatCapacityInitialized_;
 
  618    std::vector<Scalar> gasDensity_;
 
  619    std::vector<Scalar> liquidDensity_;
 
  620    bool gasDensityInitialized_;
 
  621    bool liquidDensityInitialized_;
 
  623    std::vector<Scalar> gasViscosity_;
 
  624    std::vector<Scalar> liquidViscosity_;
 
  625    bool gasViscosityInitialized_;
 
  626    bool liquidViscosityInitialized_;
 
  628    std::vector<Scalar> gasThermalConductivity_;
 
  629    std::vector<Scalar> liquidThermalConductivity_;
 
  630    bool gasThermalConductivityInitialized_;
 
  631    bool liquidThermalConductivityInitialized_;
 
  634    std::vector<Scalar> gasPressure_;
 
  635    std::vector<Scalar> liquidPressure_;
 
  636    bool gasPressureInitialized_;
 
  637    bool liquidPressureInitialized_;
 
  650    std::size_t nDensity_;
 
 
  670template <
class RawComponent, 
bool useVaporPressure=true>
 
  676    struct InterpolatePolicy
 
  678        using Scalar = 
typename RawComponent::Scalar;
 
  682        Scalar tempIdx(
Scalar T)
 const { 
return table.tempIdx(T); }
 
  683        Scalar tempMin()
 const { 
return table.tempMin(); }
 
  684        Scalar tempMax()
 const { 
return table.tempMax(); }
 
  685        std::size_t nTemp()
 const { 
return table.nTemp(); }
 
  686        std::size_t nPress()
 const { 
return table.nPress(); }
 
  687        std::size_t nDensity()
 const { 
return table.nDensity(); }
 
  690    struct InterpolateGasPolicy : 
public InterpolatePolicy
 
  692        using Scalar = 
typename RawComponent::Scalar;
 
  693        Scalar pressIdx(
Scalar p, std::size_t tempIdx)
 const { 
return this->table.pressGasIdx(p, tempIdx); }
 
  694        Scalar rhoIdx(
Scalar rho, std::size_t tempIdx)
 const { 
return this->table.densityGasIdx(rho, tempIdx); }
 
  695        Scalar minP(
int tempIdx)
 const { 
return this->table.minGasPressure(tempIdx); }
 
  696        Scalar maxP(
int tempIdx)
 const { 
return this->table.maxGasPressure(tempIdx); }
 
  697        Scalar minRho(
int tempIdx)
 const { 
return this->table.minGasDensity(tempIdx); }
 
  698        Scalar maxRho(
int tempIdx)
 const { 
return this->table.maxGasDensity(tempIdx); }
 
  701    struct InterpolateLiquidPolicy : 
public InterpolatePolicy
 
  703        using Scalar = 
typename RawComponent::Scalar;
 
  704        Scalar pressIdx(
Scalar p, std::size_t tempIdx)
 const { 
return this->table.pressLiquidIdx(p, tempIdx); }
 
  705        Scalar rhoIdx(
Scalar rho, std::size_t tempIdx)
 const { 
return this->table.densityLiquidIdx(rho, tempIdx); }
 
  706        Scalar minP(
int tempIdx)
 const { 
return this->table.minLiquidPressure(tempIdx); }
 
  707        Scalar maxP(
int tempIdx)
 const { 
return this->table.maxLiquidPressure(tempIdx); }
 
  708        Scalar minRho(
int tempIdx)
 const { 
return this->table.minLiquidDensity(tempIdx); }
 
  709        Scalar maxRho(
int tempIdx)
 const { 
return this->table.maxLiquidDensity(tempIdx); }
 
  713    using Scalar = 
typename RawComponent::Scalar;
 
  732        warningPrinted_ = 
false;
 
  734        std::cout << 
"-------------------------------------------------------------------------\n" 
  735                  << 
"Initializing tables for the " << RawComponent::name()
 
  736                  << 
" fluid properties (" << nTemp*nPress  << 
" entries).\n" 
  737                  << 
"Temperature -> min: " << std::scientific << std::setprecision(3)
 
  738                  << tempMin << 
", max: "  << tempMax << 
", n: " << nTemp << 
'\n' 
  739                  << 
"Pressure    -> min: " << std::scientific << std::setprecision(3)
 
  740                  << pressMin << 
", max: " << pressMax << 
", n: " << nPress << 
'\n' 
  741                  << 
"-------------------------------------------------------------------------" << std::endl;
 
  743        table().init(tempMin, tempMax, nTemp, pressMin, pressMax, nPress);
 
 
  752    { 
return RawComponent::name(); }
 
 
  758    { 
return RawComponent::molarMass(); }
 
 
  764    { 
return RawComponent::criticalTemperature(); }
 
 
  770    { 
return RawComponent::criticalPressure(); }
 
 
  776    { 
return RawComponent::tripleTemperature(); }
 
 
  782    { 
return RawComponent::triplePressure(); }
 
 
  793        Scalar result = interpolateT_(table().vaporPressure_, T, InterpolatePolicy{{ table() }});
 
  795            return RawComponent::vaporPressure(T);
 
 
  808        return RawComponent::vaporTemperature(pressure);
 
 
  819        Scalar result = interpolateTP_(table().gasEnthalpy_, temperature, pressure, InterpolateGasPolicy{{ table() }});
 
  823            printWarningTP_(
"gasEnthalpy", temperature, pressure, InterpolateGasPolicy{{ table() }});
 
  824            return RawComponent::gasEnthalpy(temperature, pressure);
 
 
  837        Scalar result = interpolateTP_(table().liquidEnthalpy_, temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
  841            printWarningTP_(
"liquidEnthalpy", temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
  842            return RawComponent::liquidEnthalpy(temperature, pressure);
 
 
  855        Scalar result = interpolateTP_(table().gasHeatCapacity_, temperature, pressure, InterpolateGasPolicy{{ table() }});
 
  859            printWarningTP_(
"gasHeatCapacity", temperature, pressure, InterpolateGasPolicy{{ table() }});
 
  860            return RawComponent::gasHeatCapacity(temperature, pressure);
 
 
  873        Scalar result = interpolateTP_(table().liquidHeatCapacity_, temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
  877            printWarningTP_(
"liquidHeatCapacity", temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
  878            return RawComponent::liquidHeatCapacity(temperature, pressure);
 
 
  913        Scalar result = interpolateTRho_(table().gasPressure_, temperature, density, InterpolateGasPolicy{{ table() }});
 
  917            printWarningTRho_(
"gasPressure", temperature, density, InterpolateGasPolicy{{ table() }});
 
  918            return RawComponent::gasPressure(temperature, density);
 
 
  931        Scalar result = interpolateTRho_(table().liquidPressure_, temperature, density, InterpolateLiquidPolicy{{ table() }});
 
  935            printWarningTRho_(
"liquidPressure", temperature, density, InterpolateLiquidPolicy{{ table() }});
 
  936            return RawComponent::liquidPressure(temperature, density);
 
 
  945    { 
return RawComponent::gasIsCompressible(); }
 
 
  951    { 
return RawComponent::liquidIsCompressible(); }
 
 
  957    { 
return RawComponent::gasIsIdeal(); }
 
 
  969        Scalar result = interpolateTP_(table().gasDensity_, temperature, pressure, InterpolateGasPolicy{{ table() }});
 
  973            printWarningTP_(
"gasDensity", temperature, pressure, InterpolateGasPolicy{{ table() }});
 
  974            return RawComponent::gasDensity(temperature, pressure);
 
 
  999        Scalar result = interpolateTP_(table().liquidDensity_, temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
 1003            printWarningTP_(
"liquidDensity", temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
 1004            return RawComponent::liquidDensity(temperature, pressure);
 
 
 1029        Scalar result = interpolateTP_(table().gasViscosity_, temperature, pressure, InterpolateGasPolicy{{ table() }});
 
 1033            printWarningTP_(
"gasViscosity", temperature, pressure, InterpolateGasPolicy{{ table() }});
 
 1034            return RawComponent::gasViscosity(temperature, pressure);
 
 
 1047        Scalar result = interpolateTP_(table().liquidViscosity_, temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
 1051            printWarningTP_(
"liquidViscosity",temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
 1052            return RawComponent::liquidViscosity(temperature, pressure);
 
 
 1065        Scalar result = interpolateTP_(table().gasThermalConductivity_, temperature, pressure, InterpolateGasPolicy{{ table() }});
 
 1069            printWarningTP_(
"gasThermalConductivity", temperature, pressure, InterpolateGasPolicy{{ table() }});
 
 1070            return RawComponent::gasThermalConductivity(temperature, pressure);
 
 
 1083        Scalar result = interpolateTP_(table().liquidThermalConductivity_, temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
 1087            printWarningTP_(
"liquidThermalConductivity", temperature, pressure, InterpolateLiquidPolicy{{ table() }});
 
 1088            return RawComponent::liquidThermalConductivity(temperature, pressure);
 
 
 1096    template<
class Policy>
 
 1097    static void printWarningTP_(
const std::string& quantity, 
Scalar T, 
Scalar p, Policy policy)
 
 1104            std::cerr << 
"Warning: tabulated component '" << 
name()
 
 1105                      << 
"' has not been initialized. " 
 1106                      << 
"Call FluidSystem::init() to use the tabulation in order to reduce runtime. \n";
 
 1108            std::cerr << 
"Warning: "<<quantity<<
"(T="<<T<<
", p="<<p<<
") of component '"<<
name()
 
 1109                      << 
"' is outside tabulation range: ("<< policy.tempMin() <<
"<=T<="<< policy.tempMax() <<
"), (" 
 1110                      << policy.minP(0) <<
"<=p<=" << policy.maxP(policy.nTemp()-1) <<
"). " 
 1111                      << 
"Forwarded to FluidSystem for direct evaluation of "<<quantity<<
". \n";
 
 1117    template<
class Policy>
 
 1118    static void printWarningTRho_(
const std::string& quantity, 
Scalar T, 
Scalar rho, Policy policy)
 
 1125            std::cerr << 
"Warning: tabulated component '" << 
name()
 
 1126                      << 
"' has not been initialized. " 
 1127                      << 
"Call FluidSystem::init() to use the tabulation in order to reduce runtime. \n";
 
 1130            const auto [densityMin, densityMax] = [&]
 
 1132                const Scalar alphaT = policy.tempIdx(T);
 
 1134                const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, policy.nTemp() - 2);
 
 1135                return std::make_pair( policy.minRho(iT), policy.maxRho(iT) );
 
 1138            std::cerr << 
"Warning: "<<quantity<<
"(T="<<T<<
", density="<<rho<<
") of component '"<<
name()
 
 1139                      << 
"' is outside tabulation range: ("<< policy.tempMin() <<
"<=T<="<< policy.tempMax() <<
"), (" 
 1140                      << densityMin <<
"<=density<=" << densityMax <<
"). " 
 1141                      << 
"Forwarded to FluidSystem for direct evaluation of "<<quantity<<
". \n";
 
 1143        warningPrinted_ = 
true;
 
 1148    template<
class Policy>
 
 1149    static Scalar interpolateT_(
const std::vector<Scalar>& values, 
Scalar T, Policy policy)
 
 1151        Scalar alphaT = policy.tempIdx(T);
 
 1152        const auto nTemp = policy.nTemp();
 
 1153        if (alphaT < 0 - 1e-7*nTemp || alphaT >= nTemp - 1 + 1e-7*nTemp)
 
 1154            return std::numeric_limits<Scalar>::quiet_NaN();
 
 1157        const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, nTemp - 2);
 
 1160        return values[iT    ]*(1 - alphaT) +
 
 1161               values[iT + 1]*(    alphaT);
 
 1165    template<
class Policy>
 
 1166    static Scalar interpolateTP_(
const std::vector<Scalar>& values, 
const Scalar T, 
const Scalar p, Policy policy)
 
 1168        const auto nTemp = policy.nTemp();
 
 1169        const auto nPress = policy.nPress();
 
 1171        Scalar alphaT = policy.tempIdx(T);
 
 1172        if (alphaT < 0 - 1e-7*nTemp || alphaT >= nTemp - 1 + 1e-7*nTemp)
 
 1173            return std::numeric_limits<Scalar>::quiet_NaN();
 
 1176        const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, nTemp - 2);
 
 1179        Scalar alphaP1 = policy.pressIdx(p, iT);
 
 1180        Scalar alphaP2 = policy.pressIdx(p, iT + 1);
 
 1182        const auto iP1 = clamp<int>(
static_cast<int>(alphaP1), 0, nPress - 2);
 
 1183        const auto iP2 = clamp<int>(
static_cast<int>(alphaP2), 0, nPress - 2);
 
 1187#if 0 && !defined NDEBUG 
 1188        const auto tempMin = policy.tempMin();
 
 1189        const auto tempMin = policy.tempMax();
 
 1190        if(!(0 <= alphaT && alphaT <= 1.0))
 
 1191            DUNE_THROW(NumericalProblem, 
"Temperature out of range: " 
 1192                       << 
"T=" << T << 
" range: [" << tempMin_ << 
", " << tempMax_ << 
"]");
 
 1193        if(!(0 <= alphaP1 && alphaP1 <= 1.0))
 
 1194            DUNE_THROW(NumericalProblem, 
"First pressure out of range: " 
 1195                       << 
"p=" << p << 
" range: [" << policy.minP(policy.tempIdx(T)) << 
", " << policy.maxP(policy.tempIdx(T)) << 
"]");
 
 1196        if(!(0 <= alphaP2 && alphaP2 <= 1.0))
 
 1197            DUNE_THROW(NumericalProblem, 
"Second pressure out of range: " 
 1198                       << 
"p=" << p << 
" range: [" << policy.minP(policy.tempIdx(T) + 1) << 
", " << policy.maxP(policy.tempIdx(T) + 1) << 
"]");
 
 1200        return values[(iT    ) + (iP1    )*nTemp]*(1 - alphaT)*(1 - alphaP1) +
 
 1201               values[(iT    ) + (iP1 + 1)*nTemp]*(1 - alphaT)*(    alphaP1) +
 
 1202               values[(iT + 1) + (iP2    )*nTemp]*(    alphaT)*(1 - alphaP2) +
 
 1203               values[(iT + 1) + (iP2 + 1)*nTemp]*(    alphaT)*(    alphaP2);
 
 1207    template<
class Policy>
 
 1208    static Scalar interpolateTRho_(
const std::vector<Scalar>& values, 
const Scalar T, 
const Scalar rho, Policy policy)
 
 1210        const auto nTemp = policy.nTemp();
 
 1211        const auto nDensity = policy.nDensity();
 
 1214        Scalar alphaT = policy.tempIdx(T);
 
 1215        if (alphaT < 0 - 1e-7*nTemp || alphaT >= nTemp - 1 + 1e-7*nTemp)
 
 1216            return std::numeric_limits<Scalar>::quiet_NaN();
 
 1218        const auto iT = clamp<int>(
static_cast<int>(alphaT), 0, nTemp - 2);
 
 1221        Scalar alphaP1 = policy.rhoIdx(rho, iT);
 
 1222        Scalar alphaP2 = policy.rhoIdx(rho, iT + 1);
 
 1223        const auto iP1 = clamp<int>(
static_cast<int>(alphaP1), 0, nDensity - 2);
 
 1224        const auto iP2 = clamp<int>(
static_cast<int>(alphaP2), 0, nDensity - 2);
 
 1228        return values[(iT    ) + (iP1    )*nTemp]*(1 - alphaT)*(1 - alphaP1) +
 
 1229               values[(iT    ) + (iP1 + 1)*nTemp]*(1 - alphaT)*(    alphaP1) +
 
 1230               values[(iT + 1) + (iP2    )*nTemp]*(    alphaT)*(1 - alphaP2) +
 
 1231               values[(iT + 1) + (iP2 + 1)*nTemp]*(    alphaT)*(    alphaP2);
 
 1235    static bool initialized_;
 
 1239    static bool warningPrinted_;
 
 1242    static Table& table()
 
 
 1249template <
class RawComponent, 
bool useVaporPressure>
 
 1250bool TabulatedComponent<RawComponent, useVaporPressure>::initialized_ = 
false;
 
 1253template <
class RawComponent, 
bool useVaporPressure>
 
 1254bool TabulatedComponent<RawComponent, useVaporPressure>::warningPrinted_ = 
false;
 
 1258template <
class Component>
 
 1262template <
class RawComponent, 
bool useVaporPressure>
 
Definition tabulatedcomponent.hh:112
std::size_t nPress() const
Definition tabulatedcomponent.hh:292
Scalar tempIdx(Scalar temperature) const
returns the index of an entry in a temperature field
Definition tabulatedcomponent.hh:198
Scalar densityLiquidIdx(Scalar density, std::size_t tempIdx) const
returns the index of an entry in a density field
Definition tabulatedcomponent.hh:220
void init(Scalar tempMin, Scalar tempMax, std::size_t nTemp, Scalar pressMin, Scalar pressMax, std::size_t nPress)
Definition tabulatedcomponent.hh:130
Scalar pressGasIdx(Scalar pressure, std::size_t tempIdx) const
returns the index of an entry in a temperature field
Definition tabulatedcomponent.hh:212
Scalar minLiquidPressure(int tempIdx) const
returns the minimum tabularized liquid pressure at a given temperature index
Definition tabulatedcomponent.hh:236
Scalar densityGasIdx(Scalar density, std::size_t tempIdx) const
returns the index of an entry in a density field
Definition tabulatedcomponent.hh:228
Scalar maxGasPressure(int tempIdx) const
returns the maximum tabularized gas pressure at a given temperature index
Definition tabulatedcomponent.hh:266
Scalar minGasDensity(int tempIdx) const
returns the minimum tabularized gas density at a given temperature index
Definition tabulatedcomponent.hh:284
Scalar maxLiquidDensity(int tempIdx) const
returns the maximum tabularized liquid density at a given temperature index
Definition tabulatedcomponent.hh:280
Scalar maxGasDensity(int tempIdx) const
returns the maximum tabularized gas density at a given temperature index
Definition tabulatedcomponent.hh:288
Scalar tempMin() const
Definition tabulatedcomponent.hh:296
Scalar maxLiquidPressure(int tempIdx) const
returns the maximum tabularized liquid pressure at a given temperature index
Definition tabulatedcomponent.hh:246
Scalar pressLiquidIdx(Scalar pressure, std::size_t tempIdx) const
returns the index of an entry in a pressure field
Definition tabulatedcomponent.hh:204
Scalar tempMax() const
Definition tabulatedcomponent.hh:295
std::size_t nDensity() const
Definition tabulatedcomponent.hh:293
Scalar minLiquidDensity(int tempIdx) const
returns the minimum tabularized liquid density at a given temperature index
Definition tabulatedcomponent.hh:276
std::size_t nTemp() const
Definition tabulatedcomponent.hh:291
Scalar minGasPressure(int tempIdx) const
returns the minimum tabularized gas pressure at a given temperature index
Definition tabulatedcomponent.hh:256
Tabulates all thermodynamic properties of a given component.
Definition tabulatedcomponent.hh:672
static const Scalar gasEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of the gas .
Definition tabulatedcomponent.hh:817
static Scalar gasPressure(Scalar temperature, Scalar density)
The pressure of gas in  at a given density and temperature.
Definition tabulatedcomponent.hh:911
static Scalar criticalTemperature()
Returns the critical temperature in  of the component.
Definition tabulatedcomponent.hh:763
static Scalar liquidPressure(Scalar temperature, Scalar density)
The pressure of liquid in  at a given density and temperature.
Definition tabulatedcomponent.hh:929
static const Scalar gasHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of the gas .
Definition tabulatedcomponent.hh:853
static std::string name()
A human readable name for the component.
Definition tabulatedcomponent.hh:751
static Scalar vaporTemperature(Scalar pressure)
The vapor pressure in  of the component at a given temperature.
Definition tabulatedcomponent.hh:806
static Scalar liquidThermalConductivity(Scalar temperature, Scalar pressure)
The thermal conductivity of liquid water .
Definition tabulatedcomponent.hh:1081
static Scalar gasDensity(Scalar temperature, Scalar pressure)
The density of gas at a given pressure and temperature .
Definition tabulatedcomponent.hh:967
static const Scalar liquidEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of the liquid .
Definition tabulatedcomponent.hh:835
static Scalar triplePressure()
Returns the pressure in  at the component's triple point.
Definition tabulatedcomponent.hh:781
static Scalar criticalPressure()
Returns the critical pressure in  of the component.
Definition tabulatedcomponent.hh:769
static const Scalar gasInternalEnergy(Scalar temperature, Scalar pressure)
Specific internal energy of the gas .
Definition tabulatedcomponent.hh:889
static Scalar liquidMolarDensity(Scalar temperature, Scalar pressure)
The molar density of liquid in  at a given pressure and temperature.
Definition tabulatedcomponent.hh:1018
static constexpr Scalar molarMass()
The molar mass in  of the component.
Definition tabulatedcomponent.hh:757
static Scalar liquidViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity  of liquid.
Definition tabulatedcomponent.hh:1045
static Scalar gasViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity  of gas.
Definition tabulatedcomponent.hh:1027
static Scalar tripleTemperature()
Returns the temperature in  at the component's triple point.
Definition tabulatedcomponent.hh:775
static constexpr bool liquidIsCompressible()
Returns true if the liquid phase is assumed to be compressible.
Definition tabulatedcomponent.hh:950
static Scalar liquidDensity(Scalar temperature, Scalar pressure)
The density of liquid at a given pressure and temperature .
Definition tabulatedcomponent.hh:997
static Scalar gasThermalConductivity(Scalar temperature, Scalar pressure)
The thermal conductivity of gaseous water .
Definition tabulatedcomponent.hh:1063
static Scalar gasMolarDensity(Scalar temperature, Scalar pressure)
The molar density of gas in  at a given pressure and temperature.
Definition tabulatedcomponent.hh:987
static constexpr bool isTabulated
Definition tabulatedcomponent.hh:716
static const Scalar liquidInternalEnergy(Scalar temperature, Scalar pressure)
Specific internal energy of the liquid .
Definition tabulatedcomponent.hh:900
static Scalar vaporPressure(Scalar T)
The vapor pressure in  of the component at a given temperature.
Definition tabulatedcomponent.hh:790
static constexpr bool gasIsCompressible()
Returns true if the gas phase is assumed to be compressible.
Definition tabulatedcomponent.hh:944
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:728
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition tabulatedcomponent.hh:956
static const Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of the liquid .
Definition tabulatedcomponent.hh:871
typename RawComponent::Scalar Scalar
export scalar type
Definition tabulatedcomponent.hh:713
Component traits, i.e. information extracted from components.
Some exceptions thrown in DuMux
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition parallel_for.hh:160
Definition tabulatedcomponent.hh:60
decltype(C::gasPressure(0.0, 0.0)) CompHasGasPressure
Definition tabulatedcomponent.hh:82
decltype(C::template liquidViscosity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidViscosity
Definition tabulatedcomponent.hh:74
decltype(C::liquidPressure(0.0, 0.0)) CompHasLiquidPressure
Definition tabulatedcomponent.hh:75
constexpr bool hasGasEnthalpy()
Definition tabulatedcomponent.hh:97
constexpr bool hasGasHeatCapacity()
Definition tabulatedcomponent.hh:103
constexpr bool hasLiquidThermalConductivity()
Definition tabulatedcomponent.hh:88
constexpr bool hasGasViscosity()
Definition tabulatedcomponent.hh:105
constexpr bool hasLiquidPressure()
Definition tabulatedcomponent.hh:94
constexpr bool hasLiquidEnthalpy()
Definition tabulatedcomponent.hh:84
decltype(C::template liquidDensity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidDensity
Definition tabulatedcomponent.hh:71
constexpr bool hasGasDensity()
Definition tabulatedcomponent.hh:99
decltype(C::template gasDensity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasDensity
Definition tabulatedcomponent.hh:78
decltype(C::template liquidThermalConductivity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidThermalCond
Definition tabulatedcomponent.hh:72
constexpr bool hasGasThermalConductivity()
Definition tabulatedcomponent.hh:101
constexpr bool hasLiquidViscosity()
Definition tabulatedcomponent.hh:92
constexpr bool hasGasPressure()
Definition tabulatedcomponent.hh:107
decltype(C::template liquidHeatCapacity< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidHeatCapacity
Definition tabulatedcomponent.hh:73
decltype(C::template liquidEnthalpy< DisableStaticAssert >(0.0, 0.0)) CompHasNoLiquidEnthalpy
Definition tabulatedcomponent.hh:70
decltype(C::template gasThermalConductivity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasThermalCond
Definition tabulatedcomponent.hh:79
constexpr bool hasLiquidHeatCapacity()
Definition tabulatedcomponent.hh:90
decltype(C::template gasEnthalpy< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasEnthalpy
Definition tabulatedcomponent.hh:77
decltype(C::template gasHeatCapacity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasHeatCapacity
Definition tabulatedcomponent.hh:80
constexpr bool hasLiquidDensity()
Definition tabulatedcomponent.hh:86
decltype(C::template gasViscosity< DisableStaticAssert >(0.0, 0.0)) CompHasNoGasViscosity
Definition tabulatedcomponent.hh:81
bool TabulatedComponent< RawComponent, useVaporPressure >::warningPrinted_
Definition tabulatedcomponent.hh:1254
bool TabulatedComponent< RawComponent, useVaporPressure >::initialized_
Definition tabulatedcomponent.hh:1250
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition name.hh:39
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition name.hh:22
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition name.hh:53
bool ShomateMethod< Scalar, intervals >::warningPrinted_
Definition shomate.hh:143
Parallel for loop (multithreading)
Template which always yields a false value.
Definition common/typetraits/typetraits.hh:24
typename RawComponent::Scalar Scalar
Definition tabulatedcomponent.hh:47
static constexpr bool hasGasState
if the component implements a gaseous state
Definition tabulatedcomponent.hh:56
static constexpr bool hasLiquidState
if the component implements a liquid state
Definition tabulatedcomponent.hh:53
static constexpr bool hasSolidState
if the component implements a solid state
Definition tabulatedcomponent.hh:50
Component traits, i.e. information extracted from components.
Definition componenttraits.hh:31
static constexpr bool hasLiquidState
if the component implements a liquid state
Definition componenttraits.hh:38
static constexpr bool hasGasState
if the component implements a gaseous state
Definition componenttraits.hh:41
Definition tabulatedcomponent.hh:61
IsAqueous struct.
Definition components/base.hh:34