From 37f07a1b18160f1a931fc3de5532387659de59b4 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 10 Jun 2021 13:59:58 +0200 Subject: [PATCH] Remove stale class TimeMap --- CMakeLists_files.cmake | 3 - .../eclipse/EclipseState/Schedule/TimeMap.hpp | 127 --- .../eclipse/EclipseState/Schedule/TimeMap.cpp | 449 ---------- tests/parser/EclipseStateTests.cpp | 3 +- tests/parser/IOConfigTests.cpp | 1 - tests/parser/RFTConfigTests.cpp | 1 - tests/parser/ScheduleRestartTests.cpp | 1 - tests/parser/ScheduleSerializeTest.cpp | 1 - tests/parser/ScheduleTests.cpp | 5 +- tests/parser/TimeMapTest.cpp | 844 ------------------ tests/parser/WTEST.cpp | 1 - tests/parser/WellTests.cpp | 1 - .../integration/IOConfigIntegrationTest.cpp | 1 - .../integration/ScheduleCreateFromDeck.cpp | 5 +- tests/test_DoubHEAD.cpp | 1 - tests/test_EclipseIO.cpp | 1 - tests/test_InteHEAD.cpp | 53 +- tests/test_restartwellinfo.cpp | 1 - 18 files changed, 36 insertions(+), 1463 deletions(-) delete mode 100644 opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp delete mode 100644 src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp delete mode 100644 tests/parser/TimeMapTest.cpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 89f1f7836..b4c6f1f56 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -138,7 +138,6 @@ if(ENABLE_ECL_INPUT) src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp src/opm/parser/eclipse/EclipseState/Schedule/ScheduleTypes.cpp src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp - src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp src/opm/parser/eclipse/EclipseState/Schedule/Tuning.cpp src/opm/parser/eclipse/EclipseState/Schedule/Well/Connection.cpp src/opm/parser/eclipse/EclipseState/Schedule/Well/injection.cpp @@ -403,7 +402,6 @@ if(ENABLE_ECL_INPUT) tests/parser/TableManagerTests.cpp tests/parser/TableSchemaTests.cpp tests/parser/ThresholdPressureTest.cpp - tests/parser/TimeMapTest.cpp tests/parser/TracerTests.cpp tests/parser/TransMultTests.cpp tests/parser/TuningTests.cpp @@ -749,7 +747,6 @@ if(ENABLE_ECL_INPUT) opm/parser/eclipse/EclipseState/Schedule/Network/Branch.hpp opm/parser/eclipse/EclipseState/Schedule/Network/ExtNetwork.hpp opm/parser/eclipse/EclipseState/Schedule/Network/Node.hpp - opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp diff --git a/opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp b/opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp deleted file mode 100644 index 84b48b1a2..000000000 --- a/opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - Copyright 2013 Statoil ASA. - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . -*/ - - -#ifndef TIMEMAP_HPP_ -#define TIMEMAP_HPP_ - -#include - -#include -#include -#include -#include -#include - -#include - -namespace Opm { - - class Deck; - class DeckKeyword; - class DeckRecord; - class KeywordLocation; - struct TimeMapContext; - - class TimeMap { - public: - TimeMap() = default; - explicit TimeMap(const Deck& deck, const std::pair& restart = std::make_pair(std::time_t{0}, std::size_t{0})); - explicit TimeMap(const std::vector& time_points, std::size_t restart_offset = 0); - - static TimeMap serializeObject(); - - size_t size() const; - double getTotalTime() const; - double seconds(size_t timeStep) const; - - std::time_t operator[] (size_t index) const; - /// Return the date and time where a given time step starts. - std::time_t getStartTime(size_t tStepIdx) const; - std::time_t getEndTime() const; - /// Return the period of time in seconds which passed between the start of the simulation and a given point in time. - double getTimePassedUntil(size_t tLevelIdx) const; - /// Return the length of a given time step in seconds. - double getTimeStepLength(size_t tStepIdx) const; - - const std::vector& timeList() const; - bool operator==(const TimeMap& data) const; - - /// Return true if the given timestep is the first one of a new month or year, or if frequency > 1, - /// return true if the step is the first of each n-month or n-month period, starting from start_timestep - 1. - bool isTimestepInFirstOfMonthsYearsSequence(size_t timestep, bool years = true, size_t start_timestep = 1, size_t frequency = 1) const; - - static std::time_t timeFromEclipse(const DeckRecord &dateRecord); - - static std::time_t forward(std::time_t t0, int64_t hours, int64_t minutes, int64_t seconds); - static std::time_t forward(std::time_t t0, int64_t seconds); - static std::time_t mkdate(int year, int month, int day); - static std::time_t mkdatetime(int year, int month, int day, int hour, int minute, int second); - static const std::map& eclipseMonthIndices(); - static bool valid_month(const std::string& month_name); - - template - void serializeOp(Serializer& serializer) - { - serializer(m_timeList); - serializer.vector(m_first_timestep_years); - serializer.vector(m_first_timestep_months); - serializer(m_restart_offset); - } - - private: - struct StepData - { - size_t stepnumber; - TimeStampUTC timestamp; - - bool operator==(const StepData& data) const - { - return stepnumber == data.stepnumber && - timestamp == data.timestamp; - } - - template - void serializeOp(Serializer& serializer) - { - serializer(stepnumber); - timestamp.serializeOp(serializer); - } - }; - - bool isTimestepInFreqSequence (size_t timestep, size_t start_timestep, size_t frequency, bool years) const; - size_t closest(const std::vector & vec, size_t value) const; - void addTime(std::time_t newTime, TimeMapContext& context, const KeywordLocation& location); - void addFromTSTEPKeyword( const DeckKeyword& TSTEPKeyword, TimeMapContext& context); - void init_start(std::time_t start_time); - - std::vector m_timeList; - std::vector m_first_timestep_years; // A list of the first timestep of every year - std::vector m_first_timestep_months; // A list of the first timestep of every month - std::size_t m_restart_offset = 0; - std::time_t m_restart_time; - }; - -std::ostream& operator<<(std::ostream& stream, const TimeMap& tm); - -} - - - -#endif /* TIMEMAP_HPP_ */ diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp deleted file mode 100644 index 924e9564a..000000000 --- a/src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/* - Copyright 2013 Statoil ASA. - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . -*/ -#include - -#include -#include -#include -#include - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Opm { - - - -namespace { - const std::map month_indices = {{"JAN", 1}, - {"FEB", 2}, - {"MAR", 3}, - {"APR", 4}, - {"MAI", 5}, - {"MAY", 5}, - {"JUN", 6}, - {"JUL", 7}, - {"JLY", 7}, - {"AUG", 8}, - {"SEP", 9}, - {"OCT", 10}, - {"OKT", 10}, - {"NOV", 11}, - {"DEC", 12}, - {"DES", 12}}; - - -} - -struct TimeMapContext { - bool rst_skip; - std::time_t last_time; - - TimeMapContext(bool skip, std::time_t t) : - rst_skip(skip), - last_time(t) - {} -}; - - - - void TimeMap::init_start(std::time_t start_time) { - auto timestamp = TimeStampUTC{start_time}; - - this->m_timeList.push_back(start_time); - this->m_first_timestep_months.push_back({0, timestamp}); - this->m_first_timestep_years.push_back({0, timestamp}); - } - - - TimeMap::TimeMap(const std::vector& time_points, std::size_t restart_offset) { - if (time_points.empty()) - throw std::invalid_argument("Can not initialize with empty list of time points"); - - auto start_time = time_points[0]; - TimeMapContext context(restart_offset > 0, start_time); - this->init_start(start_time); - for (std::size_t ti = 1; ti < time_points.size(); ti++) { - if (context.rst_skip) - this->m_timeList.push_back(start_time); - else - this->addTime( time_points[ti], context, {} ); - } - this->m_restart_offset = restart_offset; - } - - - TimeMap::TimeMap( const Deck& deck, const std::pair& restart) { - std::time_t start_time; - if (deck.hasKeyword("START")) { - // Use the 'START' keyword to find out the start date (if the - // keyword was specified) - const auto& keyword = deck.getKeyword("START"); - start_time = timeFromEclipse(keyword.getRecord(0)); - } else { - // The default start date is not specified in the Eclipse - // reference manual. We hence just assume it is same as for - // the START keyword for Eclipse R100, i.e., January 1st, - // 1983... - start_time = mkdate(1983, 1, 1); - } - this->init_start(start_time); - - this->m_restart_time = restart.first; - this->m_restart_offset = restart.second; - - // In the case of restart we do in general not have access to the prober - // timepoints, and we artificially fix all the timepoints before the - // restart time to the start time. - for (std::size_t it = 1; it < this->m_restart_offset; it++) - this->m_timeList.push_back(start_time); - - TimeMapContext context(this->m_restart_offset > 0, start_time); - for( const auto& keyword : SCHEDULESection(deck)) { - // We're only interested in "TSTEP" and "DATES" keywords, - // so we ignore everything else here... - if (keyword.name() != "TSTEP" && keyword.name() != "DATES") - continue; - - if (keyword.name() == "DATES") { - for (size_t recordIndex = 0; recordIndex < keyword.size(); recordIndex++) { - const auto &record = keyword.getRecord(recordIndex); - std::time_t nextTime; - - try { - nextTime = TimeMap::timeFromEclipse(record); - } catch (const std::exception& e) { - const OpmInputError opm_error { e, keyword.location() } ; - OpmLog::error(opm_error.what()); - std::throw_with_nested(opm_error); - } - - this->addTime(nextTime, context, keyword.location()); - } - continue; - } - this->addFromTSTEPKeyword(keyword, context); - } - } - - TimeMap TimeMap::serializeObject() - { - TimeMap result({123}); - result.m_restart_offset = 4; - result.m_restart_time = 19867234; - return result; - } - - - - std::time_t TimeMap::getStartTime(size_t tStepIdx) const { - return this->operator[](tStepIdx); - } - - std::time_t TimeMap::getEndTime() const { - return this->operator[]( this->size( ) - 1); - } - - - double TimeMap::seconds(size_t timeStep) const { - return std::difftime( this->operator[](timeStep), this->operator[](0)); - } - - double TimeMap::getTotalTime() const - { - if (m_timeList.size() < 2) - return 0.0; - - return std::difftime(this->m_timeList.back(), - this->m_timeList.front()); - } - - void TimeMap::addTime(std::time_t newTime, TimeMapContext& context, const KeywordLocation& location) { - context.last_time = newTime; - if (context.rst_skip) { - if (newTime < this->m_restart_time) - return; - - if (newTime == this->m_restart_time) - context.rst_skip = false; - - if (newTime > this->m_restart_time) { - TimeStampUTC ts(this->m_restart_time); - auto reason = fmt::format("Have scanned past restart data: {:4d}-{:02d}-{:02d}", ts.year(), ts.month(), ts.day()); - throw OpmInputError(reason, location); - } - } - - const std::time_t lastTime = m_timeList.back(); - const size_t step = m_timeList.size(); - if (newTime > lastTime) { - const auto nw = TimeStampUTC{ newTime }; - const auto last = TimeStampUTC{ lastTime }; - - const auto new_month = nw .month(); - const auto last_month = last.month(); - - const auto new_year = nw .year(); - const auto last_year = last.year(); - - if (new_month != last_month || new_year != last_year) - m_first_timestep_months.push_back({step, nw}); - - if (new_year != last_year) - m_first_timestep_years.push_back({step, nw}); - - m_timeList.push_back(newTime); - } else - throw std::invalid_argument("Times added must be in strictly increasing order."); - } - - size_t TimeMap::size() const { - return m_timeList.size(); - } - - const std::map& TimeMap::eclipseMonthIndices() { - return month_indices; - } - - - - std::time_t TimeMap::timeFromEclipse(const DeckRecord &dateRecord) { - const auto &dayItem = dateRecord.getItem(0); - const auto &monthItem = dateRecord.getItem(1); - const auto &yearItem = dateRecord.getItem(2); - const auto &timeItem = dateRecord.getItem(3); - - int hour = 0, min = 0, second = 0; - if (timeItem.hasValue(0)) { - if (sscanf(timeItem.get(0).c_str(), "%d:%d:%d" , &hour,&min,&second) != 3) { - hour = min = second = 0; - } - } - - // Accept lower- and mixed-case month names. - std::string monthname = uppercase(monthItem.get(0)); - - std::time_t date = mkdatetime(yearItem.get(0), - eclipseMonthIndices().at(monthname), - dayItem.get(0), - hour, - min, - second); - return date; - } - - - void TimeMap::addFromTSTEPKeyword(const DeckKeyword &TSTEPKeyword, TimeMapContext& context) { - if (TSTEPKeyword.name() != "TSTEP") - throw std::invalid_argument("Method requires TSTEP keyword input."); - { - const auto &item = TSTEPKeyword.getRecord(0).getItem(0); - - for (size_t itemIndex = 0; itemIndex < item.data_size(); itemIndex++) { - const int64_t seconds = static_cast(item.getSIDouble(itemIndex)); - std::time_t next_time = TimeMap::forward(context.last_time, seconds); - this->addTime(next_time, context, TSTEPKeyword.location()); - } - } - } - - double TimeMap::getTimeStepLength(size_t tStepIdx) const - { - assert(tStepIdx < (this->size() - 1)); - - return std::difftime(this->m_timeList[tStepIdx + 1], - this->m_timeList[tStepIdx + 0]); - } - - double TimeMap::getTimePassedUntil(size_t tLevelIdx) const - { - assert(tLevelIdx < m_timeList.size()); - - return std::difftime(this->m_timeList[tLevelIdx], - this->m_timeList.front()); - } - - const std::vector& TimeMap::timeList() const - { - return m_timeList; - } - - - bool TimeMap::operator==(const TimeMap& data) const - { - return this->m_timeList == data.m_timeList && - this->m_first_timestep_months == data.m_first_timestep_months && - this->m_first_timestep_years == data.m_first_timestep_years && - this->m_restart_offset == data.m_restart_offset; - } - - bool TimeMap::isTimestepInFirstOfMonthsYearsSequence(size_t timestep, bool years, size_t start_timestep, size_t frequency) const { - bool timestep_first_of_month_year = false; - const auto& timesteps = (years) ? m_first_timestep_years : m_first_timestep_months; - - auto same_step = [timestep](const StepData& sd) { return sd.stepnumber == timestep; }; - auto ci_timestep = std::find_if(timesteps.begin(), timesteps.end(), same_step); - if (ci_timestep != timesteps.end() && ci_timestep != timesteps.begin()) { - if (1 >= frequency) { - timestep_first_of_month_year = true; - } else { //Frequency given - timestep_first_of_month_year = isTimestepInFreqSequence(timestep, start_timestep, frequency, years); - } - } - return timestep_first_of_month_year; - } - - - // Return true if the step is the first of each n-month or n-month - // period, starting from start_timestep - 1, with n = frequency. - bool TimeMap::isTimestepInFreqSequence (size_t timestep, size_t start_timestep, size_t frequency, bool years) const { - // Find iterator to data for 'start_timestep' or first - // in-sequence step following it, set start_year and - // start_month. - const auto& timesteps = (years) ? m_first_timestep_years : m_first_timestep_months; - auto compare_stepnumber = [](const StepData& sd, size_t value) { return sd.stepnumber < value; }; - auto ci_start_timestep = std::lower_bound(timesteps.begin(), timesteps.end(), start_timestep - 1, compare_stepnumber); - if (ci_start_timestep == timesteps.end()) { - // We are after the end of the sequence. - return false; - } - const int start_year = ci_start_timestep->timestamp.year(); - const int start_month = ci_start_timestep->timestamp.month() - 1; // For 0-indexing. - - // Find iterator to data for 'timestep'. - auto same_step = [timestep](const StepData& sd) { return sd.stepnumber == timestep; }; - auto ci_timestep = std::find_if(timesteps.begin(), timesteps.end(), same_step); - // The ci_timestep can be assumed to be different from - // timesteps.end(), or we would not be in this function. - // If, however, it is at or before the first timestep we should - // always return false. - if (ci_timestep <= ci_start_timestep) { - return false; - } - - if (years) { - // Year logic. - const int my_year = ci_timestep->timestamp.year(); - if ((my_year - start_year) % frequency == 0) { - return true; - } else { - // Check if we are in a new (frequency-year) period. - const auto prev_it = ci_timestep - 1; - const int prev_year = prev_it->timestamp.year(); - return (my_year - start_year)/frequency > (prev_year - start_year)/frequency; - } - } else { - // Month logic. - const int my_year = ci_timestep->timestamp.year(); - const int my_month = (my_year - start_year) * 12 + ci_timestep->timestamp.month() - 1; - // my_month is now the count of months since start_month. - assert(my_month > start_month); - if ((my_month - start_month) % frequency == 0) { - return true; - } else { - // Check if we are in a new (frequency-month) period. - const auto prev_it = ci_timestep - 1; - const int prev_year = prev_it->timestamp.year(); - const int prev_month = (prev_year - start_year) * 12 + prev_it->timestamp.month() - 1; - return (my_month - start_month)/frequency > (prev_month - start_month)/frequency; - } - } - } - - - // vec is assumed to be sorted - size_t TimeMap::closest(const std::vector & vec, size_t value) const - { - std::vector::const_iterator ci = - std::lower_bound(vec.begin(), vec.end(), value); - if (ci != vec.end()) { - return *ci; - } - return 0; - } - - - std::time_t TimeMap::operator[] (size_t index) const { - return m_timeList.at(index); - } - - std::time_t TimeMap::mkdate(int in_year, int in_month, int in_day) { - return mkdatetime(in_year , in_month , in_day, 0,0,0); - } - - std::time_t TimeMap::mkdatetime(int in_year, int in_month, int in_day, int hour, int minute, int second) { - const auto tp = TimeStampUTC{ TimeStampUTC::YMD { in_year, in_month, in_day } } - .hour(hour).minutes(minute).seconds(second); - - std::time_t t = asTimeT(tp); - { - /* - The underlying mktime( ) function will happily wrap - around dates like January 33, this function will check - that no such wrap-around has taken place. - */ - const auto check = TimeStampUTC{ t }; - if ((in_day != check.day()) || (in_month != check.month()) || (in_year != check.year())) - throw std::invalid_argument("Invalid input arguments for date."); - } - return t; - } - - std::time_t TimeMap::forward(std::time_t t, int64_t seconds) { - return t + seconds; - } - - std::time_t TimeMap::forward(std::time_t t, int64_t hours, int64_t minutes, int64_t seconds) { - return t + seconds + minutes * 60 + hours * 3600; - } - - -std::ostream& operator<<(std::ostream& stream, const TimeMap& tm) { - std::stringstream ss; - ss << "{"; - std::size_t index = 0; - for (const auto& tp : tm.timeList()) { - auto ts = TimeStampUTC(tp); - ss << ts.year() << "-" << std::setfill('0') << std::setw(2) << ts.month() << "-" << std::setfill('0') << std::setw(2) << ts.day(); - index += 1; - if (index < tm.timeList().size()) - ss << ", "; - if (index % 12 == 0) - ss << std::endl; - } - ss << "}"; - return stream << ss.str(); -} -} - - diff --git a/tests/parser/EclipseStateTests.cpp b/tests/parser/EclipseStateTests.cpp index 172990d72..1478a906f 100644 --- a/tests/parser/EclipseStateTests.cpp +++ b/tests/parser/EclipseStateTests.cpp @@ -25,7 +25,6 @@ along with OPM. If not, see . #include #include -#include #include #include #include @@ -200,7 +199,7 @@ BOOST_AUTO_TEST_CASE(CreateSchedule) { auto python = std::make_shared(); EclipseState state(deck); Schedule schedule(deck, state, python); - BOOST_CHECK_EQUAL(schedule.getStartTime(), TimeMap::mkdate( 1998 , 3 , 8)); + BOOST_CHECK_EQUAL(schedule.getStartTime(), asTimeT(TimeStampUTC( 1998 , 3 , 8))); } diff --git a/tests/parser/IOConfigTests.cpp b/tests/parser/IOConfigTests.cpp index cc2e3a605..d570b970b 100644 --- a/tests/parser/IOConfigTests.cpp +++ b/tests/parser/IOConfigTests.cpp @@ -27,7 +27,6 @@ #include #include #include -#include using namespace Opm; diff --git a/tests/parser/RFTConfigTests.cpp b/tests/parser/RFTConfigTests.cpp index 9038c56a3..2f4b6e2b1 100644 --- a/tests/parser/RFTConfigTests.cpp +++ b/tests/parser/RFTConfigTests.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include diff --git a/tests/parser/ScheduleRestartTests.cpp b/tests/parser/ScheduleRestartTests.cpp index ce60bcfdb..735555eb8 100644 --- a/tests/parser/ScheduleRestartTests.cpp +++ b/tests/parser/ScheduleRestartTests.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/parser/ScheduleSerializeTest.cpp b/tests/parser/ScheduleSerializeTest.cpp index fd09a8bf5..1b447956f 100644 --- a/tests/parser/ScheduleSerializeTest.cpp +++ b/tests/parser/ScheduleSerializeTest.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index 823ac980b..79580d970 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -362,7 +361,7 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckMissingReturnsDefaults) { FieldPropsManager fp( deck, Phases{true, true, true}, grid, table); Runspec runspec (deck); Schedule schedule(deck, grid , fp, runspec, python); - BOOST_CHECK_EQUAL( schedule.getStartTime() , TimeMap::mkdate(1983, 1 , 1)); + BOOST_CHECK_EQUAL( schedule.getStartTime() , asTimeT( TimeStampUTC(1983, 1, 1))); } BOOST_AUTO_TEST_CASE(CreateScheduleDeckWellsOrdered) { @@ -472,7 +471,7 @@ BOOST_AUTO_TEST_CASE(GroupTree2TEST) { BOOST_AUTO_TEST_CASE(CreateScheduleDeckWithStart) { const auto& schedule = make_schedule( createDeck() ); - BOOST_CHECK_EQUAL( schedule.getStartTime() , TimeMap::mkdate(1998, 3 , 8 )); + BOOST_CHECK_EQUAL( schedule.getStartTime() , asTimeT(TimeStampUTC(1998, 3 , 8 ))); } BOOST_AUTO_TEST_CASE(CreateScheduleDeckWithSCHEDULENoThrow) { diff --git a/tests/parser/TimeMapTest.cpp b/tests/parser/TimeMapTest.cpp deleted file mode 100644 index d0d309b0f..000000000 --- a/tests/parser/TimeMapTest.cpp +++ /dev/null @@ -1,844 +0,0 @@ -/* - Copyright 2013 Statoil ASA. - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . - */ - -#include -#include - -#define BOOST_TEST_MODULE TimeMapTests - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - - -const std::time_t startDateJan1st2010 = Opm::TimeMap::mkdate(2010, 1, 1); - -Opm::DeckRecord createDeckRecord(int day, const std::string &month, int year, const std::string &time = "00:00:00.000"); - -BOOST_AUTO_TEST_CASE(GetStartDate) { - Opm::TimeMap timeMap({ startDateJan1st2010 }); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2010, 1, 1) , timeMap.getStartTime(/*timeStepIdx=*/0)); -} - - - -BOOST_AUTO_TEST_CASE(AddDateNegativeStepThrows) { - std::vector time_points = { Opm::asTimeT(Opm::TimeStampUTC(2000,1,1)), Opm::asTimeT(Opm::TimeStampUTC(1999,1,1))}; - BOOST_CHECK_THROW(Opm::TimeMap timeMap(time_points), std::invalid_argument); -} - - -BOOST_AUTO_TEST_CASE(AddStepSizeCorrect) { - std::vector time_points = { Opm::asTimeT(Opm::TimeStampUTC(2010,1,1)), - Opm::asTimeT(Opm::TimeStampUTC(2010,1,2)), - Opm::asTimeT(Opm::TimeStampUTC(2010,1,3))}; - Opm::TimeMap timeMap(time_points); - BOOST_CHECK_EQUAL(3U, timeMap.size()); - - 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 )); -} - - -BOOST_AUTO_TEST_CASE( dateFromEclipseThrowsInvalidRecord ) { - Opm::DeckRecord startRecord; - Opm::DeckItem dayItem("DAY", int() ); - Opm::DeckItem monthItem("MONTH", std::string() ); - Opm::DeckItem yearItem("YEAR", int() ); - Opm::DeckItem timeItem("TIME", std::string() ); - Opm::DeckItem extraItem("EXTRA", int() ); - - dayItem.push_back( 10 ); - yearItem.push_back(1987 ); - monthItem.push_back("FEB"); - timeItem.push_back("00:00:00.000"); - - BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::out_of_range ); - - startRecord.addItem( dayItem ); - BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::out_of_range ); - - startRecord.addItem( monthItem ); - BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::out_of_range ); - - startRecord.addItem( yearItem ); - BOOST_CHECK_THROW(Opm::TimeMap::timeFromEclipse( startRecord ) , std::out_of_range ); - - startRecord.addItem( timeItem ); - BOOST_CHECK_NO_THROW(Opm::TimeMap::timeFromEclipse( startRecord )); -} - - - -BOOST_AUTO_TEST_CASE( dateFromEclipseInvalidMonthThrows ) { - Opm::DeckRecord startRecord; - Opm::DeckItem dayItem( "DAY", int() ); - Opm::DeckItem monthItem( "MONTH", std::string() ); - Opm::DeckItem yearItem( "YEAR", int() ); - Opm::DeckItem timeItem( "TIME", std::string() ); - - dayItem.push_back( 10 ); - yearItem.push_back(1987 ); - monthItem.push_back("XXX"); - timeItem.push_back("00:00:00.000"); - - startRecord.addItem( dayItem ); - startRecord.addItem( monthItem ); - startRecord.addItem( yearItem ); - startRecord.addItem( timeItem ); - - BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::out_of_range ); -} - - -BOOST_AUTO_TEST_CASE( timeFromEclipseCheckMonthNames ) { - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 1, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "JAN", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 2, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "FEB", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 3, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "MAR", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 4, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "APR", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 5, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "MAI", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 5, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "MAY", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 6, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "JUN", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 7, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "JUL", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 7, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "JLY", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 8, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "AUG", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 9, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "SEP", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 10, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "OKT", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 10, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "OCT", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 11, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "NOV", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 12, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "DEC", 2000))); - BOOST_CHECK_EQUAL( Opm::TimeMap::mkdate(2000, 12, 1), Opm::TimeMap::timeFromEclipse(createDeckRecord(1, "DES", 2000))); -} - - -BOOST_AUTO_TEST_CASE( timeFromEclipseInputRecord ) { - Opm::DeckRecord startRecord; - Opm::DeckItem dayItem( "DAY", int() ); - Opm::DeckItem monthItem( "MONTH", std::string() ); - Opm::DeckItem yearItem("YEAR", int()); - Opm::DeckItem timeItem("TIME", std::string() ); - - dayItem.push_back( 10 ); - yearItem.push_back( 1987 ); - monthItem.push_back("JAN"); - timeItem.push_back("00:00:00.000"); - - startRecord.addItem( std::move( dayItem ) ); - startRecord.addItem( std::move( monthItem ) ); - startRecord.addItem( std::move( yearItem ) ); - startRecord.addItem( std::move( timeItem ) ); - - BOOST_CHECK_EQUAL(Opm::TimeMap::mkdate(1987, 1 , 10 ), Opm::TimeMap::timeFromEclipse( startRecord )); -} - - - - -BOOST_AUTO_TEST_CASE(TimeStepsCorrect) { - const char *deckData = - "START\n" - " 21 MAY 1981 /\n" - "\n" - "SCHEDULE\n" - "TSTEP\n" - " 1 2 3 4 5 /\n" - "\n" - "DATES\n" - " 1 JAN 1982 /\n" - " 1 JAN 1982 13:55:44 /\n" - " 3 JAN 1982 14:56:45.123 /\n" - "/\n" - "\n" - "TSTEP\n" - " 6 7 /\n"; - - Opm::Parser parser( true ); - auto deck = parser.parseString(deckData); - Opm::TimeMap tmap(deck); - - BOOST_CHECK_EQUAL(tmap.getStartTime(0),Opm::TimeMap::mkdate( 1981 , 5 , 21 )); - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(0), 1*24*60*60); - BOOST_CHECK_EQUAL(tmap.getTimePassedUntil(1), 1.0*24*60*60); - - - BOOST_CHECK_EQUAL(tmap.getStartTime(1), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1981 , 5 , 21 ) , 3600*24)); - - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(1), 2*24*60*60); - BOOST_CHECK_EQUAL(tmap.getTimePassedUntil(2), (1.0 + 2.0)*24*60*60); - BOOST_CHECK_EQUAL(tmap.getStartTime(2), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1981 , 5 , 21 ) , 3*24*3600)); - - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(2), 3*24*60*60); - BOOST_CHECK_EQUAL(tmap.getTimePassedUntil(3), (1.0 + 2.0 + 3.0)*24*60*60); - BOOST_CHECK_EQUAL(tmap.getStartTime(3), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1981 , 5 , 21 ) , 6*3600*24)); - - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(3), 4*24*60*60); - BOOST_CHECK_EQUAL(tmap.getTimePassedUntil(4), (1.0 + 2.0 + 3.0 + 4.0)*24*60*60); - BOOST_CHECK_EQUAL(tmap.getStartTime(4), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1981 , 5 , 21 ) , 10*3600*24)); - - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(4), 5*24*60*60); - BOOST_CHECK_EQUAL(tmap.getTimePassedUntil(5), (1.0 + 2.0 + 3.0 + 4.0 + 5.0)*24*60*60); - BOOST_CHECK_EQUAL(tmap.getStartTime(5), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1981 , 5 , 21 ) , 15*3600*24)); - - // timestep 5 is the period between the last step specified using - // of the TIMES keyword and the first record of DATES - BOOST_CHECK_EQUAL(tmap.getStartTime(6), - Opm::TimeMap::mkdate( 1982 , 1 , 1 )); - - BOOST_CHECK_EQUAL(tmap.getStartTime(7), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1982 , 1 , 1 ) , 13,55,44 )); - - BOOST_CHECK_EQUAL(tmap.getStartTime(8), - Opm::TimeMap::forward( Opm::TimeMap::mkdate( 1982 , 1 , 3 ) , 14,56,45)); - - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(8), 6*24*60*60); - BOOST_CHECK_EQUAL(tmap.getTimeStepLength(9), 7*24*60*60); -} - - -BOOST_AUTO_TEST_CASE(initTimestepsYearsAndMonths) { - const char *deckData = - "START\n" - " 21 MAY 1981 /\n" - "\n" - "SCHEDULE\n" - "TSTEP\n" - " 1 2 3 4 5 /\n" - "\n" - "DATES\n" - " 5 JUL 1981 /\n" - " 6 JUL 1981 /\n" - " 5 AUG 1981 /\n" - " 5 SEP 1981 /\n" - " 1 OCT 1981 /\n" - " 1 NOV 1981 /\n" - " 1 DEC 1981 /\n" - " 1 JAN 1982 /\n" - " 1 JAN 1982 13:55:44 /\n" - " 3 JAN 1982 14:56:45.123 /\n" - "/\n" - "\n" - "TSTEP\n" - " 6 7 /\n"; - - Opm::Parser parser; - auto deck = parser.parseString(deckData); - const Opm::TimeMap tmap(deck); - - /*deckData timesteps: - 0 21 may 1981 START - 1 22 may 1981 - 2 24 may 1981 - 3 27 may 1981 - 4 31 may 1981 - 5 5 jun 1981 - 6 5 jul 1981 - 7 6 jul 1981 - 8 5 aug 1981 - 9 5 sep 1981 - 10 1 oct 1981 - 11 1 nov 1981 - 12 1 dec 1981 - 13 1 jan 1982 - 14 1 jan 1982 - 15 3 jan 1982 - 16 9 jan 1982 - 17 16 jan 1982*/ - - for (size_t timestep = 0; timestep <= 17; ++timestep) { - if ((5 == timestep) || (6 == timestep) || (8 == timestep) || (9 == timestep) || - (10 == timestep) || (11 == timestep) || (12 == timestep) || (13 == timestep)) { - BOOST_CHECK_EQUAL(true, tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, false)); - } else { - BOOST_CHECK_EQUAL(false, tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, false)); - } - } - - for (size_t timestep = 0; timestep <= 17; ++timestep) { - if (13 == timestep) { - BOOST_CHECK_EQUAL(true, tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, true)); - } else { - BOOST_CHECK_EQUAL(false, tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, true)); - } - } -} - -BOOST_AUTO_TEST_CASE(initTimestepsYearsAndMonthsSkippingMonthsFrequency) { - const char *deckData = - "START\n" - " 21 MAY 1981 /\n" - "\n" - "SCHEDULE\n" - "DATES\n" - " 5 JUL 1981 /\n" - " 6 JUL 1981 /\n" - " 5 AUG 1981 /\n" - " 5 SEP 1981 /\n" - " 1 OCT 1981 /\n" - " 1 NOV 1981 /\n" - " 1 DEC 1981 /\n" - " 1 JAN 1982 /\n" - " 1 JAN 1982 13:55:44 /\n" - " 3 JAN 1982 14:56:45.123 /\n" - " 1 JAN 1983 /\n" - " 1 JAN 1984 /\n" - " 1 JAN 1985 /\n" - " 1 JAN 1988 /\n" - "/\n"; - - Opm::Parser parser; - auto deck = parser.parseString(deckData); - const Opm::TimeMap tmap(deck); - - /*deckData timesteps: - 0 21 may 1981 START - 1 5 jul 1981 - 2 6 jul 1981 - 3 5 aug 1981 - 4 5 sep 1981 - 5 1 oct 1981 - 6 1 nov 1981 - 7 1 dec 1981 - 8 1 jan 1982 - 9 1 jan 1982 - 10 3 jan 1982 - 11 1 jan 1983 - 12 1 jan 1984 - 13 1 jan 1985 - 14 1 jan 1988*/ - - // Month, not set frequency. - { - std::vector expected = { - false, // 0 21 may 1981 START - true, // 1 5 jul 1981 - false, // 2 6 jul 1981 - true, // 3 5 aug 1981 - true, // 4 5 sep 1981 - true, // 5 1 oct 1981 - true, // 6 1 nov 1981 - true, // 7 1 dec 1981 - true, // 8 1 jan 1982 - false, // 9 1 jan 1982 - false, // 10 3 jan 1982 - true, // 11 1 jan 1983 - true, // 12 1 jan 1984 - true, // 13 1 jan 1985 - true // 14 1 jan 1988 - }; - - for (size_t timestep = 0; timestep < expected.size(); ++timestep) { - const bool ok = tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, false) == expected[timestep]; - BOOST_CHECK_MESSAGE(ok, "failing for timestep " << timestep); - } - } - - // Month, frequency 2. - { - std::vector expected = { - false, // 0 21 may 1981 START - true, // 1 5 jul 1981 - false, // 2 6 jul 1981 - false, // 3 5 aug 1981 - true, // 4 5 sep 1981 - false, // 5 1 oct 1981 - true, // 6 1 nov 1981 - false, // 7 1 dec 1981 - true, // 8 1 jan 1982 - false, // 9 1 jan 1982 - false, // 10 3 jan 1982 - true, // 11 1 jan 1983 - true, // 12 1 jan 1984 - true, // 13 1 jan 1985 - true // 14 1 jan 1988 - }; - - for (size_t timestep = 0; timestep < expected.size(); ++timestep) { - const bool ok = tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, false, 1, 2) == expected[timestep]; - BOOST_CHECK_MESSAGE(ok, "failing for timestep " << timestep); - } - } - - // Year, not set frequency. - { - std::vector expected = { - false, // 0 21 may 1981 START - false, // 1 5 jul 1981 - false, // 2 6 jul 1981 - false, // 3 5 aug 1981 - false, // 4 5 sep 1981 - false, // 5 1 oct 1981 - false, // 6 1 nov 1981 - false, // 7 1 dec 1981 - true, // 8 1 jan 1982 - false, // 9 1 jan 1982 - false, // 10 3 jan 1982 - true, // 11 1 jan 1983 - true, // 12 1 jan 1984 - true, // 13 1 jan 1985 - true // 14 1 jan 1988 - }; - - for (size_t timestep = 0; timestep < expected.size(); ++timestep) { - const bool ok = tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, true) == expected[timestep]; - BOOST_CHECK_MESSAGE(ok, "failing for timestep " << timestep); - } - } - - // Year, frequency 2. - { - std::vector expected = { - false, // 0 21 may 1981 START - false, // 1 5 jul 1981 - false, // 2 6 jul 1981 - false, // 3 5 aug 1981 - false, // 4 5 sep 1981 - false, // 5 1 oct 1981 - false, // 6 1 nov 1981 - false, // 7 1 dec 1981 - false, // 8 1 jan 1982 - false, // 9 1 jan 1982 - false, // 10 3 jan 1982 - true, // 11 1 jan 1983 - false, // 12 1 jan 1984 - true, // 13 1 jan 1985 - true // 14 1 jan 1988 - }; - - for (size_t timestep = 0; timestep < expected.size(); ++timestep) { - const bool ok = tmap.isTimestepInFirstOfMonthsYearsSequence(timestep, true, 1, 2) == expected[timestep]; - BOOST_CHECK_MESSAGE(ok, "failing for timestep " << timestep); - } - } -} - - -BOOST_AUTO_TEST_CASE(initTimestepsLongStep) { - const char *deckData = - "START\n" - " 1 JAN 1983 /\n" - "\n" - "SCHEDULE\n" - "TSTEP\n" - " 25550 /\n"; - - Opm::Parser parser; - auto deck = parser.parseString(deckData); - const Opm::TimeMap tmap(deck); - - /*deckData timesteps: - 0 1 jan 1983 START - 1 14 dec 2052*/ - - const auto tEnd = Opm::TimeStampUTC { tmap.getEndTime() }; - - BOOST_CHECK_EQUAL(tEnd.year(), 2052); - BOOST_CHECK_EQUAL(tEnd.month(), 12); - BOOST_CHECK_EQUAL(tEnd.day(), 14); -} - - -BOOST_AUTO_TEST_CASE(TimestepsLabUnit) { - const char *deckData = - "START\n" - " 1 JAN 1983 /\n" - "\n" - "LAB\n" - " \n" - "SCHEDULE\n" - "TSTEP\n" - " 24*10 /\n"; - - Opm::Parser parser; - auto deck = parser.parseString(deckData); - const Opm::TimeMap tmap(deck); - - /*deckData timesteps: - 0 1 jan 1983 START - 1 11 jan 1983*/ - - const auto tEnd = Opm::TimeStampUTC { tmap.getEndTime() }; - - BOOST_CHECK_EQUAL(tEnd.year(), 1983); - BOOST_CHECK_EQUAL(tEnd.month(), 1); - BOOST_CHECK_EQUAL(tEnd.day(), 11); -} - - -BOOST_AUTO_TEST_CASE(initTimestepsDistantDates) { - const char *deckData = - "START\n" - " 1 JAN 1983 /\n" - "\n" - "SCHEDULE\n" - "DATES\n" - " 1 JAN 2040 /\n" - " 1 JAN 2050 /\n" - "/\n"; - - Opm::Parser parser; - auto deck = parser.parseString(deckData); - const Opm::TimeMap tmap(deck); - - /*deckData timesteps: - 0 1 jan 1983 START - 1 1 jan 2040 - 2 1 jan 2050*/ - - const auto t1 = Opm::TimeStampUTC { tmap.getStartTime(1) }; - const auto t2 = Opm::TimeStampUTC { tmap.getEndTime() }; - - BOOST_CHECK_EQUAL(t1.year(), 2040); - BOOST_CHECK_EQUAL(t1.month(), 1); - BOOST_CHECK_EQUAL(t1.day(), 1); - - BOOST_CHECK_EQUAL(t2.year(), 2050); - BOOST_CHECK_EQUAL(t2.month(), 1); - BOOST_CHECK_EQUAL(t2.day(), 1); -} - - -BOOST_AUTO_TEST_CASE(mkdate) { - BOOST_CHECK_THROW( Opm::TimeMap::mkdate( 2010 , 0 , 0 ) , std::invalid_argument); - auto t0 = Opm::TimeStampUTC { Opm::TimeMap::mkdate( 2010 , 1, 1) }; - auto t1 = Opm::TimeStampUTC { Opm::TimeMap::forward( asTimeT(t0) , 24*3600) }; - - BOOST_CHECK_EQUAL( t1.year() , 2010 ); - BOOST_CHECK_EQUAL( t1.month() , 1 ); - BOOST_CHECK_EQUAL( t1.day() , 2 ); - - t1 = Opm::TimeMap::forward( asTimeT(t1) , -24*3600); - BOOST_CHECK_EQUAL( t1.year() , 2010 ); - BOOST_CHECK_EQUAL( t1.month() , 1 ); - BOOST_CHECK_EQUAL( t1.day() , 1 ); - - t1 = Opm::TimeMap::forward( asTimeT(t0) , 23, 55 , 300); - BOOST_CHECK_EQUAL( t1.year() , 2010 ); - BOOST_CHECK_EQUAL( t1.month() , 1 ); - BOOST_CHECK_EQUAL( t1.day() , 2 ); - -} - -BOOST_AUTO_TEST_CASE(mkdatetime) { - BOOST_CHECK_THROW(Opm::TimeMap::mkdatetime(2010, 0, 0, 0, 0, 0), std::invalid_argument); - auto t0 = Opm::TimeStampUTC { Opm::TimeMap::mkdatetime(2010, 1, 1, 0, 0, 0) }; - auto t1 = Opm::TimeStampUTC { Opm::TimeMap::forward(asTimeT(t0), 24 * 3600) }; - - BOOST_CHECK_EQUAL(t1.year(), 2010); - BOOST_CHECK_EQUAL(t1.month(), 1); - BOOST_CHECK_EQUAL(t1.day(), 2); - - t1 = Opm::TimeMap::forward(asTimeT(t1), -24 * 3600); - BOOST_CHECK_EQUAL(t1.year(), 2010); - BOOST_CHECK_EQUAL(t1.month(), 1); - BOOST_CHECK_EQUAL(t1.day(), 1); - - t1 = Opm::TimeMap::forward(asTimeT(t0), 23, 55, 300); - BOOST_CHECK_EQUAL(t1.year(), 2010); - BOOST_CHECK_EQUAL(t1.month(), 1); - BOOST_CHECK_EQUAL(t1.day(), 2); -} - -Opm::DeckRecord createDeckRecord(int day, const std::string &month, int year, const std::string &time) { - Opm::DeckRecord deckRecord; - Opm::DeckItem dayItem("DAY", int() ); - Opm::DeckItem monthItem("MONTH", std::string() ); - Opm::DeckItem yearItem("YEAR", int() ); - Opm::DeckItem timeItem("TIME", std::string() ); - - yearItem.push_back(year); - monthItem.push_back(month); - dayItem.push_back(day); - timeItem.push_back(time); - - deckRecord.addItem(dayItem); - deckRecord.addItem(monthItem); - deckRecord.addItem(yearItem); - deckRecord.addItem(timeItem); - - return deckRecord; -} - - -BOOST_AUTO_TEST_CASE(TimeServiceOperatorPlus) { - Opm::TimeStampUTC t0(Opm::TimeMap::mkdatetime(2010,1,1,0,0,0)); - auto t1 = t0 + std::chrono::duration(3600*24); - - BOOST_CHECK_EQUAL(t1.year(), 2010); - BOOST_CHECK_EQUAL(t1.month(), 1); - BOOST_CHECK_EQUAL(t1.day(), 2); - - auto tl = Opm::asLocalTimeT(t0); - auto tu = Opm::asTimeT(t0); - auto diff1 = std::difftime(tl, tu); - - auto tml = *std::gmtime(&tl); - auto tmu = *std::gmtime(&tu); - - auto diff2 = std::difftime( std::mktime(&tml), std::mktime(&tmu) ); - - BOOST_CHECK_CLOSE( diff1, diff2, 1e-6); -} - - -BOOST_AUTO_TEST_CASE(RESTART) { - std::string deck_string1 = R"( -START - 1 JAN 2000 / - -RESTART - 'CASE' 5 / - -SCHEDULE - -SKIPREST - -DATES - 1 JAN 2001 / - 1 JAN 2002 / - 1 JAN 2003 / - 1 JAN 2004 / -/ - -DATES - 1 JAN 2005 / -/ - -DATES - 1 JAN 2006 / - 1 JAN 2007 / - 1 JAN 2008 / - 1 JAN 2009 / - 1 JAN 2010 / -/ -)"; - - std::string deck_string2 = R"( -START - 1 JAN 2000 / - -RESTART - 'CASE' 5 / - -SCHEDULE - --- The period before the restart dates has been removed - the restart date --- should still be picked up as report step 5. ---DATES --- 1 JAN 2001 / --- 1 JAN 2002 / --- 1 JAN 2003 / --- 1 JAN 2004 / ---/ - -DATES - 1 JAN 2005 / -/ - -DATES - 1 JAN 2006 / - 1 JAN 2007 / - 1 JAN 2008 / - 1 JAN 2009 / - 1 JAN 2010 / -/ -)"; - - - Opm::Parser parser; - const auto deck1 = parser.parseString(deck_string1); - const auto deck2 = parser.parseString(deck_string2); - - // The date 2005-01-02 is not present as a DATES in the deck; invalid input. - auto invalid_restart = std::make_pair(Opm::asTimeT(Opm::TimeStampUTC(2005, 1, 2)), 5); - auto valid_restart = std::make_pair(Opm::asTimeT(Opm::TimeStampUTC(2005, 1, 1)), 5); - - BOOST_CHECK_THROW( Opm::TimeMap(deck1, invalid_restart) , std::exception); - Opm::TimeMap tm1(deck1, valid_restart); - 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))); - - Opm::TimeMap tm2(deck2, valid_restart); - BOOST_CHECK_EQUAL(tm2[5], Opm::asTimeT(Opm::TimeStampUTC(2005,1,1))); - BOOST_CHECK_EQUAL(tm2[6], Opm::asTimeT(Opm::TimeStampUTC(2006,1,1))); - -} - -BOOST_AUTO_TEST_CASE(RESTART2) { - std::string deck_string1 = R"( -START - 1 JAN 2000 / - -RESTART - 'CASE' 5 / - -SCHEDULE - -DATES - 1 JAN 2001 / - 1 JAN 2002 / - 1 JAN 2003 / - 1 JAN 2004 / -- 4 -/ - -DATES -- Report step 5 - 1 JAN 2005 / -/ - -DATES - 1 JAN 2006 / -- 6 - 1 JAN 2007 / -- 7 - 1 JAN 2008 / -- 8 - 1 JAN 2009 / -- 9 - 1 JAN 2010 / -- 10 -/ -)"; - - std::string deck_string2 = R"( -START - 1 JAN 2000 / - -RESTART - 'CASE' 5 / - -SCHEDULE - -DATES - 1 JAN 2001 / - 1 JAN 2002 / - 1 JAN 2004 / -- 3 -/ - -DATES -- Report step 4 - 1 JAN 2005 / -/ - -TSTEP -1 / -- <- Restart from here 5 - -DATES - 1 JAN 2006 / -- 6 - 1 JAN 2007 / -- 7 - 1 JAN 2008 / -- 8 - 1 JAN 2009 / -- 9 - 1 JAN 2010 / -- 10 -/ -)"; - - std::string deck_string3 = R"( -START - 1 JAN 2000 / - -RESTART - 'CASE' 5 / - -SCHEDULE - -DATES - 1 JAN 2001 / - 1 JAN 2002 / - 1 JAN 2004 / -- 3 -/ - -DATES -- Report step 4 - 1 JAN 2005 / -/ - -TSTEP -1 / -- <- Restart from here 5 - -)"; - - std::string deck_string4 = R"( -START - 1 JAN 2000 / - -RESTART - 'CASE' 5 / - -SCHEDULE - -DATES - 1 JAN 2001 / - 1 JAN 2002 / - 1 JAN 2004 / -- 3 -/ - -DATES -- Report step 4 - 1 JAN 2005 / -/ - -TSTEP -2 / -- <- Restart from here 5 - -)"; - Opm::Parser parser; - const auto deck1 = parser.parseString(deck_string1); - const auto deck2 = parser.parseString(deck_string2); - const auto deck3 = parser.parseString(deck_string3); - const auto deck4 = parser.parseString(deck_string4); - auto restart = std::make_pair(Opm::asTimeT(Opm::TimeStampUTC(2005, 1, 2)), 5); - BOOST_CHECK_THROW( Opm::TimeMap(deck1, restart) , std::exception); - BOOST_CHECK_NO_THROW( Opm::TimeMap(deck2, restart) ); - BOOST_CHECK_NO_THROW( Opm::TimeMap(deck3, restart) ); - BOOST_CHECK_THROW( Opm::TimeMap(deck4, restart) , std::exception); - - -} - - - -BOOST_AUTO_TEST_CASE(Overflow) { - auto year = 226300; - auto month = 1; - auto day = 2; - auto ts0 = Opm::TimeStampUTC(year, month, day); - auto t0 = Opm::asTimeT(ts0); - - { - auto ts = Opm::TimeStampUTC(t0); - BOOST_CHECK_EQUAL(ts.year(), year); - BOOST_CHECK_EQUAL(ts.month(), month); - BOOST_CHECK_EQUAL(ts.day(), day); - } - - { - auto tc = Opm::TimeService::from_time_t(t0); - auto ts = Opm::TimeStampUTC( Opm::TimeService::to_time_t(tc) ); - BOOST_CHECK_EQUAL(ts.year(), year); - BOOST_CHECK_EQUAL(ts.month(), month); - BOOST_CHECK_EQUAL(ts.day(), day); - } -} - - diff --git a/tests/parser/WTEST.cpp b/tests/parser/WTEST.cpp index 306057dd0..136184556 100644 --- a/tests/parser/WTEST.cpp +++ b/tests/parser/WTEST.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/parser/WellTests.cpp b/tests/parser/WellTests.cpp index 1740a55b3..969697e52 100644 --- a/tests/parser/WellTests.cpp +++ b/tests/parser/WellTests.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/parser/integration/IOConfigIntegrationTest.cpp b/tests/parser/integration/IOConfigIntegrationTest.cpp index f620d2708..755e71bb4 100644 --- a/tests/parser/integration/IOConfigIntegrationTest.cpp +++ b/tests/parser/integration/IOConfigIntegrationTest.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include using namespace Opm; diff --git a/tests/parser/integration/ScheduleCreateFromDeck.cpp b/tests/parser/integration/ScheduleCreateFromDeck.cpp index 194f3683a..712e54a0e 100644 --- a/tests/parser/integration/ScheduleCreateFromDeck.cpp +++ b/tests/parser/integration/ScheduleCreateFromDeck.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -61,7 +60,7 @@ BOOST_AUTO_TEST_CASE(CreateSchedule) { FieldPropsManager fp(deck, Phases{true, true, true}, grid, table); Runspec runspec (deck); Schedule sched(deck, grid , fp, runspec, python); - BOOST_CHECK_EQUAL(TimeMap::mkdate(2007 , 5 , 10), sched.getStartTime()); + BOOST_CHECK_EQUAL(asTimeT(TimeStampUTC(2007 , 5 , 10)), sched.getStartTime()); BOOST_CHECK_EQUAL(9U, sched.size()); BOOST_CHECK( deck.hasKeyword("NETBALAN") ); } @@ -78,7 +77,7 @@ BOOST_AUTO_TEST_CASE(CreateSchedule_Comments_After_Keywords) { Runspec runspec (deck); auto python = std::make_shared(); Schedule sched(deck, grid , fp, runspec, python); - BOOST_CHECK_EQUAL(TimeMap::mkdate(2007, 5 , 10) , sched.getStartTime()); + BOOST_CHECK_EQUAL(asTimeT(TimeStampUTC(2007, 5 , 10)) , sched.getStartTime()); BOOST_CHECK_EQUAL(9U, sched.size()); } diff --git a/tests/test_DoubHEAD.cpp b/tests/test_DoubHEAD.cpp index 74940a24a..88f471749 100644 --- a/tests/test_DoubHEAD.cpp +++ b/tests/test_DoubHEAD.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include diff --git a/tests/test_EclipseIO.cpp b/tests/test_EclipseIO.cpp index 7d18b6caa..9af2390ff 100644 --- a/tests/test_EclipseIO.cpp +++ b/tests/test_EclipseIO.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/test_InteHEAD.cpp b/tests/test_InteHEAD.cpp index fb6359d31..09a7dd287 100644 --- a/tests/test_InteHEAD.cpp +++ b/tests/test_InteHEAD.cpp @@ -25,10 +25,10 @@ #include +#include #include #include #include -#include #include #include @@ -44,25 +44,25 @@ namespace VI = ::Opm::RestartIO::Helpers::VectorItems; namespace { - std::vector elapsedTime(const Opm::TimeMap& tmap) +std::vector elapsedTime(const Opm::Schedule& sched) +{ + auto elapsed = std::vector{}; + + elapsed.reserve(sched.size()); + elapsed.push_back(0.0); + + for (auto nstep = sched.size() - 1, + step = 0*nstep; step < nstep; ++step) { - auto elapsed = std::vector{}; - - elapsed.reserve(tmap.size()); - elapsed.push_back(0.0); - - for (auto nstep = tmap.size() - 1, - step = 0*nstep; step < nstep; ++step) - { - elapsed.push_back(tmap.getTimeStepLength(step)); - } - - std::partial_sum(std::begin(elapsed), std::end(elapsed), - std::begin(elapsed)); - - return elapsed; + elapsed.push_back(sched.stepLength(step)); } + std::partial_sum(std::begin(elapsed), std::end(elapsed), + std::begin(elapsed)); + + return elapsed; +} + void expectDate(const Opm::RestartIO::InteHEAD::TimePoint& tp, const int year, const int month, const int day) { @@ -476,6 +476,17 @@ BOOST_AUTO_TEST_CASE(ngroups) BOOST_CHECK_EQUAL(v[VI::intehead::NGRP], ngroup); } + +static Opm::Schedule make_schedule(const std::string& deck_string) { + const auto& deck = Opm::Parser{}.parseString(deck_string); + auto python = std::make_shared(); + Opm::EclipseGrid grid(10,10,10); + Opm::TableManager table ( deck ); + Opm::FieldPropsManager fp( deck, Opm::Phases{true, true, true}, grid, table); + Opm::Runspec runspec (deck); + return Opm::Schedule(deck, grid , fp, runspec, python); +} + BOOST_AUTO_TEST_CASE(SimulationDate) { const auto input = std::string { R"( @@ -496,12 +507,10 @@ TSTEP 10*365.0D0 / )" }; - const auto tmap = ::Opm::TimeMap { - ::Opm::Parser{}.parseString(input) - }; + auto sched = make_schedule(input); - const auto start = tmap.getStartTime(0); - const auto elapsed = elapsedTime(tmap); + const auto start = sched.getStartTime(); + const auto elapsed = elapsedTime(sched); auto checkDate = [start, &elapsed] (const std::vector::size_type i, diff --git a/tests/test_restartwellinfo.cpp b/tests/test_restartwellinfo.cpp index a05df7b59..73ea8eee9 100644 --- a/tests/test_restartwellinfo.cpp +++ b/tests/test_restartwellinfo.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include