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 <ostream>
26 #include <vector>
27 
28 #include <opm/common/OpmLog/KeywordLocation.hpp>
29 #include <opm/input/eclipse/Deck/DeckKeyword.hpp>
30 #include <opm/input/eclipse/Deck/Deck.hpp>
31 #include <opm/common/utility/TimeService.hpp>
32 
33 #include <opm/io/eclipse/rst/state.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  class DeckOutput;
47  struct ScheduleDeckContext;
48  class Runspec;
49 
50  /*
51  The ScheduleBlock is collection of all the Schedule keywords from one
52  report step.
53  */
54 
55  class ScheduleBlock {
56  public:
57  ScheduleBlock() = default;
58  ScheduleBlock(const KeywordLocation& location, ScheduleTimeType time_type, const time_point& start_time);
59  std::size_t size() const;
60  void push_back(const DeckKeyword& keyword);
61  std::optional<DeckKeyword> get(const std::string& kw) const;
62  const time_point& start_time() const;
63  const std::optional<time_point>& end_time() const;
64  void end_time(const time_point& t);
65  ScheduleTimeType time_type() const;
66  const KeywordLocation& location() const;
67  const DeckKeyword& operator[](const std::size_t index) const;
68  std::vector<DeckKeyword>::const_iterator begin() const;
69  std::vector<DeckKeyword>::const_iterator end() const;
70 
71  bool operator==(const ScheduleBlock& other) const;
72  static ScheduleBlock serializeObject();
73  template<class Serializer>
74  void serializeOp(Serializer& serializer) {
75  serializer(m_time_type);
76  serializer(m_start_time);
77  serializer(m_end_time);
78  serializer.vector(m_keywords);
79  m_location.serializeOp(serializer);
80  }
81 
82  void dump_time(time_point current_time, DeckOutput& output) const;
83  void dump_deck(DeckOutput& output, time_point& current_time) const;
84  private:
85  ScheduleTimeType m_time_type;
86  time_point m_start_time;
87  std::optional<time_point> m_end_time;
88  KeywordLocation m_location;
89  std::vector<DeckKeyword> m_keywords;
90  };
91 
92 
94  std::time_t time{0};
95  std::size_t report_step{0};
96  bool skiprest{false};
97 
98  ScheduleRestartInfo() = default;
99 
100  ScheduleRestartInfo(const RestartIO::RstState * rst, const Deck& deck);
101  bool operator==(const ScheduleRestartInfo& other) const;
102  static ScheduleRestartInfo serializeObject();
103 
104  template<class Serializer>
105  void serializeOp(Serializer& serializer)
106  {
107  serializer(this->time);
108  serializer(this->report_step);
109  serializer(this->skiprest);
110  }
111  };
112 
113 
114 
115 
116  /*
117  The purpose of the ScheduleDeck class is to serve as a container holding
118  all the keywords of the SCHEDULE section, when the Schedule class is
119  assembled that is done by iterating over the contents of the ScheduleDeck.
120  The ScheduleDeck class can be indexed with report step through operator[].
121  Internally the ScheduleDeck class is a vector of ScheduleBlock instances -
122  one for each report step.
123  */
124 
125  class ScheduleDeck {
126  public:
127  explicit ScheduleDeck(time_point start_time, const Deck& deck, const ScheduleRestartInfo& rst_info);
128  ScheduleDeck();
129  void add_block(ScheduleTimeType time_type, const time_point& t, ScheduleDeckContext& context, const KeywordLocation& location);
130  void add_TSTEP(const DeckKeyword& TSTEPKeyword, ScheduleDeckContext& context);
131  ScheduleBlock& operator[](const std::size_t index);
132  const ScheduleBlock& operator[](const std::size_t index) const;
133  std::vector<ScheduleBlock>::const_iterator begin() const;
134  std::vector<ScheduleBlock>::const_iterator end() const;
135  std::size_t size() const;
136  std::size_t restart_offset() const;
137  const KeywordLocation& location() const;
138  double seconds(std::size_t timeStep) const;
139 
140  bool operator==(const ScheduleDeck& other) const;
141  static ScheduleDeck serializeObject();
142  template<class Serializer>
143  void serializeOp(Serializer& serializer) {
144  serializer(m_restart_time);
145  serializer(m_restart_offset);
146  serializer(skiprest);
147  serializer.vector(m_blocks);
148  m_location.serializeOp(serializer);
149  }
150 
151  void dump_deck(std::ostream& os) const;
152 
153  private:
154  time_point m_restart_time;
155  std::size_t m_restart_offset;
156  bool skiprest;
157  KeywordLocation m_location;
158  std::vector<ScheduleBlock> m_blocks;
159  };
160 }
161 
162 #endif
Definition: DeckKeyword.hpp:36
Definition: DeckOutput.hpp:29
Definition: Deck.hpp:63
Definition: KeywordLocation.hpp:27
Definition: ScheduleDeck.hpp:55
Definition: ScheduleDeck.hpp:125
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:51
Definition: ScheduleDeck.hpp:93