opm-common
EGrid.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_EGRID_HPP
20 #define OPM_IO_EGRID_HPP
21 
22 #include <opm/io/eclipse/EclFile.hpp>
23 
24 #include <array>
25 #include <filesystem>
26 #include <string>
27 #include <vector>
28 #include <map>
29 
30 namespace Opm { namespace EclIO {
31 
32 class EGrid : public EclFile
33 {
34 public:
35  explicit EGrid(const std::string& filename, const std::string& grid_name = "global");
36 
37  int global_index(int i, int j, int k) const;
38  int active_index(int i, int j, int k) const;
39 
40  const std::array<int, 3>& dimension() const { return nijk; }
41 
42  std::array<int, 3> ijk_from_active_index(int actInd) const;
43  std::array<int, 3> ijk_from_global_index(int globInd) const;
44 
45  void getCellCorners(int globindex, std::array<double, 8>& X, std::array<double, 8>& Y, std::array<double, 8>& Z);
46  void getCellCorners(const std::array<int, 3>& ijk, std::array<double, 8>& X, std::array<double, 8>& Y, std::array<double, 8>& Z);
47 
48  std::vector<std::array<float, 3>> getXYZ_layer(int layer, bool bottom=false);
49  std::vector<std::array<float, 3>> getXYZ_layer(int layer, const std::array<int, 4>& box, bool bottom=false);
50 
51  int activeCells() const { return nactive; }
52  int totalNumberOfCells() const { return nijk[0] * nijk[1] * nijk[2]; }
53 
54  void load_grid_data();
55  void load_nnc_data();
56  bool with_mapaxes() const { return m_mapaxes_loaded; }
57  void mapaxes_transform(double& x, double& y) const;
58  bool is_radial() const { return m_radial; }
59 
60  const std::vector<int>& hostCellsGlobalIndex() const { return host_cells; }
61  std::vector<std::array<int, 3>> hostCellsIJK();
62 
63  // zero based: i1,j1,k1, i2,j2,k2, transmisibility
64  using NNCentry = std::tuple<int, int, int, int, int, int, float>;
65  std::vector<NNCentry> get_nnc_ijk();
66 
67  const std::vector<std::string>& list_of_lgrs() const { return lgr_names; }
68 
69  const std::array<double, 6>& get_mapaxes() const { return m_mapaxes; }
70  const std::string& get_mapunits() const { return m_mapunits; }
71  const std::vector<float>& get_coord() const { return coord_array; }
72  const std::vector<float>& get_zcorn() const { return zcorn_array; }
73 
74 private:
75  std::filesystem::path inputFileName, initFileName;
76  std::string m_grid_name;
77  bool m_radial{false};
78 
79  std::array<double, 6> m_mapaxes{};
80  std::string m_mapunits;
81  bool m_mapaxes_loaded{false};
82  std::array<double, 4> origin{};
83  std::array<double, 2> unit_x{};
84  std::array<double, 2> unit_y{};
85 
86  std::array<int, 3> nijk{};
87  std::array<int, 3> host_nijk{};
88 
89  int nactive{};
90  mutable bool m_nncs_loaded{false};
91 
92  std::vector<int> act_index;
93  std::vector<int> glob_index;
94 
95  std::vector<float> coord_array;
96  std::vector<float> zcorn_array;
97 
98  std::vector<int> nnc1_array;
99  std::vector<int> nnc2_array;
100  std::vector<float> transnnc_array;
101  std::vector<int> host_cells;
102  std::map<int,int> res;
103 
104  std::vector<std::string> lgr_names;
105 
106  int numres{};
107 
108  int zcorn_array_index{-1};
109  int coord_array_index{-1};
110  int coordsys_array_index{-1};
111  int actnum_array_index{-1};
112  int nnc1_array_index{-1};
113  int nnc2_array_index{-1};
114 
115  std::vector<float> get_zcorn_from_disk(int layer, bool bottom);
116 
117  void getCellCorners(const std::array<int, 3>& ijk, const std::vector<float>& zcorn_layer,
118  std::array<double, 4>& X, std::array<double, 4>& Y, std::array<double, 4>& Z);
119 
120  void mapaxes_init();
121 
122 };
123 
124 }} // namespace Opm::EclIO
125 
126 #endif // OPM_IO_EGRID_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: EGrid.hpp:32