diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp index 2ce0eb0fb37..f515429bd3a 100644 --- a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp +++ b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp @@ -32,9 +32,9 @@ namespace Opm { -template -BrineCo2Pvt:: -BrineCo2Pvt(const std::vector& salinity, +template +BrineCo2Pvt:: +BrineCo2Pvt(const ContainerT& salinity, int activityModel, int thermalMixingModelSalt, int thermalMixingModelLiquid, @@ -60,8 +60,8 @@ BrineCo2Pvt(const std::vector& salinity, } #if HAVE_ECL_INPUT -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: initFromState(const EclipseState& eclState, const Schedule&) { bool co2sol = eclState.runspec().co2Sol(); @@ -150,8 +150,8 @@ initFromState(const EclipseState& eclState, const Schedule&) } #endif -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: setNumRegions(std::size_t numRegions) { brineReferenceDensity_.resize(numRegions); @@ -159,8 +159,8 @@ setNumRegions(std::size_t numRegions) salinity_.resize(numRegions); } -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: setReferenceDensities(unsigned regionIdx, Scalar rhoRefBrine, Scalar rhoRefCO2, @@ -170,8 +170,8 @@ setReferenceDensities(unsigned regionIdx, co2ReferenceDensity_[regionIdx] = rhoRefCO2; } -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: setActivityModelSalt(int activityModel) { switch (activityModel) { @@ -182,8 +182,8 @@ setActivityModelSalt(int activityModel) } } -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: setThermalMixingModel(int thermalMixingModelSalt, int thermalMixingModelLiquid) { switch (thermalMixingModelSalt) { @@ -200,8 +200,8 @@ setThermalMixingModel(int thermalMixingModelSalt, int thermalMixingModelLiquid) } } -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: setEzrokhiDenCoeff(const std::vector& denaqa) { if (denaqa.empty()) @@ -216,8 +216,8 @@ setEzrokhiDenCoeff(const std::vector& denaqa) static_cast(denaqa[0].getC2("CO2"))}; } -template -void BrineCo2Pvt:: +template +void BrineCo2Pvt:: setEzrokhiViscCoeff(const std::vector& viscaqa) { if (viscaqa.empty()) diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp index fdb18bb06d7..04f74844020 100644 --- a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -58,7 +59,7 @@ class EzrokhiTable; * \brief This class represents the Pressure-Volume-Temperature relations of the liquid phase * for a CO2-Brine system */ -template >> +template >, class ContainerT = std::vector> class BrineCo2Pvt { static constexpr bool extrapolate = true; @@ -74,20 +75,37 @@ class BrineCo2Pvt public: using H2O = SimpleHuDuanH2O; using Brine = ::Opm::BrineDynamic; - using CO2 = ::Opm::CO2; + using CO2 = ::Opm::CO2; //! The binary coefficients for brine and CO2 used by this fluid system using BinaryCoeffBrineCO2 = BinaryCoeff::Brine_CO2; explicit BrineCo2Pvt() = default; - explicit BrineCo2Pvt(const std::vector& salinity, + explicit BrineCo2Pvt(const ContainerT& salinity, int activityModel = 3, int thermalMixingModelSalt = 1, int thermalMixingModelLiquid = 2, Scalar T_ref = 288.71, //(273.15 + 15.56) Scalar P_ref = 101325); + explicit BrineCo2Pvt(ContainerT brineReferenceDensity, + ContainerT co2ReferenceDensity, + ContainerT salinity, + int activityModel, + Co2StoreConfig::SaltMixingType thermalMixingModelSalt, + Co2StoreConfig::LiquidMixingType thermalMixingModelLiquid, + Params params) : + brineReferenceDensity_(brineReferenceDensity), + co2ReferenceDensity_(co2ReferenceDensity), + salinity_(salinity), + activityModel_(activityModel), + liquidMixType_(thermalMixingModelLiquid), + saltMixType_(thermalMixingModelSalt), + co2Tables_(params) +{ +} + #if HAVE_ECL_INPUT /*! * \brief Initialize the parameters for Brine-CO2 system using an ECL deck. @@ -155,7 +173,7 @@ class BrineCo2Pvt unsigned numRegions() const { return brineReferenceDensity_.size(); } - Scalar hVap(unsigned ) const{ + OPM_HOST_DEVICE Scalar hVap(unsigned ) const{ return 0; } @@ -163,7 +181,7 @@ class BrineCo2Pvt * \brief Returns the specific enthalpy [J/kg] of gas given a set of parameters. */ template - Evaluation internalEnergy(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation internalEnergy(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& Rs, @@ -182,7 +200,7 @@ class BrineCo2Pvt * \brief Returns the specific enthalpy [J/kg] of gas given a set of parameters. */ template - Evaluation internalEnergy(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation internalEnergy(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& Rs) const @@ -200,7 +218,7 @@ class BrineCo2Pvt * \brief Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters. */ template - Evaluation viscosity(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation viscosity(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& /*Rs*/) const @@ -213,7 +231,7 @@ class BrineCo2Pvt * \brief Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters. */ template - Evaluation saturatedViscosity(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& saltConcentration) const @@ -234,7 +252,7 @@ class BrineCo2Pvt * \brief Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters. */ template - Evaluation viscosity(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation viscosity(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& /*Rsw*/, @@ -249,7 +267,7 @@ class BrineCo2Pvt * \brief Returns the dynamic viscosity [Pa s] of oil saturated gas at given pressure. */ template - Evaluation saturatedViscosity(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure) const { @@ -270,7 +288,7 @@ class BrineCo2Pvt * \brief Returns the formation volume factor [-] of the fluid phase. */ template - Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& saltconcentration) const @@ -287,7 +305,7 @@ class BrineCo2Pvt * \brief Returns the formation volume factor [-] of the fluid phase. */ template - Evaluation inverseFormationVolumeFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& Rs, @@ -304,7 +322,7 @@ class BrineCo2Pvt * \brief Returns the formation volume factor [-] of the fluid phase. */ template - Evaluation inverseFormationVolumeFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& Rs) const @@ -318,7 +336,7 @@ class BrineCo2Pvt * \brief Returns the formation volume factor [-] of brine saturated with CO2 at a given pressure. */ template - Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure) const { @@ -336,12 +354,16 @@ class BrineCo2Pvt * \param Rs */ template - Evaluation saturationPressure(unsigned /*regionIdx*/, + OPM_HOST_DEVICE Evaluation saturationPressure(unsigned /*regionIdx*/, const Evaluation& /*temperature*/, const Evaluation& /*Rs*/) const { +#if OPM_IS_INSIDE_DEVICE_FUNCTION + assert(false && "Requested the saturation pressure for the brine-co2 pvt module. Not yet implemented."); +#else throw std::runtime_error("Requested the saturation pressure for the brine-co2 pvt module. " "Not yet implemented."); +#endif } /*! @@ -351,20 +373,24 @@ class BrineCo2Pvt * \param Rs */ template - Evaluation saturationPressure(unsigned /*regionIdx*/, + OPM_HOST_DEVICE Evaluation saturationPressure(unsigned /*regionIdx*/, const Evaluation& /*temperature*/, const Evaluation& /*Rs*/, const Evaluation& /*saltConcentration*/) const { +#if OPM_IS_INSIDE_DEVICE_FUNCTION + assert(false && "Requested the saturation pressure for the brine-co2 pvt module. Not yet implemented."); +#else throw std::runtime_error("Requested the saturation pressure for the brine-co2 pvt module. " "Not yet implemented."); +#endif } /*! * \brief Returns the gas dissoluiton factor \f$R_s\f$ [m^3/m^3] of the liquid phase. */ template - Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& /*oilSaturation*/, @@ -378,7 +404,7 @@ class BrineCo2Pvt * \brief Returns the gas dissoluiton factor \f$R_s\f$ [m^3/m^3] of the liquid phase. */ template - Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& saltConcentration) const @@ -392,27 +418,48 @@ class BrineCo2Pvt * \brief Returns thegas dissoluiton factor \f$R_s\f$ [m^3/m^3] of the liquid phase. */ template - Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure) const { return rsSat(regionIdx, temperature, pressure, Evaluation(salinity_[regionIdx])); } - Scalar oilReferenceDensity(unsigned regionIdx) const + OPM_HOST_DEVICE Scalar oilReferenceDensity(unsigned regionIdx) const { return brineReferenceDensity_[regionIdx]; } - Scalar waterReferenceDensity(unsigned regionIdx) const + OPM_HOST_DEVICE Scalar waterReferenceDensity(unsigned regionIdx) const { return brineReferenceDensity_[regionIdx]; } - Scalar gasReferenceDensity(unsigned regionIdx) const + OPM_HOST_DEVICE Scalar gasReferenceDensity(unsigned regionIdx) const { return co2ReferenceDensity_[regionIdx]; } - Scalar salinity(unsigned regionIdx) const + OPM_HOST_DEVICE Scalar salinity(unsigned regionIdx) const { return salinity_[regionIdx]; } + OPM_HOST_DEVICE const ContainerT& getBrineReferenceDensity() const + { return brineReferenceDensity_; } + + OPM_HOST_DEVICE const ContainerT& getCo2ReferenceDensity() const + { return co2ReferenceDensity_; } + + OPM_HOST_DEVICE const ContainerT& getSalinity() const + { return salinity_; } + + OPM_HOST_DEVICE const Params& getParams() const + { return co2Tables_; } + + OPM_HOST_DEVICE Co2StoreConfig::SaltMixingType getThermalMixingModelSalt() const + { return saltMixType_; } + + OPM_HOST_DEVICE Co2StoreConfig::LiquidMixingType getThermalMixingModelLiquid() const + { return liquidMixType_; } + + OPM_HOST_DEVICE int getActivityModel() const + { return activityModel_; } + template - Evaluation diffusionCoefficient(const Evaluation& temperature, + OPM_HOST_DEVICE Evaluation diffusionCoefficient(const Evaluation& temperature, const Evaluation& pressure, unsigned /*compIdx*/) const { @@ -443,7 +490,7 @@ class BrineCo2Pvt } template - Evaluation density(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation density(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& Rs, @@ -461,7 +508,7 @@ class BrineCo2Pvt } template - Evaluation rsSat(unsigned regionIdx, + OPM_HOST_DEVICE Evaluation rsSat(unsigned regionIdx, const Evaluation& temperature, const Evaluation& pressure, const Evaluation& salinity) const @@ -493,15 +540,15 @@ class BrineCo2Pvt private: template - LhsEval ezrokhiExponent_(const LhsEval& temperature, - const std::vector& ezrokhiCoeff) const + OPM_HOST_DEVICE LhsEval ezrokhiExponent_(const LhsEval& temperature, + const ContainerT& ezrokhiCoeff) const { const LhsEval& tempC = temperature - 273.15; return ezrokhiCoeff[0] + tempC * (ezrokhiCoeff[1] + ezrokhiCoeff[2] * tempC); } template - LhsEval liquidDensity_(const LhsEval& T, + OPM_HOST_DEVICE LhsEval liquidDensity_(const LhsEval& T, const LhsEval& pl, const LhsEval& xlCO2, const LhsEval& salinity) const @@ -512,18 +559,26 @@ class BrineCo2Pvt Valgrind::CheckDefined(xlCO2); if (!extrapolate && T < 273.15) { +#if OPM_IS_INSIDE_DEVICE_FUNCTION + assert(false && "Liquid density for Brine and CO2 is only defined above 273.15K"); +#else const std::string msg = "Liquid density for Brine and CO2 is only " "defined above 273.15K (is " + std::to_string(getValue(T)) + "K)"; throw NumericalProblem(msg); +#endif } if (!extrapolate && pl >= 2.5e8) { +#if OPM_IS_INSIDE_DEVICE_FUNCTION + assert(false && "Liquid density for Brine and CO2 is only defined below 250MPa"); +#else const std::string msg = "Liquid density for Brine and CO2 is only " "defined below 250MPa (is " + std::to_string(getValue(pl)) + "Pa)"; throw NumericalProblem(msg); +#endif } const LhsEval& rho_pure = H2O::liquidDensity(T, pl, extrapolate); @@ -542,7 +597,7 @@ class BrineCo2Pvt } template - LhsEval liquidDensityWaterCO2_(const LhsEval& temperature, + OPM_HOST_DEVICE LhsEval liquidDensityWaterCO2_(const LhsEval& temperature, const LhsEval& pl, const LhsEval& xlCO2) const { @@ -570,7 +625,7 @@ class BrineCo2Pvt * of the gas component in the oil phase. */ template - LhsEval convertRsToXoG_(const LhsEval& Rs, unsigned regionIdx) const + OPM_HOST_DEVICE LhsEval convertRsToXoG_(const LhsEval& Rs, unsigned regionIdx) const { OPM_TIMEFUNCTION_LOCAL(); Scalar rho_oRef = brineReferenceDensity_[regionIdx]; @@ -584,7 +639,7 @@ class BrineCo2Pvt * \brief Convert a gas mass fraction in the oil phase the corresponding mole fraction. */ template - LhsEval convertXoGToxoG_(const LhsEval& XoG, const LhsEval& salinity) const + OPM_HOST_DEVICE LhsEval convertXoGToxoG_(const LhsEval& XoG, const LhsEval& salinity) const { OPM_TIMEFUNCTION_LOCAL(); Scalar M_CO2 = CO2::molarMass(); @@ -596,7 +651,7 @@ class BrineCo2Pvt * \brief Convert a gas mole fraction in the oil phase the corresponding mass fraction. */ template - LhsEval convertxoGToXoG(const LhsEval& xoG, const LhsEval& salinity) const + OPM_HOST_DEVICE LhsEval convertxoGToXoG(const LhsEval& xoG, const LhsEval& salinity) const { OPM_TIMEBLOCK_LOCAL(convertxoGToXoG); Scalar M_CO2 = CO2::molarMass(); @@ -610,7 +665,7 @@ class BrineCo2Pvt * corresponding gas dissolution factor. */ template - LhsEval convertXoGToRs(const LhsEval& XoG, unsigned regionIdx) const + OPM_HOST_DEVICE LhsEval convertXoGToRs(const LhsEval& XoG, unsigned regionIdx) const { Scalar rho_oRef = brineReferenceDensity_[regionIdx]; Scalar rho_gRef = co2ReferenceDensity_[regionIdx]; @@ -619,7 +674,7 @@ class BrineCo2Pvt } template - LhsEval liquidEnthalpyBrineCO2_(const LhsEval& T, + OPM_HOST_DEVICE LhsEval liquidEnthalpyBrineCO2_(const LhsEval& T, const LhsEval& p, const LhsEval& salinity, const LhsEval& X_CO2_w) const @@ -708,7 +763,7 @@ class BrineCo2Pvt } template - const LhsEval salinityFromConcentration(unsigned regionIdx, + OPM_HOST_DEVICE const LhsEval salinityFromConcentration(unsigned regionIdx, const LhsEval&T, const LhsEval& P, const LhsEval& saltConcentration) const @@ -720,12 +775,12 @@ class BrineCo2Pvt return salinity(regionIdx); } - std::vector brineReferenceDensity_{}; - std::vector co2ReferenceDensity_{}; - std::vector salinity_{}; - std::vector ezrokhiDenNaClCoeff_{}; - std::vector ezrokhiDenCo2Coeff_{}; - std::vector ezrokhiViscNaClCoeff_{}; + ContainerT brineReferenceDensity_{}; + ContainerT co2ReferenceDensity_{}; + ContainerT salinity_{}; + ContainerT ezrokhiDenNaClCoeff_{}; + ContainerT ezrokhiDenCo2Coeff_{}; + ContainerT ezrokhiViscNaClCoeff_{}; bool enableEzrokhiDensity_ = false; bool enableEzrokhiViscosity_ = false; bool enableDissolution_ = true; @@ -738,4 +793,44 @@ class BrineCo2Pvt } // namespace Opm +namespace Opm::gpuistl { + template + BrineCo2Pvt + move_to_gpu(BrineCo2Pvt cpuBrineCo2) { + return BrineCo2Pvt( + GPUContainer(cpuBrineCo2.getBrineReferenceDensity()), + GPUContainer(cpuBrineCo2.getCo2ReferenceDensity()), + GPUContainer(cpuBrineCo2.getSalinity()), + cpuBrineCo2.getActivityModel(), + cpuBrineCo2.getThermalMixingModelSalt(), + cpuBrineCo2.getThermalMixingModelLiquid(), + move_to_gpu, GPUContainer>(cpuBrineCo2.getParams()) + ); + } + + template + BrineCo2Pvt + make_view(const BrineCo2Pvt& brineCo2Pvt) { + + using containedType = typename ContainerType::value_type; + using viewedTypeNoConst = typename std::remove_const_t; + + static_assert(std::is_same_v); + + ViewType newBrineReferenceDensity = make_view(brineCo2Pvt.getBrineReferenceDensity()); + ViewType newGasReferenceDensity = make_view(brineCo2Pvt.getCo2ReferenceDensity()); + ViewType newSalinity = make_view(brineCo2Pvt.getSalinity()); + + return BrineCo2Pvt( + newBrineReferenceDensity, + newGasReferenceDensity, + newSalinity, + brineCo2Pvt.getActivityModel(), + brineCo2Pvt.getThermalMixingModelSalt(), + brineCo2Pvt.getThermalMixingModelLiquid(), + make_view(brineCo2Pvt.getParams()) + ); + } +} + #endif diff --git a/opm/material/fluidsystems/blackoilpvt/Co2GasPvt.hpp b/opm/material/fluidsystems/blackoilpvt/Co2GasPvt.hpp index 069df024734..0a62c5fffba 100644 --- a/opm/material/fluidsystems/blackoilpvt/Co2GasPvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/Co2GasPvt.hpp @@ -84,14 +84,14 @@ class Co2GasPvt bool enableVaporization, int activityModel, Co2StoreConfig::GasMixingType gastype) - : brineReferenceDensity_(brineReferenceDensity) - , gasReferenceDensity_(gasReferenceDensity) - , salinity_(salinity) - , enableEzrokhiDensity_(enableEzrokhiDensity) - , enableVaporization_(enableVaporization) - , activityModel_(activityModel) - , gastype_(gastype) - , co2Tables(params) + : brineReferenceDensity_(brineReferenceDensity) + , gasReferenceDensity_(gasReferenceDensity) + , salinity_(salinity) + , enableEzrokhiDensity_(enableEzrokhiDensity) + , enableVaporization_(enableVaporization) + , activityModel_(activityModel) + , gastype_(gastype) + , co2Tables(params) { assert(enableEzrokhiDensity == false && "Ezrokhi density not supported by GPUs"); }