TimeMap.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2013 Statoil ASA.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 #ifndef TIMEMAP_HPP_
22 #define TIMEMAP_HPP_
23 
24 #include <vector>
25 
26 #include <boost/date_time.hpp>
27 
31 
32 namespace Opm {
33 
34  class TimeMap {
35  public:
36  TimeMap(boost::posix_time::ptime startDate);
38  void addTime(boost::posix_time::ptime newTime);
39  void addTStep(boost::posix_time::time_duration step);
40  void addFromDATESKeyword( DeckKeywordConstPtr DATESKeyword );
41  void addFromTSTEPKeyword( DeckKeywordConstPtr TSTEPKeyword );
44  size_t size() const;
45  size_t numTimesteps() const;
46  double getTotalTime() const;
47  const boost::posix_time::ptime& operator[] (size_t index) const;
49  boost::posix_time::ptime getStartTime(size_t tStepIdx) const;
51  double getTimePassedUntil(size_t tLevelIdx) const;
53  double getTimeStepLength(size_t tStepIdx) const;
54 
58  bool isTimestepInFirstOfMonthsYearsSequence(size_t timestep, bool years = true, size_t start_timestep = 1, size_t frequency = 1) const;
59 
60  static boost::posix_time::ptime timeFromEclipse(DeckRecordConstPtr dateRecord);
61  static boost::posix_time::ptime timeFromEclipse(int day , const std::string& month, int year, const std::string& eclipseTimeString = "00:00:00.000");
62  static boost::posix_time::time_duration dayTimeFromEclipse(const std::string& eclipseTimeString);
63  private:
64  static const std::map<std::string , boost::gregorian::greg_month>& eclipseMonthNames();
65 
66  std::vector<boost::posix_time::ptime> m_timeList;
67 
68  const std::vector<size_t>& getFirstTimestepMonths() const;
69  const std::vector<size_t>& getFirstTimestepYears() const;
70  bool isTimestepInFreqSequence (size_t timestep, size_t start_timestep, size_t frequency, bool years) const;
71  size_t closest(const std::vector<size_t> & vec, size_t value) const;
72 
73  std::vector<size_t> m_first_timestep_years; // A list of the first timestep of every year
74  std::vector<size_t> m_first_timestep_months; // A list of the first timestep of every month
75  };
76  typedef std::shared_ptr<TimeMap> TimeMapPtr;
77  typedef std::shared_ptr<const TimeMap> TimeMapConstPtr;
78 }
79 
80 
81 
82 #endif /* TIMEMAP_HPP_ */
Definition: TimeMap.hpp:34
boost::posix_time::ptime getStartTime(size_t tStepIdx) const
Return the date and time where a given time step starts.
std::shared_ptr< const TimeMap > TimeMapConstPtr
Definition: TimeMap.hpp:77
bool isTimestepInFirstOfMonthsYearsSequence(size_t timestep, bool years=true, size_t start_timestep=1, size_t frequency=1) const
Definition: Deck.hpp:29
double getTimePassedUntil(size_t tLevelIdx) const
Return the period of time in seconds which passed between the start of the simulation and a given poi...
std::shared_ptr< const DeckKeyword > DeckKeywordConstPtr
Definition: DeckKeyword.hpp:71
static boost::posix_time::time_duration dayTimeFromEclipse(const std::string &eclipseTimeString)
std::shared_ptr< const Deck > DeckConstPtr
Definition: Deck.hpp:86
void addTStep(boost::posix_time::time_duration step)
size_t size() const
const double day
Definition: ConversionFactors.hpp:101
const double year
Definition: ConversionFactors.hpp:102
TimeMap(boost::posix_time::ptime startDate)
size_t numTimesteps() const
double getTotalTime() const
void initFirstTimestepsYears()
void addTime(boost::posix_time::ptime newTime)
static boost::posix_time::ptime timeFromEclipse(DeckRecordConstPtr dateRecord)
std::shared_ptr< const DeckRecord > DeckRecordConstPtr
Definition: DeckRecord.hpp:54
double getTimeStepLength(size_t tStepIdx) const
Return the length of a given time step in seconds.
void initFirstTimestepsMonths()
void addFromDATESKeyword(DeckKeywordConstPtr DATESKeyword)
const boost::posix_time::ptime & operator[](size_t index) const
std::shared_ptr< TimeMap > TimeMapPtr
Definition: TimeMap.hpp:76
void addFromTSTEPKeyword(DeckKeywordConstPtr TSTEPKeyword)