opm-common
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 hasArray(const std::string& name, int number) const;
44  //overload to check if array exists for specific lgr
45  bool hasArray(const std::string& name, int number, const std::string& gridname);
46 
47  bool hasLGR(const std::string& gridname, int reportStepNumber) const;
48 
49  void loadReportStepNumber(int number);
50 
51  template <typename T>
52  const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber)
53  {
54  return getRestartData<T>(name,reportStepNumber, 0);
55  }
56 
57  template <typename T>
58  const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber, int occurrence);
59 
60  template <typename T>
61  const std::vector<T>& getRestartData(int index, int reportStepNumber)
62  {
63  auto indRange = this->getIndexRange(reportStepNumber);
64  return this->get<T>(index + std::get<0>(indRange));
65  }
66 
67  template <typename T>
68  const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber, const std::string& lgr_name);
69 
70  template <typename T>
71  const std::vector<T>& getRestartData(int index, int reportStepNumber, const std::string& lgr_name);
72 
73  int occurrence_count(const std::string& name, int reportStepNumber) const;
74  size_t numberOfReportSteps() const { return seqnum.size(); };
75 
76  const std::vector<int>& listOfReportStepNumbers() const { return seqnum; }
77 
78  std::vector<EclEntry> listOfRstArrays(int reportStepNumber);
79  std::vector<EclEntry> listOfRstArrays(int reportStepNumber, const std::string& lgr_name);
80 
81  friend class OutputStream::Restart;
82 
83 private:
84  int nReports;
85  std::vector<int> seqnum; // report step numbers, from SEQNUM array in restart file
86  mutable std::unordered_map<int,bool> reportLoaded;
87  std::map<int, std::pair<int,int>> arrIndexRange; // mapping report step number to array indeces (start and end)
88  std::vector<std::vector<std::string>> lgr_names; // report step numbers, from SEQNUM array in restart file
89 
90  void initUnified();
91  void initSeparate(const int number);
92 
93  int get_start_index_lgrname(int number, const std::string& lgr_name);
94 
95  int getArrayIndex(const std::string& name, int seqnum, int occurrence);
96  int getArrayIndex(const std::string& name, int number, const std::string& lgr_name);
97 
98  std::tuple<int,int> getIndexRange(int reportStepNumber) const;
99 
100  std::streampos
101  restartStepWritePosition(const int seqnumValue) const;
102 
103 };
104 
105 }} // namespace Opm::EclIO
106 
107 #endif // OPM_IO_ERST_HPP
File manager for restart output streams.
Definition: OutputStream.hpp:149
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: EclFile.hpp:34
Definition: ERst.hpp:37