Add small struct ScheduleRestartInfo
This commit is contained in:
@@ -63,7 +63,7 @@ namespace Opm
|
||||
struct ScheduleStatic {
|
||||
std::shared_ptr<const Python> m_python_handle;
|
||||
std::string m_input_path;
|
||||
std::pair<std::time_t, std::size_t> m_restart_info;
|
||||
ScheduleRestartInfo rst_info;
|
||||
MessageLimits m_deck_message_limits;
|
||||
UnitSystem m_unit_system;
|
||||
Runspec m_runspec;
|
||||
@@ -77,7 +77,7 @@ namespace Opm
|
||||
{}
|
||||
|
||||
ScheduleStatic(std::shared_ptr<const Python> python_handle,
|
||||
const std::pair<std::time_t, std::size_t>& restart_info,
|
||||
const ScheduleRestartInfo& restart_info,
|
||||
const Deck& deck,
|
||||
const Runspec& runspec,
|
||||
const std::optional<int>& output_interval_,
|
||||
@@ -88,10 +88,11 @@ namespace Opm
|
||||
void serializeOp(Serializer& serializer)
|
||||
{
|
||||
m_deck_message_limits.serializeOp(serializer);
|
||||
serializer(this->m_restart_info);
|
||||
this->rst_info.serializeOp(serializer);
|
||||
m_runspec.serializeOp(serializer);
|
||||
m_unit_system.serializeOp(serializer);
|
||||
serializer(this->m_input_path);
|
||||
rst_info.serializeOp(serializer);
|
||||
rst_config.serializeOp(serializer);
|
||||
serializer(this->output_interval);
|
||||
}
|
||||
@@ -105,7 +106,7 @@ namespace Opm
|
||||
st.m_unit_system = UnitSystem::newFIELD();
|
||||
st.m_input_path = "Some/funny/path";
|
||||
st.rst_config = RSTConfig::serializeObject();
|
||||
st.m_restart_info = std::make_pair(0, 0);
|
||||
st.rst_info = ScheduleRestartInfo::serializeObject();
|
||||
return st;
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ namespace Opm
|
||||
this->m_deck_message_limits == other.m_deck_message_limits &&
|
||||
this->m_unit_system == other.m_unit_system &&
|
||||
this->rst_config == other.rst_config &&
|
||||
this->m_restart_info == other.m_restart_info &&
|
||||
this->rst_info == other.rst_info &&
|
||||
this->m_runspec == other.m_runspec;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -26,8 +26,11 @@
|
||||
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/common/utility/TimeService.hpp>
|
||||
|
||||
#include <opm/io/eclipse/rst/state.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/S.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@@ -83,6 +86,49 @@ namespace Opm {
|
||||
};
|
||||
|
||||
|
||||
struct ScheduleRestartInfo {
|
||||
std::time_t time{0};
|
||||
std::size_t report_step{0};
|
||||
bool skiprest{false};
|
||||
|
||||
ScheduleRestartInfo() = default;
|
||||
|
||||
ScheduleRestartInfo(const RestartIO::RstState * rst, const Deck& deck) {
|
||||
if (rst) {
|
||||
const auto& [t,r] = rst->header.restart_info();
|
||||
this->time = t;
|
||||
this->report_step = r;
|
||||
this->skiprest = deck.hasKeyword<ParserKeywords::SKIPREST>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const ScheduleRestartInfo& other) const {
|
||||
return this->time == other.time &&
|
||||
this->report_step == other.report_step &&
|
||||
this->skiprest == other.skiprest;
|
||||
}
|
||||
|
||||
|
||||
static ScheduleRestartInfo serializeObject() {
|
||||
ScheduleRestartInfo rst_info;
|
||||
rst_info.report_step = 12345;
|
||||
rst_info.skiprest = false;
|
||||
return rst_info;
|
||||
}
|
||||
|
||||
|
||||
template<class Serializer>
|
||||
void serializeOp(Serializer& serializer)
|
||||
{
|
||||
serializer(this->time);
|
||||
serializer(this->report_step);
|
||||
serializer(this->skiprest);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
The purpose of the ScheduleDeck class is to serve as a container holding
|
||||
@@ -95,7 +141,7 @@ namespace Opm {
|
||||
|
||||
class ScheduleDeck {
|
||||
public:
|
||||
explicit ScheduleDeck(const Deck& deck, const std::pair<std::time_t, std::size_t>& restart);
|
||||
explicit ScheduleDeck(const Deck& deck, const ScheduleRestartInfo& rst_info);
|
||||
ScheduleDeck();
|
||||
void add_block(ScheduleTimeType time_type, const time_point& t, ScheduleDeckContext& context, const KeywordLocation& location);
|
||||
void add_TSTEP(const DeckKeyword& TSTEPKeyword, ScheduleDeckContext& context);
|
||||
@@ -114,6 +160,7 @@ namespace Opm {
|
||||
void serializeOp(Serializer& serializer) {
|
||||
serializer(m_restart_time);
|
||||
serializer(m_restart_offset);
|
||||
serializer(skiprest);
|
||||
serializer.vector(m_blocks);
|
||||
m_location.serializeOp(serializer);
|
||||
}
|
||||
@@ -121,6 +168,7 @@ namespace Opm {
|
||||
private:
|
||||
time_point m_restart_time;
|
||||
std::size_t m_restart_offset;
|
||||
bool skiprest;
|
||||
KeywordLocation m_location;
|
||||
std::vector<ScheduleBlock> m_blocks;
|
||||
};
|
||||
|
||||
@@ -93,16 +93,10 @@ namespace {
|
||||
return (fnmatch(pattern.c_str(), name.c_str(), flags) == 0);
|
||||
}
|
||||
|
||||
std::pair<std::time_t, std::size_t> restart_info(const RestartIO::RstState * rst) {
|
||||
if (!rst)
|
||||
return std::make_pair(std::time_t{0}, std::size_t{0});
|
||||
else
|
||||
return rst->header.restart_info();
|
||||
}
|
||||
}
|
||||
|
||||
ScheduleStatic::ScheduleStatic(std::shared_ptr<const Python> python_handle,
|
||||
const std::pair<std::time_t, std::size_t>& restart_info,
|
||||
const ScheduleRestartInfo& restart_info,
|
||||
const Deck& deck,
|
||||
const Runspec& runspec,
|
||||
const std::optional<int>& output_interval_,
|
||||
@@ -110,7 +104,7 @@ namespace {
|
||||
ErrorGuard& errors) :
|
||||
m_python_handle(python_handle),
|
||||
m_input_path(deck.getInputPath()),
|
||||
m_restart_info(restart_info),
|
||||
rst_info(restart_info),
|
||||
m_deck_message_limits( deck ),
|
||||
m_unit_system( deck.getActiveUnitSystem() ),
|
||||
m_runspec( runspec ),
|
||||
@@ -129,14 +123,14 @@ namespace {
|
||||
const std::optional<int>& output_interval,
|
||||
const RestartIO::RstState * rst)
|
||||
try :
|
||||
m_static( python, restart_info(rst), deck, runspec, output_interval, parseContext, errors ),
|
||||
m_sched_deck(deck, m_static.m_restart_info)
|
||||
m_static( python, ScheduleRestartInfo(rst, deck), deck, runspec, output_interval, parseContext, errors ),
|
||||
m_sched_deck(deck, m_static.rst_info )
|
||||
{
|
||||
this->restart_output.resize(this->m_sched_deck.size());
|
||||
this->restart_output.clearRemainingEvents(0);
|
||||
|
||||
if (rst) {
|
||||
auto restart_step = this->m_static.m_restart_info.second;
|
||||
auto restart_step = this->m_static.rst_info.report_step;
|
||||
this->iterateScheduleSection( 0, restart_step, parseContext, errors, false, nullptr, &grid, &fp, "");
|
||||
this->load_rst(*rst, grid, fp);
|
||||
if (! this->restart_output.writeRestartFile(restart_step))
|
||||
@@ -372,16 +366,15 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e
|
||||
these keywords will be assigned to report step 0.
|
||||
*/
|
||||
|
||||
auto restart_skip = load_start < this->m_static.m_restart_info.second;
|
||||
auto restart_skip = load_start < this->m_static.rst_info.report_step;
|
||||
ScheduleLogger logger(restart_skip);
|
||||
{
|
||||
const auto& location = this->m_sched_deck.location();
|
||||
current_file = location.filename;
|
||||
logger.info(fmt::format("{0}\n{0}Processing dynamic information from\n{0}{1} line {2}", prefix, current_file, location.lineno));
|
||||
if (restart_skip) {
|
||||
auto [restart_time, restart_offset] = this->m_static.m_restart_info;
|
||||
logger.info(fmt::format("{}This is a restarted run - skipping until report step {} at {}", prefix, restart_offset, Schedule::formatDate(restart_time)));
|
||||
}
|
||||
if (restart_skip)
|
||||
logger.info(fmt::format("{}This is a restarted run - skipping until report step {} at {}", prefix, this->m_static.rst_info.report_step, Schedule::formatDate(this->m_static.rst_info.time)));
|
||||
|
||||
logger(fmt::format("{}Initializing report step {}/{} at {} {} {} line {}",
|
||||
prefix,
|
||||
load_start + 1,
|
||||
|
||||
@@ -181,7 +181,7 @@ std::size_t ScheduleDeck::restart_offset() const {
|
||||
}
|
||||
|
||||
|
||||
ScheduleDeck::ScheduleDeck(const Deck& deck, const std::pair<std::time_t, std::size_t>& restart) {
|
||||
ScheduleDeck::ScheduleDeck(const Deck& deck, const ScheduleRestartInfo& rst_info) {
|
||||
const std::unordered_set<std::string> skiprest_include = {"VFPPROD", "VFPINJ", "RPTSCHED", "RPTRST", "TUNING", "MESSAGES"};
|
||||
time_point start_time;
|
||||
if (deck.hasKeyword("START")) {
|
||||
@@ -197,10 +197,10 @@ ScheduleDeck::ScheduleDeck(const Deck& deck, const std::pair<std::time_t, std::s
|
||||
start_time = TimeService::from_time_t( mkdate(1983, 1, 1) );
|
||||
}
|
||||
|
||||
const auto& [restart_time, restart_offset] = restart;
|
||||
this->m_restart_time = TimeService::from_time_t(restart_time);
|
||||
this->m_restart_offset = restart_offset;
|
||||
if (restart_offset > 0) {
|
||||
this->m_restart_time = TimeService::from_time_t(rst_info.time);
|
||||
this->m_restart_offset = rst_info.report_step;
|
||||
this->skiprest = rst_info.skiprest;
|
||||
if (this->m_restart_offset > 0) {
|
||||
for (std::size_t it = 0; it < this->m_restart_offset; it++) {
|
||||
this->m_blocks.emplace_back(KeywordLocation{}, ScheduleTimeType::RESTART, start_time);
|
||||
if (it < this->m_restart_offset - 1)
|
||||
|
||||
@@ -4467,7 +4467,7 @@ BOOST_AUTO_TEST_CASE(ScheduleDeckTest) {
|
||||
{
|
||||
Parser parser;
|
||||
auto deck = parser.parseString( createDeckWTEST() );
|
||||
ScheduleDeck sched_deck( deck, {0,0} );
|
||||
ScheduleDeck sched_deck( deck, {} );
|
||||
BOOST_CHECK_EQUAL( sched_deck.size(), 6 );
|
||||
|
||||
std::vector<std::string> first_kw = {"WELSPECS", "WTEST", "SUMTHIN", "WCONINJH", "WELOPEN", "WCONINJH"};
|
||||
|
||||
Reference in New Issue
Block a user