Add DAY, MONTH and YEAR and summary keys

This commit is contained in:
Joakim Hove 2020-04-02 17:13:26 +02:00
parent 90940ed7b5
commit 934def46d2
4 changed files with 154 additions and 5 deletions

View File

@ -237,6 +237,14 @@ namespace {
return ret;
}
Opm::TimeStampUTC make_sim_time(const Opm::Schedule& sched, const Opm::SummaryState& st, double sim_step) {
auto elapsed = st.get_elapsed() + sim_step;
return Opm::TimeStampUTC( sched.getStartTime() ) + std::chrono::duration<double>(elapsed);
}
/*
* This class takes simulator state and parser-provided information and
* orchestrates ert to write simulation results as requested by the SUMMARY
@ -1724,6 +1732,69 @@ namespace Evaluator {
std::string saveKey_;
};
class Day : public Base
{
public:
explicit Day(std::string saveKey)
: saveKey_(std::move(saveKey))
{}
void update(const std::size_t /* sim_step */,
const double stepSize,
const InputData& input,
const SimulatorResults& /* simRes */,
Opm::SummaryState& st) const override
{
auto sim_time = make_sim_time(input.sched, st, stepSize);
st.update(this->saveKey_, sim_time.day());
}
private:
std::string saveKey_;
};
class Month : public Base
{
public:
explicit Month(std::string saveKey)
: saveKey_(std::move(saveKey))
{}
void update(const std::size_t /* sim_step */,
const double stepSize,
const InputData& input,
const SimulatorResults& /* simRes */,
Opm::SummaryState& st) const override
{
auto sim_time = make_sim_time(input.sched, st, stepSize);
st.update(this->saveKey_, sim_time.month());
}
private:
std::string saveKey_;
};
class Year : public Base
{
public:
explicit Year(std::string saveKey)
: saveKey_(std::move(saveKey))
{}
void update(const std::size_t /* sim_step */,
const double stepSize,
const InputData& input,
const SimulatorResults& /* simRes */,
Opm::SummaryState& st) const override
{
auto sim_time = make_sim_time(input.sched, st, stepSize);
st.update(this->saveKey_, sim_time.year());
}
private:
std::string saveKey_;
};
class Years : public Base
{
public:
@ -2226,7 +2297,7 @@ private:
std::unique_ptr<Opm::EclIO::OutputStream::SummarySpecification> smspec_{};
std::unique_ptr<Opm::EclIO::EclOutput> stream_{};
void configureTimeVectors(const EclipseState& es);
void configureTimeVectors(const EclipseState& es, const SummaryConfig& sumcfg);
void configureSummaryInput(const EclipseState& es,
const SummaryConfig& sumcfg,
@ -2258,7 +2329,7 @@ SummaryImplementation(const EclipseState& es,
, fmt_ { es.cfg().io().getFMTOUT() }
, unif_ { es.cfg().io().getUNIFOUT() }
{
this->configureTimeVectors(es);
this->configureTimeVectors(es, sumcfg);
this->configureSummaryInput(es, sumcfg, grid, sched);
this->configureRequiredRestartParameters(sumcfg, sched);
}
@ -2351,7 +2422,7 @@ void Opm::out::Summary::SummaryImplementation::write(const MiniStep& ms)
void
Opm::out::Summary::SummaryImplementation::
configureTimeVectors(const EclipseState& es)
configureTimeVectors(const EclipseState& es, const SummaryConfig& sumcfg)
{
const auto dfltwgname = std::string(":+:+:+:+");
const auto dfltnum = 0;
@ -2369,11 +2440,38 @@ configureTimeVectors(const EclipseState& es)
const auto& kw = std::string("TIME");
makeKey(kw);
const auto* utime = es.getUnits().name(UnitSystem::measure::time);
const std::string& unit_string = es.getUnits().name(UnitSystem::measure::time);
auto eval = std::make_unique<Evaluator::Time>(this->valueKeys_.back());
this->outputParameters_
.makeParameter(kw, dfltwgname, dfltnum, utime, std::move(eval));
.makeParameter(kw, dfltwgname, dfltnum, unit_string, std::move(eval));
}
if (sumcfg.hasKeyword("DAY")) {
const auto& kw = std::string("DAY");
makeKey(kw);
auto eval = std::make_unique<Evaluator::Day>(this->valueKeys_.back());
this->outputParameters_
.makeParameter(kw, dfltwgname, dfltnum, "", std::move(eval));
}
if (sumcfg.hasKeyword("MONTH")) {
const auto& kw = std::string("MONTH");
makeKey(kw);
auto eval = std::make_unique<Evaluator::Month>(this->valueKeys_.back());
this->outputParameters_
.makeParameter(kw, dfltwgname, dfltnum, "", std::move(eval));
}
if (sumcfg.hasKeyword("YEAR")) {
const auto& kw = std::string("YEAR");
makeKey(kw);
auto eval = std::make_unique<Evaluator::Year>(this->valueKeys_.back());
this->outputParameters_
.makeParameter(kw, dfltwgname, dfltnum, "", std::move(eval));
}
#if NOT_YET

View File

@ -281,6 +281,8 @@ RSVD
SUMMARY
-- -------------------------------------------------------------------------
DATE
RUNSUM
-- 1a) Oil rate vs time

View File

@ -98,6 +98,18 @@ BOOST_AUTO_TEST_CASE(RUN) {
double seconds_elapsed = time[time_index] * 86400;
BOOST_CHECK_CLOSE(seconds_elapsed, press[time_index], 1e-3);
}
const auto& dates = smry.dates();
const auto& day = smry.get("DAY");
const auto& month = smry.get("MONTH");
const auto& year = smry.get("YEAR");
for (auto nstep = dates.size(), time_index=0*nstep; time_index < nstep; time_index++) {
auto ts = TimeStampUTC( std::chrono::system_clock::to_time_t( dates[time_index]) );
BOOST_CHECK_EQUAL( ts.day(), day[time_index]);
BOOST_CHECK_EQUAL( ts.month(), month[time_index]);
BOOST_CHECK_EQUAL( ts.year(), year[time_index]);
}
}
{

View File

@ -910,6 +910,43 @@ BOOST_AUTO_TEST_CASE(completion_kewords) {
BOOST_CHECK_CLOSE( 200.3, ecl_sum_get_well_completion_var( resp, 1, "W_2", "CNFR", 2, 1, 1 ), 1e-5 );
}
BOOST_AUTO_TEST_CASE(DATE) {
setup cfg( "test_summary_DATE" );
out::Summary writer( cfg.es, cfg.config, cfg.grid, cfg.schedule, cfg.name );
SummaryState st(std::chrono::system_clock::now());
writer.eval( st, 1, 1 * day, cfg.es, cfg.schedule, cfg.wells , cfg.groups, {});
writer.add_timestep( st, 1);
writer.eval( st, 2, 2 * day, cfg.es, cfg.schedule, cfg.wells , cfg.groups, {});
writer.add_timestep( st, 2);
writer.eval( st, 3, 18 * day, cfg.es, cfg.schedule, cfg.wells , cfg.groups, {});
writer.add_timestep( st, 3);
writer.eval( st, 4, 22 * day, cfg.es, cfg.schedule, cfg.wells , cfg.groups, {});
writer.add_timestep( st, 4);
writer.write();
auto res = readsum( cfg.name );
const auto* resp = res.get();
const auto& days = resp->get_at_rstep("DAY");
BOOST_CHECK_EQUAL(days[0], 11);
BOOST_CHECK_EQUAL(days[1], 12);
BOOST_CHECK_EQUAL(days[2], 28);
BOOST_CHECK_EQUAL(days[3], 1);
const auto& month = resp->get_at_rstep("MONTH");
BOOST_CHECK_EQUAL(month[0], 5);
BOOST_CHECK_EQUAL(month[1], 5);
BOOST_CHECK_EQUAL(month[2], 5);
BOOST_CHECK_EQUAL(month[3], 6);
const auto& year = resp->get_at_rstep("YEAR");
BOOST_CHECK_EQUAL(year[0], 2007);
BOOST_CHECK_EQUAL(year[1], 2007);
BOOST_CHECK_EQUAL(year[2], 2007);
BOOST_CHECK_EQUAL(year[3], 2007);
}
BOOST_AUTO_TEST_CASE(field_keywords) {
setup cfg( "test_summary_field" );