My Project
ESmry.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_ESMRY_HPP
20 #define OPM_IO_ESMRY_HPP
21 
22 #include <chrono>
23 #include <filesystem>
24 #include <ostream>
25 #include <string>
26 #include <unordered_map>
27 #include <vector>
28 #include <map>
29 #include <stdint.h>
30 
31 #include <opm/common/utility/TimeService.hpp>
32 #include <opm/io/eclipse/SummaryNode.hpp>
33 
34 namespace Opm { namespace EclIO {
35 
36 using ArrSourceEntry = std::tuple<std::string, std::string, int, uint64_t>;
37 using TimeStepEntry = std::tuple<int, int, uint64_t>;
38 using RstEntry = std::tuple<std::string, int>;
39 
40 class ESmry
41 {
42 public:
43 
44  // input is smspec (or fsmspec file)
45  explicit ESmry(const std::string& filename, bool loadBaseRunData=false);
46 
47  int numberOfVectors() const { return nVect; }
48 
49  bool hasKey(const std::string& key) const;
50 
51  const std::vector<float>& get(const std::string& name) const;
52  const std::vector<float>& get(const SummaryNode& node) const;
53  std::vector<time_point> dates() const;
54 
55  std::vector<float> get_at_rstep(const std::string& name) const;
56  std::vector<float> get_at_rstep(const SummaryNode& node) const;
57  std::vector<time_point> dates_at_rstep() const;
58 
59  void loadData(const std::vector<std::string>& vectList) const;
60  void loadData() const;
61 
62  bool make_esmry_file();
63 
64  time_point startdate() const { return startdat; }
65 
66  const std::vector<std::string>& keywordList() const;
67  std::vector<std::string> keywordList(const std::string& pattern) const;
68  const std::vector<SummaryNode>& summaryNodeList() const;
69 
70  int timestepIdxAtReportstepStart(const int reportStep) const;
71 
72  size_t numberOfTimeSteps() const { return nTstep; }
73 
74  const std::string& get_unit(const std::string& name) const;
75  const std::string& get_unit(const SummaryNode& node) const;
76 
77  void write_rsm(std::ostream&) const;
78  void write_rsm_file(std::optional<std::filesystem::path> = std::nullopt) const;
79 
80  bool all_steps_available();
81  std::string rootname() { return inputFileName.stem(); }
82  std::tuple<double, double> get_io_elapsed() const;
83 
84 private:
85  std::filesystem::path inputFileName;
86  RstEntry restart_info;
87 
88  int nI, nJ, nK, nSpecFiles;
89  bool fromSingleRun;
90  size_t nVect, nTstep;
91 
92  std::vector<bool> formattedFiles;
93  std::vector<std::string> dataFileList;
94  mutable std::vector<std::vector<float>> vectorData;
95  mutable std::vector<bool> vectorLoaded;
96  std::vector<TimeStepEntry> timeStepList;
97  std::vector<TimeStepEntry> miniStepList;
98  std::vector<std::map<int, int>> arrayPos;
99  std::vector<std::string> keyword;
100  std::map<std::string, int> keyword_index;
101  std::vector<int> nParamsSpecFile;
102 
103  std::vector<std::vector<std::string>> keywordListSpecFile;
104 
105  std::vector<int> seqIndex;
106  std::vector<int> mini_steps;
107 
108  void ijk_from_global_index(int glob, int &i, int &j, int &k) const;
109 
110  std::vector<SummaryNode> summaryNodes;
111  std::unordered_map<std::string, std::string> kwunits;
112 
113  time_point startdat;
114 
115  mutable double m_io_opening;
116  mutable double m_io_loading;
117 
118  std::vector<std::string> checkForMultipleResultFiles(const std::filesystem::path& rootN, bool formatted) const;
119 
120  void getRstString(const std::vector<std::string>& restartArray,
121  std::filesystem::path& pathRst,
122  std::filesystem::path& rootN) const;
123 
124  void updatePathAndRootName(std::filesystem::path& dir, std::filesystem::path& rootN) const;
125 
126 
127  std::string makeKeyString(const std::string& keyword, const std::string& wgname, int num,
128  const std::optional<Opm::EclIO::lgr_info> lgr_info) const;
129 
130  std::string unpackNumber(const SummaryNode&) const;
131  std::string lookupKey(const SummaryNode&) const;
132 
133 
134  void write_block(std::ostream &, bool write_dates, const std::vector<std::string>& time_column, const std::vector<SummaryNode>&) const;
135 
136  template <typename T>
137  std::vector<T> rstep_vector(const std::vector<T>& full_vector) const {
138  std::vector<T> result;
139  result.reserve(seqIndex.size());
140 
141  for (const auto& ind : seqIndex){
142  result.push_back(full_vector[ind]);
143  }
144 
145  return result;
146  }
147 
148  std::vector<std::tuple <std::string, uint64_t>> getListOfArrays(std::string filename, bool formatted);
149  std::vector<int> makeKeywPosVector(int speInd) const;
150  std::string read_string_from_disk(std::fstream& fileH, uint64_t size) const;
151 
152  void read_ministeps_from_disk();
153  int read_ministep_formatted(std::fstream& fileH);
154 };
155 
156 }} // namespace Opm::EclIO
157 
158 inline std::ostream& operator<<(std::ostream& os, const Opm::EclIO::ESmry& smry) {
159  smry.write_rsm(os);
160 
161  return os;
162 }
163 
164 #endif // OPM_IO_ESMRY_HPP
Definition: ESmry.hpp:41
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: SummaryNode.hpp:37
Definition: SummaryNode.hpp:32