Merge pull request #2698 from joakim-hove/load-action-state

Load action state
This commit is contained in:
Joakim Hove
2021-09-22 12:35:52 +02:00
committed by GitHub
7 changed files with 58 additions and 16 deletions

View File

@@ -58,12 +58,14 @@ struct RstAction {
};
RstAction(const std::string& name_arg, int max_run_arg, double min_wait_arg, std::time_t start_time, std::vector<Condition> conditions_arg);
RstAction(const std::string& name_arg, int max_run_arg, int run_count_arg, double min_wait_arg, std::time_t start_time, std::time_t last_run, std::vector<Condition> conditions_arg);
std::string name;
int max_run;
int run_count;
double min_wait;
std::time_t start_time;
std::optional<std::time_t> last_run;
std::vector<Condition> conditions;
std::vector<DeckKeyword> keywords;
};

View File

@@ -38,7 +38,6 @@
namespace Opm {
class EclipseGrid;
class Parser;
class Actdims;
class Parser;
} // namespace Opm
@@ -104,7 +103,7 @@ private:
const std::vector<double>& dudf);
void add_actions(const Parser& parser,
const Actdims& actdims,
const Runspec& runspec,
std::time_t sim_time,
const std::vector<std::string>& zact,
const std::vector<int>& iact,

View File

@@ -26,9 +26,15 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp>
namespace Opm {
namespace RestartIO {
struct RstState;
}
namespace Action {
class ActionX;
class Actions;
class State {
struct RunState {
@@ -51,6 +57,7 @@ public:
std::size_t run_count(const ActionX& action) const;
std::time_t run_time(const ActionX& action) const;
std::optional<Result> result(const std::string& action) const;
void load_rst(const Actions& action_config, const RestartIO::RstState& rst_state);
private:
using action_id = std::pair<std::string, std::size_t>;
static action_id make_id(const ActionX& action);

View File

@@ -30,13 +30,16 @@ namespace SACN = Helpers::VectorItems::SACN;
namespace ZACN = Helpers::VectorItems::ZACN;
RstAction::RstAction(const std::string& name_arg, int max_run_arg, double min_wait_arg, std::time_t start_time_arg, std::vector<RstAction::Condition> conditions_arg)
RstAction::RstAction(const std::string& name_arg, int max_run_arg, int run_count_arg, double min_wait_arg, std::time_t start_time_arg, std::time_t last_run_arg, std::vector<RstAction::Condition> conditions_arg)
: name(name_arg)
, max_run(max_run_arg)
, run_count(run_count_arg)
, min_wait(min_wait_arg)
, start_time(start_time_arg)
, conditions(conditions_arg)
{
if (this->run_count > 0)
this->last_run = last_run_arg;
}

View File

@@ -30,6 +30,7 @@
#include <opm/io/eclipse/rst/state.hpp>
#include <opm/output/eclipse/WriteRestartHelpers.hpp>
#include <opm/common/utility/TimeService.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/common/utility/String.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
@@ -279,7 +280,7 @@ std::string oper_string(Action::Logical logic) {
void RstState::add_actions(const Parser& parser,
const Actdims& actdims,
const Runspec& runspec,
std::time_t sim_time,
const std::vector<std::string>& zact,
const std::vector<int>& iact,
@@ -289,6 +290,7 @@ void RstState::add_actions(const Parser& parser,
const std::vector<double>& sacn,
const std::vector<std::string>& zlact)
{
const auto& actdims = runspec.actdims();
auto zact_action_size = RestartIO::Helpers::entriesPerZACT();
auto iact_action_size = RestartIO::Helpers::entriesPerIACT();
auto sact_action_size = RestartIO::Helpers::entriesPerSACT();
@@ -314,8 +316,12 @@ void RstState::add_actions(const Parser& parser,
const auto& name = zact[index * zact_action_size + 0];
const auto& max_run = iact[index * iact_action_size + 5];
const auto& run_count = iact[index * iact_action_size + 2] - 1;
const auto& min_wait = this->unit_system.to_si(UnitSystem::measure::time, sact[index * sact_action_size + 3]);
this->actions.emplace_back(name, max_run, min_wait, sim_time, conditions );
const auto& last_run_elapsed = this->unit_system.to_si(UnitSystem::measure::time, sact[index * sact_action_size + 4]);
auto last_run_time = TimeService::advance( runspec.start_time(), last_run_elapsed );
this->actions.emplace_back(name, max_run, run_count, min_wait, sim_time, last_run_time, conditions );
std::string action_deck;
@@ -418,7 +424,7 @@ RstState RstState::load(std::shared_ptr<EclIO::RestartFileView> rstView,
const auto& iacn = rstView->getKeyword<int>("IACN");
const auto& sacn = rstView->getKeyword<double>("SACN");
const auto& zlact= rstView->getKeyword<std::string>("ZLACT");
state.add_actions(parser, runspec.actdims(), state.header.sim_time(), zact, iact, sact, zacn, iacn, sacn, zlact);
state.add_actions(parser, runspec, state.header.sim_time(), zact, iact, sact, zacn, iacn, sacn, zlact);
}

View File

@@ -23,6 +23,8 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
#include <opm/io/eclipse/rst/state.hpp>
namespace Opm {
namespace Action {
@@ -66,5 +68,20 @@ std::optional<Result> State::result(const std::string& action) const {
return iter->second;
}
/*
When restoring from restart file we initialize the number of times it has run
and the last run time. From the evaluation only the 'true' evaluation is
restored, not the well/group set.
*/
void State::load_rst(const Actions& action_config, const RestartIO::RstState& rst_state) {
for (const auto& rst_action : rst_state.actions) {
if (rst_action.run_count > 0) {
const auto& action = action_config[rst_action.name];
this->add_run(action, rst_action.last_run.value(), Action::Result{ true });
}
}
}
}
}

View File

@@ -30,6 +30,8 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
@@ -95,10 +97,10 @@ BOOST_AUTO_TEST_CASE(LoadRST) {
}
std::pair<Schedule, Schedule> load_schedule_pair(const std::string& base_deck,
const std::string& rst_deck,
const std::string& rst_fname,
std::size_t restart_step) {
std::tuple<Schedule, Schedule, RestartIO::RstState> load_schedule_pair(const std::string& base_deck,
const std::string& rst_deck,
const std::string& rst_fname,
std::size_t restart_step) {
Parser parser;
auto python = std::make_shared<Python>();
auto deck = parser.parseFile(base_deck);
@@ -112,7 +114,7 @@ std::pair<Schedule, Schedule> load_schedule_pair(const std::string& base_deck,
EclipseState ecl_state_restart(restart_deck);
Schedule restart_sched(restart_deck, ecl_state_restart, python, {}, &rst_state);
return {sched, restart_sched};
return {sched, restart_sched, rst_state};
}
@@ -121,8 +123,8 @@ void compare_sched(const std::string& base_deck,
const std::string& rst_fname,
std::size_t restart_step)
{
const auto& [sched, restart_sched] = load_schedule_pair(base_deck, rst_deck, rst_fname, restart_step);
const auto& [sched, restart_sched, _] = load_schedule_pair(base_deck, rst_deck, rst_fname, restart_step);
(void) _;
BOOST_CHECK_EQUAL(restart_sched.size(), sched.size());
for (std::size_t report_step=restart_step; report_step < sched.size(); report_step++) {
const auto& base = sched[report_step];
@@ -147,7 +149,7 @@ BOOST_AUTO_TEST_CASE(LoadRestartSim) {
BOOST_AUTO_TEST_CASE(LoadUDQRestartSim) {
const auto& [sched, restart_sched] = load_schedule_pair("UDQ_WCONPROD.DATA", "UDQ_WCONPROD_RESTART.DATA", "UDQ_WCONPROD.X0006", 6);
const auto& [sched, restart_sched, rst_state] = load_schedule_pair("UDQ_WCONPROD.DATA", "UDQ_WCONPROD_RESTART.DATA", "UDQ_WCONPROD.X0006", 6);
std::size_t report_step = 10;
SummaryState st(TimeService::now());
st.update_well_var("OPL02", "WUOPRL", 1);
@@ -171,10 +173,13 @@ BOOST_AUTO_TEST_CASE(LoadUDQRestartSim) {
BOOST_CHECK( controls == rst_controls );
}
}
UDQState udq_state(0);
udq_state.load_rst(rst_state);
}
BOOST_AUTO_TEST_CASE(LoadActionRestartSim) {
const auto& [sched, restart_sched] = load_schedule_pair("UDQ_ACTIONX.DATA", "UDQ_ACTIONX_RESTART.DATA", "UDQ_ACTIONX.X0007", 7);
const auto& [sched, restart_sched, rst_state] = load_schedule_pair("UDQ_ACTIONX.DATA", "UDQ_ACTIONX_RESTART.DATA", "UDQ_ACTIONX.X0007", 7);
const auto& input_actions = sched[7].actions();
const auto& rst_actions = restart_sched[7].actions();
@@ -195,4 +200,7 @@ BOOST_AUTO_TEST_CASE(LoadActionRestartSim) {
rst_iter++;
}
}
Action::State action_state;
action_state.load_rst(rst_actions, rst_state);
}