diff --git a/opm/simulators/aquifers/AquiferInterface.hpp b/opm/simulators/aquifers/AquiferInterface.hpp index fcc997f8c..74180a2d9 100644 --- a/opm/simulators/aquifers/AquiferInterface.hpp +++ b/opm/simulators/aquifers/AquiferInterface.hpp @@ -143,24 +143,31 @@ public: const unsigned timeIdx) { const unsigned cellIdx = context.globalSpaceIndex(spaceIdx, timeIdx); + addToSource(rates, cellIdx, timeIdx); + } + + void addToSource(RateVector& rates, + const unsigned cellIdx, + const unsigned timeIdx) + { + const auto& model = ebos_simulator_.model(); const int idx = this->cellToConnectionIdx_[cellIdx]; if (idx < 0) return; - // We are dereferencing the value of IntensiveQuantities because - // cachedIntensiveQuantities return a const pointer to - // IntensiveQuantities of that particular cell_id - const auto& intQuants = context.intensiveQuantities(spaceIdx, timeIdx); + const auto* intQuantsPtr = model.cachedIntensiveQuantities(cellIdx, timeIdx); + if (intQuantsPtr == nullptr) { + throw std::logic_error("Invalid intensive quantities cache detected in AquiferInterface::addToSource()"); + } // This is the pressure at td + dt - this->updateCellPressure(this->pressure_current_, idx, intQuants); - this->calculateInflowRate(idx, context.simulator()); + this->updateCellPressure(this->pressure_current_, idx, *intQuantsPtr); + this->calculateInflowRate(idx, ebos_simulator_); rates[BlackoilIndices::conti0EqIdx + compIdx_()] - += this->Qai_[idx] / context.dofVolume(spaceIdx, timeIdx); + += this->Qai_[idx] / model.dofTotalVolume(cellIdx); } - std::size_t size() const { return this->connections_.size(); } diff --git a/opm/simulators/aquifers/BlackoilAquiferModel.hpp b/opm/simulators/aquifers/BlackoilAquiferModel.hpp index 1e2ae5468..342f614af 100644 --- a/opm/simulators/aquifers/BlackoilAquiferModel.hpp +++ b/opm/simulators/aquifers/BlackoilAquiferModel.hpp @@ -95,6 +95,7 @@ public: // add the water rate due to aquifers to the source term. template void addToSource(RateVector& rates, const Context& context, unsigned spaceIdx, unsigned timeIdx) const; + void addToSource(RateVector& rates, unsigned globalSpaceIdx, unsigned timeIdx) const; void endIteration(); void endTimeStep(); void endEpisode(); diff --git a/opm/simulators/aquifers/BlackoilAquiferModel_impl.hpp b/opm/simulators/aquifers/BlackoilAquiferModel_impl.hpp index 3ad985fc2..829c5835c 100644 --- a/opm/simulators/aquifers/BlackoilAquiferModel_impl.hpp +++ b/opm/simulators/aquifers/BlackoilAquiferModel_impl.hpp @@ -126,6 +126,24 @@ BlackoilAquiferModel::addToSource(RateVector& rates, } } +template +void +BlackoilAquiferModel::addToSource(RateVector& rates, + unsigned globalSpaceIdx, + unsigned timeIdx) const +{ + if (aquiferCarterTracyActive()) { + for (auto& aquifer : aquifers_CarterTracy) { + aquifer.addToSource(rates, globalSpaceIdx, timeIdx); + } + } + if (aquiferFetkovichActive()) { + for (auto& aquifer : aquifers_Fetkovich) { + aquifer.addToSource(rates, globalSpaceIdx, timeIdx); + } + } +} + template void BlackoilAquiferModel::endIteration()