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 <ostream>
24 #include <string>
25 #include <unordered_map>
26 #include <vector>
27 #include <map>
28 #include <stdint.h>
29 
30 #include <opm/common/utility/FileSystem.hpp>
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<filesystem::path> = std::nullopt) const;
79 
80  bool all_steps_available();
81 
82 private:
83 
84  filesystem::path inputFileName;
85  RstEntry restart_info;
86 
87  int nI, nJ, nK, nSpecFiles;
88  bool fromSingleRun;
89  size_t nVect, nTstep;
90 
91  std::vector<bool> formattedFiles;
92  std::vector<std::string> dataFileList;
93  mutable std::vector<std::vector<float>> vectorData;
94  mutable std::vector<bool> vectorLoaded;
95  std::vector<TimeStepEntry> timeStepList;
96  std::vector<TimeStepEntry> miniStepList;
97  std::vector<std::map<int, int>> arrayPos;
98  std::vector<std::string> keyword;
99  std::map<std::string, int> keyword_index;
100  std::vector<int> nParamsSpecFile;
101 
102  std::vector<std::vector<std::string>> keywordListSpecFile;
103 
104  std::vector<int> seqIndex;
105  std::vector<int> mini_steps;
106 
107  void ijk_from_global_index(int glob, int &i, int &j, int &k) const;
108 
109  std::vector<SummaryNode> summaryNodes;
110  std::unordered_map<std::string, std::string> kwunits;
111 
112  time_point startdat;
113 
114  std::vector<std::string> checkForMultipleResultFiles(const filesystem::path& rootN, bool formatted) const;
115 
116  void getRstString(const std::vector<std::string>& restartArray,
117  filesystem::path& pathRst,
118  filesystem::path& rootN) const;
119 
120  void updatePathAndRootName(filesystem::path& dir, filesystem::path& rootN) const;
121 
122 
123  std::string makeKeyString(const std::string& keyword, const std::string& wgname, int num,
124  const std::optional<Opm::EclIO::lgr_info> lgr_info) const;
125 
126  std::string unpackNumber(const SummaryNode&) const;
127  std::string lookupKey(const SummaryNode&) const;
128 
129 
130  void write_block(std::ostream &, bool write_dates, const std::vector<std::string>& time_column, const std::vector<SummaryNode>&) const;
131 
132  template <typename T>
133  std::vector<T> rstep_vector(const std::vector<T>& full_vector) const {
134  std::vector<T> result;
135  result.reserve(seqIndex.size());
136 
137  for (const auto& ind : seqIndex){
138  result.push_back(full_vector[ind]);
139  }
140 
141  return result;
142  }
143 
144  std::vector<std::tuple <std::string, uint64_t>> getListOfArrays(std::string filename, bool formatted);
145  std::vector<int> makeKeywPosVector(int speInd) const;
146  std::string read_string_from_disk(std::fstream& fileH, uint64_t size) const;
147 
148  void read_ministeps_from_disk();
149  int read_ministep_formatted(std::fstream& fileH);
150 };
151 
152 }} // namespace Opm::EclIO
153 
154 inline std::ostream& operator<<(std::ostream& os, const Opm::EclIO::ESmry& smry) {
155  smry.write_rsm(os);
156 
157  return os;
158 }
159 
160 #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