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 <iosfwd>
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 tp_startdat; }
65  std::vector<int> start_v() const { return start_vect; }
66 
67  const std::vector<std::string>& keywordList() const;
68  std::vector<std::string> keywordList(const std::string& pattern) const;
69  const std::vector<SummaryNode>& summaryNodeList() const;
70 
71  int timestepIdxAtReportstepStart(const int reportStep) const;
72 
73  size_t numberOfTimeSteps() const { return nTstep; }
74 
75  const std::string& get_unit(const std::string& name) const;
76  const std::string& get_unit(const SummaryNode& node) const;
77 
78  void write_rsm(std::ostream&) const;
79  void write_rsm_file(std::optional<std::filesystem::path> = std::nullopt) const;
80 
81  bool all_steps_available();
82  std::string rootname() { return inputFileName.stem(); }
83  std::tuple<double, double> get_io_elapsed() const;
84 
85 private:
86  std::filesystem::path inputFileName;
87  RstEntry restart_info;
88 
89  int nI, nJ, nK, nSpecFiles;
90  bool fromSingleRun;
91  size_t nVect, nTstep;
92 
93  std::vector<bool> formattedFiles;
94  std::vector<std::string> dataFileList;
95  mutable std::vector<std::vector<float>> vectorData;
96  mutable std::vector<bool> vectorLoaded;
97  std::vector<TimeStepEntry> timeStepList;
98  std::vector<TimeStepEntry> miniStepList;
99  std::vector<std::map<int, int>> arrayPos;
100  std::vector<std::string> keyword;
101  std::map<std::string, int> keyword_index;
102  std::vector<int> nParamsSpecFile;
103 
104  std::vector<std::vector<std::string>> keywordListSpecFile;
105 
106  std::vector<int> seqIndex;
107  std::vector<int> mini_steps;
108 
109  void ijk_from_global_index(int glob, int &i, int &j, int &k) const;
110 
111  std::vector<SummaryNode> summaryNodes;
112  std::unordered_map<std::string, std::string> kwunits;
113 
114  time_point tp_startdat;
115  std::vector<int> start_vect;
116 
117  mutable double m_io_opening;
118  mutable double m_io_loading;
119 
120  std::vector<std::string> checkForMultipleResultFiles(const std::filesystem::path& rootN, bool formatted) const;
121 
122  void getRstString(const std::vector<std::string>& restartArray,
123  std::filesystem::path& pathRst,
124  std::filesystem::path& rootN) const;
125 
126  void updatePathAndRootName(std::filesystem::path& dir, std::filesystem::path& rootN) const;
127 
128 
129  std::string makeKeyString(const std::string& keyword, const std::string& wgname, int num,
130  const std::optional<Opm::EclIO::lgr_info> lgr_info) const;
131 
132  std::string unpackNumber(const SummaryNode&) const;
133  std::string lookupKey(const SummaryNode&) const;
134 
135 
136  void write_block(std::ostream &, bool write_dates, const std::vector<std::string>& time_column, const std::vector<SummaryNode>&) const;
137 
138  template <typename T>
139  std::vector<T> rstep_vector(const std::vector<T>& full_vector) const {
140  std::vector<T> result;
141  result.reserve(seqIndex.size());
142 
143  for (const auto& ind : seqIndex){
144  result.push_back(full_vector[ind]);
145  }
146 
147  return result;
148  }
149 
150  std::vector<std::tuple <std::string, uint64_t>> getListOfArrays(std::string filename, bool formatted);
151  std::vector<int> makeKeywPosVector(int speInd) const;
152  std::string read_string_from_disk(std::fstream& fileH, uint64_t size) const;
153 
154  void read_ministeps_from_disk();
155  int read_ministep_formatted(std::fstream& fileH);
156 };
157 
158 }} // namespace Opm::EclIO
159 
160 inline std::ostream& operator<<(std::ostream& os, const Opm::EclIO::ESmry& smry) {
161  smry.write_rsm(os);
162 
163  return os;
164 }
165 
166 #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:36
Definition: SummaryNode.hpp:31