From f83e99c6aafc2b5863653cd21691c842adaa0567 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Tue, 1 Oct 2019 14:30:11 +0200 Subject: [PATCH] sync restart --- ebos/eclwellmanager.hh | 7 +++ ebos/eclwriter.hh | 14 ++---- .../SimulatorFullyImplicitBlackoilEbos.hpp | 48 ++----------------- .../wells/BlackoilWellModel_impl.hpp | 2 + 4 files changed, 16 insertions(+), 55 deletions(-) diff --git a/ebos/eclwellmanager.hh b/ebos/eclwellmanager.hh index 8dbd99651..89d152b6c 100644 --- a/ebos/eclwellmanager.hh +++ b/ebos/eclwellmanager.hh @@ -39,6 +39,8 @@ #include #include #include +#include + #include #include @@ -613,6 +615,11 @@ public: reportStepIdx); } + void initFromRestartFile(const RestartValue& restartValues OPM_UNUSED){ + // not implemented + } + + protected: bool wellTopologyChanged_(const Opm::EclipseState& eclState OPM_UNUSED, const Opm::Schedule& schedule, diff --git a/ebos/eclwriter.hh b/ebos/eclwriter.hh index 0b173f1dd..daa38cbe3 100644 --- a/ebos/eclwriter.hh +++ b/ebos/eclwriter.hh @@ -418,16 +418,7 @@ public: eclOutputModule_.allocBuffers(numElements, restartStepIdx, /*isSubStep=*/false, /*log=*/false); { - /* - When running a restarted simulation the restart file is loaded - twice, first here as part of the state initialization and then - subsequently in the Simulator::run() method. The global - SummaryState instance is accumulates total variables like FOPT, if - the same instance is used twice when loading the restart file, the - cumulatives will be counted doubly, we therefor use a temporary - SummaryState instance in this call to loadRestart(). - */ - Opm::SummaryState summaryState(std::chrono::system_clock::from_time_t(simulator_.vanguard().schedule().getStartTime())); + Opm::SummaryState& summaryState = simulator_.vanguard().summaryState(); auto restartValues = eclIO_->loadRestart(summaryState, solutionKeys, extraKeys); for (unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) { @@ -442,6 +433,9 @@ public: thpres.setFromRestart(thpresValues); } restartTimeStepSize_ = restartValues.getExtra("OPMEXTRA")[0]; + + // initialize the well model from restart values + simulator_.problem().wellModel().initFromRestartFile(restartValues); } } diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp index 5e5e4ef32..9e73c7873 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp @@ -134,18 +134,6 @@ public: ebosSimulator_.setEpisodeIndex(-1); - // handle restarts - std::unique_ptr restartValues; - if (isRestart()) { - Opm::SummaryState& summaryState = ebosSimulator_.vanguard().summaryState(); - std::vector extraKeys = { - {"OPMEXTRA" , Opm::UnitSystem::measure::identity, false} - }; - - std::vector solutionKeys = {}; - restartValues.reset(new RestartValue(ebosSimulator_.problem().eclIO().loadRestart(summaryState, solutionKeys, extraKeys))); - } - // Create timers and file for writing timing info. Opm::time::StopWatch solverTimer; Opm::time::StopWatch totalTimer; @@ -164,46 +152,16 @@ public: adaptiveTimeStepping.reset(new TimeStepper(terminalOutput_)); } - double suggestedStepSize = -1.0; if (isRestart()) { - // This is a restart, determine the time step size from the restart data - if (restartValues->hasExtra("OPMEXTRA")) { - std::vector opmextra = restartValues->getExtra("OPMEXTRA"); - assert(opmextra.size() == 1); - suggestedStepSize = opmextra[0]; - } - else { - OpmLog::warning("Restart data is missing OPMEXTRA field, restart run may deviate from original run."); - suggestedStepSize = -1.0; - } - - if (suggestedStepSize > 0.0) { - adaptiveTimeStepping->setSuggestedNextStep(suggestedStepSize); - } + // For restarts the ebosSimulator may have gotten some information + // about the next timestep size from the OPMEXTRA field + adaptiveTimeStepping->setSuggestedNextStep(ebosSimulator_.timeStepSize()); } } SimulatorReport report; SimulatorReport stepReport; - if (isRestart()) { - // Set the start time of the simulation - const auto& schedule = ebosSimulator_.vanguard().schedule(); - const auto& eclState = ebosSimulator_.vanguard().eclState(); - const auto& timeMap = schedule.getTimeMap(); - const auto& initconfig = eclState.getInitConfig(); - int episodeIdx = initconfig.getRestartStep() - 1; - - ebosSimulator_.setStartTime(timeMap.getStartTime(/*timeStepIdx=*/0)); - ebosSimulator_.setTime(timeMap.getTimePassedUntil(episodeIdx)); - - ebosSimulator_.startNextEpisode(ebosSimulator_.startTime() + ebosSimulator_.time(), - timeMap.getTimeStepLength(episodeIdx)); - ebosSimulator_.setEpisodeIndex(episodeIdx); - wellModel_().beginEpisode(); - wellModel_().initFromRestartFile(*restartValues); - } - // Main simulation loop. while (!timer.done()) { // Report timestep. diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 17d93691d..cdb147cce 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -493,6 +493,8 @@ namespace Opm { const Wells* wells = wellsmanager.c_wells(); + wells_ecl_ = schedule().getWells2(report_step); + const int nw = wells->number_of_wells; if (nw > 0) { const auto phaseUsage = phaseUsageFromDeck(eclState());