My Project
ERst.hpp
1 /*
2  Copyright 2019 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 it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  OPM is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with OPM. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef OPM_IO_ERST_HPP
20 #define OPM_IO_ERST_HPP
21 
22 #include <opm/io/eclipse/EclFile.hpp>
23 
24 #include <ios>
25 #include <map>
26 #include <string>
27 #include <unordered_map>
28 #include <vector>
29 
30 
31 namespace Opm { namespace EclIO { namespace OutputStream {
32  class Restart;
33 }}}
34 
35 namespace Opm { namespace EclIO {
36 
37 class ERst : public EclFile
38 {
39 public:
40  explicit ERst(const std::string& filename);
41 
42  bool hasReportStepNumber(int number) const;
43  bool hasLGR(const std::string& gridname, int reportStepNumber) const;
44 
45  void loadReportStepNumber(int number);
46 
47  template <typename T>
48  const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber)
49  {
50  return getRestartData<T>(name,reportStepNumber, 0);
51  }
52 
53  template <typename T>
54  const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber, int occurrence);
55 
56  template <typename T>
57  const std::vector<T>& getRestartData(int index, int reportStepNumber)
58  {
59  auto indRange = this->getIndexRange(reportStepNumber);
60  return this->get<T>(index + std::get<0>(indRange));
61  }
62 
63  template <typename T>
64  const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber, const std::string& lgr_name);
65 
66  template <typename T>
67  const std::vector<T>& getRestartData(int index, int reportStepNumber, const std::string& lgr_name);
68 
69  int occurrence_count(const std::string& name, int reportStepNumber) const;
70  size_t numberOfReportSteps() const { return seqnum.size(); };
71 
72  const std::vector<int>& listOfReportStepNumbers() const { return seqnum; }
73 
74  std::vector<EclEntry> listOfRstArrays(int reportStepNumber);
75  std::vector<EclEntry> listOfRstArrays(int reportStepNumber, const std::string& lgr_name);
76 
77  friend class OutputStream::Restart;
78 
79 private:
80  int nReports;
81  std::vector<int> seqnum; // report step numbers, from SEQNUM array in restart file
82  mutable std::unordered_map<int,bool> reportLoaded;
83  std::map<int, std::pair<int,int>> arrIndexRange; // mapping report step number to array indeces (start and end)
84  std::vector<std::vector<std::string>> lgr_names; // report step numbers, from SEQNUM array in restart file
85 
86  void initUnified();
87  void initSeparate(const int number);
88 
89  int get_start_index_lgrname(int number, const std::string& lgr_name);
90 
91  int getArrayIndex(const std::string& name, int seqnum, int occurrence);
92  int getArrayIndex(const std::string& name, int number, const std::string& lgr_name);
93 
94  std::tuple<int,int> getIndexRange(int reportStepNumber) const;
95 
96  std::streampos
97  restartStepWritePosition(const int seqnumValue) const;
98 
99 };
100 
101 }} // namespace Opm::EclIO
102 
103 #endif // OPM_IO_ERST_HPP
Definition: ERst.hpp:38
Definition: EclFile.hpp:35
File manager for restart output streams.
Definition: OutputStream.hpp:136
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29