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
25
26#include <vector>
27#include <ctime>
28#include <map>
29#include <utility>
30#include <iostream>
31
32#include <stddef.h>
33
34namespace Opm {
35
36 class Deck;
37 class DeckKeyword;
38 class DeckRecord;
39
40 class TimeMap {
41 public:
42 TimeMap() = default;
43 explicit TimeMap(const Deck& deck, const std::pair<std::time_t, std::size_t>& restart = std::make_pair(std::time_t{0}, std::size_t{0}));
44 explicit TimeMap(const std::vector<std::time_t>& time_points);
45
47
48 size_t size() const;
49 size_t last() const;
50 size_t numTimesteps() const;
51 double getTotalTime() const;
52 double seconds(size_t timeStep) const;
53 std::size_t restart_offset() const;
54
55 std::time_t operator[] (size_t index) const;
57 std::time_t getStartTime(size_t tStepIdx) const;
58 std::time_t getEndTime() const;
59 bool skiprest() const;
61 double getTimePassedUntil(size_t tLevelIdx) const;
63 double getTimeStepLength(size_t tStepIdx) const;
64
65 const std::vector<std::time_t>& timeList() const;
66 bool operator==(const TimeMap& data) const;
67
70 bool isTimestepInFirstOfMonthsYearsSequence(size_t timestep, bool years = true, size_t start_timestep = 1, size_t frequency = 1) const;
71
72 static std::time_t timeFromEclipse(const DeckRecord &dateRecord);
73
74 static std::time_t forward(std::time_t t0, int64_t hours, int64_t minutes, int64_t seconds);
75 static std::time_t forward(std::time_t t0, int64_t seconds);
76 static std::time_t mkdate(int year, int month, int day);
77 static std::time_t mkdatetime(int year, int month, int day, int hour, int minute, int second);
78 static const std::map<std::string, int>& eclipseMonthIndices();
79
80 template<class Serializer>
81 void serializeOp(Serializer& serializer)
82 {
83 serializer(m_timeList);
84 serializer.vector(m_first_timestep_years);
85 serializer.vector(m_first_timestep_months);
86 serializer(m_skiprest);
87 serializer(m_restart_offset);
88 }
89
90 private:
91 struct StepData
92 {
93 size_t stepnumber;
94 TimeStampUTC timestamp;
95
96 bool operator==(const StepData& data) const
97 {
98 return stepnumber == data.stepnumber &&
99 timestamp == data.timestamp;
100 }
101
102 template<class Serializer>
103 void serializeOp(Serializer& serializer)
104 {
105 serializer(stepnumber);
106 timestamp.serializeOp(serializer);
107 }
108 };
109
110 bool isTimestepInFreqSequence (size_t timestep, size_t start_timestep, size_t frequency, bool years) const;
111 size_t closest(const std::vector<size_t> & vec, size_t value) const;
112 void addTStep(int64_t step);
113 void addTime(std::time_t newTime);
114 void addFromTSTEPKeyword( const DeckKeyword& TSTEPKeyword );
115 void init_start(std::time_t start_time);
116
117 std::vector<std::time_t> m_timeList;
118 std::vector<StepData> m_first_timestep_years; // A list of the first timestep of every year
119 std::vector<StepData> m_first_timestep_months; // A list of the first timestep of every month
120 bool m_skiprest = false;
121 std::size_t m_restart_offset = 0;
122 };
123
124std::ostream& operator<<(std::ostream& stream, const TimeMap& tm);
125
126}
127
128
129
130#endif /* TIMEMAP_HPP_ */
int index
Definition: cJSON.h:168
Definition: Deck.hpp:115
Definition: DeckRecord.hpp:32
Definition: Serializer.hpp:38
Definition: TimeMap.hpp:40
static TimeMap serializeObject()
std::size_t restart_offset() const
double getTimeStepLength(size_t tStepIdx) const
Return the length of a given time step in 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 std::time_t timeFromEclipse(const DeckRecord &dateRecord)
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::time_t getEndTime() const
static std::time_t forward(std::time_t t0, int64_t seconds)
const std::vector< std::time_t > & timeList() const
std::time_t getStartTime(size_t tStepIdx) const
Return the date and time where a given time step starts.
TimeMap(const std::vector< std::time_t > &time_points)
void serializeOp(Serializer &serializer)
Definition: TimeMap.hpp:81
TimeMap()=default
double getTotalTime() const
static const std::map< std::string, int > & eclipseMonthIndices()
TimeMap(const Deck &deck, const std::pair< std::time_t, std::size_t > &restart=std::make_pair(std::time_t{0}, std::size_t{0}))
size_t numTimesteps() const
size_t last() const
bool operator==(const TimeMap &data) const
static std::time_t forward(std::time_t t0, int64_t hours, int64_t minutes, int64_t seconds)
bool skiprest() const
std::time_t operator[](size_t index) const
bool isTimestepInFirstOfMonthsYearsSequence(size_t timestep, bool years=true, size_t start_timestep=1, size_t frequency=1) const
size_t size() const
double seconds(size_t timeStep) const
Definition: TimeService.hpp:45
void serializeOp(Serializer &serializer)
Definition: TimeService.hpp:97
constexpr const double hour
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Units/Units.hpp:106
constexpr const double year
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Units/Units.hpp:108
constexpr const double minute
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Units/Units.hpp:105
constexpr const double second
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Units/Units.hpp:104
constexpr const double day
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Units/Units.hpp:107
Definition: A.hpp:4
std::ostream & operator<<(std::ostream &os, const UniformTableLinear< T > &t)
Definition: UniformTableLinear.hpp:249
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
static std::string data()
Definition: exprtk.hpp:40022