From 95f52cca9a4a4a909c1cec4c4812c21f9be8bde6 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 01/29] BlackOilBioEffectsParams: separate out state verification to lower congnitive load --- .../blackoil/blackoilbioeffectsparams.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/opm/models/blackoil/blackoilbioeffectsparams.cpp b/opm/models/blackoil/blackoilbioeffectsparams.cpp index 8b23ad3db68..23bed6538a2 100644 --- a/opm/models/blackoil/blackoilbioeffectsparams.cpp +++ b/opm/models/blackoil/blackoilbioeffectsparams.cpp @@ -34,12 +34,10 @@ #include -namespace Opm { +namespace { -template -template -void BlackOilBioeffectsParams:: -initFromState(const EclipseState& eclState) +template +void verifyState(const Opm::EclipseState& eclState) { // some sanity checks: // if biofilm is enabled, the BIOFILM keyword must be present, @@ -70,6 +68,18 @@ initFromState(const EclipseState& eclState) "contains the MICP keyword"); } } +} + +} + +namespace Opm { + +template +template +void BlackOilBioeffectsParams:: +initFromState(const EclipseState& eclState) +{ + verifyState(eclState); if (!eclState.runspec().micp() && !eclState.runspec().biof()) return; // bioeffects are supposed to be disabled From e9801cf3b64ed2d16d6d7922f3fe4922732661ed Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 02/29] BlackOilBrineParams: separate out state verification to lower congnitive load --- opm/models/blackoil/blackoilbrineparams.cpp | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/opm/models/blackoil/blackoilbrineparams.cpp b/opm/models/blackoil/blackoilbrineparams.cpp index 7bf963c70ca..c05aee1a52c 100644 --- a/opm/models/blackoil/blackoilbrineparams.cpp +++ b/opm/models/blackoil/blackoilbrineparams.cpp @@ -36,27 +36,37 @@ #include #include -namespace Opm { +namespace { -template template -void BlackOilBrineParams:: -initFromState(const EclipseState& eclState) +void verifyState(const Opm::EclipseState& eclState) { // some sanity checks: if brine are enabled, the BRINE keyword must be // present, if brine are disabled the keyword must not be present. if constexpr (enableBrine) { - if (!eclState.runspec().phases().active(Phase::BRINE)) { + if (!eclState.runspec().phases().active(Opm::Phase::BRINE)) { throw std::runtime_error("Non-trivial brine treatment requested at compile time, but " "the deck does not contain the BRINE keyword"); } } else { - if (eclState.runspec().phases().active(Phase::BRINE)) { + if (eclState.runspec().phases().active(Opm::Phase::BRINE)) { throw std::runtime_error("Brine treatment disabled at compile time, but the deck " "contains the BRINE keyword"); } } +} + +} + +namespace Opm { + +template +template +void BlackOilBrineParams:: +initFromState(const EclipseState& eclState) +{ + verifyState(eclState); if (!eclState.runspec().phases().active(Phase::BRINE)) { return; // brine treatment is supposed to be disabled From 21461f46f5650c250f7fca1ebb2cbe45aab916b1 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 03/29] BlackOilExtBoParams: separate out state verification to lower congnitive load --- opm/models/blackoil/blackoilextboparams.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/opm/models/blackoil/blackoilextboparams.cpp b/opm/models/blackoil/blackoilextboparams.cpp index b79e532d119..8527ace8d3d 100644 --- a/opm/models/blackoil/blackoilextboparams.cpp +++ b/opm/models/blackoil/blackoilextboparams.cpp @@ -37,28 +37,37 @@ #include #include -namespace Opm { +namespace { -template template -void BlackOilExtboParams:: -initFromState(const EclipseState& eclState) +void verifyState(const Opm::EclipseState& eclState) { // some sanity checks: if extended BO is enabled, the PVTSOL keyword must be // present, if extended BO is disabled the keyword must not be present. if constexpr (enableExtbo) { - if (!eclState.runspec().phases().active(Phase::ZFRACTION)) { + if (!eclState.runspec().phases().active(Opm::Phase::ZFRACTION)) { throw std::runtime_error("Extended black oil treatment requested at compile " "time, but the deck does not contain the PVTSOL keyword"); } } else { - if (!enableExtbo && eclState.runspec().phases().active(Phase::ZFRACTION)) { + if (eclState.runspec().phases().active(Opm::Phase::ZFRACTION)) { throw std::runtime_error("Extended black oil treatment disabled at compile time, but the deck " "contains the PVTSOL keyword"); } } +} + +} +namespace Opm { + +template +template +void BlackOilExtboParams:: +initFromState(const EclipseState& eclState) +{ + verifyState(eclState); if (!eclState.runspec().phases().active(Phase::ZFRACTION)) { return; // solvent treatment is supposed to be disabled } From f306e23ddd6a30443b7f506b7c8069818f0cb9a0 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 04/29] BlackOilExtBoParams: separate out sdensity parsing to lower congnitive load --- opm/models/blackoil/blackoilextboparams.cpp | 45 ++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/opm/models/blackoil/blackoilextboparams.cpp b/opm/models/blackoil/blackoilextboparams.cpp index 8527ace8d3d..cfcbc5742a0 100644 --- a/opm/models/blackoil/blackoilextboparams.cpp +++ b/opm/models/blackoil/blackoilextboparams.cpp @@ -58,6 +58,25 @@ void verifyState(const Opm::EclipseState& eclState) } } +template +std::vector +parseSdensity(const Opm::EclipseState& eclState, + const std::size_t numPvtRegions) +{ + const auto& sdensityTables = eclState.getTableManager().getSolventDensityTables(); + if (sdensityTables.size() == numPvtRegions) { + std::vector zReferenceDensity(numPvtRegions); + for (std::size_t regionIdx = 0; regionIdx < numPvtRegions; ++regionIdx) { + const Scalar rhoRefS = sdensityTables[regionIdx].getSolventDensityColumn().front(); + zReferenceDensity[regionIdx] = rhoRefS; + } + return zReferenceDensity; + } + else { + throw std::runtime_error("Extbo: kw SDENSITY is missing or not aligned with NTPVT\n"); + } +} + } namespace Opm { @@ -73,11 +92,10 @@ initFromState(const EclipseState& eclState) } // pvt properties from kw PVTSOL: - const auto& tableManager = eclState.getTableManager(); const auto& pvtsolTables = tableManager.getPvtsolTables(); - std::size_t numPvtRegions = pvtsolTables.size(); + const std::size_t numPvtRegions = pvtsolTables.size(); BO_.resize(numPvtRegions, Tabulated2DFunction{Tabulated2DFunction::InterpolationPolicy::LeftExtreme}); BG_.resize(numPvtRegions, Tabulated2DFunction{Tabulated2DFunction::InterpolationPolicy::LeftExtreme}); @@ -129,7 +147,7 @@ initFromState(const EclipseState& eclState) PBUB_RV_[regionIdx].appendXPos(ZCO2); const auto& underSaturatedTable = pvtsolTable.getUnderSaturatedTable(outerIdx); - std::size_t numRows = underSaturatedTable.numRows(); + const std::size_t numRows = underSaturatedTable.numRows(); Scalar bo0 = 0.0; Scalar po0 = 0.0; @@ -147,7 +165,7 @@ initFromState(const EclipseState& eclState) if (bo0 > bo) { // This is undersaturated oil-phase for ZCO2 <= zLim ... // Here we assume tabulated bo to decay beyond boiling point if (extractCmpFromPvt) { - Scalar cmpFactor = (bo - bo0) / (po - po0); + const Scalar cmpFactor = (bo - bo0) / (po - po0); oilCmp[outerIdx] = cmpFactor; zLim_[regionIdx] = ZCO2; //std::cout << "### cmpFactorOil: " << cmpFactor << " zLim: " << zLim_[regionIdx] << std::endl; @@ -156,9 +174,9 @@ initFromState(const EclipseState& eclState) } else if (bo0 == bo) { // This is undersaturated gas-phase for ZCO2 > zLim ... // Here we assume tabulated bo to be constant extrapolated beyond dew point if (innerIdx+1 < numRows && ZCO2<1.0 && extractCmpFromPvt) { - Scalar rvNxt = underSaturatedTable.get("RV", innerIdx + 1) + innerIdx * 1.0e-10; - Scalar bgNxt = underSaturatedTable.get("B_G", innerIdx + 1); - Scalar cmpFactor = (bgNxt - bg) / (rvNxt - rv); + const Scalar rvNxt = underSaturatedTable.get("RV", innerIdx + 1) + innerIdx * 1.0e-10; + const Scalar bgNxt = underSaturatedTable.get("B_G", innerIdx + 1); + const Scalar cmpFactor = (bgNxt - bg) / (rvNxt - rv); gasCmp[outerIdx] = cmpFactor; //std::cout << "### cmpFactorGas: " << cmpFactor << " zLim: " << zLim_[regionIdx] << std::endl; } @@ -198,17 +216,8 @@ initFromState(const EclipseState& eclState) gasCmp_[regionIdx].setXYContainers(zArg, gasCmp, /*sortInput=*/false); } - // Reference density for pure z-component taken from kw SDENSITY - const auto& sdensityTables = eclState.getTableManager().getSolventDensityTables(); - if (sdensityTables.size() == numPvtRegions) { - zReferenceDensity_.resize(numPvtRegions); - for (unsigned regionIdx = 0; regionIdx < numPvtRegions; ++regionIdx) { - Scalar rhoRefS = sdensityTables[regionIdx].getSolventDensityColumn().front(); - zReferenceDensity_[regionIdx] = rhoRefS; - } - } - else - throw std::runtime_error("Extbo: kw SDENSITY is missing or not aligned with NTPVT\n"); + // Reference density for pure z-component taken from kw SDENSITY + zReferenceDensity_ = parseSdensity(eclState, numPvtRegions); } #define INSTANTIATE_TYPE(T) \ From 07943ca2ec9965758d823c8df0082a416329c76f Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 13:05:34 +0200 Subject: [PATCH 05/29] BlackOilPolymerParams: mark utility methods private --- opm/models/blackoil/blackoilpolymerparams.hpp | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 56ac139f6ca..9bd9f9bba58 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -49,32 +49,6 @@ struct BlackOilPolymerParams { template void initFromState(const EclipseState& eclState); - /*! - * \brief Specify the number of satuation regions. - * - * This must be called before setting the PLYROCK and PLYADS of any region. - */ - void setNumSatRegions(unsigned numRegions); - - /*! - * \brief Specify the number of mix regions. - * - * This must be called before setting the PLYMAC and PLMIXPAR of any region. - */ - void setNumMixRegions(unsigned numRegions, bool enablePolymerMolarWeight); - - /*! - * \brief Specify the polymer rock properties a single region. - * - * The index of specified here must be in range [0, numSatRegions) - */ - void setPlyrock(unsigned satRegionIdx, - const Scalar& plyrockDeadPoreVolume, - const Scalar& plyrockResidualResistanceFactor, - const Scalar& plyrockRockDensityFactor, - const Scalar& plyrockAdsorbtionIndex, - const Scalar& plyrockMaxAdsorbtion); - // a struct containing the constants to calculate polymer viscosity // based on Mark-Houwink equation and Huggins equation, the constants are provided // by the keyword PLYVMH @@ -110,6 +84,33 @@ struct BlackOilPolymerParams { std::map skprwatTables_{}; std::map skprpolyTables_{}; + +private: + /*! + * \brief Specify the number of saturation regions. + * + * This must be called before setting the PLYROCK and PLYADS of any region. + */ + void setNumSatRegions(unsigned numRegions); + + /*! + * \brief Specify the number of mix regions. + * + * This must be called before setting the PLYMAX and PLMIXPAR of any region. + */ + void setNumMixRegions(unsigned numRegions, bool enablePolymerMolarWeight); + + /*! + * \brief Specify the polymer rock properties a single region. + * + * The index of specified here must be in range [0, numSatRegions) + */ + void setPlyrock(unsigned satRegionIdx, + const Scalar& plyrockDeadPoreVolume, + const Scalar& plyrockResidualResistanceFactor, + const Scalar& plyrockRockDensityFactor, + const Scalar& plyrockAdsorbtionIndex, + const Scalar& plyrockMaxAdsorbtion); }; } // namespace Opm From 8c76fef08736f214fb4b71074379e53e9917d6e7 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 06/29] BlackOilPolymerParams: separate out state verification to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index c76cece8d6e..05e6f0bc01b 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -51,38 +51,32 @@ convertVecToVec(const std::vector>& input) return output; } -} - -namespace Opm { - -template template -void BlackOilPolymerParams:: -initFromState(const EclipseState& eclState) +void verifyState(const Opm::EclipseState& eclState) { // some sanity checks: if polymers are enabled, the POLYMER keyword must be // present, if polymers are disabled the keyword must not be present. if constexpr (enablePolymer) { - if (!eclState.runspec().phases().active(Phase::POLYMER)) { + if (!eclState.runspec().phases().active(Opm::Phase::POLYMER)) { throw std::runtime_error("Non-trivial polymer treatment requested at compile time, but " "the deck does not contain the POLYMER keyword"); } } else { - if (eclState.runspec().phases().active(Phase::POLYMER)) { + if (eclState.runspec().phases().active(Opm::Phase::POLYMER)) { throw std::runtime_error("Polymer treatment disabled at compile time, but the deck " "contains the POLYMER keyword"); } } if constexpr (enablePolymerMolarWeight) { - if (!eclState.runspec().phases().active(Phase::POLYMW)) { + if (!eclState.runspec().phases().active(Opm::Phase::POLYMW)) { throw std::runtime_error("Polymer molecular weight tracking is enabled at compile time, but " "the deck does not contain the POLYMW keyword"); } } else { - if (eclState.runspec().phases().active(Phase::POLYMW)) { + if (eclState.runspec().phases().active(Opm::Phase::POLYMW)) { throw std::runtime_error("Polymer molecular weight tracking is disabled at compile time, but the deck " "contains the POLYMW keyword"); } @@ -92,7 +86,18 @@ initFromState(const EclipseState& eclState) throw std::runtime_error("Polymer molecular weight tracking is enabled while polymer treatment " "is disabled at compile time"); } +} +} + +namespace Opm { + +template +template +void BlackOilPolymerParams:: +initFromState(const EclipseState& eclState) +{ + verifyState(eclState); if (!eclState.runspec().phases().active(Phase::POLYMER)) { return; // polymer treatment is supposed to be disabled } From f4b124e758ab10e37cac8d433491fd9d3e6d8f4e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 07/29] BlackOilPolymerParams: separate out plyRock processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 55 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 ++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index 05e6f0bc01b..49ddf637f2f 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -107,25 +107,10 @@ initFromState(const EclipseState& eclState) unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); setNumSatRegions(numSatRegions); - // initialize the objects which deal with the PLYROCK keyword - const auto& plyrockTables = tableManager.getPlyrockTables(); - if (!plyrockTables.empty()) { - assert(numSatRegions == plyrockTables.size()); - for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { - const auto& plyrockTable = plyrockTables.template getTable(satRegionIdx); - setPlyrock(satRegionIdx, - plyrockTable.getDeadPoreVolumeColumn()[0], - plyrockTable.getResidualResistanceFactorColumn()[0], - plyrockTable.getRockDensityFactorColumn()[0], - static_cast(plyrockTable.getAdsorbtionIndexColumn()[0]), - plyrockTable.getMaxAdsorbtionColumn()[0]); - } - } - else { - throw std::runtime_error("PLYROCK must be specified in POLYMER runs\n"); - } + // initialize the objects which deal with the PLYROCK keyword + processPlyrock(eclState); - // initialize the objects which deal with the PLYADS keyword + // initialize the objects which deal with the PLYADS keyword const auto& plyadsTables = tableManager.getPlyadsTables(); if (!plyadsTables.empty()) { assert(numSatRegions == plyadsTables.size()); @@ -145,7 +130,7 @@ initFromState(const EclipseState& eclState) unsigned numPvtRegions = tableManager.getTabdims().getNumPVTTables(); plyviscViscosityMultiplierTable_.resize(numPvtRegions); - // initialize the objects which deal with the PLYVISC keyword + // initialize the objects which deal with the PLYVISC keyword const auto& plyviscTables = tableManager.getPlyviscTables(); if (!plyviscTables.empty()) { // different viscosity model is used for POLYMW @@ -168,7 +153,7 @@ initFromState(const EclipseState& eclState) throw std::runtime_error("PLYVISC must be specified in POLYMER runs\n"); } - // initialize the objects which deal with the PLYMAX keyword + // initialize the objects which deal with the PLYMAX keyword const auto& plymaxTables = tableManager.getPlymaxTables(); const unsigned numMixRegions = plymaxTables.size(); setNumMixRegions(numMixRegions, enablePolymerMolarWeight); @@ -278,7 +263,7 @@ initFromState(const EclipseState& eclState) throw std::runtime_error("PLYVMH keyword must be specified in POLYMW rus \n"); } - // handling PLYMWINJ keyword + // handling PLYMWINJ keyword const auto& plymwinjTables = tableManager.getPlymwinjTables(); for (const auto& table : plymwinjTables) { const int tableNumber = table.first; @@ -298,7 +283,7 @@ initFromState(const EclipseState& eclState) } } - // handling SKPRWAT keyword + // handling SKPRWAT keyword const auto& skprwatTables = tableManager.getSkprwatTables(); for (const auto& table : skprwatTables) { const int tableNumber = table.first; @@ -318,7 +303,7 @@ initFromState(const EclipseState& eclState) } } - // handling SKPRPOLY keyword + // handling SKPRPOLY keyword const auto& skprpolyTables = tableManager.getSkprpolyTables(); for (const auto& table : skprpolyTables) { const int tableNumber = table.first; @@ -371,6 +356,30 @@ setNumMixRegions(unsigned numRegions, bool enablePolymerMolarWeight) } } +template +void BlackOilPolymerParams:: +processPlyrock(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); + const auto& plyrockTables = tableManager.getPlyrockTables(); + if (!plyrockTables.empty()) { + assert(numSatRegions == plyrockTables.size()); + for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { + const auto& plyrockTable = plyrockTables.template getTable(satRegionIdx); + setPlyrock(satRegionIdx, + plyrockTable.getDeadPoreVolumeColumn()[0], + plyrockTable.getResidualResistanceFactorColumn()[0], + plyrockTable.getRockDensityFactorColumn()[0], + static_cast(plyrockTable.getAdsorbtionIndexColumn()[0]), + plyrockTable.getMaxAdsorbtionColumn()[0]); + } + } + else { + throw std::runtime_error("PLYROCK must be specified in POLYMER runs\n"); + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 9bd9f9bba58..78377a0b4e9 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -111,6 +111,11 @@ struct BlackOilPolymerParams { const Scalar& plyrockRockDensityFactor, const Scalar& plyrockAdsorbtionIndex, const Scalar& plyrockMaxAdsorbtion); + + /*! + * \brief Process the Plyrock data. + */ + void processPlyrock(const EclipseState& eclState); }; } // namespace Opm From 4681f042bafa09c00935cca07206f424fbf85993 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 08/29] BlackOilPolymerParams: separate out plyAds processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 41 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 +++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index 49ddf637f2f..d1c8755956e 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -111,23 +111,9 @@ initFromState(const EclipseState& eclState) processPlyrock(eclState); // initialize the objects which deal with the PLYADS keyword - const auto& plyadsTables = tableManager.getPlyadsTables(); - if (!plyadsTables.empty()) { - assert(numSatRegions == plyadsTables.size()); - for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { - const auto& plyadsTable = plyadsTables.template getTable(satRegionIdx); - // Copy data - const auto& c = plyadsTable.getPolymerConcentrationColumn(); - const auto& ads = plyadsTable.getAdsorbedPolymerColumn(); - plyadsAdsorbedPolymer_[satRegionIdx].setXYContainers(c, ads); - } - } - else { - throw std::runtime_error("PLYADS must be specified in POLYMER runs\n"); - } - + processPlyads(eclState); - unsigned numPvtRegions = tableManager.getTabdims().getNumPVTTables(); + const unsigned numPvtRegions = tableManager.getTabdims().getNumPVTTables(); plyviscViscosityMultiplierTable_.resize(numPvtRegions); // initialize the objects which deal with the PLYVISC keyword @@ -380,6 +366,28 @@ processPlyrock(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processPlyads(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); + const auto& plyadsTables = tableManager.getPlyadsTables(); + if (!plyadsTables.empty()) { + assert(numSatRegions == plyadsTables.size()); + for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { + const auto& plyadsTable = plyadsTables.template getTable(satRegionIdx); + // Copy data + const auto& c = plyadsTable.getPolymerConcentrationColumn(); + const auto& ads = plyadsTable.getAdsorbedPolymerColumn(); + plyadsAdsorbedPolymer_[satRegionIdx].setXYContainers(c, ads); + } + } + else { + throw std::runtime_error("PLYADS must be specified in POLYMER runs\n"); + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, @@ -396,6 +404,7 @@ setPlyrock(unsigned satRegionIdx, plyrockMaxAdsorbtion_[satRegionIdx] = plyrockMaxAdsorbtion; } + #define INSTANTIATE_TYPE(T) \ template struct BlackOilPolymerParams; \ template void BlackOilPolymerParams::initFromState(const EclipseState&); \ diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 78377a0b4e9..b2e37ce5e7c 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -116,6 +116,11 @@ struct BlackOilPolymerParams { * \brief Process the Plyrock data. */ void processPlyrock(const EclipseState& eclState); + + /*! + * \brief Process the Plyads data. + */ + void processPlyads(const EclipseState& eclState); }; } // namespace Opm From ff54ccf045690eab2d4ea30a7c4fc2dff1aba6a7 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 09/29] BlackOilPolymerParams: separate out plyVisc processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 54 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 7 +++ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index d1c8755956e..bdbccb6174c 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -117,27 +117,7 @@ initFromState(const EclipseState& eclState) plyviscViscosityMultiplierTable_.resize(numPvtRegions); // initialize the objects which deal with the PLYVISC keyword - const auto& plyviscTables = tableManager.getPlyviscTables(); - if (!plyviscTables.empty()) { - // different viscosity model is used for POLYMW - if constexpr (enablePolymerMolarWeight) { - OpmLog::warning("PLYVISC should not be used in POLYMW runs, " - "it will have no effect. A viscosity model based on PLYVMH is used instead.\n"); - } - else { - assert(numPvtRegions == plyviscTables.size()); - for (unsigned pvtRegionIdx = 0; pvtRegionIdx < numPvtRegions; ++pvtRegionIdx) { - const auto& plyadsTable = plyviscTables.template getTable(pvtRegionIdx); - // Copy data - const auto& c = plyadsTable.getPolymerConcentrationColumn(); - const auto& visc = plyadsTable.getViscosityMultiplierColumn(); - plyviscViscosityMultiplierTable_[pvtRegionIdx].setXYContainers(c, visc); - } - } - } - else if constexpr (!enablePolymerMolarWeight) { - throw std::runtime_error("PLYVISC must be specified in POLYMER runs\n"); - } + processPlyvisc(eclState); // initialize the objects which deal with the PLYMAX keyword const auto& plymaxTables = tableManager.getPlymaxTables(); @@ -388,6 +368,38 @@ processPlyads(const EclipseState& eclState) } } +template +template +void BlackOilPolymerParams:: +processPlyvisc(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& plyviscTables = tableManager.getPlyviscTables(); + const unsigned numPvtRegions = tableManager.getTabdims().getNumPVTTables(); + if (!plyviscTables.empty()) { + // different viscosity model is used for POLYMW + if constexpr (enablePolymerMolarWeight) { + OpmLog::warning("PLYVISC should not be used in POLYMW runs, " + "it will have no effect. A viscosity model based on PLYVMH is used instead.\n"); + } + else { + assert(numPvtRegions == plyviscTables.size()); + for (unsigned pvtRegionIdx = 0; pvtRegionIdx < numPvtRegions; ++pvtRegionIdx) { + const auto& plyadsTable = plyviscTables.template getTable(pvtRegionIdx); + // Copy data + const auto& c = plyadsTable.getPolymerConcentrationColumn(); + const auto& visc = plyadsTable.getViscosityMultiplierColumn(); + plyviscViscosityMultiplierTable_[pvtRegionIdx].setXYContainers(c, visc); + } + } + } + else { + if constexpr (!enablePolymerMolarWeight) { + throw std::runtime_error("PLYVISC must be specified in POLYMER runs\n"); + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index b2e37ce5e7c..de3d54e00d9 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -121,6 +121,13 @@ struct BlackOilPolymerParams { * \brief Process the Plyads data. */ void processPlyads(const EclipseState& eclState); + + /*! + * + * \brief Process the Plyvisc data. + */ + template + void processPlyvisc(const EclipseState& eclState); }; } // namespace Opm From 6be1afea240425d9399e5f8333e2bd843ba2a6b0 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 10/29] BlackOilPolymerParams: separate out plyMax processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 33 ++++++++++++------- opm/models/blackoil/blackoilpolymerparams.hpp | 7 +++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index bdbccb6174c..cd22f81ffd2 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -120,18 +120,7 @@ initFromState(const EclipseState& eclState) processPlyvisc(eclState); // initialize the objects which deal with the PLYMAX keyword - const auto& plymaxTables = tableManager.getPlymaxTables(); - const unsigned numMixRegions = plymaxTables.size(); - setNumMixRegions(numMixRegions, enablePolymerMolarWeight); - if (!plymaxTables.empty()) { - for (unsigned mixRegionIdx = 0; mixRegionIdx < numMixRegions; ++mixRegionIdx) { - const auto& plymaxTable = plymaxTables.template getTable(mixRegionIdx); - plymaxMaxConcentration_[mixRegionIdx] = plymaxTable.getPolymerConcentrationColumn()[0]; - } - } - else { - throw std::runtime_error("PLYMAX must be specified in POLYMER runs\n"); - } + processPlymax(eclState); if (!eclState.getTableManager().getPlmixparTable().empty()) { if constexpr (enablePolymerMolarWeight) { @@ -400,6 +389,26 @@ processPlyvisc(const EclipseState& eclState) } } +template +template +void BlackOilPolymerParams:: +processPlymax(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& plymaxTables = tableManager.getPlymaxTables(); + const unsigned numMixRegions = plymaxTables.size(); + setNumMixRegions(numMixRegions, enablePolymerMolarWeight); + if (!plymaxTables.empty()) { + for (unsigned mixRegionIdx = 0; mixRegionIdx < numMixRegions; ++mixRegionIdx) { + const auto& plymaxTable = plymaxTables.template getTable(mixRegionIdx); + plymaxMaxConcentration_[mixRegionIdx] = plymaxTable.getPolymerConcentrationColumn()[0]; + } + } + else { + throw std::runtime_error("PLYMAX must be specified in POLYMER runs\n"); + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index de3d54e00d9..e1d44fd120f 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -123,11 +123,16 @@ struct BlackOilPolymerParams { void processPlyads(const EclipseState& eclState); /*! - * * \brief Process the Plyvisc data. */ template void processPlyvisc(const EclipseState& eclState); + + /*! + * \brief Process the Plymax data. + */ + template + void processPlymax(const EclipseState& eclState); }; } // namespace Opm From 32714accab4d2f9b32ac68adb1848fe8982deb24 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 11/29] BlackOilPolymerParams: separate out plmixpar processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 45 ++++++++++++------- opm/models/blackoil/blackoilpolymerparams.hpp | 6 +++ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index cd22f81ffd2..65a88f0e7f4 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -122,21 +122,7 @@ initFromState(const EclipseState& eclState) // initialize the objects which deal with the PLYMAX keyword processPlymax(eclState); - if (!eclState.getTableManager().getPlmixparTable().empty()) { - if constexpr (enablePolymerMolarWeight) { - OpmLog::warning("PLMIXPAR should not be used in POLYMW runs, it will have no effect.\n"); - } - else { - const auto& plmixparTable = eclState.getTableManager().getPlmixparTable(); - // initialize the objects which deal with the PLMIXPAR keyword - for (unsigned mixRegionIdx = 0; mixRegionIdx < numMixRegions; ++mixRegionIdx) { - plymixparToddLongstaff_[mixRegionIdx] = plmixparTable[mixRegionIdx].todd_langstaff; - } - } - } - else if constexpr (!enablePolymerMolarWeight) { - throw std::runtime_error("PLMIXPAR must be specified in POLYMER runs\n"); - } + processPlmixpar(eclState); hasPlyshlog_ = eclState.getTableManager().hasTables("PLYSHLOG"); hasShrate_ = eclState.getTableManager().useShrate(); @@ -205,6 +191,8 @@ initFromState(const EclipseState& eclState) if constexpr (enablePolymerMolarWeight) { const auto& plyvmhTable = eclState.getTableManager().getPlyvmhTable(); + const auto& plymaxTables = tableManager.getPlymaxTables(); + const unsigned numMixRegions = plymaxTables.size(); if (!plyvmhTable.empty()) { assert(plyvmhTable.size() == numMixRegions); for (std::size_t regionIdx = 0; regionIdx < numMixRegions; ++regionIdx) { @@ -409,6 +397,33 @@ processPlymax(const EclipseState& eclState) } } +template +template +void BlackOilPolymerParams:: +processPlmixpar(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& plmixparTable = tableManager.getPlmixparTable(); + const auto& plymaxTables = tableManager.getPlymaxTables(); + const unsigned numMixRegions = plymaxTables.size(); + if (!plmixparTable.empty()) { + if constexpr (enablePolymerMolarWeight) { + OpmLog::warning("PLMIXPAR should not be used in POLYMW runs, it will have no effect.\n"); + } + else { + // initialize the objects which deal with the PLMIXPAR keyword + for (unsigned mixRegionIdx = 0; mixRegionIdx < numMixRegions; ++mixRegionIdx) { + plymixparToddLongstaff_[mixRegionIdx] = plmixparTable[mixRegionIdx].todd_langstaff; + } + } + } + else { + if constexpr (!enablePolymerMolarWeight) { + throw std::runtime_error("PLMIXPAR must be specified in POLYMER runs\n"); + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index e1d44fd120f..f64f89d638d 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -133,6 +133,12 @@ struct BlackOilPolymerParams { */ template void processPlymax(const EclipseState& eclState); + + /*! + * \brief Process the Plmixpar data. + */ + template + void processPlmixpar(const EclipseState& eclState); }; } // namespace Opm From b33fc18651b76184776667956ef28e8dac25e0b3 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 12/29] BlackOilPolymerParams: separate out Plyshlog processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 88 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 ++ 2 files changed, 55 insertions(+), 38 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index 65a88f0e7f4..81e6f1d8723 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -31,6 +31,7 @@ copyright holders. #include #include +#include #include #include #include @@ -124,50 +125,15 @@ initFromState(const EclipseState& eclState) processPlmixpar(eclState); - hasPlyshlog_ = eclState.getTableManager().hasTables("PLYSHLOG"); - hasShrate_ = eclState.getTableManager().useShrate(); + hasPlyshlog_ = tableManager.hasTables("PLYSHLOG"); + hasShrate_ = tableManager.useShrate(); if ((hasPlyshlog_ || hasShrate_) && enablePolymerMolarWeight) { OpmLog::warning("PLYSHLOG and SHRATE should not be used in POLYMW runs, they will have no effect.\n"); } if (hasPlyshlog_ && !enablePolymerMolarWeight) { - const auto& plyshlogTables = tableManager.getPlyshlogTables(); - assert(numPvtRegions == plyshlogTables.size()); - plyshlogShearEffectRefMultiplier_.resize(numPvtRegions); - plyshlogShearEffectRefLogVelocity_.resize(numPvtRegions); - for (unsigned pvtRegionIdx = 0; pvtRegionIdx < numPvtRegions; ++pvtRegionIdx) { - const auto& plyshlogTable = plyshlogTables.template getTable(pvtRegionIdx); - - Scalar plyshlogRefPolymerConcentration = plyshlogTable.getRefPolymerConcentration(); - auto waterVelocity = plyshlogTable.getWaterVelocityColumn().vectorCopy(); - auto shearMultiplier = plyshlogTable.getShearMultiplierColumn().vectorCopy(); - - // do the unit version here for the waterVelocity - UnitSystem unitSystem = eclState.getDeckUnitSystem(); - double siFactor = hasShrate_? unitSystem.parse("1/Time").getSIScaling() : unitSystem.parse("Length/Time").getSIScaling(); - for (std::size_t i = 0; i < waterVelocity.size(); ++i) { - waterVelocity[i] *= siFactor; - // for plyshlog the input must be stored as logarithms - // the interpolation is then done the log-space. - waterVelocity[i] = std::log(waterVelocity[i]); - } - - Scalar refViscMult = plyviscViscosityMultiplierTable_[pvtRegionIdx].eval(plyshlogRefPolymerConcentration, /*extrapolate=*/true); - // convert the table using referece conditions - for (std::size_t i = 0; i < waterVelocity.size(); ++i) { - shearMultiplier[i] *= refViscMult; - shearMultiplier[i] -= 1; - shearMultiplier[i] /= (refViscMult - 1); - } - plyshlogShearEffectRefMultiplier_[pvtRegionIdx].resize(waterVelocity.size()); - plyshlogShearEffectRefLogVelocity_[pvtRegionIdx].resize(waterVelocity.size()); - - for (std::size_t i = 0; i < waterVelocity.size(); ++i) { - plyshlogShearEffectRefMultiplier_[pvtRegionIdx][i] = shearMultiplier[i]; - plyshlogShearEffectRefLogVelocity_[pvtRegionIdx][i] = waterVelocity[i]; - } - } + processPlyshlog(eclState); } if (hasShrate_ && !enablePolymerMolarWeight) { @@ -424,6 +390,52 @@ processPlmixpar(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processPlyshlog(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& plyshlogTables = tableManager.getPlyshlogTables(); + const unsigned numPvtRegions = tableManager.getTabdims().getNumPVTTables(); + assert(numPvtRegions == plyshlogTables.size()); + plyshlogShearEffectRefMultiplier_.resize(numPvtRegions); + plyshlogShearEffectRefLogVelocity_.resize(numPvtRegions); + for (unsigned pvtRegionIdx = 0; pvtRegionIdx < numPvtRegions; ++pvtRegionIdx) { + const auto& plyshlogTable = plyshlogTables.template getTable(pvtRegionIdx); + + const Scalar plyshlogRefPolymerConcentration = plyshlogTable.getRefPolymerConcentration(); + auto waterVelocity = plyshlogTable.getWaterVelocityColumn().vectorCopy(); + auto shearMultiplier = plyshlogTable.getShearMultiplierColumn().vectorCopy(); + + // do the unit version here for the waterVelocity + UnitSystem unitSystem = eclState.getDeckUnitSystem(); + const double siFactor = hasShrate_? unitSystem.parse("1/Time").getSIScaling() + : unitSystem.parse("Length/Time").getSIScaling(); + + // for plyshlog the input must be stored as logarithms + // the interpolation is then done in log-space. + std::ranges::transform(waterVelocity, waterVelocity.begin(), + [siFactor](const double input) + { return std::log(input * siFactor); }); + + const Scalar refViscMult = plyviscViscosityMultiplierTable_[pvtRegionIdx]. + eval(plyshlogRefPolymerConcentration, /*extrapolate=*/true); + + // convert the table using reference conditions + std::ranges::transform(shearMultiplier, shearMultiplier.begin(), + [refViscMult](const double input) + { return (input * refViscMult - 1.0) / (refViscMult - 1.0); }); + + plyshlogShearEffectRefMultiplier_[pvtRegionIdx].resize(waterVelocity.size()); + plyshlogShearEffectRefLogVelocity_[pvtRegionIdx].resize(waterVelocity.size()); + + for (std::size_t i = 0; i < waterVelocity.size(); ++i) { + plyshlogShearEffectRefMultiplier_[pvtRegionIdx][i] = shearMultiplier[i]; + plyshlogShearEffectRefLogVelocity_[pvtRegionIdx][i] = waterVelocity[i]; + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index f64f89d638d..f8b1ca317b1 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -139,6 +139,11 @@ struct BlackOilPolymerParams { */ template void processPlmixpar(const EclipseState& eclState); + + /*! + * \brief Process the Plyshlog data. + */ + void processPlyshlog(const EclipseState& eclState); }; } // namespace Opm From 7ef7b0f719c94a9bb16ec9dbbd61221e4c16b08e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 13/29] BlackOilPolymerParams: separate out Shrate processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 35 ++++++++++++------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 +++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index 81e6f1d8723..e53a8383bbe 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -140,19 +140,7 @@ initFromState(const EclipseState& eclState) if (!hasPlyshlog_) { throw std::runtime_error("PLYSHLOG must be specified if SHRATE is used in POLYMER runs\n"); } - const auto& shrateTable = eclState.getTableManager().getShrateTable(); - shrate_.resize(numPvtRegions); - for (unsigned pvtRegionIdx = 0; pvtRegionIdx < numPvtRegions; ++pvtRegionIdx) { - if (shrateTable.empty()) { - shrate_[pvtRegionIdx] = 4.8; //default; - } - else if (shrateTable.size() == numPvtRegions) { - shrate_[pvtRegionIdx] = shrateTable[pvtRegionIdx].rate; - } - else { - throw std::runtime_error("SHRATE must either have 0 or number of NUMPVT entries\n"); - } - } + processShrate(eclState); } if constexpr (enablePolymerMolarWeight) { @@ -436,6 +424,27 @@ processPlyshlog(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processShrate(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& shrateTable = tableManager.getShrateTable(); + const unsigned numPvtRegions = tableManager.getTabdims().getNumPVTTables(); + shrate_.resize(numPvtRegions); + for (unsigned pvtRegionIdx = 0; pvtRegionIdx < numPvtRegions; ++pvtRegionIdx) { + if (shrateTable.empty()) { + shrate_[pvtRegionIdx] = 4.8; //default; + } + else if (shrateTable.size() == numPvtRegions) { + shrate_[pvtRegionIdx] = shrateTable[pvtRegionIdx].rate; + } + else { + throw std::runtime_error("SHRATE must either have 0 or number of NUMPVT entries\n"); + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index f8b1ca317b1..5b44448d9f2 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -144,6 +144,11 @@ struct BlackOilPolymerParams { * \brief Process the Plyshlog data. */ void processPlyshlog(const EclipseState& eclState); + + /*! + * \brief Process the Shrate data. + */ + void processShrate(const EclipseState& eclState); }; } // namespace Opm From 50b75fbc29ec9fa237f789d29ebae1599fc46d3b Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 14/29] BlackOilPolymerParams: separate out Plyvmh processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 38 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 +++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index e53a8383bbe..f417b2774e9 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -144,21 +144,7 @@ initFromState(const EclipseState& eclState) } if constexpr (enablePolymerMolarWeight) { - const auto& plyvmhTable = eclState.getTableManager().getPlyvmhTable(); - const auto& plymaxTables = tableManager.getPlymaxTables(); - const unsigned numMixRegions = plymaxTables.size(); - if (!plyvmhTable.empty()) { - assert(plyvmhTable.size() == numMixRegions); - for (std::size_t regionIdx = 0; regionIdx < numMixRegions; ++regionIdx) { - plyvmhCoefficients_[regionIdx].k_mh = plyvmhTable[regionIdx].k_mh; - plyvmhCoefficients_[regionIdx].a_mh = plyvmhTable[regionIdx].a_mh; - plyvmhCoefficients_[regionIdx].gamma = plyvmhTable[regionIdx].gamma; - plyvmhCoefficients_[regionIdx].kappa = plyvmhTable[regionIdx].kappa; - } - } - else { - throw std::runtime_error("PLYVMH keyword must be specified in POLYMW rus \n"); - } + processPlyvmh(eclState); // handling PLYMWINJ keyword const auto& plymwinjTables = tableManager.getPlymwinjTables(); @@ -445,6 +431,28 @@ processShrate(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processPlyvmh(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& plyvmhTable = tableManager.getPlyvmhTable(); + const auto& plymaxTables = tableManager.getPlymaxTables(); + const unsigned numMixRegions = plymaxTables.size(); + if (!plyvmhTable.empty()) { + assert(plyvmhTable.size() == numMixRegions); + for (std::size_t regionIdx = 0; regionIdx < numMixRegions; ++regionIdx) { + plyvmhCoefficients_[regionIdx].k_mh = plyvmhTable[regionIdx].k_mh; + plyvmhCoefficients_[regionIdx].a_mh = plyvmhTable[regionIdx].a_mh; + plyvmhCoefficients_[regionIdx].gamma = plyvmhTable[regionIdx].gamma; + plyvmhCoefficients_[regionIdx].kappa = plyvmhTable[regionIdx].kappa; + } + } + else { + throw std::runtime_error("PLYVMH keyword must be specified in POLYMW runs\n"); + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 5b44448d9f2..4fcb5e036b2 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -149,6 +149,11 @@ struct BlackOilPolymerParams { * \brief Process the Shrate data. */ void processShrate(const EclipseState& eclState); + + /*! + * \brief Process the Plyvmh data. + */ + void processPlyvmh(const EclipseState& eclState); }; } // namespace Opm From c4d6815a3e204cbb364f2c592354c9d611c5f1f2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 15/29] BlackOilPolymerParams: separate out Plymwinj processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 46 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 ++ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index f417b2774e9..6f2267aabf3 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -145,26 +145,7 @@ initFromState(const EclipseState& eclState) if constexpr (enablePolymerMolarWeight) { processPlyvmh(eclState); - - // handling PLYMWINJ keyword - const auto& plymwinjTables = tableManager.getPlymwinjTables(); - for (const auto& table : plymwinjTables) { - const int tableNumber = table.first; - const auto& plymwinjtable = table.second; - const std::vector& throughput = plymwinjtable.getThroughputs(); - const std::vector& watervelocity = plymwinjtable.getVelocities(); - const std::vector>& molecularweight = plymwinjtable.getMoleWeights(); - if constexpr (std::is_same_v) { - const std::vector tp(throughput.begin(), throughput.end()); - const std::vector wv(watervelocity.begin(), watervelocity.end()); - const auto mw = convertVecToVec(molecularweight); - TabulatedTwoDFunction tablefunc(tp, wv, mw, true, false); - plymwinjTables_[tableNumber] = std::move(tablefunc); - } else { - TabulatedTwoDFunction tablefunc(throughput, watervelocity, molecularweight, true, false); - plymwinjTables_[tableNumber] = std::move(tablefunc); - } - } + processPlymwinj(eclState); // handling SKPRWAT keyword const auto& skprwatTables = tableManager.getSkprwatTables(); @@ -453,6 +434,31 @@ processPlyvmh(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processPlymwinj(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& plymwinjTables = tableManager.getPlymwinjTables(); + for (const auto& table : plymwinjTables) { + const int tableNumber = table.first; + const auto& plymwinjtable = table.second; + const std::vector& throughput = plymwinjtable.getThroughputs(); + const std::vector& watervelocity = plymwinjtable.getVelocities(); + const std::vector>& molecularweight = plymwinjtable.getMoleWeights(); + if constexpr (std::is_same_v) { + const std::vector tp(throughput.begin(), throughput.end()); + const std::vector wv(watervelocity.begin(), watervelocity.end()); + const auto mw = convertVecToVec(molecularweight); + TabulatedTwoDFunction tablefunc(tp, wv, mw, true, false); + plymwinjTables_[tableNumber] = std::move(tablefunc); + } else { + TabulatedTwoDFunction tablefunc(throughput, watervelocity, molecularweight, true, false); + plymwinjTables_[tableNumber] = std::move(tablefunc); + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 4fcb5e036b2..4b1616cdd74 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -154,6 +154,11 @@ struct BlackOilPolymerParams { * \brief Process the Plyvmh data. */ void processPlyvmh(const EclipseState& eclState); + + /*! + * \brief Process the Plymwinj data. + */ + void processPlymwinj(const EclipseState& eclState); }; } // namespace Opm From e427c055d568db5855eb95bc3002c155de8594f2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 16/29] BlackOilPolymerParams: separate out Skprwat processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 46 +++++++++++-------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 ++ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index 6f2267aabf3..292dbbb1a1e 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -146,26 +146,7 @@ initFromState(const EclipseState& eclState) if constexpr (enablePolymerMolarWeight) { processPlyvmh(eclState); processPlymwinj(eclState); - - // handling SKPRWAT keyword - const auto& skprwatTables = tableManager.getSkprwatTables(); - for (const auto& table : skprwatTables) { - const int tableNumber = table.first; - const auto& skprwattable = table.second; - const std::vector& throughput = skprwattable.getThroughputs(); - const std::vector& watervelocity = skprwattable.getVelocities(); - const std::vector>& skinpressure = skprwattable.getSkinPressures(); - if constexpr (std::is_same_v) { - const std::vector tp(throughput.begin(), throughput.end()); - const std::vector wv(watervelocity.begin(), watervelocity.end()); - const auto sp = convertVecToVec(skinpressure); - TabulatedTwoDFunction tablefunc(tp, wv, sp, true, false); - skprwatTables_[tableNumber] = std::move(tablefunc); - } else { - TabulatedTwoDFunction tablefunc(throughput, watervelocity, skinpressure, true, false); - skprwatTables_[tableNumber] = std::move(tablefunc); - } - } + processSkprwat(eclState); // handling SKPRPOLY keyword const auto& skprpolyTables = tableManager.getSkprpolyTables(); @@ -459,6 +440,31 @@ processPlymwinj(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processSkprwat(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& skprwatTables = tableManager.getSkprwatTables(); + for (const auto& table : skprwatTables) { + const int tableNumber = table.first; + const auto& skprwattable = table.second; + const std::vector& throughput = skprwattable.getThroughputs(); + const std::vector& watervelocity = skprwattable.getVelocities(); + const std::vector>& skinpressure = skprwattable.getSkinPressures(); + if constexpr (std::is_same_v) { + const std::vector tp(throughput.begin(), throughput.end()); + const std::vector wv(watervelocity.begin(), watervelocity.end()); + const auto sp = convertVecToVec(skinpressure); + TabulatedTwoDFunction tablefunc(tp, wv, sp, true, false); + skprwatTables_[tableNumber] = std::move(tablefunc); + } else { + TabulatedTwoDFunction tablefunc(throughput, watervelocity, skinpressure, true, false); + skprwatTables_[tableNumber] = std::move(tablefunc); + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 4b1616cdd74..981377515a8 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -159,6 +159,11 @@ struct BlackOilPolymerParams { * \brief Process the Plymwinj data. */ void processPlymwinj(const EclipseState& eclState); + + /*! + * \brief Process the Skprwat data. + */ + void processSkprwat(const EclipseState& eclState); }; } // namespace Opm From 99a3f3469899d148afbf3d07be358b196916e6e5 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 17/29] BlackOilPolymerParams: separate out Skprpoly processing to lower congnitive load --- opm/models/blackoil/blackoilpolymerparams.cpp | 60 ++++++++++--------- opm/models/blackoil/blackoilpolymerparams.hpp | 5 ++ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/opm/models/blackoil/blackoilpolymerparams.cpp b/opm/models/blackoil/blackoilpolymerparams.cpp index 292dbbb1a1e..4008cfa4930 100644 --- a/opm/models/blackoil/blackoilpolymerparams.cpp +++ b/opm/models/blackoil/blackoilpolymerparams.cpp @@ -147,33 +147,7 @@ initFromState(const EclipseState& eclState) processPlyvmh(eclState); processPlymwinj(eclState); processSkprwat(eclState); - - // handling SKPRPOLY keyword - const auto& skprpolyTables = tableManager.getSkprpolyTables(); - for (const auto& table : skprpolyTables) { - const int tableNumber = table.first; - const auto& skprpolytable = table.second; - const std::vector& throughput = skprpolytable.getThroughputs(); - const std::vector& watervelocity = skprpolytable.getVelocities(); - const std::vector>& skinpressure = skprpolytable.getSkinPressures(); - const double refPolymerConcentration = skprpolytable.referenceConcentration(); - if constexpr (std::is_same_v) { - const std::vector tp(throughput.begin(), throughput.end()); - const std::vector wv(watervelocity.begin(), watervelocity.end()); - const auto sp = convertVecToVec(skinpressure); - SkprpolyTable tablefunc { - refPolymerConcentration, - TabulatedTwoDFunction(tp, wv, sp, true, false) - }; - skprpolyTables_[tableNumber] = std::move(tablefunc); - } else { - SkprpolyTable tablefunc { - refPolymerConcentration, - TabulatedTwoDFunction(throughput, watervelocity, skinpressure, true, false) - }; - skprpolyTables_[tableNumber] = std::move(tablefunc); - } - } + processSkprpoly(eclState); } } @@ -465,6 +439,38 @@ processSkprwat(const EclipseState& eclState) } } +template +void BlackOilPolymerParams:: +processSkprpoly(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& skprpolyTables = tableManager.getSkprpolyTables(); + for (const auto& table : skprpolyTables) { + const int tableNumber = table.first; + const auto& skprpolytable = table.second; + const std::vector& throughput = skprpolytable.getThroughputs(); + const std::vector& watervelocity = skprpolytable.getVelocities(); + const std::vector>& skinpressure = skprpolytable.getSkinPressures(); + const double refPolymerConcentration = skprpolytable.referenceConcentration(); + if constexpr (std::is_same_v) { + const std::vector tp(throughput.begin(), throughput.end()); + const std::vector wv(watervelocity.begin(), watervelocity.end()); + const auto sp = convertVecToVec(skinpressure); + SkprpolyTable tablefunc { + refPolymerConcentration, + TabulatedTwoDFunction(tp, wv, sp, true, false) + }; + skprpolyTables_[tableNumber] = std::move(tablefunc); + } else { + SkprpolyTable tablefunc { + refPolymerConcentration, + TabulatedTwoDFunction(throughput, watervelocity, skinpressure, true, false) + }; + skprpolyTables_[tableNumber] = std::move(tablefunc); + } + } +} + template void BlackOilPolymerParams:: setPlyrock(unsigned satRegionIdx, diff --git a/opm/models/blackoil/blackoilpolymerparams.hpp b/opm/models/blackoil/blackoilpolymerparams.hpp index 981377515a8..b062c7e0273 100644 --- a/opm/models/blackoil/blackoilpolymerparams.hpp +++ b/opm/models/blackoil/blackoilpolymerparams.hpp @@ -164,6 +164,11 @@ struct BlackOilPolymerParams { * \brief Process the Skprwat data. */ void processSkprwat(const EclipseState& eclState); + + /*! + * \brief Process the Skprpoly data. + */ + void processSkprpoly(const EclipseState& eclState); }; } // namespace Opm From b8943d8a877ffd2dd391e8c1abd7d83c482874ce Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 18/29] BlackOilSolventParams: separate out state verification to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index 465a920df86..1c422d41fc1 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -34,27 +34,36 @@ #include #include -namespace Opm { +namespace { -template template -void BlackOilSolventParams:: -initFromState(const EclipseState& eclState, const Schedule& schedule) +void verifyState(const Opm::EclipseState& eclState) { // some sanity checks: if solvents are enabled, the SOLVENT keyword must be // present, if solvents are disabled the keyword must not be present. if constexpr (enableSolvent) { - if (!eclState.runspec().phases().active(Phase::SOLVENT)) { + if (!eclState.runspec().phases().active(Opm::Phase::SOLVENT)) { throw std::runtime_error("Non-trivial solvent treatment requested at compile " "time, but the deck does not contain the SOLVENT keyword"); } } else { - if (eclState.runspec().phases().active(Phase::SOLVENT)) { + if (eclState.runspec().phases().active(Opm::Phase::SOLVENT)) { throw std::runtime_error("Solvent treatment disabled at compile time, but the deck " "contains the SOLVENT keyword"); } } +} + +} +namespace Opm { + +template +template +void BlackOilSolventParams:: +initFromState(const EclipseState& eclState, const Schedule& schedule) +{ + verifyState(eclState); if (!eclState.runspec().phases().active(Phase::SOLVENT)) { return; // solvent treatment is supposed to be disabled } From c78ff6fb479d8726786988bcbbf51855d6c94d81 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 13:05:34 +0200 Subject: [PATCH 19/29] BlackOilSolventParams: mark utility methods private --- opm/models/blackoil/blackoilsolventparams.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 3d2ba1c397a..42afab61152 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -80,8 +80,9 @@ struct BlackOilSolventParams bool co2sol_ = false; bool h2sol_ = false; +private: /*! - * \brief Specify the number of satuation regions. + * \brief Specify the number of saturation regions. * * This must be called before setting the SSFN of any region. */ From 4a13c8b58f6b8d181321c99c071e54467e89bb45 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 13:05:34 +0200 Subject: [PATCH 20/29] BlackOilSolventParams: split out pvt setup to lower cognitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 51 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 6 +++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index 1c422d41fc1..f05c3d9b115 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -68,26 +68,7 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) return; // solvent treatment is supposed to be disabled } - co2sol_ = eclState.runspec().co2Sol(); - h2sol_ = eclState.runspec().h2Sol(); - - if (co2sol_ && h2sol_) { - throw std::runtime_error("CO2SOL and H2SOL can not be used together"); - } - - if (co2sol_ || h2sol_) { - if (co2sol_) { - co2GasPvt_.initFromState(eclState, schedule); - brineCo2Pvt_.initFromState(eclState, schedule); - } else { - h2GasPvt_.initFromState(eclState, schedule); - brineH2Pvt_.initFromState(eclState, schedule); - } - if (eclState.getSimulationConfig().hasDISGASW()) { - rsSolw_active_ = true; - } - } else - solventPvt_.initFromState(eclState, schedule); + setupPvts(eclState, schedule); const auto& tableManager = eclState.getTableManager(); // initialize the objects which deal with the SSFN keyword @@ -325,6 +306,36 @@ setMsfn(unsigned satRegionIdx, msfnKro_[satRegionIdx] = msfnKro; } +template +void BlackOilSolventParams:: +setupPvts(const EclipseState& eclState, + const Schedule& schedule) +{ + co2sol_ = eclState.runspec().co2Sol(); + h2sol_ = eclState.runspec().h2Sol(); + + if (co2sol_ && h2sol_) { + throw std::runtime_error("CO2SOL and H2SOL can not be used together"); + } + + if (co2sol_ || h2sol_) { + if (co2sol_) { + co2GasPvt_.initFromState(eclState, schedule); + brineCo2Pvt_.initFromState(eclState, schedule); + } + else { + h2GasPvt_.initFromState(eclState, schedule); + brineH2Pvt_.initFromState(eclState, schedule); + } + if (eclState.getSimulationConfig().hasDISGASW()) { + rsSolw_active_ = true; + } + } + else { + solventPvt_.initFromState(eclState, schedule); + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 42afab61152..1507acf6a33 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -96,6 +96,12 @@ struct BlackOilSolventParams void setMsfn(unsigned satRegionIdx, const TabulatedFunction& msfnKrsg, const TabulatedFunction& msfnKro); + + /*! + * \brief Setup active pvt members. + */ + void setupPvts(const EclipseState& eclState, + const Schedule& schedule); }; } // namespace Opm From c20e4b48e4395686c34cb379766d70a4e920952c Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 21/29] BlackOilSolventParams: separate out SSFN processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 33 ++++++++++++------- opm/models/blackoil/blackoilsolventparams.hpp | 5 +++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index f05c3d9b115..2284aa703ed 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -69,21 +69,10 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) } setupPvts(eclState, schedule); + processSsfn(eclState); const auto& tableManager = eclState.getTableManager(); - // initialize the objects which deal with the SSFN keyword - const auto& ssfnTables = tableManager.getSsfnTables(); unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); - setNumSatRegions(numSatRegions); - for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { - const auto& ssfnTable = ssfnTables.template getTable(satRegionIdx); - ssfnKrg_[satRegionIdx].setXYContainers(ssfnTable.getSolventFractionColumn(), - ssfnTable.getGasRelPermMultiplierColumn(), - /*sortInput=*/true); - ssfnKrs_[satRegionIdx].setXYContainers(ssfnTable.getSolventFractionColumn(), - ssfnTable.getSolventRelPermMultiplierColumn(), - /*sortInput=*/true); - } // initialize the objects needed for miscible solvent and oil simulations isMiscible_ = false; @@ -336,6 +325,26 @@ setupPvts(const EclipseState& eclState, } } +template +void BlackOilSolventParams:: +processSsfn(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + // initialize the objects which deal with the SSFN keyword + const auto& ssfnTables = tableManager.getSsfnTables(); + const unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); + setNumSatRegions(numSatRegions); + for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { + const auto& ssfnTable = ssfnTables.template getTable(satRegionIdx); + ssfnKrg_[satRegionIdx].setXYContainers(ssfnTable.getSolventFractionColumn(), + ssfnTable.getGasRelPermMultiplierColumn(), + /*sortInput=*/true); + ssfnKrs_[satRegionIdx].setXYContainers(ssfnTable.getSolventFractionColumn(), + ssfnTable.getSolventRelPermMultiplierColumn(), + /*sortInput=*/true); + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 1507acf6a33..5b3c3771dd0 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -102,6 +102,11 @@ struct BlackOilSolventParams */ void setupPvts(const EclipseState& eclState, const Schedule& schedule); + + /*! + * \brief Process the SSFN data. + */ + void processSsfn(const EclipseState& eclState); }; } // namespace Opm From cf9481f3f94f60b71911702b5336e985cfe99bfa Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 22/29] BlackOilSolventParams: separate out SOF2 processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 41 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 +++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index 2284aa703ed..eecbdee816d 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -78,24 +78,8 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) isMiscible_ = false; if (!eclState.getTableManager().getMiscTables().empty()) { isMiscible_ = true; - unsigned numMiscRegions = 1; - - // misicible hydrocabon relative permeability wrt water - const auto& sof2Tables = tableManager.getSof2Tables(); - if (!sof2Tables.empty()) { - // resize the attributes of the object - sof2Krn_.resize(numSatRegions); - for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { - const auto& sof2Table = sof2Tables.template getTable(satRegionIdx); - sof2Krn_[satRegionIdx].setXYContainers(sof2Table.getSoColumn(), - sof2Table.getKroColumn(), - /*sortInput=*/true); - } - } - else if (eclState.runspec().phases().active(Phase::OIL)) { - throw std::runtime_error("SOF2 must be specified in MISCIBLE (SOLVENT and OIL) runs\n"); - } + processSof2(eclState); const auto& miscTables = tableManager.getMiscTables(); if (!miscTables.empty()) { @@ -345,6 +329,29 @@ processSsfn(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processSof2(const EclipseState& eclState) +{ + // miscible hydrocarbon relative permeability wrt water + const auto& tableManager = eclState.getTableManager(); + const auto& sof2Tables = tableManager.getSof2Tables(); + const unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); + if (!sof2Tables.empty()) { + // resize the attributes of the object + sof2Krn_.resize(numSatRegions); + for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) { + const auto& sof2Table = sof2Tables.template getTable(satRegionIdx); + sof2Krn_[satRegionIdx].setXYContainers(sof2Table.getSoColumn(), + sof2Table.getKroColumn(), + /*sortInput=*/true); + } + } + else if (eclState.runspec().phases().active(Phase::OIL)) { + throw std::runtime_error("SOF2 must be specified in MISCIBLE (SOLVENT and OIL) runs\n"); + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 5b3c3771dd0..2263f0687cf 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -107,6 +107,11 @@ struct BlackOilSolventParams * \brief Process the SSFN data. */ void processSsfn(const EclipseState& eclState); + + /*! + * \brief Process the SOF2 data. + */ + void processSof2(const EclipseState& eclState); }; } // namespace Opm From 550fa2610e590699aa970e3ae1e05139cd91a993 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 23/29] BlackOilSolventParams: separate out MISC processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 50 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 ++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index eecbdee816d..1e4a8d09712 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -76,29 +76,11 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) // initialize the objects needed for miscible solvent and oil simulations isMiscible_ = false; - if (!eclState.getTableManager().getMiscTables().empty()) { + if (!tableManager.getMiscTables().empty()) { isMiscible_ = true; - unsigned numMiscRegions = 1; + const unsigned numMiscRegions = 1; processSof2(eclState); - - const auto& miscTables = tableManager.getMiscTables(); - if (!miscTables.empty()) { - assert(numMiscRegions == miscTables.size()); - - // resize the attributes of the object - misc_.resize(numMiscRegions); - for (unsigned miscRegionIdx = 0; miscRegionIdx < numMiscRegions; ++miscRegionIdx) { - const auto& miscTable = miscTables.template getTable(miscRegionIdx); - - // solventFraction = Ss / (Ss + Sg); - const auto& solventFraction = miscTable.getSolventFractionColumn(); - const auto& misc = miscTable.getMiscibilityColumn(); - misc_[miscRegionIdx].setXYContainers(solventFraction, misc); - } - } - else { - throw std::runtime_error("MISC must be specified in MISCIBLE (SOLVENT) runs\n"); - } + processMisc(eclState); // resize the attributes of the object pmisc_.resize(numMiscRegions); @@ -352,6 +334,32 @@ processSof2(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processMisc(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const auto& miscTables = tableManager.getMiscTables(); + const unsigned numMiscRegions = 1; + if (!miscTables.empty()) { + assert(numMiscRegions == miscTables.size()); + + // resize the attributes of the object + misc_.resize(numMiscRegions); + for (unsigned miscRegionIdx = 0; miscRegionIdx < numMiscRegions; ++miscRegionIdx) { + const auto& miscTable = miscTables.template getTable(miscRegionIdx); + + // solventFraction = Ss / (Ss + Sg); + const auto& solventFraction = miscTable.getSolventFractionColumn(); + const auto& misc = miscTable.getMiscibilityColumn(); + misc_[miscRegionIdx].setXYContainers(solventFraction, misc); + } + } + else { + throw std::runtime_error("MISC must be specified in MISCIBLE (SOLVENT) runs\n"); + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 2263f0687cf..014ff1c47f0 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -112,6 +112,11 @@ struct BlackOilSolventParams * \brief Process the SOF2 data. */ void processSof2(const EclipseState& eclState); + + /*! + * \brief Process the MISC data. + */ + void processMisc(const EclipseState& eclState); }; } // namespace Opm From 3d343e1f8558da269b20b4dadfc17852717a0a56 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 24/29] BlackOilSolventParams: separate out PMISC processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 59 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 ++ 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index 1e4a8d09712..87de8467e2c 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -81,31 +81,7 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) const unsigned numMiscRegions = 1; processSof2(eclState); processMisc(eclState); - - // resize the attributes of the object - pmisc_.resize(numMiscRegions); - const auto& pmiscTables = tableManager.getPmiscTables(); - if (!pmiscTables.empty()) { - assert(numMiscRegions == pmiscTables.size()); - - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - const auto& pmiscTable = pmiscTables.template getTable(regionIdx); - - // Copy data - const auto& po = pmiscTable.getOilPhasePressureColumn(); - const auto& pmisc = pmiscTable.getMiscibilityColumn(); - - pmisc_[regionIdx].setXYContainers(po, pmisc); - } - } - else { - std::vector x = {0.0,1.0e20}; - std::vector y = {1.0,1.0}; - TabulatedFunction constant = TabulatedFunction(2, x, y); - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - pmisc_[regionIdx] = constant; - } - } + processPmisc(eclState); // miscible relative permeability multipleiers msfnKrsg_.resize(numSatRegions); @@ -360,6 +336,39 @@ processMisc(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processPmisc(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numMiscRegions = 1; + + // resize the attributes of the object + pmisc_.resize(numMiscRegions); + const auto& pmiscTables = tableManager.getPmiscTables(); + if (!pmiscTables.empty()) { + assert(numMiscRegions == pmiscTables.size()); + + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + const auto& pmiscTable = pmiscTables.template getTable(regionIdx); + + // Copy data + const auto& po = pmiscTable.getOilPhasePressureColumn(); + const auto& pmisc = pmiscTable.getMiscibilityColumn(); + + pmisc_[regionIdx].setXYContainers(po, pmisc); + } + } + else { + const std::vector x = {0.0,1.0e20}; + const std::vector y = {1.0,1.0}; + const TabulatedFunction constant = TabulatedFunction(2, x, y); + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + pmisc_[regionIdx] = constant; + } + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 014ff1c47f0..4383bd1ef68 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -117,6 +117,11 @@ struct BlackOilSolventParams * \brief Process the MISC data. */ void processMisc(const EclipseState& eclState); + + /*! + * \brief Process the PMISC data. + */ + void processPmisc(const EclipseState& eclState); }; } // namespace Opm From fd8156b0b9b3a5eabcc2753e7f652816a33fd502 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 25/29] BlackOilSolventParams: separate out MSFN processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 71 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 ++ 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index 87de8467e2c..20d552e308d 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -72,7 +72,6 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) processSsfn(eclState); const auto& tableManager = eclState.getTableManager(); - unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); // initialize the objects needed for miscible solvent and oil simulations isMiscible_ = false; @@ -82,37 +81,8 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) processSof2(eclState); processMisc(eclState); processPmisc(eclState); + processMsfn(eclState); - // miscible relative permeability multipleiers - msfnKrsg_.resize(numSatRegions); - msfnKro_.resize(numSatRegions); - const auto& msfnTables = tableManager.getMsfnTables(); - if (!msfnTables.empty()) { - assert(numSatRegions == msfnTables.size()); - - for (unsigned regionIdx = 0; regionIdx < numSatRegions; ++regionIdx) { - const MsfnTable& msfnTable = msfnTables.template getTable(regionIdx); - - // Copy data - // Ssg = Ss + Sg; - const auto& Ssg = msfnTable.getGasPhaseFractionColumn(); - const auto& krsg = msfnTable.getGasSolventRelpermMultiplierColumn(); - const auto& kro = msfnTable.getOilRelpermMultiplierColumn(); - - msfnKrsg_[regionIdx].setXYContainers(Ssg, krsg); - msfnKro_[regionIdx].setXYContainers(Ssg, kro); - } - } - else { - std::vector x = {0.0,1.0}; - std::vector y = {1.0,0.0}; - TabulatedFunction unit = TabulatedFunction(2, x, x); - TabulatedFunction invUnit = TabulatedFunction(2, x, y); - - for (unsigned regionIdx = 0; regionIdx < numSatRegions; ++regionIdx) { - setMsfn(regionIdx, unit, invUnit); - } - } // resize the attributes of the object sorwmis_.resize(numMiscRegions); const auto& sorwmisTables = tableManager.getSorwmisTables(); @@ -369,6 +339,45 @@ processPmisc(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processMsfn(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numSatRegions = tableManager.getTabdims().getNumSatTables(); + + // miscible relative permeability multipleiers + msfnKrsg_.resize(numSatRegions); + msfnKro_.resize(numSatRegions); + const auto& msfnTables = tableManager.getMsfnTables(); + if (!msfnTables.empty()) { + assert(numSatRegions == msfnTables.size()); + + for (unsigned regionIdx = 0; regionIdx < numSatRegions; ++regionIdx) { + const MsfnTable& msfnTable = msfnTables.template getTable(regionIdx); + + // Copy data + // Ssg = Ss + Sg; + const auto& Ssg = msfnTable.getGasPhaseFractionColumn(); + const auto& krsg = msfnTable.getGasSolventRelpermMultiplierColumn(); + const auto& kro = msfnTable.getOilRelpermMultiplierColumn(); + + msfnKrsg_[regionIdx].setXYContainers(Ssg, krsg); + msfnKro_[regionIdx].setXYContainers(Ssg, kro); + } + } + else { + const std::vector x = {0.0,1.0}; + const std::vector y = {1.0,0.0}; + const TabulatedFunction unit = TabulatedFunction(2, x, x); + const TabulatedFunction invUnit = TabulatedFunction(2, x, y); + + for (unsigned regionIdx = 0; regionIdx < numSatRegions; ++regionIdx) { + setMsfn(regionIdx, unit, invUnit); + } + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 4383bd1ef68..4abf699c680 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -122,6 +122,11 @@ struct BlackOilSolventParams * \brief Process the PMISC data. */ void processPmisc(const EclipseState& eclState); + + /*! + * \brief Process the MSFN data. + */ + void processMsfn(const EclipseState& eclState); }; } // namespace Opm From 8ff2a1e6430763fda6fe1540d9bf303f3de31561 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 26/29] BlackOilSolventParams: separate out SORWMIS processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 59 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 ++ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index 20d552e308d..b1279cce940 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -82,32 +82,7 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) processMisc(eclState); processPmisc(eclState); processMsfn(eclState); - - // resize the attributes of the object - sorwmis_.resize(numMiscRegions); - const auto& sorwmisTables = tableManager.getSorwmisTables(); - if (!sorwmisTables.empty()) { - assert(numMiscRegions == sorwmisTables.size()); - - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - const auto& sorwmisTable = sorwmisTables.template getTable(regionIdx); - - // Copy data - const auto& sw = sorwmisTable.getWaterSaturationColumn(); - const auto& sorwmis = sorwmisTable.getMiscibleResidualOilColumn(); - - sorwmis_[regionIdx].setXYContainers(sw, sorwmis); - } - } - else { - // default - std::vector x = {0.0,1.0}; - std::vector y = {0.0,0.0}; - TabulatedFunction zero = TabulatedFunction(2, x, y); - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - sorwmis_[regionIdx] = zero; - } - } + processSorwmis(eclState); // resize the attributes of the object sgcwmis_.resize(numMiscRegions); @@ -378,6 +353,38 @@ processMsfn(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processSorwmis(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numMiscRegions = 1; + sorwmis_.resize(numMiscRegions); + const auto& sorwmisTables = tableManager.getSorwmisTables(); + if (!sorwmisTables.empty()) { + assert(numMiscRegions == sorwmisTables.size()); + + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + const auto& sorwmisTable = sorwmisTables.template getTable(regionIdx); + + // Copy data + const auto& sw = sorwmisTable.getWaterSaturationColumn(); + const auto& sorwmis = sorwmisTable.getMiscibleResidualOilColumn(); + + sorwmis_[regionIdx].setXYContainers(sw, sorwmis); + } + } + else { + // default + const std::vector x = {0.0,1.0}; + const std::vector y = {0.0,0.0}; + const TabulatedFunction zero = TabulatedFunction(2, x, y); + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + sorwmis_[regionIdx] = zero; + } + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 4abf699c680..c429ea4aa93 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -127,6 +127,11 @@ struct BlackOilSolventParams * \brief Process the MSFN data. */ void processMsfn(const EclipseState& eclState); + + /*! + * \brief Process the SORWMIS data. + */ + void processSorwmis(const EclipseState& eclState); }; } // namespace Opm From c6641217a5caca653870a5b8d4a71ee45370f93c Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 27/29] BlackOilSolventParams: separate out SGCWMIS processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 60 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 ++ 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index b1279cce940..fd58b7a7725 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -83,31 +83,7 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) processPmisc(eclState); processMsfn(eclState); processSorwmis(eclState); - - // resize the attributes of the object - sgcwmis_.resize(numMiscRegions); - const auto& sgcwmisTables = tableManager.getSgcwmisTables(); - if (!sgcwmisTables.empty()) { - assert(numMiscRegions == sgcwmisTables.size()); - - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - const auto& sgcwmisTable = sgcwmisTables.template getTable(regionIdx); - - // Copy data - const auto& sw = sgcwmisTable.getWaterSaturationColumn(); - const auto& sgcwmis = sgcwmisTable.getMiscibleResidualGasColumn(); - - sgcwmis_[regionIdx].setXYContainers(sw, sgcwmis); - } - } - else { - // default - std::vector x = {0.0,1.0}; - std::vector y = {0.0,0.0}; - TabulatedFunction zero = TabulatedFunction(2, x, y); - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) - sgcwmis_[regionIdx] = zero; - } + processSgcwmis(eclState); const auto& tlmixpar = eclState.getTableManager().getTLMixpar(); if (!tlmixpar.empty()) { @@ -385,6 +361,40 @@ processSorwmis(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processSgcwmis(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numMiscRegions = 1; + + // resize the attributes of the object + sgcwmis_.resize(numMiscRegions); + const auto& sgcwmisTables = tableManager.getSgcwmisTables(); + if (!sgcwmisTables.empty()) { + assert(numMiscRegions == sgcwmisTables.size()); + + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + const auto& sgcwmisTable = sgcwmisTables.template getTable(regionIdx); + + // Copy data + const auto& sw = sgcwmisTable.getWaterSaturationColumn(); + const auto& sgcwmis = sgcwmisTable.getMiscibleResidualGasColumn(); + + sgcwmis_[regionIdx].setXYContainers(sw, sgcwmis); + } + } + else { + // default + const std::vector x = {0.0,1.0}; + const std::vector y = {0.0,0.0}; + const TabulatedFunction zero = TabulatedFunction(2, x, y); + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + sgcwmis_[regionIdx] = zero; + } + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index c429ea4aa93..023da770c4f 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -132,6 +132,11 @@ struct BlackOilSolventParams * \brief Process the SORWMIS data. */ void processSorwmis(const EclipseState& eclState); + + /*! + * \brief Process the SGCWMIS data. + */ + void processSgcwmis(const EclipseState& eclState); }; } // namespace Opm From df70acd93fbfc284a39aa5b987fc5892788994d3 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 28/29] BlackOilSolventParams: separate out TLMIXPAR processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 41 +++++++++++-------- opm/models/blackoil/blackoilsolventparams.hpp | 5 +++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index fd58b7a7725..e312515b506 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -84,22 +84,7 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) processMsfn(eclState); processSorwmis(eclState); processSgcwmis(eclState); - - const auto& tlmixpar = eclState.getTableManager().getTLMixpar(); - if (!tlmixpar.empty()) { - // resize the attributes of the object - tlMixParamViscosity_.resize(numMiscRegions); - tlMixParamDensity_.resize(numMiscRegions); - - assert(numMiscRegions == tlmixpar.size()); - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - const auto& tlp = tlmixpar[regionIdx]; - tlMixParamViscosity_[regionIdx] = tlp.viscosity_parameter; - tlMixParamDensity_[regionIdx] = tlp.density_parameter; - } - } - else - throw std::runtime_error("TLMIXPAR must be specified in MISCIBLE (SOLVENT) runs\n"); + processTlmixpar(eclState); // resize the attributes of the object tlPMixTable_.resize(numMiscRegions); @@ -395,6 +380,30 @@ processSgcwmis(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processTlmixpar(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numMiscRegions = 1; + const auto& tlmixpar = tableManager.getTLMixpar(); + if (!tlmixpar.empty()) { + // resize the attributes of the object + tlMixParamViscosity_.resize(numMiscRegions); + tlMixParamDensity_.resize(numMiscRegions); + + assert(numMiscRegions == tlmixpar.size()); + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + const auto& tlp = tlmixpar[regionIdx]; + tlMixParamViscosity_[regionIdx] = tlp.viscosity_parameter; + tlMixParamDensity_[regionIdx] = tlp.density_parameter; + } + } + else { + throw std::runtime_error("TLMIXPAR must be specified in MISCIBLE (SOLVENT) runs\n"); + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index 023da770c4f..d9f0868be11 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -137,6 +137,11 @@ struct BlackOilSolventParams * \brief Process the SGCWMIS data. */ void processSgcwmis(const EclipseState& eclState); + + /*! + * \brief Process the Tlmixpar data. + */ + void processTlmixpar(const EclipseState& eclState); }; } // namespace Opm From 295154f984ba2e5e07e9fccbda03eaa69384c820 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 28 May 2026 11:50:29 +0200 Subject: [PATCH 29/29] BlackOilSolventParams: separate out TLPMIXPA processing to lower congnitive load --- opm/models/blackoil/blackoilsolventparams.cpp | 76 +++++++++---------- opm/models/blackoil/blackoilsolventparams.hpp | 7 +- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/opm/models/blackoil/blackoilsolventparams.cpp b/opm/models/blackoil/blackoilsolventparams.cpp index e312515b506..cc6d9e258b8 100644 --- a/opm/models/blackoil/blackoilsolventparams.cpp +++ b/opm/models/blackoil/blackoilsolventparams.cpp @@ -77,7 +77,6 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) isMiscible_ = false; if (!tableManager.getMiscTables().empty()) { isMiscible_ = true; - const unsigned numMiscRegions = 1; processSof2(eclState); processMisc(eclState); processPmisc(eclState); @@ -85,43 +84,7 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) processSorwmis(eclState); processSgcwmis(eclState); processTlmixpar(eclState); - - // resize the attributes of the object - tlPMixTable_.resize(numMiscRegions); - if (!eclState.getTableManager().getTlpmixpaTables().empty()) { - const auto& tlpmixparTables = tableManager.getTlpmixpaTables(); - if (!tlpmixparTables.empty()) { - assert(numMiscRegions == tlpmixparTables.size()); - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { - const auto& tlpmixparTable = tlpmixparTables.template getTable(regionIdx); - - // Copy data - const auto& po = tlpmixparTable.getOilPhasePressureColumn(); - const auto& tlpmixpa = tlpmixparTable.getMiscibilityColumn(); - - tlPMixTable_[regionIdx].setXYContainers(po, tlpmixpa); - } - } - else { - // if empty keyword. Try to use the pmisc table as default. - if (!pmisc_.empty()) { - tlPMixTable_ = pmisc_; - } - else { - throw std::invalid_argument("If the pressure dependent TL values in " - "TLPMIXPA is defaulted (no entries), then " - "the PMISC tables must be specified."); - } - } - } - else { - // default - std::vector x = {0.0,1.0e20}; - std::vector y = {1.0,1.0}; - TabulatedFunction ones = TabulatedFunction(2, x, y); - for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) - tlPMixTable_[regionIdx] = ones; - } + processTlpmixpa(eclState); } } @@ -404,6 +367,43 @@ processTlmixpar(const EclipseState& eclState) } } +template +void BlackOilSolventParams:: +processTlpmixpa(const EclipseState& eclState) +{ + const auto& tableManager = eclState.getTableManager(); + const unsigned numMiscRegions = 1; + const auto& tlpmixparTables = tableManager.getTlpmixpaTables(); + + // resize the attributes of the object + tlPMixTable_.resize(numMiscRegions); + if (!tableManager.getTlpmixpaTables().empty()) { + assert(numMiscRegions == tlpmixparTables.size()); + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + const auto& tlpmixparTable = tlpmixparTables.template getTable(regionIdx); + + // Copy data + const auto& po = tlpmixparTable.getOilPhasePressureColumn(); + const auto& tlpmixpa = tlpmixparTable.getMiscibilityColumn(); + + tlPMixTable_[regionIdx].setXYContainers(po, tlpmixpa); + } + } + else { + OpmLog::warning("The pressure dependent TL values in " + "TLPMIXPA is missing or defaulted," + "using dummy values"); + + // default + const std::vector x = {0.0,1.0e20}; + const std::vector y = {1.0,1.0}; + const TabulatedFunction ones = TabulatedFunction(2, x, y); + for (unsigned regionIdx = 0; regionIdx < numMiscRegions; ++regionIdx) { + tlPMixTable_[regionIdx] = ones; + } + } +} + #define INSTANTIATE_TYPE(T) \ template struct BlackOilSolventParams; \ template void BlackOilSolventParams::initFromState(const EclipseState&, const Schedule&); \ diff --git a/opm/models/blackoil/blackoilsolventparams.hpp b/opm/models/blackoil/blackoilsolventparams.hpp index d9f0868be11..3562f691513 100644 --- a/opm/models/blackoil/blackoilsolventparams.hpp +++ b/opm/models/blackoil/blackoilsolventparams.hpp @@ -139,9 +139,14 @@ struct BlackOilSolventParams void processSgcwmis(const EclipseState& eclState); /*! - * \brief Process the Tlmixpar data. + * \brief Process the TLMIXPAR data. */ void processTlmixpar(const EclipseState& eclState); + + /*! + * \brief Process the TLPMIXPA data. + */ + void processTlpmixpa(const EclipseState& eclState); }; } // namespace Opm