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