From 581cf9f03755e710084d5245a715b91638296c6c Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Tue, 29 Oct 2024 16:26:54 +0100 Subject: [PATCH 1/7] WIP make brineco2pvt work on gpu --- .../fluidsystems/blackoilpvt/BrineCo2Pvt.cpp | 34 ++-- .../fluidsystems/blackoilpvt/BrineCo2Pvt.hpp | 179 ++++++++++++++---- 2 files changed, 155 insertions(+), 58 deletions(-) diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp index 227b7f55a2f..9c2cb1adc28 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..2aff7624832 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; @@ -81,13 +82,29 @@ class BrineCo2Pvt 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, + int thermalMixingModelSalt, + int thermalMixingModelLiquid, + Params params) : + brineReferenceDensity_(brineReferenceDensity), + co2ReferenceDensity_(co2ReferenceDensity), + salinity_(salinity), + activityModel_(activityModel), + co2Tables_(params) +{ + setThermalMixingModel(thermalMixingModelSalt, thermalMixingModelLiquid); +} + #if HAVE_ECL_INPUT /*! * \brief Initialize the parameters for Brine-CO2 system using an ECL deck. @@ -155,7 +172,7 @@ class BrineCo2Pvt unsigned numRegions() const { return brineReferenceDensity_.size(); } - Scalar hVap(unsigned ) const{ + OPM_HOST_DEVICE Scalar hVap(unsigned ) const{ return 0; } @@ -163,7 +180,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 +199,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 +217,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 +230,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 +251,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 +266,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 +287,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 +304,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 +321,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 +335,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 +353,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 +372,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 +403,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 +417,51 @@ 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_; + } + template - Evaluation diffusionCoefficient(const Evaluation& temperature, + OPM_HOST_DEVICE Evaluation diffusionCoefficient(const Evaluation& temperature, const Evaluation& pressure, unsigned /*compIdx*/) const { @@ -443,7 +492,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 +510,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 +542,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 +561,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 +599,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 +627,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 +641,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 +653,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 +667,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 +676,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 +765,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 +777,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 +795,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.getGasReferenceDensity()); + ViewType newSalinity = make_view(brineCo2Pvt.getSalinity()); + + return BrineCo2Pvt( + newBrineReferenceDensity, + newGasReferenceDensity, + newSalinity, + brineCo2Pvt.getActivityModel(), + brineCo2Pvt.getThermalMixingModelSalt(), + brineCo2Pvt.getThermalMixingModelLiquid(), + make_view(brineCo2Pvt.getParams()) + ); + } +} + #endif From 8c46c4407cca61bb6c5aa667504676a32dd4b5b8 Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Wed, 30 Oct 2024 10:20:57 +0100 Subject: [PATCH 2/7] brineco2pvt now works on gpu --- .../fluidsystems/blackoilpvt/BrineCo2Pvt.hpp | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp index 2aff7624832..4b7dc91a83b 100644 --- a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp @@ -75,7 +75,7 @@ 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; @@ -93,16 +93,17 @@ class BrineCo2Pvt ContainerT co2ReferenceDensity, ContainerT salinity, int activityModel, - int thermalMixingModelSalt, - int thermalMixingModelLiquid, + Co2StoreConfig::SaltMixingType thermalMixingModelSalt, + Co2StoreConfig::LiquidMixingType thermalMixingModelLiquid, Params params) : brineReferenceDensity_(brineReferenceDensity), co2ReferenceDensity_(co2ReferenceDensity), salinity_(salinity), activityModel_(activityModel), + liquidMixType_(thermalMixingModelLiquid), + saltMixType_(thermalMixingModelSalt), co2Tables_(params) { - setThermalMixingModel(thermalMixingModelSalt, thermalMixingModelLiquid); } #if HAVE_ECL_INPUT @@ -436,29 +437,26 @@ class BrineCo2Pvt 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& getBrineReferenceDensity() const + { return brineReferenceDensity_; } - OPM_HOST_DEVICE const ContainerT& getCo2ReferenceDensity() const { - return co2ReferenceDensity_; - } + OPM_HOST_DEVICE const ContainerT& getCo2ReferenceDensity() const + { return co2ReferenceDensity_; } - OPM_HOST_DEVICE const ContainerT& getSalinity() const { - return salinity_; - } + OPM_HOST_DEVICE const ContainerT& getSalinity() const + { return salinity_; } - OPM_HOST_DEVICE const Params& getParams() const { - return co2Tables_; - } + OPM_HOST_DEVICE const Params& getParams() const + { return co2Tables_; } - OPM_HOST_DEVICE Co2StoreConfig::SaltMixingType getThermalMixingModelSalt() const { - return saltMixType_; - } + OPM_HOST_DEVICE Co2StoreConfig::SaltMixingType getThermalMixingModelSalt() const + { return saltMixType_; } - OPM_HOST_DEVICE Co2StoreConfig::LiquidMixingType getThermalMixingModelLiquid() const { - return liquidMixType_; - } + OPM_HOST_DEVICE Co2StoreConfig::LiquidMixingType getThermalMixingModelLiquid() const + { return liquidMixType_; } + + OPM_HOST_DEVICE int getActivityModel() const + { return activityModel_; } template OPM_HOST_DEVICE Evaluation diffusionCoefficient(const Evaluation& temperature, @@ -820,7 +818,7 @@ namespace Opm::gpuistl { static_assert(std::is_same_v); ViewType newBrineReferenceDensity = make_view(brineCo2Pvt.getBrineReferenceDensity()); - ViewType newGasReferenceDensity = make_view(brineCo2Pvt.getGasReferenceDensity()); + ViewType newGasReferenceDensity = make_view(brineCo2Pvt.getCo2ReferenceDensity()); ViewType newSalinity = make_view(brineCo2Pvt.getSalinity()); return BrineCo2Pvt( From ed074196e79e4a5dd990ea723dbb37aeb08cefb8 Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Wed, 6 Nov 2024 13:59:56 +0100 Subject: [PATCH 3/7] rebase code --- opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp index 4b7dc91a83b..f5c399f7464 100644 --- a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp @@ -828,7 +828,7 @@ namespace Opm::gpuistl { brineCo2Pvt.getActivityModel(), brineCo2Pvt.getThermalMixingModelSalt(), brineCo2Pvt.getThermalMixingModelLiquid(), - make_view(brineCo2Pvt.getParams()) + make_view(brineCo2Pvt.getParams()) ); } } From 469e5464c8f0aad5be2a8d91661a7720ad144134 Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Wed, 6 Nov 2024 14:46:33 +0100 Subject: [PATCH 4/7] reorder arguments to make instantiation simpler --- opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp index f5c399f7464..04f74844020 100644 --- a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp @@ -808,7 +808,7 @@ namespace Opm::gpuistl { ); } - template + template BrineCo2Pvt make_view(const BrineCo2Pvt& brineCo2Pvt) { From 9d2342e48352e19b5b15c174078182e2383c5ae9 Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Wed, 6 Nov 2024 14:49:58 +0100 Subject: [PATCH 5/7] fix indentation --- .../fluidsystems/blackoilpvt/Co2GasPvt.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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"); } From 68ebd79852e6e36a5672aa573d069e1b6a924f6e Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Fri, 3 Jan 2025 08:31:52 +0100 Subject: [PATCH 6/7] avoid static variable on the GPU --- opm/material/components/BrineDynamic.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/opm/material/components/BrineDynamic.hpp b/opm/material/components/BrineDynamic.hpp index 11da85f18eb..3021d8e9e1a 100644 --- a/opm/material/components/BrineDynamic.hpp +++ b/opm/material/components/BrineDynamic.hpp @@ -83,7 +83,7 @@ class BrineDynamic : public Component > { const Scalar M1 = H2O::molarMass(); const Evaluation X2 = salinity; // mass fraction of salt in brine - return M1*mM_salt/(mM_salt + X2*(M1 - mM_salt)); + return M1*mM_salt()/(mM_salt() + X2*(M1 - mM_salt())); } /*! @@ -349,9 +349,12 @@ class BrineDynamic : public Component > return mu_brine/1000.0; // convert to [Pa s] (todo: check if correct cP->Pa s is times 10...) } - +private: //Molar mass salt (assumes pure NaCl) [kg/mol] - static constexpr Scalar mM_salt = 58.44e-3; + static constexpr Scalar mM_salt() + { + return 58.44e-3; + } }; From 29ef6a8ff7d8262eaaf045c48ecbddf5a83fcdd9 Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Fri, 3 Jan 2025 16:47:45 +0100 Subject: [PATCH 7/7] adjust formatting --- .../fluidsystems/blackoilpvt/BrineCo2Pvt.hpp | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp index 04f74844020..2bec1e10e6d 100644 --- a/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.hpp @@ -80,7 +80,7 @@ class BrineCo2Pvt //! The binary coefficients for brine and CO2 used by this fluid system using BinaryCoeffBrineCO2 = BinaryCoeff::Brine_CO2; - explicit BrineCo2Pvt() = default; + BrineCo2Pvt() = default; explicit BrineCo2Pvt(const ContainerT& salinity, int activityModel = 3, @@ -90,19 +90,19 @@ class BrineCo2Pvt 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) + 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) { } @@ -793,10 +793,13 @@ class BrineCo2Pvt } // namespace Opm -namespace Opm::gpuistl { +namespace Opm::gpuistl +{ + template BrineCo2Pvt - move_to_gpu(BrineCo2Pvt cpuBrineCo2) { + move_to_gpu(const BrineCo2Pvt& cpuBrineCo2) + { return BrineCo2Pvt( GPUContainer(cpuBrineCo2.getBrineReferenceDensity()), GPUContainer(cpuBrineCo2.getCo2ReferenceDensity()), @@ -810,8 +813,8 @@ namespace Opm::gpuistl { template BrineCo2Pvt - make_view(const BrineCo2Pvt& brineCo2Pvt) { - + make_view(const BrineCo2Pvt& brineCo2Pvt) + { using containedType = typename ContainerType::value_type; using viewedTypeNoConst = typename std::remove_const_t;