From aa5940a2ff69bab9499f92f836cfadb062684129 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Mon, 20 Mar 2017 16:35:46 +0100 Subject: [PATCH] Prevent using dangling references in BlackoilModelEbos::updateState. Using cachedIntensiveQuantities on parallel grids will cause/is causing dereferencing a null pointer here. Therefore we resort to iterating over the grid and using the element Context. If this turns out ot be performance regression @andlaus owes me a beer! Closes #1110 --- opm/autodiff/BlackoilModelEbos.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/opm/autodiff/BlackoilModelEbos.hpp b/opm/autodiff/BlackoilModelEbos.hpp index 5df798688..0b2e9140d 100644 --- a/opm/autodiff/BlackoilModelEbos.hpp +++ b/opm/autodiff/BlackoilModelEbos.hpp @@ -586,7 +586,17 @@ namespace Opm { const int np = fluid_.numPhases(); const int nc = numCells(grid_); - for (int cell_idx = 0; cell_idx < nc; ++cell_idx) { + ElementContext elemCtx(ebosSimulator_); + const auto& gridView = grid_.leafGridView(); + const auto& elemEndIt = gridView.template end(); + for (auto elemIt = gridView.template begin(); + elemIt != elemEndIt; + ++elemIt) + { + const auto& elem = *elemIt; + elemCtx.updatePrimaryStencil(elem); + elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); + const unsigned cell_idx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0); const double& dp = dx[cell_idx][flowPhaseToEbosCompIdx(0)]; //reservoir_state.pressure()[cell_idx] -= dp; double& p = reservoir_state.pressure()[cell_idx]; @@ -668,7 +678,7 @@ namespace Opm { // phase translation sg <-> rs const HydroCarbonState hydroCarbonState = reservoir_state.hydroCarbonState()[cell_idx]; - const auto& intQuants = *(ebosSimulator_.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/0)); + const auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0); const auto& fs = intQuants.fluidState(); switch (hydroCarbonState) { case HydroCarbonState::GasAndOil: {