My Project
ScheduleDeck.hpp
1 /*
2  Copyright 2021 Equinor 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 #ifndef SCHEDULE_DECK_HPP
20 #define SCHEDULE_DECK_HPP
21 
22 #include <chrono>
23 #include <cstddef>
24 #include <optional>
25 #include <vector>
26 
27 #include <opm/common/OpmLog/KeywordLocation.hpp>
28 #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
29 #include <opm/parser/eclipse/Deck/Deck.hpp>
30 #include <opm/common/utility/TimeService.hpp>
31 
32 #include <opm/io/eclipse/rst/state.hpp>
33 #include <opm/parser/eclipse/Parser/ParserKeywords/S.hpp>
34 
35 namespace Opm {
36 
37  enum class ScheduleTimeType {
38  START = 0,
39  DATES = 1,
40  TSTEP = 2,
41  RESTART = 3
42  };
43 
44 
45  class Deck;
46  struct ScheduleDeckContext;
47  class Runspec;
48 
49  /*
50  The ScheduleBlock is collection of all the Schedule keywords from one
51  report step.
52  */
53 
54  class ScheduleBlock {
55  public:
56  ScheduleBlock() = default;
57  ScheduleBlock(const KeywordLocation& location, ScheduleTimeType time_type, const time_point& start_time);
58  std::size_t size() const;
59  void push_back(const DeckKeyword& keyword);
60  std::optional<DeckKeyword> get(const std::string& kw) const;
61  const time_point& start_time() const;
62  const std::optional<time_point>& end_time() const;
63  void end_time(const time_point& t);
64  ScheduleTimeType time_type() const;
65  const KeywordLocation& location() const;
66  const DeckKeyword& operator[](const std::size_t index) const;
67  std::vector<DeckKeyword>::const_iterator begin() const;
68  std::vector<DeckKeyword>::const_iterator end() const;
69 
70  bool operator==(const ScheduleBlock& other) const;
71  static ScheduleBlock serializeObject();
72  template<class Serializer>
73  void serializeOp(Serializer& serializer) {
74  serializer(m_time_type);
75  serializer(m_start_time);
76  serializer(m_end_time);
77  serializer.vector(m_keywords);
78  m_location.serializeOp(serializer);
79  }
80  private:
81  ScheduleTimeType m_time_type;
82  time_point m_start_time;
83  std::optional<time_point> m_end_time;
84  KeywordLocation m_location;
85  std::vector<DeckKeyword> m_keywords;
86  };
87 
88 
90  std::time_t time{0};
91  std::size_t report_step{0};
92  bool skiprest{false};
93 
94  ScheduleRestartInfo() = default;
95 
96  ScheduleRestartInfo(const RestartIO::RstState * rst, const Deck& deck) {
97  if (rst) {
98  const auto& [t,r] = rst->header.restart_info();
99  this->time = t;
100  this->report_step = r;
101  this->skiprest = deck.hasKeyword<ParserKeywords::SKIPREST>();
102  }
103  }
104 
105 
106  bool operator==(const ScheduleRestartInfo& other) const {
107  return this->time == other.time &&
108  this->report_step == other.report_step &&
109  this->skiprest == other.skiprest;
110  }
111 
112 
113  static ScheduleRestartInfo serializeObject() {
114  ScheduleRestartInfo rst_info;
115  rst_info.report_step = 12345;
116  rst_info.skiprest = false;
117  return rst_info;
118  }
119 
120 
121  template<class Serializer>
122  void serializeOp(Serializer& serializer)
123  {
124  serializer(this->time);
125  serializer(this->report_step);
126  serializer(this->skiprest);
127  }
128  };
129 
130 
131 
132 
133  /*
134  The purpose of the ScheduleDeck class is to serve as a container holding
135  all the keywords of the SCHEDULE section, when the Schedule class is
136  assembled that is done by iterating over the contents of the ScheduleDeck.
137  The ScheduleDeck class can be indexed with report step through operator[].
138  Internally the ScheduleDeck class is a vector of ScheduleBlock instances -
139  one for each report step.
140  */
141 
142  class ScheduleDeck {
143  public:
144  explicit ScheduleDeck(const Runspec& runspec, const Deck& deck, const ScheduleRestartInfo& rst_info);
145  ScheduleDeck();
146  void add_block(ScheduleTimeType time_type, const time_point& t, ScheduleDeckContext& context, const KeywordLocation& location);
147  void add_TSTEP(const DeckKeyword& TSTEPKeyword, ScheduleDeckContext& context);
148  ScheduleBlock& operator[](const std::size_t index);
149  const ScheduleBlock& operator[](const std::size_t index) const;
150  std::vector<ScheduleBlock>::const_iterator begin() const;
151  std::vector<ScheduleBlock>::const_iterator end() const;
152  std::size_t size() const;
153  std::size_t restart_offset() const;
154  const KeywordLocation& location() const;
155  double seconds(std::size_t timeStep) const;
156 
157  bool operator==(const ScheduleDeck& other) const;
158  static ScheduleDeck serializeObject();
159  template<class Serializer>
160  void serializeOp(Serializer& serializer) {
161  serializer(m_restart_time);
162  serializer(m_restart_offset);
163  serializer(skiprest);
164  serializer.vector(m_blocks);
165  m_location.serializeOp(serializer);
166  }
167 
168  private:
169  time_point m_restart_time;
170  std::size_t m_restart_offset;
171  bool skiprest;
172  KeywordLocation m_location;
173  std::vector<ScheduleBlock> m_blocks;
174  };
175 }
176 
177 #endif
Definition: DeckKeyword.hpp:36
Definition: Deck.hpp:119
Definition: KeywordLocation.hpp:27
Definition: Runspec.hpp:402
Definition: ScheduleDeck.hpp:54
Definition: ScheduleDeck.hpp:142
Definition: Serializer.hpp:38
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: state.hpp:50
Definition: ScheduleDeck.hpp:89