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