diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index bf3568fc8a..a7b3b50de4 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -20,7 +20,6 @@ along with OPM. If not, see . */ - #ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED #define OPM_BLACKOILWELLMODEL_HEADER_INCLUDED @@ -198,39 +197,33 @@ template class WellContributions; data::Wells wellData() const { auto wsrpt = this->wellState() - .report(simulator_.vanguard().globalCell().data(), - [this](const int well_index) -> bool + .report(this->simulator_.vanguard().globalCell().data(), + [this](const int well_index) { return this->wasDynamicallyShutThisTimeStep(well_index); }); - { - const auto& tracerRates = this->simulator_.problem() - .tracerModel().getWellTracerRates(); - const auto& freeTracerRates = simulator_.problem() - .tracerModel().getWellFreeTracerRates(); - const auto& solTracerRates = simulator_.problem() - .tracerModel().getWellSolTracerRates(); - const auto& mswTracerRates = simulator_.problem() - .tracerModel().getMswTracerRates(); - - this->assignWellTracerRates(wsrpt, tracerRates, this->reportStepIndex()); - this->assignWellTracerRates(wsrpt, freeTracerRates, this->reportStepIndex()); - this->assignWellTracerRates(wsrpt, solTracerRates, this->reportStepIndex()); - this->assignMswTracerRates(wsrpt, mswTracerRates, this->reportStepIndex()); - } - BlackoilWellModelGuideRates(*this) .assignWellGuideRates(wsrpt, this->reportStepIndex()); - this->assignWellTargets(wsrpt); - this->assignShutConnections(wsrpt, this->reportStepIndex()); - // only used to compute gas injection mass rates for CO2STORE/H2STORE runs - // The gas reference density is thus the same for all pvt regions - // We therefore for simplicity use 0 here - if (eclState().runspec().co2Storage() || eclState().runspec().h2Storage()) { + this->assignWellTracerRates(wsrpt); + + if (const auto& rspec = eclState().runspec(); + rspec.co2Storage() || rspec.h2Storage()) + { + // The gas reference density (surface condition) is the + // same for all PVT regions in CO2STORE/H2STORE runs so, + // for simplicity, we use region zero (0) here. + this->assignMassGasRate(wsrpt, FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, 0)); } + + this->assignWellTargets(wsrpt); + + // Assigning (a subset of the) property values in shut + // connections should be the last step of wellData(). + this->assignShutConnections(wsrpt, this->reportStepIndex()); + return wsrpt; } @@ -512,11 +505,12 @@ template class WellContributions; // Their state is not relevant between function calls, so they can // (and must) be mutable, as the functions using them are const. mutable BVector x_local_; - }; + void assignWellTracerRates(data::Wells& wsrpt) const; + }; } // namespace Opm #include "BlackoilWellModel_impl.hpp" -#endif +#endif // OPM_BLACKOILWELLMODEL_HEADER_INCLUDED diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 28f0b628d9..ce095aec7b 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -1832,12 +1832,14 @@ getWellsForTesting(const int timeStepIdx, template void BlackoilWellModelGeneric:: assignMassGasRate(data::Wells& wsrpt, - const Scalar& gasDensity) const + const Scalar gasDensity) const { using rt = data::Rates::opt; + for (auto& wrpt : wsrpt) { auto& well_rates = wrpt.second.rates; const auto w_mass_rate = well_rates.get(rt::gas, 0.0) * gasDensity; + well_rates.set(rt::mass_gas, w_mass_rate); } } @@ -1870,8 +1872,9 @@ assignMswTracerRates(data::Wells& wsrpt, const MswTracerRates& mswTracerRates, const unsigned reportStep) const { - if (mswTracerRates.empty()) + if (mswTracerRates.empty()) { return; + } for (const auto& mswTR : mswTracerRates) { const auto& eclWell = schedule_.getWell(mswTR.first, reportStep); diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index 83e4173b08..2b0e50be84 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -461,7 +461,7 @@ protected: const unsigned reportStep) const; void assignMassGasRate(data::Wells& wsrpt, - const Scalar& gasDensity) const; + const Scalar gasDensity) const; Schedule& schedule_; const SummaryState& summaryState_; diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 7436422ddc..f09280b2aa 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -2351,6 +2351,22 @@ namespace Opm { } } } + + + template + void BlackoilWellModel:: + assignWellTracerRates(data::Wells& wsrpt) const + { + const auto reportStepIdx = static_cast(this->reportStepIndex()); + const auto& trMod = this->simulator_.problem().tracerModel(); + + BlackoilWellModelGeneric::assignWellTracerRates(wsrpt, trMod.getWellTracerRates(), reportStepIdx); + BlackoilWellModelGeneric::assignWellTracerRates(wsrpt, trMod.getWellFreeTracerRates(), reportStepIdx); + BlackoilWellModelGeneric::assignWellTracerRates(wsrpt, trMod.getWellSolTracerRates(), reportStepIdx); + + this->assignMswTracerRates(wsrpt, trMod.getMswTracerRates(), reportStepIdx); + } + } // namespace Opm -#endif +#endif // OPM_BLACKOILWELLMODEL_IMPL_HEADER_INCLUDED