From ad1fe8fac0e007e73210183bb171c076681d0744 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Mon, 20 Mar 2017 16:38:17 +0100 Subject: [PATCH] Prevent using dangling references in BlackoilModelEbos::getConvergence. 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! --- opm/autodiff/BlackoilModelEbos.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/opm/autodiff/BlackoilModelEbos.hpp b/opm/autodiff/BlackoilModelEbos.hpp index 0b2e9140d..31beeebf2 100644 --- a/opm/autodiff/BlackoilModelEbos.hpp +++ b/opm/autodiff/BlackoilModelEbos.hpp @@ -885,15 +885,27 @@ namespace Opm { const auto& ebosResid = ebosSimulator_.model().linearizer().residual(); + ElementContext elemCtx(ebosSimulator_); + const auto& gridView = grid_.leafGridView(); + const auto& elemEndIt = gridView.template end(); + for ( int idx = 0; idx < np; ++idx ) { Vector& R2_idx = R2[ idx ]; Vector& B_idx = B[ idx ]; const int ebosPhaseIdx = flowPhaseToEbosPhaseIdx(idx); const int ebosCompIdx = flowPhaseToEbosCompIdx(idx); + const auto& elemEndIt = gridView.template end(); - for (int cell_idx = 0; cell_idx < nc; ++cell_idx) { - const auto& intQuants = *(ebosSimulator_.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/0)); + 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 auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0); const auto& fs = intQuants.fluidState(); B_idx [cell_idx] = 1 / fs.invB(ebosPhaseIdx).value();