diff --git a/opm/autodiff/BlackoilModelEbos.hpp b/opm/autodiff/BlackoilModelEbos.hpp index 5276fe46e..efca6a432 100644 --- a/opm/autodiff/BlackoilModelEbos.hpp +++ b/opm/autodiff/BlackoilModelEbos.hpp @@ -1177,6 +1177,24 @@ namespace Opm { return values; } + void updateSimCache() const + { + const auto& simulator = ebosSimulator(); + // Force update of the cache for all elements + const auto& gridView = simulator.gridView(); + auto elemIt = gridView.template begin(); + const auto& elemEndIt = gridView.template end(); + ElementContext elemCtx(simulator); + for (; elemIt != elemEndIt; ++elemIt) { + + const auto& elem = *elemIt; + if (elem.partitionType() != Dune::InteriorEntity) + continue; + + elemCtx.updateAll(elem); + } + } + SimulationDataContainer getSimulatorData () const { typedef std::vector VectorType; @@ -1263,8 +1281,16 @@ namespace Opm { std::vector failed_cells_pb; std::vector failed_cells_pd; + if ( ebosModel.cachedIntensiveQuantities(/*cellIdx=*/0, /*timeIdx=*/0) == nullptr ) { + updateSimCache(); + } + for (int cellIdx = 0; cellIdx < numCells; ++cellIdx) { - const auto& intQuants = *ebosModel.cachedIntensiveQuantities(cellIdx, /*timeIdx=*/0); + const auto* intQuantsPtr = ebosModel.cachedIntensiveQuantities(cellIdx, /*timeIdx=*/0); + assert(intQuantsPtr != nullptr); + const auto& intQuants = *intQuantsPtr; + + const auto& fs = intQuants.fluidState(); const int satIdx = cellIdx * num_phases; diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp index 9b66c6acd..9bf9cb4b5 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp @@ -235,18 +235,6 @@ public: // give the polymer and surfactant simulators the chance to do their stuff handleAdditionalWellInflow(timer, wells_manager, well_state, wells); - // write the inital state at the report stage - if (timer.initialStep()) { - Dune::Timer perfTimer; - perfTimer.start(); - - // No per cell data is written for initial step, but will be - // for subsequent steps, when we have started simulating - output_writer_.writeTimeStepWithoutCellProperties( timer, state, well_state ); - - report.output_write_time += perfTimer.stop(); - } - // Compute reservoir volumes for RESV controls. computeRESV(timer.currentStepNum(), wells, state, well_state); @@ -257,6 +245,18 @@ public: auto solver = createSolver(well_model); + // write the inital state at the report stage + if (timer.initialStep()) { + Dune::Timer perfTimer; + perfTimer.start(); + + // No per cell data is written for initial step, but will be + // for subsequent steps, when we have started simulating + output_writer_.writeTimeStep( timer, state, well_state, solver->model() ); + + report.output_write_time += perfTimer.stop(); + } + // Compute orignal fluid in place if this has not been done yet if (originalFluidInPlace.empty()) { solver->model().convertInput(/*iterationIdx=*/0, state, ebosSimulator_ ); diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp index bcc099083..093b56567 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp @@ -532,6 +532,8 @@ namespace Opm /** * Returns the data requested in the restartConfig + * NOTE: Since this function steals data from the SimulationDataContainer (std::move), + * the variable sd becomes "invalid" after calling this function. */ template void getRestartData(data::Solution& output,