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 <iosfwd>
26 #include <vector>
27 
28 #include <opm/common/OpmLog/KeywordLocation.hpp>
29 #include <opm/input/eclipse/Deck/DeckKeyword.hpp>
30 #include <opm/common/utility/TimeService.hpp>
31 
32 #include <opm/io/eclipse/rst/state.hpp>
33 
34 namespace Opm {
35 
36  enum class ScheduleTimeType {
37  START = 0,
38  DATES = 1,
39  TSTEP = 2,
40  RESTART = 3
41  };
42 
43 
44  class Deck;
45  class DeckOutput;
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 serializationTestObject();
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(m_keywords);
78  serializer(m_location);
79  }
80 
81  void dump_time(time_point current_time, DeckOutput& output) const;
82  void dump_deck(DeckOutput& output, time_point& current_time) const;
83  private:
84  ScheduleTimeType m_time_type;
85  time_point m_start_time;
86  std::optional<time_point> m_end_time;
87  KeywordLocation m_location;
88  std::vector<DeckKeyword> m_keywords;
89  };
90 
91 
93  std::time_t time{0};
94  std::size_t report_step{0};
95  bool skiprest{false};
96 
97  ScheduleRestartInfo() = default;
98 
99  ScheduleRestartInfo(const RestartIO::RstState * rst, const Deck& deck);
100  bool operator==(const ScheduleRestartInfo& other) const;
101  static ScheduleRestartInfo serializationTestObject();
102 
103  template<class Serializer>
104  void serializeOp(Serializer& serializer)
105  {
106  serializer(this->time);
107  serializer(this->report_step);
108  serializer(this->skiprest);
109  }
110  };
111 
112 
113 
114 
115  /*
116  The purpose of the ScheduleDeck class is to serve as a container holding
117  all the keywords of the SCHEDULE section, when the Schedule class is
118  assembled that is done by iterating over the contents of the ScheduleDeck.
119  The ScheduleDeck class can be indexed with report step through operator[].
120  Internally the ScheduleDeck class is a vector of ScheduleBlock instances -
121  one for each report step.
122  */
123 
124  class ScheduleDeck {
125  public:
126  explicit ScheduleDeck(time_point start_time, const Deck& deck, const ScheduleRestartInfo& rst_info);
127  ScheduleDeck();
128  void add_block(ScheduleTimeType time_type, const time_point& t, ScheduleDeckContext& context, const KeywordLocation& location);
129  void add_TSTEP(const DeckKeyword& TSTEPKeyword, ScheduleDeckContext& context);
130  ScheduleBlock& operator[](const std::size_t index);
131  const ScheduleBlock& operator[](const std::size_t index) const;
132  std::vector<ScheduleBlock>::const_iterator begin() const;
133  std::vector<ScheduleBlock>::const_iterator end() const;
134  std::size_t size() const;
135  std::size_t restart_offset() const;
136  const KeywordLocation& location() const;
137  double seconds(std::size_t timeStep) const;
138 
139  bool operator==(const ScheduleDeck& other) const;
140  static ScheduleDeck serializationTestObject();
141  template<class Serializer>
142  void serializeOp(Serializer& serializer) {
143  serializer(m_restart_time);
144  serializer(m_restart_offset);
145  serializer(skiprest);
146  serializer(m_blocks);
147  serializer(m_location);
148  }
149 
150  void dump_deck(std::ostream& os) const;
151 
152  private:
153  time_point m_restart_time;
154  std::size_t m_restart_offset;
155  bool skiprest;
156  KeywordLocation m_location;
157  std::vector<ScheduleBlock> m_blocks;
158  };
159 }
160 
161 #endif
Definition: DeckKeyword.hpp:36
Definition: DeckOutput.hpp:29
Definition: Deck.hpp:63
Definition: KeywordLocation.hpp:27
Definition: ScheduleDeck.hpp:54
Definition: ScheduleDeck.hpp:124
Class for (de-)serializing.
Definition: Serializer.hpp:75
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: state.hpp:54
Definition: ScheduleDeck.hpp:92