Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions lib/eclipse/EclipseState/IOConfig/IOConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ namespace Opm {
IOConfig::IOConfig( const Deck& deck ) :
IOConfig( GRIDSection( deck ),
RUNSPECSection( deck ),
TimeMap( deck ),
deck.hasKeyword("NOSIM"),
deck.getDataFile() )
{}

IOConfig::IOConfig( const std::string& input_path ) :
m_timemap( TimeMap{ Deck{} } ),
m_deck_filename( input_path ),
m_output_dir( outputdir( input_path ) ),
m_base_name( basename( input_path ) )
Expand Down Expand Up @@ -97,10 +95,8 @@ namespace Opm {

IOConfig::IOConfig( const GRIDSection& grid,
const RUNSPECSection& runspec,
TimeMap timemap,
bool nosim,
const std::string& input_path ) :
m_timemap( std::move( timemap ) ),
m_write_INIT_file( grid.hasKeyword( "INIT" ) ),
m_write_EGRID_file( write_egrid_file( grid ) ),
m_UNIFIN( runspec.hasKeyword( "UNIFIN" ) ),
Expand Down Expand Up @@ -169,13 +165,6 @@ namespace Opm {



boost::gregorian::date IOConfig::getTimestepDate(size_t reportStep) const {
const auto& time = m_timemap[reportStep];
return time.date();
}



std::string IOConfig::getRestartFileName(const std::string& restart_base, int report_step, bool output) const {
bool unified = output ? getUNIFOUT() : getUNIFIN();
bool fmt_file = output ? getFMTOUT() : getFMTIN();
Expand Down
17 changes: 4 additions & 13 deletions lib/eclipse/EclipseState/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@

namespace Opm {

namespace {

time_t posixTime( const boost::posix_time::ptime& t) {
boost::posix_time::ptime epoch( boost::gregorian::date( 1970, 1, 1 ) );
return time_t( ( t - epoch ).total_seconds() );
}

}

Schedule::Schedule( const ParseContext& parseContext,
const EclipseGrid& grid,
const Eclipse3DProperties& eclipseProperties,
Expand Down Expand Up @@ -101,16 +92,16 @@ namespace Opm {
}
}

boost::posix_time::ptime Schedule::getStartTime() const {
return m_timeMap.getStartTime(/*timeStepIdx=*/0);
std::time_t Schedule::getStartTime() const {
return this->posixStartTime( );
}

time_t Schedule::posixStartTime() const {
return posixTime(this->getStartTime());
return m_timeMap.getStartTime( 0 );
}

time_t Schedule::posixEndTime() const {
return posixTime( this->m_timeMap.getEndTime() );
return this->m_timeMap.getEndTime();
}

void Schedule::iterateScheduleSection(const ParseContext& parseContext , const SCHEDULESection& section , const EclipseGrid& grid,
Expand Down
50 changes: 42 additions & 8 deletions lib/eclipse/EclipseState/Schedule/TimeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/

#include <boost/date_time/posix_time/posix_time.hpp>
#include <ctime>

#include <ert/util/util.h>

#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
Expand Down Expand Up @@ -73,12 +76,12 @@ namespace Opm {
}


boost::posix_time::ptime TimeMap::getStartTime(size_t tStepIdx) const {
return m_timeList[tStepIdx];
std::time_t TimeMap::getStartTime(size_t tStepIdx) const {
return this->operator[]( tStepIdx );
}

boost::posix_time::ptime TimeMap::getEndTime() const {
return m_timeList.back();
std::time_t TimeMap::getEndTime() const {
return this->operator[]( this->size( ) - 1);
}

double TimeMap::getTotalTime() const
Expand Down Expand Up @@ -320,14 +323,45 @@ namespace Opm {
}


const boost::posix_time::ptime& TimeMap::operator[] (size_t index) const {
if (index < m_timeList.size())
return m_timeList[index];
else
std::time_t TimeMap::operator[] (size_t index) const {
if (index < m_timeList.size()) {
boost::posix_time::ptime boost_time = m_timeList[index];
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
boost::posix_time::time_duration::sec_type duration = (boost_time - epoch).total_seconds();

return std::time_t( duration );
} else
throw std::invalid_argument("Index out of range");
}



std::time_t TimeMap::mkdate(int in_year, int in_month, int in_day) {
std::time_t t = util_make_date_utc( in_day , in_month , in_year );
{
/*
The underlying mktime( ) function will happily wrap
around dates like January 33, this function will check
that no such wrap-around has taken place.
*/
int out_year, out_day, out_month;
util_set_date_values_utc( t, &out_day , &out_month, &out_year);
if ((in_day != out_day) || (in_month != out_month) || (in_year != out_year))
throw std::invalid_argument("Invalid input arguments for date.");
}
return t;
}


std::time_t TimeMap::forward(std::time_t t, long seconds) {
return t + seconds;
}

std::time_t TimeMap::forward(std::time_t t, int hours, int minutes, long seconds) {
return t + seconds + minutes * 60 + hours * 3600;
}


}


13 changes: 9 additions & 4 deletions lib/eclipse/IntegrationTests/IOConfigIntegrationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline std::string prefix() {
return boost::unit_test::framework::master_test_suite().argv[1];
}

inline void verifyRestartConfig( const RestartConfig& rst, std::vector<std::tuple<int , bool, boost::gregorian::date>>& rptConfig) {
inline void verifyRestartConfig( const TimeMap& tm, const RestartConfig& rst, std::vector<std::tuple<int , bool, boost::gregorian::date>>& rptConfig) {

for (auto rptrst : rptConfig) {
int report_step = std::get<0>(rptrst);
Expand All @@ -49,7 +49,12 @@ inline void verifyRestartConfig( const RestartConfig& rst, std::vector<std::tupl

BOOST_CHECK_EQUAL( save, rst.getWriteRestartFile( report_step ) );
if (save) {
BOOST_CHECK_EQUAL( report_date, rst.getTimestepDate( report_step ));
std::time_t t = tm[report_step];
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
boost::posix_time::ptime report_date_ptime(report_date);
boost::posix_time::time_duration::sec_type duration = (report_date_ptime - epoch).total_seconds();

BOOST_CHECK_EQUAL( duration , t );
}
}
}
Expand Down Expand Up @@ -301,7 +306,7 @@ BOOST_AUTO_TEST_CASE( NorneRestartConfig ) {


auto state = Parser::parse(prefix() + "IOConfig/RPTRST_DECK.DATA");
verifyRestartConfig(state.cfg().restart(), rptConfig);
verifyRestartConfig(state.getSchedule().getTimeMap(), state.cfg().restart(), rptConfig);
}


Expand Down Expand Up @@ -344,7 +349,7 @@ BOOST_AUTO_TEST_CASE( RestartConfig2 ) {
auto deck = parser.parseFile(prefix() + "IOConfig/RPT_TEST2.DATA", parseContext);
EclipseState state( deck , parseContext );
const auto& rstConfig = state.cfg().restart();
verifyRestartConfig( rstConfig, rptConfig );
verifyRestartConfig(state.getSchedule().getTimeMap(), state.cfg().restart(), rptConfig);

BOOST_CHECK_EQUAL( rstConfig.getFirstRestartStep() , 0 );
}
Expand Down
5 changes: 3 additions & 2 deletions lib/eclipse/IntegrationTests/ScheduleCreateFromDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/GroupTree.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
Expand All @@ -54,7 +55,7 @@ BOOST_AUTO_TEST_CASE(CreateSchedule) {
Eclipse3DProperties eclipseProperties ( deck , table, grid);
Schedule sched(parseContext , grid , eclipseProperties, deck, Phases(true, true, true) );
const auto& timeMap = sched.getTimeMap();
BOOST_CHECK_EQUAL(boost::posix_time::ptime(boost::gregorian::date(2007, boost::gregorian::May, 10)), sched.getStartTime());
BOOST_CHECK_EQUAL(TimeMap::mkdate(2007 , 5 , 10), sched.getStartTime());
BOOST_CHECK_EQUAL(9U, timeMap.size());
BOOST_CHECK( deck.hasKeyword("NETBALAN") );
}
Expand All @@ -70,7 +71,7 @@ BOOST_AUTO_TEST_CASE(CreateSchedule_Comments_After_Keywords) {
Eclipse3DProperties eclipseProperties ( deck , table, grid);
Schedule sched(parseContext , grid , eclipseProperties, deck, Phases(true, true, true) );
const auto& timeMap = sched.getTimeMap();
BOOST_CHECK_EQUAL(boost::posix_time::ptime(boost::gregorian::date(2007, boost::gregorian::May, 10)), sched.getStartTime());
BOOST_CHECK_EQUAL(TimeMap::mkdate(2007, 5 , 10) , sched.getStartTime());
BOOST_CHECK_EQUAL(9U, timeMap.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#include <boost/date_time/gregorian/gregorian_types.hpp>

#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>

namespace Opm {

class Deck;
Expand Down Expand Up @@ -133,9 +131,6 @@ namespace Opm {
void overrideNOSIM(bool nosim);



boost::gregorian::date getTimestepDate(size_t timestep) const;

std::string getRestartFileName(const std::string& restart_base, int report_step, bool output) const;

bool getOutputEnabled() const;
Expand All @@ -161,7 +156,6 @@ namespace Opm {
void setWriteInitialRestartFile(bool writeInitialRestartFile);

private:
TimeMap m_timemap;
bool m_write_INIT_file = false;
bool m_write_EGRID_file = true;
bool m_UNIFIN = false;
Expand All @@ -178,7 +172,6 @@ namespace Opm {

IOConfig( const GRIDSection&,
const RUNSPECSection&,
TimeMap,
bool nosim,
const std::string& input_path );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ namespace Opm {
void handleSolutionSection(const SOLUTIONSection& solutionSection);
void setWriteInitialRestartFile(bool writeInitialRestartFile);

boost::gregorian::date getTimestepDate(size_t reportStep) const {
const auto& time = this->m_timemap[reportStep];
return time.date();
}

RestartSchedule getNode( size_t timestep ) const;
static std::string getRestartFileName(const std::string& restart_base, int report_step, bool unified, bool fmt_file);
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace Opm
* If the input deck does not specify a start time, Eclipse's 1. Jan
* 1983 is defaulted
*/
boost::posix_time::ptime getStartTime() const;
time_t getStartTime() const;
time_t posixStartTime() const;
time_t posixEndTime() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define TIMEMAP_HPP_

#include <vector>
#include <ctime>

#include <boost/date_time/posix_time/posix_time_types.hpp>

Expand All @@ -44,10 +45,12 @@ namespace Opm {
size_t last() const;
size_t numTimesteps() const;
double getTotalTime() const;
const boost::posix_time::ptime& operator[] (size_t index) const;

//boost::posix_time::ptime operator[] (size_t index) const;
std::time_t operator[] (size_t index) const;
/// Return the date and time where a given time step starts.
boost::posix_time::ptime getStartTime(size_t tStepIdx) const;
boost::posix_time::ptime getEndTime() const;
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.
Expand All @@ -61,6 +64,10 @@ namespace Opm {
static boost::posix_time::ptime timeFromEclipse( const DeckRecord& dateRecord);
static boost::posix_time::ptime timeFromEclipse(int day , const std::string& month, int year, const std::string& eclipseTimeString = "00:00:00.000");
static boost::posix_time::time_duration dayTimeFromEclipse(const std::string& eclipseTimeString);

static std::time_t forward(std::time_t t0, int hours, int minutes, long seconds);
static std::time_t forward(std::time_t t0, long seconds);
static std::time_t mkdate(int year, int month, int day);
private:
static const std::map<std::string , boost::gregorian::greg_month>& eclipseMonthNames();

Expand Down
3 changes: 2 additions & 1 deletion lib/eclipse/tests/EclipseStateTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ along with OPM. If not, see <http://www.gnu.org/licenses/>.
#include <boost/test/unit_test.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp>
Expand Down Expand Up @@ -201,7 +202,7 @@ BOOST_AUTO_TEST_CASE(CreateSchedule) {
EclipseState state(deck, ParseContext());
const auto& schedule = state.getSchedule();

BOOST_CHECK_EQUAL(schedule.getStartTime(), boost::posix_time::ptime(boost::gregorian::date(1998, 3, 8)));
BOOST_CHECK_EQUAL(schedule.getStartTime(), TimeMap::mkdate( 1998 , 3 , 8));
}


Expand Down
5 changes: 3 additions & 2 deletions lib/eclipse/tests/ScheduleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/GroupTree.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/CompletionSet.hpp>
Expand Down Expand Up @@ -201,7 +202,7 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckMissingReturnsDefaults) {
TableManager table ( deck );
Eclipse3DProperties eclipseProperties ( deck , table, grid);
Schedule schedule(ParseContext() , grid , eclipseProperties, deck, Phases(true, true, true) );
BOOST_CHECK_EQUAL( schedule.getStartTime() , boost::posix_time::ptime(boost::gregorian::date( 1983 , boost::gregorian::Jan , 1)));
BOOST_CHECK_EQUAL( schedule.getStartTime() , TimeMap::mkdate(1983, 1 , 1));
}

BOOST_AUTO_TEST_CASE(CreateScheduleDeckWellsOrdered) {
Expand All @@ -223,7 +224,7 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckWithStart) {
TableManager table ( deck );
Eclipse3DProperties eclipseProperties ( deck , table, grid);
Schedule schedule(ParseContext() , grid , eclipseProperties, deck, Phases(true, true, true) );
BOOST_CHECK_EQUAL( schedule.getStartTime() , boost::posix_time::ptime(boost::gregorian::date( 1998 , boost::gregorian::Mar , 8)));
BOOST_CHECK_EQUAL( schedule.getStartTime() , TimeMap::mkdate(1998, 3 , 8 ));
}

BOOST_AUTO_TEST_CASE(CreateScheduleDeckWithSCHEDULENoThrow) {
Expand Down
Loading