Merge pull request #2211 from joakim-hove/sched-action

Sched action
This commit is contained in:
Joakim Hove 2021-01-15 09:18:32 +01:00 committed by GitHub
commit bc3c3490bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 49 additions and 43 deletions

View File

@ -75,7 +75,7 @@ UDAValue msim::uda_val() {
void msim::post_step(Schedule& schedule, Action::State& action_state, SummaryState& st, data::Solution& /* sol */, data::Wells& /* well_data */, data::GroupAndNetworkValues& /* grp_nwrk_data */, size_t report_step) {
const auto& actions = schedule.actions(report_step);
const auto& actions = schedule[report_step].actions();
if (actions.empty())
return;

View File

@ -43,7 +43,6 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellTestConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleDeck.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp>
@ -95,7 +94,6 @@
namespace Opm
{
class Actions;
class Deck;
class DeckKeyword;
class DeckRecord;
@ -281,7 +279,6 @@ namespace Opm
const UDQActive& udqActive(std::size_t timeStep) const;
const UDQConfig& getUDQConfig(std::size_t timeStep) const;
std::vector<const UDQConfig*> udqConfigList() const;
const Action::Actions& actions(std::size_t timeStep) const;
void evalAction(const SummaryState& summary_state, std::size_t timeStep);
GTNode groupTree(std::size_t report_step) const;
@ -315,6 +312,7 @@ namespace Opm
std::shared_ptr<const Python> python() const;
const ScheduleState& back() const;
const ScheduleState& operator[](std::size_t index) const;
std::vector<ScheduleState>::const_iterator begin() const;
std::vector<ScheduleState>::const_iterator end() const;
@ -345,7 +343,6 @@ namespace Opm
udq_config.serializeOp(serializer);
udq_active.serializeOp(serializer);
guide_rate_config.serializeOp(serializer);
m_actions.serializeOp(serializer);
m_glo.serializeOp(serializer);
rft_config.serializeOp(serializer);
restart_config.serializeOp(serializer);
@ -367,7 +364,6 @@ namespace Opm
DynamicState<std::shared_ptr<UDQConfig>> udq_config;
DynamicState<std::shared_ptr<UDQActive>> udq_active;
DynamicState<std::shared_ptr<GuideRateConfig>> guide_rate_config;
DynamicState<std::shared_ptr<Action::Actions>> m_actions;
DynamicState<std::shared_ptr<GasLiftOpt>> m_glo;
RFTConfig rft_config;
RestartConfig restart_config;
@ -408,7 +404,7 @@ namespace Opm
ErrorGuard& errors,
const EclipseGrid& grid,
const FieldPropsManager& fp);
void addACTIONX(const Action::ActionX& action, std::size_t currentStep);
void addACTIONX(const Action::ActionX& action);
void addGroupToGroup( const std::string& parent_group, const std::string& child_group, std::size_t timeStep);
void addGroupToGroup( const std::string& parent_group, const Group& child_group, std::size_t timeStep);
void addGroup(const std::string& groupName , std::size_t timeStep);
@ -496,7 +492,7 @@ namespace Opm
bool handleNormalKeyword(const HandlerContext& handlerContext, const ParseContext& parseContext, ErrorGuard& errors);
// Keyword Handlers
void handlePYACTION(const DeckKeyword&, std::size_t currentStep);
void handlePYACTION(const DeckKeyword&);
void handleGCONPROD(const DeckKeyword& keyword, std::size_t current_step, const ParseContext& parseContext, ErrorGuard& errors);
void handleGCONINJE(const DeckKeyword& keyword, std::size_t current_step, const ParseContext& parseContext, ErrorGuard& errors);
void handleGLIFTOPT(const DeckKeyword& keyword, std::size_t report_step, const ParseContext& parseContext, ErrorGuard& errors);

View File

@ -39,6 +39,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Network/ExtNetwork.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
namespace Opm {
@ -126,6 +127,9 @@ namespace Opm {
const VFPInjTable& vfpinj(int table_id) const;
void vfpinj(VFPInjTable vfpinj);
const Action::Actions& actions() const;
void actions(Action::Actions actions);
template<class Serializer>
void serializeOp(Serializer& serializer) {
serializer(m_start_time);
@ -147,6 +151,7 @@ namespace Opm {
serializer(m_rptconfig);
serializer.map(m_vfpprod);
serializer.map(m_vfpinj);
serializer(m_actions);
}
@ -169,6 +174,7 @@ namespace Opm {
std::shared_ptr<WListManager> m_wlist_manager;
std::shared_ptr<Network::ExtNetwork> m_network;
std::shared_ptr<RPTConfig> m_rptconfig;
std::shared_ptr<Action::Actions> m_actions;
std::map<int, std::shared_ptr<VFPProdTable>> m_vfpprod;
std::map<int, std::shared_ptr<VFPInjTable>> m_vfpinj;
};

View File

@ -687,7 +687,7 @@ captureDeclaredActionxData( const Opm::Schedule& sched,
const std::vector<int>& actDims,
const std::size_t simStep)
{
const auto& acts = sched.actions(simStep);
const auto& acts = sched[simStep].actions();
std::size_t act_ind = 0;
for (auto actx_it = acts.begin(); actx_it < acts.end(); actx_it++) {
{

View File

@ -926,7 +926,7 @@ namespace {
std::vector<std::pair<std::string, Opm::Action::Result>>
act_res_stat(const Opm::Schedule& sched, const Opm::Action::State& action_state, const Opm::SummaryState& smry, const std::size_t sim_step) {
std::vector<std::pair<std::string, Opm::Action::Result>> results;
const auto& acts = sched.actions(sim_step);
const auto& acts = sched[sim_step].actions();
Opm::Action::Context context(smry, sched[sim_step].wlist_manager());
auto sim_time = sched.simTime(sim_step);
for (const auto& action : acts.pending(action_state, sim_time)) {

View File

@ -121,7 +121,7 @@ createActionxDims( const Runspec& rspec,
const Schedule& sched,
const std::size_t simStep)
{
const auto& acts = sched.actions(simStep);
const auto& acts = sched[simStep].actions();
std::vector<int> actDims(9);
//No of Actionx keywords

View File

@ -477,7 +477,7 @@ createInteHead(const EclipseState& es,
const auto ngmax = (report_step == 0)
? 0 : numGroupsInField(sched, lookup_step);
const auto& acts = sched.actions(lookup_step);
const auto& acts = sched[lookup_step].actions();
const auto& rspec = es.runspec();
const auto& tdim = es.getTableManager();
const auto& rdim = tdim.getRegdims();

View File

@ -3209,7 +3209,7 @@ void Opm::out::Summary::SummaryImplementation::configureUDQ(const SummaryConfig&
for (const auto& udq_ptr : sched.udqConfigList())
udq_ptr->required_summary(summary_keys);
for (const auto& action : sched.actions(sched.size() - 1))
for (const auto& action : sched.back().actions())
action.required_summary(summary_keys);
for (const auto& key : summary_keys) {

View File

@ -116,7 +116,6 @@ namespace {
udq_config(this->m_timeMap, std::make_shared<UDQConfig>(deck)),
udq_active(this->m_timeMap, std::make_shared<UDQActive>()),
guide_rate_config(this->m_timeMap, std::make_shared<GuideRateConfig>()),
m_actions(this->m_timeMap, std::make_shared<Action::Actions>()),
m_glo(this->m_timeMap, std::make_shared<GasLiftOpt>()),
rft_config(this->m_timeMap),
restart_config(m_timeMap, deck, parseContext, errors)
@ -256,7 +255,6 @@ namespace {
result.m_glo = {{std::make_shared<GasLiftOpt>(GasLiftOpt::serializeObject())}, 1};
result.udq_active = {{std::make_shared<UDQActive>(UDQActive::serializeObject())}, 1};
result.guide_rate_config = {{std::make_shared<GuideRateConfig>(GuideRateConfig::serializeObject())}, 1};
result.m_actions = {{std::make_shared<Action::Actions>(Action::Actions::serializeObject())}, 1};
result.rft_config = RFTConfig::serializeObject();
result.restart_config = RestartConfig::serializeObject();
result.snapshots = { ScheduleState::serializeObject() };
@ -312,7 +310,7 @@ namespace {
rftProperties.push_back( std::make_pair( &keyword , currentStep ));
else if (keyword.name() == "PYACTION")
handlePYACTION(keyword, currentStep);
handlePYACTION(keyword);
}
namespace {
@ -466,7 +464,7 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e
parseContext.handleError( ParseContext::ACTIONX_ILLEGAL_KEYWORD, msg_fmt, action_keyword.location(), errors);
}
}
this->addACTIONX(action, report_step);
this->addACTIONX(action);
keyword_index++;
continue;
}
@ -498,13 +496,13 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e
}
}
void Schedule::addACTIONX(const Action::ActionX& action, std::size_t currentStep) {
auto new_actions = std::make_shared<Action::Actions>( this->actions(currentStep) );
new_actions->add(action);
this->m_actions.update(currentStep, new_actions);
void Schedule::addACTIONX(const Action::ActionX& action) {
auto new_actions = Action::Actions( this->snapshots.back().actions() );
new_actions.add( action );
this->snapshots.back().actions( std::move(new_actions) );
}
void Schedule::handlePYACTION(const DeckKeyword& keyword, std::size_t currentStep) {
void Schedule::handlePYACTION(const DeckKeyword& keyword) {
if (!this->m_static.m_python_handle->enabled()) {
//Must have a real Python instance here - to ensure that IMPORT works
const auto& loc = keyword.location();
@ -522,9 +520,9 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e
module = this->m_static.m_input_path + "/" + module_arg;
Action::PyAction pyaction(this->m_static.m_python_handle, name, run_count, module);
auto new_actions = std::make_shared<Action::Actions>( this->actions(currentStep) );
new_actions->add(pyaction);
this->m_actions.update(currentStep, new_actions);
auto new_actions = Action::Actions( this->snapshots.back().actions() );
new_actions.add(pyaction);
this->snapshots.back().actions( std::move(new_actions) );
}
void Schedule::applyEXIT(const DeckKeyword& keyword, std::size_t report_step) {
@ -1356,11 +1354,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e
}
const Action::Actions& Schedule::actions(std::size_t timeStep) const {
const auto& ptr = this->m_actions.get(timeStep);
return *ptr;
}
void Schedule::applyAction(std::size_t reportStep, const Action::ActionX& action, const Action::Result& result) {
ParseContext parseContext;
ErrorGuard errors;
@ -1497,7 +1490,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e
compareDynState(this->udq_config, data.udq_config) &&
compareDynState(this->udq_active, data.udq_active) &&
compareDynState(this->guide_rate_config, data.guide_rate_config) &&
compareDynState(this->m_actions, data.m_actions) &&
rft_config == data.rft_config &&
this->restart_config == data.restart_config &&
this->snapshots == data.snapshots;
@ -1874,6 +1866,10 @@ bool Schedule::cmp(const Schedule& sched1, const Schedule& sched2, std::size_t r
return (count == 0);
}
const ScheduleState& Schedule::back() const {
return this->snapshots.back();
}
const ScheduleState& Schedule::operator[](std::size_t index) const {
return this->snapshots.at(index);
}
@ -1902,7 +1898,7 @@ void Schedule::create_first(const std::chrono::system_clock::time_point& start_t
sched_state.wlist_manager( WListManager() );
sched_state.network( Network::ExtNetwork() );
sched_state.rpt_config( RPTConfig() );
sched_state.actions( Action::Actions() );
this->addGroup("FIELD", 0);
}

View File

@ -159,7 +159,6 @@ bool ScheduleState::operator==(const ScheduleState& other) const {
++it2;
}
return true;
};
@ -204,7 +203,7 @@ ScheduleState ScheduleState::serializeObject() {
ts.m_vfpprod.emplace( std::make_pair(78, std::make_shared<VFPProdTable>(VFPProdTable::serializeObject() )));
ts.m_vfpinj.emplace( std::make_pair(177, std::make_shared<VFPInjTable>(VFPInjTable::serializeObject() )));
ts.m_vfpinj.emplace( std::make_pair(178, std::make_shared<VFPInjTable>(VFPInjTable::serializeObject() )));
ts.m_actions = std::make_shared<Action::Actions>( Action::Actions::serializeObject() );
return ts;
}
@ -337,4 +336,13 @@ void ScheduleState::vfpinj(VFPInjTable vfpinj) {
int table_id = vfpinj.getTableNum();
this->m_vfpinj[table_id] = std::make_shared<VFPInjTable>( std::move(vfpinj) );
}
const Action::Actions& ScheduleState::actions() const {
return *this->m_actions;
}
void ScheduleState::actions(Action::Actions actions) {
this->m_actions = std::make_shared<Action::Actions>( std::move(actions) );
}
}

View File

@ -764,10 +764,10 @@ TSTEP
Runspec runspec (deck);
Schedule sched(deck, grid1, fp, runspec, python);
const auto& actions0 = sched.actions(0);
const auto& actions0 = sched[0].actions();
BOOST_CHECK_EQUAL(actions0.size(), 0U);
const auto& actions1 = sched.actions(1);
const auto& actions1 = sched[1].actions();
BOOST_CHECK_EQUAL(actions1.size(), 1U);
@ -804,7 +804,7 @@ TSTEP
/*****************************************************************/
const auto& actions2 = sched.actions(2);
const auto& actions2 = sched[2].actions();
BOOST_CHECK_EQUAL(actions2.size(), 2U);
const auto& actB = actions2.get("B");
@ -920,8 +920,8 @@ ENDACTIO
Runspec runspec (deck);
Schedule sched(deck, grid1, fp, runspec, python);
const auto& action1 = sched.actions(1).get("A");
const auto& action2 = sched.actions(2).get("A");
const auto& action1 = sched[1].actions().get("A");
const auto& action2 = sched[2].actions().get("A");
BOOST_CHECK(action1.id() != action2.id());
@ -976,7 +976,7 @@ TSTEP
auto unit_system = UnitSystem::newMETRIC();
const auto st = SummaryState{ std::chrono::system_clock::now() };
Schedule sched = make_schedule(deck_string);
const auto& action1 = sched.actions(0).get("A");
const auto& action1 = sched[0].actions().get("A");
{
const auto& group = sched.getGroup("G1", 0);
const auto& prod = group.productionControls(st);
@ -1040,7 +1040,7 @@ TSTEP
Opm::UnitSystem unitSystem = UnitSystem( UnitSystem::UnitType::UNIT_TYPE_METRIC );
auto sched = make_schedule(input);
const auto& action1 = sched.actions(0).get("A");
const auto& action1 = sched[0].actions().get("A");
{
const auto& glo = sched.glo(0);
BOOST_CHECK(!glo.has_group("PLAT-A"));
@ -1096,7 +1096,7 @@ TSTEP
const auto st = SummaryState{ std::chrono::system_clock::now() };
Schedule sched = make_schedule(deck_string);
const auto& action1 = sched.actions(0).get("A");
const auto& action1 = sched[0].actions().get("A");
{
const auto& well = sched.getWell("PROD1", 0);
BOOST_CHECK_EQUAL( well.getWellPIScalingFactor(1.0), 1.0);
@ -1138,7 +1138,7 @@ ENDACTIO
Opm::WListManager wlm;
Opm::Action::Context context(st, wlm);
const auto& config = sched.actions(0);
const auto& config = sched[0].actions();
const Opm::Action::ActionX& action = config.get("ACT1");
/*