AssembledConnections.hpp
Go to the documentation of this file.
1/*
2 Copyright 2016 SINTEF ICT, Applied Mathematics.
3 Copyright 2016 Statoil ASA.
4
5 This file is part of the Open Porous Media Project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef OPM_ASSEMBLEDCONNECTIONS_HEADER_INCLUDED
22#define OPM_ASSEMBLEDCONNECTIONS_HEADER_INCLUDED
23
25
26#include <cstddef>
27#include <iosfwd>
28#include <vector>
29
36
37namespace Opm {
38
42 {
43 public:
49 void addConnection(const int i, const int j);
50
58 void addConnection(const int i, const int j, const double v);
59
76 void compress(const std::size_t numRows);
77
79 using Neighbours = std::vector<int>;
80
82 using Offset = Neighbours::size_type;
83
85 using Start = std::vector<Offset>;
86
88 using ConnWeight = std::vector<double>;
89
93
97 Offset numRows() const;
98
101 const Start& startPointers() const;
102
111 const Neighbours& neighbourhood() const;
112
121
135 CellNeighbours cellNeighbourhood(const int cell) const;
136
137 private:
138 class Connections
139 {
140 public:
141 using EntityVector = std::vector<int>;
142 using WeightVector = std::vector<double>;
143
144 void add(const int i, const int j);
145 void add(const int i, const int j, const double v);
146
147 void clear();
148
149 bool empty() const;
150
151 bool isValid() const;
152
153 bool isWeighted() const;
154
155 int maxRow() const;
156 int maxCol() const;
157
158 EntityVector::size_type nnz() const;
159
160 const EntityVector& i() const;
161 const EntityVector& j() const;
162 const WeightVector& v() const;
163
164 private:
165 EntityVector i_;
166 EntityVector j_;
167 WeightVector v_;
168
169 int max_i_{ -1 };
170 int max_j_{ -1 };
171 };
172
173 class CSR
174 {
175 public:
176 void create(const Connections& conns,
177 const Offset numRows);
178
179 const Start& ia() const;
180 const Neighbours& ja() const;
181 const ConnWeight& sa() const;
182
183 private:
184 Start ia_;
185 Neighbours ja_;
186 ConnWeight sa_;
187
188 Start elmIdx_;
189
190 int numRows_{ 0 };
191 int numCols_{ 0 };
192
193 // ---------------------------------------------------------
194 // Implementation of create()
195 // ---------------------------------------------------------
196
197 void assemble(const Connections& conns);
198
199 void sort();
200
201 void condenseDuplicates();
202
203 void accumulateConnWeights(const std::vector<double>& v);
204
205 // ---------------------------------------------------------
206 // Implementation of assemble()
207 // ---------------------------------------------------------
208
209 void accumulateRowEntries(const int numRows,
210 const std::vector<int>& rowIdx);
211
212 void createGraph(const std::vector<int>& rowIdx,
213 const std::vector<int>& colIdx);
214
215 // ---------------------------------------------------------
216 // General utilities
217 // ---------------------------------------------------------
218
219 void transpose();
220
221 std::vector<int> expandStartPointers() const;
222
223 void unique(Neighbours::const_iterator begin,
224 Neighbours::const_iterator end);
225
226 void remapElementIndex(Start&& elmIdx);
227 };
228
229 Connections conns_;
230 CSR csr_;
231 };
232
233
234
235
236
242 std::ostream& operator<<(std::ostream& os, const AssembledConnections& ac);
243
244
245} // namespace Opm
246
247#endif // OPM_ASSEMBLEDCONNECTIONS_HEADER_INCLUDED
Definition: AssembledConnections.hpp:42
const Neighbours & neighbourhood() const
std::vector< double > ConnWeight
Aggregate connection weights.
Definition: AssembledConnections.hpp:88
Neighbours::size_type Offset
Offset into neighbour array.
Definition: AssembledConnections.hpp:82
std::vector< Offset > Start
CSR start pointers.
Definition: AssembledConnections.hpp:85
const ConnWeight & connectionWeight() const
void compress(const std::size_t numRows)
void addConnection(const int i, const int j)
void addConnection(const int i, const int j, const double v)
std::vector< int > Neighbours
Representation of neighbouring entities.
Definition: AssembledConnections.hpp:79
CellNeighbours cellNeighbourhood(const int cell) const
const Start & startPointers() const
not_this_one begin(...)
Definition: A.hpp:4
std::ostream & operator<<(std::ostream &os, const UniformTableLinear< T > &t)
Definition: UniformTableLinear.hpp:249
@ end
Definition: ActionValue.hpp:20
Definition: AssembledConnectionsIteration.hpp:83