diff --git a/ebos/eclbasevanguard.hh b/ebos/eclbasevanguard.hh index 7663c5d7a..ff14a72b5 100644 --- a/ebos/eclbasevanguard.hh +++ b/ebos/eclbasevanguard.hh @@ -47,6 +47,7 @@ #include #include #include +#include #if HAVE_MPI @@ -351,6 +352,7 @@ public: else eclSchedule_ = externalEclSchedule_; this->summaryState_.reset( new Opm::SummaryState( std::chrono::system_clock::from_time_t(this->eclSchedule_->getStartTime() ))); + this->actionState_.reset( new Opm::Action::State() ); if (!externalEclSummaryConfig_) { // create the schedule object. Note that if eclState is supposed to represent @@ -447,6 +449,18 @@ public: const Opm::SummaryState& summaryState() const { return *summaryState_; } + + /*! + * \brief Returns the action state + * + * The ActionState keeps track of how many times the various actions have run. + */ + Opm::Action::State& actionState() + { return *actionState_; } + + const Opm::Action::State& actionState() const + { return *actionState_; } + /*! * \brief Parameter deciding the edge-weight strategy of the load balancer. */ @@ -617,6 +631,7 @@ private: std::unique_ptr internalEclSchedule_; std::unique_ptr internalEclSummaryConfig_; std::unique_ptr summaryState_; + std::unique_ptr actionState_; // these attributes point either to the internal or to the external version of the // parser objects. diff --git a/ebos/eclproblem.hh b/ebos/eclproblem.hh index c08f2ea14..66adc0b93 100644 --- a/ebos/eclproblem.hh +++ b/ebos/eclproblem.hh @@ -997,6 +997,7 @@ public: simulator.time() + simulator.timeStepSize(), ecl_state, schedule, + simulator.vanguard().actionState(), simulator.vanguard().summaryState()); } @@ -1062,6 +1063,7 @@ public: double sim_time, Opm::EclipseState& ecl_state, Opm::Schedule& schedule, + Opm::Action::State& actionState, Opm::SummaryState& summaryState) { const auto& actions = schedule.actions(reportStep); if (actions.empty()) @@ -1084,8 +1086,8 @@ public: } auto simTime = schedule.simTime(reportStep); - for (const auto& action : actions.pending(simTime)) { - auto actionResult = action->eval(simTime, context); + for (const auto& action : actions.pending(actionState, simTime)) { + auto actionResult = action->eval(context); if (actionResult) { std::string wells_string; const auto& matching_wells = actionResult.wells(); @@ -1097,6 +1099,7 @@ public: std::string msg = "The action: " + action->name() + " evaluated to true at " + ts + " wells: " + wells_string; Opm::OpmLog::info(msg); schedule.applyAction(reportStep, *action, actionResult); + actionState.add_run(*action, simTime); } else { std::string msg = "The action: " + action->name() + " evaluated to false at " + ts; Opm::OpmLog::info(msg); diff --git a/ebos/eclwriter.hh b/ebos/eclwriter.hh index b454ace25..710b76896 100644 --- a/ebos/eclwriter.hh +++ b/ebos/eclwriter.hh @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -395,7 +396,8 @@ public: restartValue.addExtra("OPMEXTRA", std::vector(1, nextStepSize)); // first, create a tasklet to write the data for the current time step to disk - auto eclWriteTasklet = std::make_shared(summaryState(), + auto eclWriteTasklet = std::make_shared(actionState(), + summaryState(), *eclIO_, reportStepNum, isSubStep, @@ -449,7 +451,8 @@ public: { Opm::SummaryState& summaryState = simulator_.vanguard().summaryState(); - auto restartValues = loadParallelRestart(eclIO_.get(), summaryState, solutionKeys, extraKeys, + Opm::Action::State& actionState = simulator_.vanguard().actionState(); + auto restartValues = loadParallelRestart(eclIO_.get(), actionState, summaryState, solutionKeys, extraKeys, gridView.grid().comm()); for (unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) { @@ -688,6 +691,7 @@ private: struct EclWriteTasklet : public TaskletInterface { + Opm::Action::State actionState_; Opm::SummaryState summaryState_; Opm::EclipseIO& eclIO_; int reportStepNum_; @@ -696,14 +700,16 @@ private: Opm::RestartValue restartValue_; bool writeDoublePrecision_; - explicit EclWriteTasklet(const Opm::SummaryState& summaryState, + explicit EclWriteTasklet(const Opm::Action::State& actionState, + const Opm::SummaryState& summaryState, Opm::EclipseIO& eclIO, int reportStepNum, bool isSubStep, double secondsElapsed, Opm::RestartValue restartValue, bool writeDoublePrecision) - : summaryState_(summaryState) + : actionState_(actionState) + , summaryState_(summaryState) , eclIO_(eclIO) , reportStepNum_(reportStepNum) , isSubStep_(isSubStep) @@ -715,7 +721,8 @@ private: // callback to eclIO serial writeTimeStep method void run() { - eclIO_.writeTimeStep(summaryState_, + eclIO_.writeTimeStep(actionState_, + summaryState_, reportStepNum_, isSubStep_, secondsElapsed_, @@ -730,6 +737,9 @@ private: Opm::SummaryState& summaryState() { return simulator_.vanguard().summaryState(); } + Opm::Action::State& actionState() + { return simulator_.vanguard().actionState(); } + const Opm::Schedule& schedule() const { return simulator_.vanguard().schedule(); } diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 225fbb6a5..8ac89e8da 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -818,7 +818,7 @@ INSTANTIATE_PACK(std::set) } // end namespace Mpi -RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summaryState, +RestartValue loadParallelRestart(const EclipseIO* eclIO, Action::State& actionState, SummaryState& summaryState, const std::vector& solutionKeys, const std::vector& extraKeys, Dune::CollectiveCommunication comm) @@ -831,7 +831,7 @@ RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summarySt if (eclIO) { assert(comm.rank() == 0); - restartValues = eclIO->loadRestart(summaryState, solutionKeys, extraKeys); + restartValues = eclIO->loadRestart(actionState, summaryState, solutionKeys, extraKeys); int packedSize = Mpi::packSize(restartValues, comm); std::vector buffer(packedSize); int position=0; diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 7d9746fed..a22bec96f 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -313,7 +314,7 @@ ADD_PACK_PROTOTYPES(std::string) } // end namespace Mpi -RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summaryState, +RestartValue loadParallelRestart(const EclipseIO* eclIO, Action::State& actionState, SummaryState& summaryState, const std::vector& solutionKeys, const std::vector& extraKeys, Dune::CollectiveCommunication comm); diff --git a/tests/test_ecl_output.cc b/tests/test_ecl_output.cc index 7b0600599..5273d58db 100644 --- a/tests/test_ecl_output.cc +++ b/tests/test_ecl_output.cc @@ -37,6 +37,7 @@ #include #include #include +#include #if HAVE_DUNE_FEM #include