opm-common
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 <algorithm>
25 #include <map>
26 #include <string>
27 #include <tuple>
28 #include <unordered_map>
29 #include <vector>
30 #include <cstdint>
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  std::fill(arrayLoaded.begin(), arrayLoaded.end(), false);
59  }
60 
61  using EclEntry = std::tuple<std::string, eclArrType, std::int64_t>;
62  std::vector<EclEntry> getList() const;
63 
64  const std::vector<int>& getElementSizeList() const { return array_element_size; }
65 
66  template <typename T>
67  const std::vector<T>& get(int arrIndex);
68 
69  template <typename T>
70  const std::vector<T>& get(const std::string& name);
71 
72  bool hasKey(const std::string &name) const;
73  std::size_t count(const std::string& name) const;
74 
75  const std::vector<std::string>& arrayNames() const { return array_name; }
76  std::size_t size() const;
77  bool is_ix() const;
78 
79 protected:
80  bool formatted;
81  std::string inputFilename;
82 
83  std::unordered_map<int, std::vector<int>> inte_array;
84  std::unordered_map<int, std::vector<bool>> logi_array;
85  std::unordered_map<int, std::vector<double>> doub_array;
86  std::unordered_map<int, std::vector<float>> real_array;
87  std::unordered_map<int, std::vector<std::string>> char_array;
88 
89  std::vector<std::string> array_name;
90  std::vector<eclArrType> array_type;
91  std::vector<std::int64_t> array_size;
92  std::vector<int> array_element_size;
93 
94  std::vector<std::uint64_t> ifStreamPos;
95 
96  std::map<std::string, int> array_index;
97 
98  template<class T>
99  const std::vector<T>& getImpl(int arrIndex, eclArrType type,
100  const std::unordered_map<int, std::vector<T>>& array,
101  const std::string& typeStr);
102 
103  std::streampos
104  seekPosition(const std::vector<std::string>::size_type arrIndex) const;
105 
106 private:
107  std::vector<bool> arrayLoaded;
108 
109  void loadBinaryArray(std::fstream& fileH, std::size_t arrIndex);
110  void loadFormattedArray(const std::string& fileStr, std::size_t arrIndex, std::int64_t fromPos);
111  void load(bool preload);
112 
113  std::vector<unsigned int> get_bin_logi_raw_values(int arrIndex) const;
114  std::vector<std::string> get_fmt_real_raw_str_values(int arrIndex) const;
115 
116 };
117 
118 }} // namespace Opm::EclIO
119 
120 #endif // OPM_IO_ECLFILE_HPP
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: EclFile.hpp:34
Definition: EclFile.hpp:37