From 8bc16ab7fe1bb771a02fd1602870c4c7434ac8bc Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sat, 2 Jan 2021 11:12:15 +0100 Subject: [PATCH 1/2] Rewrite TimeMap::operator[] - Access to the historical period for a restarted run will not be caught. - Access to underlying timepoint will be based on at() --- src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp | 9 +-------- tests/parser/ScheduleTests.cpp | 1 - tests/parser/TimeMapTest.cpp | 4 +--- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp index 858662e8f..48a684018 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp @@ -406,14 +406,7 @@ struct TimeMapContext { std::time_t TimeMap::operator[] (size_t index) const { - if (index >= m_timeList.size()) - throw std::invalid_argument("Index out of range"); - - if (index > 0 && index < this->m_restart_offset) { - printf("What the f... \n"); - throw std::invalid_argument(fmt::format("Tried to get time information from the base case in restarted run index:{} restart_offset:{}", index, this->m_restart_offset)); - } - return m_timeList[index]; + return m_timeList.at(index); } std::time_t TimeMap::mkdate(int in_year, int in_month, int in_day) { diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index 188c35167..fa2fefa29 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -1142,7 +1142,6 @@ COMPDAT for(size_t i = 0; i < cs4.size(); i++ ) BOOST_CHECK_EQUAL(cs4.get( i ).CF(), cs1.get(i).CF()); - BOOST_CHECK_THROW(schedule.simTime(10000), std::invalid_argument); auto sim_time1 = TimeStampUTC{ schedule.simTime(1) }; BOOST_CHECK_EQUAL(sim_time1.day(), 10); BOOST_CHECK_EQUAL(sim_time1.month(), 10); diff --git a/tests/parser/TimeMapTest.cpp b/tests/parser/TimeMapTest.cpp index 65bec9dfa..b824cd87f 100644 --- a/tests/parser/TimeMapTest.cpp +++ b/tests/parser/TimeMapTest.cpp @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(AddStepSizeCorrect) { Opm::TimeMap timeMap(time_points); BOOST_CHECK_EQUAL(3U, timeMap.size()); - BOOST_CHECK_THROW(timeMap[3] , std::invalid_argument ); + BOOST_CHECK_THROW(timeMap[3] , std::exception ); BOOST_CHECK_EQUAL(timeMap[0] , Opm::TimeMap::mkdate(2010, 1, 1 )); BOOST_CHECK_EQUAL(timeMap[2] , Opm::TimeMap::mkdate(2010, 1, 3 )); } @@ -685,8 +685,6 @@ DATES BOOST_CHECK_THROW( Opm::TimeMap(deck1, invalid_restart) , std::exception); Opm::TimeMap tm1(deck1, valid_restart); - BOOST_CHECK_THROW( tm1[1], std::invalid_argument ); - BOOST_CHECK_THROW( tm1[4], std::invalid_argument ); auto start = tm1[0]; BOOST_CHECK_EQUAL(start , Opm::asTimeT(Opm::TimeStampUTC(2000,1,1))); BOOST_CHECK_EQUAL(tm1[5] , Opm::asTimeT(Opm::TimeStampUTC(2005,1,1))); From 7a4bdd4ab5806709aa5976cea06aba398c349b6e Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sat, 2 Jan 2021 11:12:59 +0100 Subject: [PATCH 2/2] Update report number in comment --- tests/parser/ScheduleTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index fa2fefa29..8131add67 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -194,7 +194,7 @@ WELOPEN 'BAN' OPEN / / -DATES -- 4 +DATES -- 5 10 NOV 2007 / /