EInit.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020 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_EINIT_HPP
20#define OPM_IO_EINIT_HPP
21
23
24#include <array>
25#include <vector>
26#include <map>
27
28namespace Opm { namespace EclIO {
29
30class EInit : public EclFile
31{
32public:
33 explicit EInit(const std::string& filename);
34
35 const std::vector<std::string>& list_of_lgrs() const { return lgr_names; }
36
37 std::vector<EclFile::EclEntry> list_arrays() const;
38 std::vector<EclFile::EclEntry> list_arrays(const std::string& grid_name) const;
39
40 const std::array<int, 3>& grid_dimension(const std::string& grid_name = "global") const;
41 int activeCells(const std::string& grid_name = "global") const;
42
43 bool hasLGR(const std::string& name) const;
44
45 template <typename T>
46 const std::vector<T>& getInitData(const std::string& name, const std::string& grid_name = "global")
47 {
48 return this->ImplgetInitData<T>(name, grid_name);
49 }
50
51protected:
52
53 template <typename T>
54 const std::vector<T>& ImplgetInitData(const std::string& name, const std::string& grid_name = "global")
55 {
56 int arr_ind = get_array_index(name, grid_name);
57
58 if constexpr (std::is_same_v<T, int>)
59 return getImpl(arr_ind, INTE, inte_array, "integer");
60
61 if constexpr (std::is_same_v<T, float>)
62 return getImpl(arr_ind, REAL, real_array, "float");
63
64 if constexpr (std::is_same_v<T, double>)
65 return getImpl(arr_ind, DOUB, doub_array, "double");
66
67 if constexpr (std::is_same_v<T, bool>)
68 return getImpl(arr_ind, LOGI, logi_array, "bool");
69
70 if constexpr (std::is_same_v<T, std::string>)
71 {
72 if (array_type[arr_ind] == Opm::EclIO::CHAR)
73 return getImpl(arr_ind, array_type[arr_ind], char_array, "char");
74
75 if (array_type[arr_ind] == Opm::EclIO::C0NN)
76 return getImpl(arr_ind, array_type[arr_ind], char_array, "c0nn");
77
78 OPM_THROW(std::runtime_error, "Array not of type CHAR or C0nn");
79 }
80
81 OPM_THROW(std::runtime_error, "type not supported");
82 }
83
84private:
85 std::array<int, 3> global_nijk;
86 std::vector<std::array<int, 3>> lgr_nijk;
87
88 int global_nactive;
89 std::vector<int> lgr_nactive;
90
91 std::vector<std::string> lgr_names;
92
93 std::map<std::string,int> global_array_index;
94 std::vector<std::map<std::string,int>> lgr_array_index;
95
96 int get_array_index(const std::string& name, const std::string& grid_name) const;
97 int get_lgr_index(const std::string& grid_name) const;
98};
99
100}} // namespace Opm::EclIO
101
102#endif // OPM_IO_EINIT_HPP
#define OPM_THROW(Exception, message)
Definition: ErrorMacros.hpp:52
const char *const name
Definition: cJSON.h:258
const char *const string
Definition: cJSON.h:170
Definition: EInit.hpp:31
const std::vector< T > & getInitData(const std::string &name, const std::string &grid_name="global")
Definition: EInit.hpp:46
const std::vector< T > & ImplgetInitData(const std::string &name, const std::string &grid_name="global")
Definition: EInit.hpp:54
bool hasLGR(const std::string &name) const
std::vector< EclFile::EclEntry > list_arrays(const std::string &grid_name) const
std::vector< EclFile::EclEntry > list_arrays() const
int activeCells(const std::string &grid_name="global") const
EInit(const std::string &filename)
const std::vector< std::string > & list_of_lgrs() const
Definition: EInit.hpp:35
const std::array< int, 3 > & grid_dimension(const std::string &grid_name="global") const
Definition: EclFile.hpp:36
std::unordered_map< int, std::vector< std::string > > char_array
Definition: EclFile.hpp:86
std::vector< eclArrType > array_type
Definition: EclFile.hpp:89
std::unordered_map< int, std::vector< double > > doub_array
Definition: EclFile.hpp:84
std::unordered_map< int, std::vector< int > > inte_array
Definition: EclFile.hpp:82
std::unordered_map< int, std::vector< float > > real_array
Definition: EclFile.hpp:85
std::unordered_map< int, std::vector< bool > > logi_array
Definition: EclFile.hpp:83
const std::vector< T > & getImpl(int arrIndex, eclArrType type, const std::unordered_map< int, std::vector< T > > &array, const std::string &typeStr)
Definition: EclFile.hpp:98
@ CHAR
Definition: EclIOdata.hpp:29
@ DOUB
Definition: EclIOdata.hpp:29
@ LOGI
Definition: EclIOdata.hpp:29
@ INTE
Definition: EclIOdata.hpp:29
@ REAL
Definition: EclIOdata.hpp:29
@ C0NN
Definition: EclIOdata.hpp:29
Definition: A.hpp:4