Merge pull request #2339 from joakim-hove/sched-state-sim-step

Sched state sim step
This commit is contained in:
Joakim Hove 2021-03-11 15:23:02 +01:00 committed by GitHub
commit 654a78a541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 1 deletions

View File

@ -271,6 +271,18 @@ namespace Opm {
time_point end_time() const;
ScheduleState next(const time_point& next_start);
// The sim_step() is the report step we are currently simulating on. The
// results when we have completed sim_step=N are stored in report_step
// N+1.
std::size_t sim_step() const;
// The month_num and year_num() functions return the accumulated number
// of full months/years to the start of the current block.
std::size_t month_num() const;
std::size_t year_num() const;
bool first_in_month() const;
bool first_in_year() const;
bool operator==(const ScheduleState& other) const;
static ScheduleState serializeObject();
@ -424,6 +436,11 @@ namespace Opm {
void serializeOp(Serializer& serializer) {
serializer(m_start_time);
serializer(m_end_time);
serializer(m_sim_step);
serializer(m_month_num);
serializer(m_year_num);
serializer(m_first_in_year);
serializer(m_first_in_month);
m_tuning.serializeOp(serializer);
serializer(m_nupcol);
m_oilvap.serializeOp(serializer);
@ -440,6 +457,11 @@ namespace Opm {
time_point m_start_time;
std::optional<time_point> m_end_time;
std::size_t m_sim_step = 0;
std::size_t m_month_num = 0;
std::size_t m_year_num = 0;
bool m_first_in_month = true;
bool m_first_in_year = true;
Tuning m_tuning;
int m_nupcol;
OilVaporizationProperties m_oilvap;

View File

@ -40,6 +40,15 @@ time_point clamp_time(time_point t) {
return TimeService::from_time_t( TimeService::to_time_t( t ) );
}
std::pair<std::size_t, std::size_t> date_diff(time_point t2, time_point t1) {
auto ts1 = TimeStampUTC(TimeService::to_time_t(t1));
auto ts2 = TimeStampUTC(TimeService::to_time_t(t2));
auto year_diff = ts2.year() - ts1.year();
auto month_diff = year_diff*12 + ts2.month() - ts1.month();
return { year_diff, month_diff };
}
}
@ -60,7 +69,7 @@ ScheduleState::ScheduleState(const ScheduleState& src, const time_point& start_t
{
this->m_start_time = clamp_time(start_time);
this->m_end_time = std::nullopt;
this->m_sim_step = src.sim_step() + 1;
this->m_events.reset();
this->m_wellgroup_events.reset();
this->m_geo_keywords.clear();
@ -69,6 +78,13 @@ ScheduleState::ScheduleState(const ScheduleState& src, const time_point& start_t
auto next_rft = this->rft_config().next();
if (next_rft.has_value())
this->rft_config.update( std::move(*next_rft) );
auto [year_diff, month_diff] = date_diff(this->m_start_time, src.m_start_time);
this->m_year_num += year_diff;
this->m_month_num += month_diff;
this->m_first_in_month = (this->m_month_num > src.m_month_num);
this->m_first_in_year = (this->m_year_num > src.m_year_num);
}
ScheduleState::ScheduleState(const ScheduleState& src, const time_point& start_time, const time_point& end_time) :
@ -86,6 +102,26 @@ time_point ScheduleState::end_time() const {
return this->m_end_time.value();
}
std::size_t ScheduleState::sim_step() const {
return this->m_sim_step;
}
std::size_t ScheduleState::month_num() const {
return this->m_month_num;
}
std::size_t ScheduleState::year_num() const {
return this->m_year_num;
}
bool ScheduleState::first_in_month() const {
return this->m_first_in_month;
}
bool ScheduleState::first_in_year() const {
return this->m_first_in_year;
}
void ScheduleState::update_nupcol(int nupcol) {
this->m_nupcol = nupcol;
}
@ -142,6 +178,11 @@ bool ScheduleState::operator==(const ScheduleState& other) const {
return this->m_start_time == other.m_start_time &&
this->m_oilvap == other.m_oilvap &&
this->m_sim_step == other.m_sim_step &&
this->m_month_num == other.m_month_num &&
this->m_first_in_month == other.m_first_in_month &&
this->m_first_in_year == other.m_first_in_year &&
this->m_year_num == other.m_year_num &&
this->target_wellpi == other.target_wellpi &&
this->m_tuning == other.m_tuning &&
this->m_end_time == other.m_end_time &&
@ -175,6 +216,9 @@ ScheduleState ScheduleState::serializeObject() {
auto t1 = TimeService::now();
auto t2 = t1 + std::chrono::hours(48);
ScheduleState ts(t1, t2);
ts.m_sim_step = 123;
ts.m_month_num = 12;
ts.m_year_num = 66;
ts.vfpprod = map_member<int, VFPProdTable>::serializeObject();
ts.vfpinj = map_member<int, VFPInjTable>::serializeObject();
ts.groups = map_member<std::string, Group>::serializeObject();

View File

@ -8054,4 +8054,8 @@ VFPPROD
/
TSTEP
1 2 3 4 5 6 /
END

View File

@ -142,6 +142,19 @@ END
BOOST_CHECK_MESSAGE(sched.write_rst_file(stepID),
"Must write restart information for included step " << stepID);
}
std::vector<bool> first_in_month{true, false, false, false, false, true, false, true, true, true, true, true, true, true, true, true, false, true, false};
std::vector<std::size_t> month_num{ 0,0,0,0,0, 1, 1, 2, 3, 4, 5, 6, 7, 10, 12, 17, 17, 18, 18 };
for (std::size_t index = 0; index < sched.size(); index++) {
const auto& state = sched[index];
BOOST_CHECK_EQUAL( state.month_num(), month_num[index] );
BOOST_CHECK_EQUAL( state.first_in_month(), first_in_month[index] );
if (index == 0 || index == 11 || index == 17)
BOOST_CHECK( state.first_in_year());
else
BOOST_CHECK(!state.first_in_year());
}
}

View File

@ -3618,6 +3618,11 @@ BOOST_AUTO_TEST_CASE(SKIPREST_VFP) {
const auto& rst = Opm::RestartIO::RstState::load(rst_file, report_step);
const auto sched = Schedule{ deck, es, python , {}, &rst};
BOOST_CHECK_NO_THROW( sched[3].vfpprod(5) );
for (std::size_t index = 0; index < sched.size(); index++) {
const auto& state = sched[index];
BOOST_CHECK_EQUAL(index, state.sim_step());
}
}
@ -4165,6 +4170,11 @@ BOOST_AUTO_TEST_CASE(VFPPROD_SCALING) {
cmp_vector(wfr, vfp_table.getWFRAxis());
cmp_vector(gfr, vfp_table.getGFRAxis());
cmp_vector(alq, vfp_table.getALQAxis());
for (std::size_t index = 0; index < sched.size(); index++) {
const auto& state = sched[index];
BOOST_CHECK_EQUAL(index, state.sim_step());
}
}