opm-common
Carfin.hpp
1 /*
2  Copyright 2022 Equinor
3  This file is part of the Open Porous Media project (OPM).
4  OPM is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8  OPM is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with OPM. If not, see <http://www.gnu.org/licenses/>.
14 */
15 
16 #ifndef CARFIN_HPP_
17 #define CARFIN_HPP_
18 
19 #include <opm/input/eclipse/EclipseState/Grid/GridDims.hpp>
20 
21 #include <array>
22 #include <cstddef>
23 #include <functional>
24 #include <vector>
25 #include <string>
26 
27 namespace Opm {
28  class DeckRecord;
29 }
30 
31 namespace Opm
32 {
33  class Carfin
34  {
35  public:
36  using IsActive = std::function<bool(const std::size_t globalIdx)>;
37  using ActiveIdx = std::function<std::size_t(const std::size_t globalIdx)>;
38 
39  struct cell_index
40  {
41  std::size_t global_index;
42  std::size_t active_index;
43  std::size_t data_index;
44 
45  cell_index(std::size_t g,std::size_t a, std::size_t d)
46  : global_index(g)
47  , active_index(a)
48  , data_index(d)
49  {}
50 
51  cell_index(std::size_t g, std::size_t d)
52  : global_index(g)
53  , active_index(g)
54  , data_index(d)
55  {}
56  };
57 
58  Carfin() = default;
59 
60  explicit Carfin(const GridDims& gridDims,
61  IsActive isActive,
62  ActiveIdx activeIdx);
63 
64  Carfin(const GridDims& gridDims,
65  IsActive isActive,
66  ActiveIdx activeIdx,
67  const std::string& name,
68  int i1, int i2,
69  int j1, int j2,
70  int k1, int k2,
71  int nx, int ny,
72  int nz);
73 
74  void update(const DeckRecord& deckRecord);
75  void reset();
76 
77  bool isGlobal() const;
78  std::size_t size() const;
79  std::size_t getDim(std::size_t idim) const;
80 
81  const std::vector<cell_index>& index_list() const;
82  const std::vector<cell_index>& global_index_list() const;
83 
84  bool operator==(const Carfin& other) const;
85  bool equal(const Carfin& other) const;
86 
87  const std::string& NAME() const;
88  const std::string& PARENT_NAME() const;
89  int I1() const;
90  int I2() const;
91  int J1() const;
92  int J2() const;
93  int K1() const;
94  int K2() const;
95  int NX() const;
96  int NY() const;
97  int NZ() const;
98  std::size_t num_parent_cells() const;
99 
100  template<class Serializer>
101  void serializeOp(Serializer& serializer)
102  {
103  serializer(m_dims);
104  serializer(m_offset);
105  serializer(m_end_offset);
106  serializer(name_grid);
107  }
108 
109  private:
110  GridDims m_globalGridDims_{};
111  IsActive m_globalIsActive_{};
112  ActiveIdx m_globalActiveIdx_{};
113 
114  std::array<std::size_t, 3> m_dims{};
115  std::array<std::size_t, 3> m_offset{};
116  std::array<std::size_t, 3> m_end_offset{};
117  std::string name_grid;
118  std::string parent_name_grid;
119 
120  std::vector<cell_index> m_active_index_list;
121  std::vector<cell_index> m_global_index_list;
122 
123  void init(const std::string& name,
124  int i1, int i2,
125  int j1, int j2,
126  int k1, int k2,
127  int nx, int ny, int nz, const std::string& parent_name = "GLOBAL");
128  void initIndexList();
129  std::size_t lower(int dim) const;
130  std::size_t upper(int dim) const;
131  std::size_t dimension(int dim) const;
132  };
133 }
134 
135 
136 #endif
Definition: Carfin.hpp:33
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: Carfin.hpp:39
Definition: GridDims.hpp:30
Definition: DeckRecord.hpp:32
Class for (de-)serializing.
Definition: Serializer.hpp:94