My Project
EclFile.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_ECLFILE_HPP
20 #define OPM_IO_ECLFILE_HPP
21 
22 #include <opm/io/eclipse/EclIOdata.hpp>
23 
24 #include <ios>
25 #include <map>
26 #include <string>
27 #include <stdexcept>
28 #include <tuple>
29 #include <unordered_map>
30 #include <vector>
31 
32 namespace Opm { namespace EclIO {
33 
34 class EclFile
35 {
36 public:
37  struct Formatted {
38  bool value;
39  };
40 
41  explicit EclFile(const std::string& filename, bool preload = false);
42  EclFile(const std::string& filename, Formatted fmt, bool preload = false);
43  bool formattedInput() const { return formatted; }
44 
45  void loadData(); // load all data
46  void loadData(const std::string& arrName); // load all arrays with array name equal to arrName
47  void loadData(int arrIndex); // load data based on array indices in vector arrIndex
48  void loadData(const std::vector<int>& arrIndex); // load data based on array indices in vector arrIndex
49 
50  void clearData()
51  {
52  inte_array.clear();
53  real_array.clear();
54  doub_array.clear();
55  logi_array.clear();
56  char_array.clear();
57  }
58 
59  using EclEntry = std::tuple<std::string, eclArrType, int64_t>;
60  std::vector<EclEntry> getList() const;
61 
62  const std::vector<int>& getElementSizeList() const { return array_element_size; }
63 
64  template <typename T>
65  const std::vector<T>& get(int arrIndex);
66 
67  template <typename T>
68  const std::vector<T>& get(const std::string& name);
69 
70  bool hasKey(const std::string &name) const;
71  std::size_t count(const std::string& name) const;
72 
73  const std::vector<std::string>& arrayNames() const { return array_name; }
74  std::size_t size() const;
75  bool is_ix() const;
76 
77 protected:
78  bool formatted;
79  std::string inputFilename;
80 
81  std::unordered_map<int, std::vector<int>> inte_array;
82  std::unordered_map<int, std::vector<bool>> logi_array;
83  std::unordered_map<int, std::vector<double>> doub_array;
84  std::unordered_map<int, std::vector<float>> real_array;
85  std::unordered_map<int, std::vector<std::string>> char_array;
86 
87  std::vector<std::string> array_name;
88  std::vector<eclArrType> array_type;
89  std::vector<int64_t> array_size;
90  std::vector<int> array_element_size;
91 
92  std::vector<uint64_t> ifStreamPos;
93 
94  std::map<std::string, int> array_index;
95 
96  template<class T>
97  const std::vector<T>& getImpl(int arrIndex, eclArrType type,
98  const std::unordered_map<int, std::vector<T>>& array,
99  const std::string& typeStr);
100 
101  std::streampos
102  seekPosition(const std::vector<std::string>::size_type arrIndex) const;
103 
104 private:
105  std::vector<bool> arrayLoaded;
106 
107  void loadBinaryArray(std::fstream& fileH, std::size_t arrIndex);
108  void loadFormattedArray(const std::string& fileStr, std::size_t arrIndex, int64_t fromPos);
109  void load(bool preload);
110 
111  std::vector<unsigned int> get_bin_logi_raw_values(int arrIndex) const;
112  std::vector<std::string> get_fmt_real_raw_str_values(int arrIndex) const;
113 
114 };
115 
116 }} // namespace Opm::EclIO
117 
118 #endif // OPM_IO_ECLFILE_HPP
Definition: EclFile.hpp:35
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: EclFile.hpp:37