ESmry.hpp
Go to the documentation of this file.
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
33
34namespace Opm { namespace EclIO {
35
36using ArrSourceEntry = std::tuple<std::string, std::string, int, uint64_t>;
37using TimeStepEntry = std::tuple<int, int, uint64_t>;
38
39class ESmry
40{
41public:
42
43 // input is smspec (or fsmspec file)
44 explicit ESmry(const std::string& filename, bool loadBaseRunData=false, bool uselodsmry=false);
45
46 int numberOfVectors() const { return nVect; }
47
48 bool hasKey(const std::string& key) const;
49
50 const std::vector<float>& get(const std::string& name) const;
51 const std::vector<float>& get(const SummaryNode& node) const;
52 std::vector<time_point> dates() const;
53
54 std::vector<float> get_at_rstep(const std::string& name) const;
55 std::vector<float> get_at_rstep(const SummaryNode& node) const;
56 std::vector<time_point> dates_at_rstep() const;
57
58 void LoadData(const std::vector<std::string>& vectList) const;
59 void LoadData() const;
60
62
63 // Added based on requirements from ResInsight
64 void use_lodsmry_file(bool enable);
65
66 time_point startdate() const { return startdat; }
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<Opm::filesystem::path> = std::nullopt) const;
81
82 void ijk_from_global_index(int glob, int &i, int &j, int &k) const;
83private:
84 bool useLodsmryFile; // Added by ResInsight use
85
86 Opm::filesystem::path inputFileName, lodFileName;
87 int nI, nJ, nK, nSpecFiles;
88 bool fromSingleRun, lodEnabeled;
89 uint64_t lod_offset, lod_arr_size;
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<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
106
107 std::vector<SummaryNode> summaryNodes;
108 std::unordered_map<std::string, std::string> kwunits;
109
110 time_point startdat;
111
112 std::vector<std::string> checkForMultipleResultFiles(const Opm::filesystem::path& rootN, bool formatted) const;
113
114 void getRstString(const std::vector<std::string>& restartArray,
115 Opm::filesystem::path& pathRst,
116 Opm::filesystem::path& rootN) const;
117
118 void updatePathAndRootName(Opm::filesystem::path& dir, Opm::filesystem::path& rootN) const;
119
120 std::string makeKeyString(const std::string& keyword, const std::string& wgname, int num, const std::string& lgr, int lgri, int lgrj, int lgrk) const;
121
122 std::string unpackNumber(const SummaryNode&) const;
123 std::string lookupKey(const SummaryNode&) const;
124
125
126 void write_block(std::ostream &, bool write_dates, const std::vector<std::string>& time_column, const std::vector<SummaryNode>&) const;
127
128 template <typename T>
129 std::vector<T> rstep_vector(const std::vector<T>& full_vector) const {
130 std::vector<T> result;
131 result.reserve(seqIndex.size());
132
133 for (const auto& ind : seqIndex){
134 result.push_back(full_vector[ind]);
135 }
136
137 return result;
138 }
139
140 std::vector<std::tuple <std::string, uint64_t>> getListOfArrays(std::string filename, bool formatted);
141 std::vector<int> makeKeywPosVector(int speInd) const;
142 std::string read_string_from_disk(std::fstream& fileH, uint64_t size) const;
143 void inspect_lodsmry();
144 void Load_from_lodsmry(const std::vector<int>& keywIndVect) const;
145};
146
147}} // namespace Opm::EclIO
148
149inline std::ostream& operator<<(std::ostream& os, const Opm::EclIO::ESmry& smry) {
150 smry.write_rsm(os);
151
152 return os;
153}
154
155#endif // OPM_IO_ESMRY_HPP
std::ostream & operator<<(std::ostream &os, const Opm::EclIO::ESmry &smry)
Definition: ESmry.hpp:149
const char *const name
Definition: cJSON.h:258
const char *const string
Definition: cJSON.h:170
Definition: ESmry.hpp:40
void LoadData() const
std::vector< time_point > dates() const
std::vector< std::string > keywordList(const std::string &pattern) const
const std::string & get_unit(const SummaryNode &node) const
ESmry(const std::string &filename, bool loadBaseRunData=false, bool uselodsmry=false)
void write_rsm(std::ostream &) const
bool hasKey(const std::string &key) const
const std::vector< std::string > & keywordList() const
const std::vector< float > & get(const SummaryNode &node) const
std::vector< float > get_at_rstep(const SummaryNode &node) const
std::vector< time_point > dates_at_rstep() const
const std::vector< SummaryNode > & summaryNodeList() const
void LoadData(const std::vector< std::string > &vectList) const
void use_lodsmry_file(bool enable)
const std::string & get_unit(const std::string &name) const
int timestepIdxAtReportstepStart(const int reportStep) const
time_point startdate() const
Definition: ESmry.hpp:66
void write_rsm_file(std::optional< Opm::filesystem::path >=std::nullopt) const
void ijk_from_global_index(int glob, int &i, int &j, int &k) const
bool make_lodsmry_file()
int numberOfVectors() const
Definition: ESmry.hpp:46
const std::vector< float > & get(const std::string &name) const
std::vector< float > get_at_rstep(const std::string &name) const
size_t numberOfTimeSteps() const
Definition: ESmry.hpp:74
std::tuple< std::string, std::string, int, uint64_t > ArrSourceEntry
Definition: ESmry.hpp:36
std::tuple< int, int, uint64_t > TimeStepEntry
Definition: ESmry.hpp:37
Definition: A.hpp:4
std::chrono::time_point< std::chrono::system_clock, std::chrono::duration< int64_t, std::ratio< 1, 1000 > > > time_point
Definition: TimeService.hpp:31
Definition: SummaryNode.hpp:30