From 7f3635145b9e15ffe0d5de498f0efac2aba8a3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 14 Jun 2023 09:20:25 +0200 Subject: [PATCH] Make solver object a member of SimulatorFullyImplicitBlackoilEbos. --- opm/simulators/flow/BlackoilModelEbos.hpp | 5 ---- .../SimulatorFullyImplicitBlackoilEbos.hpp | 27 ++++++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/opm/simulators/flow/BlackoilModelEbos.hpp b/opm/simulators/flow/BlackoilModelEbos.hpp index fcd6bd1ed..210543a27 100644 --- a/opm/simulators/flow/BlackoilModelEbos.hpp +++ b/opm/simulators/flow/BlackoilModelEbos.hpp @@ -1064,11 +1064,6 @@ namespace Opm { return convergence_reports_; } - std::vector getStepReportsDestructively() const - { - return std::move(this->convergence_reports_); - } - protected: // --------- Data members --------- diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp index 162f57e21..8608fd515 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp @@ -362,7 +362,9 @@ public: // Run a multiple steps of the solver depending on the time step control. solverTimer_->start(); - auto solver = createSolver(wellModel_()); + if (!solver_) { + solver_ = createSolver(wellModel_()); + } ebosSimulator_.startNextEpisode( ebosSimulator_.startTime() @@ -375,8 +377,7 @@ public: loadStep_ = -1; ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0); } - solver->model().beginReportStep(); - + solver_->model().beginReportStep(); bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning); // If sub stepping is enabled allow the solver to sub cycle @@ -398,13 +399,13 @@ public: events.hasEvent(ScheduleEvents::INJECTION_TYPE_CHANGED) || events.hasEvent(ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER) || events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE); - auto stepReport = adaptiveTimeStepping_->step(timer, *solver, event, nullptr); + auto stepReport = adaptiveTimeStepping_->step(timer, *solver_, event, nullptr); report_ += stepReport; //Pass simulation report to eclwriter for summary output ebosSimulator_.problem().setSimulationReport(report_); } else { // solve for complete report step - auto stepReport = solver->step(timer); + auto stepReport = solver_->step(timer); report_ += stepReport; if (terminalOutput_) { std::ostringstream ss; @@ -421,7 +422,7 @@ public: ebosSimulator_.problem().writeOutput(); report_.success.output_write_time += perfTimer.stop(); - solver->model().endReportStep(); + solver_->model().endReportStep(); // take time that was used to solve system for this reportStep solverTimer_->stop(); @@ -430,10 +431,10 @@ public: report_.success.solver_time += solverTimer_->secsSinceStart(); if (this->grid().comm().rank() == 0) { - // Destructively grab the step convergence reports. The solver - // object and the model object contained therein are about to go - // out of scope. - this->writeConvergenceOutput(solver->model().getStepReportsDestructively()); + // Grab the step convergence reports that are new since last we were here. + const auto& reps = solver_->model().stepReports(); + this->writeConvergenceOutput(std::vector{reps.begin() + already_reported_steps_, reps.end()}); + already_reported_steps_ = reps.size(); } // Increment timer, remember well state. @@ -486,6 +487,9 @@ public: serializer(adaptiveTimeStepping_); } + const Model& model() const + { return solver_->model(); } + protected: std::unique_ptr createSolver(WellModel& wellModel) @@ -702,12 +706,15 @@ protected: ModelParameters modelParam_; SolverParameters solverParam_; + std::unique_ptr solver_; + // Observed objects. PhaseUsage phaseUsage_; // Misc. data bool terminalOutput_; SimulatorReport report_; + std::size_t already_reported_steps_ = 0; std::unique_ptr solverTimer_; std::unique_ptr totalTimer_; std::unique_ptr adaptiveTimeStepping_;