opm-simulators
BlockedMatrix.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
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_BLOCKED_MATRIX_HPP
21 #define OPM_BLOCKED_MATRIX_HPP
22 
23 namespace Opm::Accelerator {
24 
27 template<class Scalar>
29 {
30 public:
35  BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_)
36  : nnzValues(new Scalar[nnzbs_*block_size_*block_size_])
37  , colIndices(new int[nnzbs_*block_size_*block_size_])
38  , rowPointers(new int[Nb_+1])
39  , Nb(Nb_)
40  , nnzbs(nnzbs_)
41  , block_size(block_size_)
42  , deleteNnzs(true)
43  , deleteSparsity(true)
44  {}
45 
49  : nnzValues(new Scalar[M.nnzbs*M.block_size*M.block_size])
50  , colIndices(M.colIndices)
51  , rowPointers(M.rowPointers)
52  , Nb(M.Nb)
53  , nnzbs(M.nnzbs)
54  , block_size(M.block_size)
55  , deleteNnzs(true)
56  , deleteSparsity(false)
57  {}
58 
66  BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_,
67  Scalar* nnzValues_, int *colIndices_, int *rowPointers_)
68  : nnzValues(nnzValues_)
69  , colIndices(colIndices_)
70  , rowPointers(rowPointers_)
71  , Nb(Nb_)
72  , nnzbs(nnzbs_)
73  , block_size(block_size_)
74  , deleteNnzs(false)
75  , deleteSparsity(false)
76  {}
77 
78  ~BlockedMatrix()
79  {
80  if (deleteNnzs) {
81  delete[] nnzValues;
82  }
83  if (deleteSparsity) {
84  delete[] colIndices;
85  delete[] rowPointers;
86  }
87  }
88 
89  Scalar* nnzValues;
90  int *colIndices;
91  int *rowPointers;
92  int Nb;
93  int nnzbs;
94  unsigned int block_size;
95  bool deleteNnzs;
96  bool deleteSparsity;
97 };
98 
105 void sortRow(int* colIndices, int* data, int left, int right);
106 
113 template<class Scalar>
114 void blockMultSub(Scalar* a, const Scalar* b,
115  const Scalar* c, unsigned int block_size);
116 
123 template<class Scalar>
124 void blockMult(Scalar* mat1, Scalar* mat2, Scalar* resMat, unsigned int block_size);
125 
126 } // namespace Opm::Accelerator
127 
128 #endif
BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_, Scalar *nnzValues_, int *colIndices_, int *rowPointers_)
Allocate BlockedMatrix, but let data arrays point to existing arrays.
Definition: BlockedMatrix.hpp:66
BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_)
Allocate BlockedMatrix and data arrays with given sizes.
Definition: BlockedMatrix.hpp:35
Definition: amgclSolverBackend.cpp:49
BlockedMatrix(const BlockedMatrix &M)
Allocate BlockedMatrix, but copy sparsity pattern instead of allocating new memory.
Definition: BlockedMatrix.hpp:48
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition: BlockedMatrix.hpp:28