Merge pull request #3035 from GitPaean/throw_wrong_time_stepping
throw when report steps has start time later than end time
This commit is contained in:
@@ -89,6 +89,7 @@
|
||||
#include <opm/input/eclipse/Units/Dimension.hpp>
|
||||
#include <opm/input/eclipse/Units/UnitSystem.hpp>
|
||||
#include <opm/input/eclipse/Units/Units.hpp>
|
||||
#include <fmt/chrono.h>
|
||||
|
||||
#include "Well/injection.hpp"
|
||||
#include "MSW/Compsegs.hpp"
|
||||
@@ -1279,8 +1280,19 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
|
||||
}
|
||||
|
||||
double Schedule::stepLength(std::size_t timeStep) const {
|
||||
auto elapsed = this->snapshots[timeStep].end_time() - this->snapshots[timeStep].start_time();
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(elapsed).count();
|
||||
const auto start = this->snapshots[timeStep].start_time();
|
||||
const auto end = this->snapshots[timeStep].end_time();
|
||||
if (start > end) {
|
||||
throw std::invalid_argument {
|
||||
fmt::format(" Report step {} has start time after end time,\n"
|
||||
" * Start time = {:%d-%b-%Y %H:%M:%S}\n"
|
||||
" * End time = {:%d-%b-%Y %H:%M:%S}.\n"
|
||||
" Possibly due to inconsistent RESTART/SKIPREST settings.",
|
||||
timeStep + 1,
|
||||
fmt::gmtime(TimeService::to_time_t(start)),
|
||||
fmt::gmtime(TimeService::to_time_t(end))) };
|
||||
}
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
||||
}
|
||||
|
||||
void Schedule::applyKeywords(
|
||||
|
||||
@@ -238,6 +238,16 @@ ScheduleDeck::ScheduleDeck(time_point start_time, const Deck& deck, const Schedu
|
||||
std::throw_with_nested(opm_error);
|
||||
}
|
||||
|
||||
const auto currenTime = std::chrono::system_clock::to_time_t(context.last_time);
|
||||
if (nextTime < currenTime) {
|
||||
auto msg = fmt::format(
|
||||
"Keyword DATES specifies a time {:%d-%b-%Y %H:%M:%S} earlier than the end time of previous report step {:%d-%b-%Y %H:%M:%S}",
|
||||
fmt::gmtime(nextTime), fmt::gmtime(currenTime));
|
||||
if (rst_info.time > 0 && !this->skiprest) { // the situation with SKIPREST is handled in function add_block
|
||||
msg += "\nin a RESTARTing simulation, Please check whether SKIPREST is supposed to be used for this circumstance";
|
||||
}
|
||||
throw OpmInputError(msg, keyword.location());
|
||||
}
|
||||
this->add_block(ScheduleTimeType::DATES, TimeService::from_time_t( nextTime ), context, keyword.location());
|
||||
}
|
||||
continue;
|
||||
@@ -332,6 +342,13 @@ void ScheduleDeck::add_block(ScheduleTimeType time_type, const time_point& t, Sc
|
||||
void ScheduleDeck::add_TSTEP(const DeckKeyword& TSTEPKeyword, ScheduleDeckContext& context) {
|
||||
const auto &item = TSTEPKeyword.getRecord(0).getItem(0);
|
||||
for (size_t itemIndex = 0; itemIndex < item.data_size(); itemIndex++) {
|
||||
{
|
||||
const auto tstep = item.get<double>(itemIndex);
|
||||
if (tstep < 0) {
|
||||
const auto msg = fmt::format("a negative TSTEP value {} is input", tstep);
|
||||
throw OpmInputError(msg, TSTEPKeyword.location());
|
||||
}
|
||||
}
|
||||
auto next_time = context.last_time + std::chrono::duration_cast<time_point::duration>(std::chrono::duration<double>(item.getSIDouble(itemIndex)));
|
||||
this->add_block(ScheduleTimeType::TSTEP, next_time, context, TSTEPKeyword.location());
|
||||
}
|
||||
|
||||
@@ -160,6 +160,10 @@ BOOST_AUTO_TEST_CASE(RUN) {
|
||||
}
|
||||
|
||||
const int report_step = 50;
|
||||
{
|
||||
const KeywordLocation location {"SKIPREST", "SPE1CASE1.DATA", 388};
|
||||
deck.addKeyword({location, "SKIPREST"});
|
||||
}
|
||||
auto rst_view = std::make_shared<EclIO::RestartFileView>(std::move(rst), report_step);
|
||||
const auto rst_state = Opm::RestartIO::RstState::load(std::move(rst_view), state.runspec(), parser);
|
||||
Schedule sched_rst(deck, state, python, {}, &rst_state);
|
||||
|
||||
@@ -5044,8 +5044,8 @@ DATES -- 4,5
|
||||
SUMTHIN
|
||||
0.0 /
|
||||
DATES -- 6,7
|
||||
10 SEP 2007 /
|
||||
10 OCT 2007 /
|
||||
10 NOV 2007 /
|
||||
10 DEC 2007 /
|
||||
/
|
||||
END
|
||||
)");
|
||||
@@ -5087,6 +5087,71 @@ END
|
||||
R"("SUMTHIN" must NOT be configured on report step 7)");
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(MISORDERD_DATES) {
|
||||
const auto deck = Parser{}.parseString(R"(RUNSPEC
|
||||
DIMENS
|
||||
10 10 10 /
|
||||
|
||||
START -- 0
|
||||
10 MAI 2007 /
|
||||
|
||||
GRID
|
||||
DXV
|
||||
10*100.0 /
|
||||
DYV
|
||||
10*100.0 /
|
||||
DZV
|
||||
10*10.0 /
|
||||
DEPTHZ
|
||||
121*2000.0 /
|
||||
|
||||
SCHEDULE
|
||||
DATES -- 1, 2, 3
|
||||
10 JUN 2007 /
|
||||
10 MAY 2007 /
|
||||
10 AUG 2007 /
|
||||
/
|
||||
END
|
||||
)");
|
||||
|
||||
const auto es = EclipseState { deck };
|
||||
BOOST_CHECK_THROW(Schedule(deck, es), Opm::OpmInputError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(NEGATIVE_TSTEPS) {
|
||||
const auto deck = Parser{}.parseString(R"(RUNSPEC
|
||||
DIMENS
|
||||
10 10 10 /
|
||||
|
||||
START -- 0
|
||||
10 MAI 2007 /
|
||||
|
||||
GRID
|
||||
DXV
|
||||
10*100.0 /
|
||||
DYV
|
||||
10*100.0 /
|
||||
DZV
|
||||
10*10.0 /
|
||||
DEPTHZ
|
||||
121*2000.0 /
|
||||
|
||||
SCHEDULE
|
||||
DATES -- 1, 2, 3
|
||||
10 MAY 2007 /
|
||||
10 JUN 2007 /
|
||||
10 AUG 2007 /
|
||||
/
|
||||
TSTEP
|
||||
-1 /
|
||||
END
|
||||
)");
|
||||
|
||||
const auto es = EclipseState { deck };
|
||||
BOOST_CHECK_THROW(Schedule(deck, es), Opm::OpmInputError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RPTONLY_IN_SUMMARY) {
|
||||
const auto deck = Parser{}.parseString(R"(RUNSPEC
|
||||
DIMENS
|
||||
|
||||
Reference in New Issue
Block a user