My Project
ExtESmry.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_ExtESmry_HPP
20 #define OPM_IO_ExtESmry_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 
33 namespace Opm { namespace EclIO {
34 
35 using ArrSourceEntry = std::tuple<std::string, std::string, int, uint64_t>;
36 using TimeStepEntry = std::tuple<int, int, uint64_t>;
37 using RstEntry = std::tuple<std::string, int>;
38 
39 // start, rstart + rstnum, keycheck, units, rstep, tstep
40 using LodsmryHeadType = std::tuple<time_point, RstEntry, std::vector<std::string>, std::vector<std::string>,
41  std::vector<int>, std::vector<int>>;
42 
43 class ExtESmry
44 {
45 public:
46 
47  // input is esmry, only binary supported.
48  explicit ExtESmry(const std::string& filename, bool loadBaseRunData=false);
49 
50  const std::vector<float>& get(const std::string& name);
51  std::vector<float> get_at_rstep(const std::string& name);
52  std::string& get_unit(const std::string& name);
53 
54  void loadData();
55  void loadData(const std::vector<std::string>& stringVect);
56 
57  time_point startdate() const { return m_startdat; }
58 
59  bool hasKey(const std::string& key) const;
60 
61  size_t numberOfTimeSteps() const { return m_nTstep; }
62  size_t numberOfVectors() const { return m_nVect; }
63 
64  const std::vector<std::string>& keywordList() const { return m_keyword;}
65  std::vector<std::string> keywordList(const std::string& pattern) const;
66 
67  std::vector<time_point> dates();
68 
69  bool all_steps_available();
70  std::string rootname() { return m_inputFileName.stem(); }
71  std::tuple<double, double> get_io_elapsed() const;
72 
73 private:
74  std::filesystem::path m_inputFileName;
75  std::vector<std::filesystem::path> m_lodsmry_files;
76 
77  bool m_loadBaseRun;
78  std::vector<std::map<std::string, int>> m_keyword_index;
79  std::vector<std::tuple<int,int>> m_tstep_range;
80  std::vector<std::string> m_keyword;
81  std::vector<int> m_rstep;
82  std::vector<int> m_tstep;
83  std::vector<std::vector<int>> m_rstep_v;
84  std::vector<std::vector<int>> m_tstep_v;
85  std::vector<std::vector<float>> m_vectorData;
86  std::vector<bool> m_vectorLoaded;
87  std::unordered_map<std::string, std::string> kwunits;
88 
89  size_t m_nVect;
90  std::vector<size_t> m_nTstep_v;
91  size_t m_nTstep;
92  std::vector<int> m_seqIndex;
93 
94  std::vector<uint64_t> m_lod_offset;
95  std::vector<uint64_t> m_lod_arr_size;
96 
97  time_point m_startdat;
98 
99  double m_io_opening;
100  double m_io_loading;
101 
102  uint64_t open_esmry(std::filesystem::path& inputFileName, LodsmryHeadType& lodsmry_head);
103 
104  void updatePathAndRootName(std::filesystem::path& dir, std::filesystem::path& rootN);
105 };
106 
107 }} // namespace Opm::EclIO
108 
109 
110 #endif // OPM_IO_ExtESmry_HPP
Definition: ExtESmry.hpp:44
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29