NiHu  2.0
matrix_block.hpp
Go to the documentation of this file.
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program 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 // This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 
25 #ifndef MATRIX_BLOCK_HPP_INCLUDED
26 #define MATRIX_BLOCK_HPP_INCLUDED
27 
28 namespace NiHu
29 {
30 
39 template <class Matrix, class RowIndex, class ColIndex = RowIndex>
41 {
42 public:
49  matrix_block(Matrix &m, RowIndex const &rows, ColIndex const &cols)
50  : m_matrix(m), m_rows(rows), m_cols(cols)
51  {
52  }
53 
59  template <class SubMatrix>
60  void operator +=(SubMatrix const &rhs) const
61  {
62  for (int i = 0; i < m_rows.size(); ++i)
63  for (int j = 0; j < m_cols.size(); ++j)
64  m_matrix(m_rows(i), m_cols(j)) += rhs(i, j);
65  }
66 
67 protected:
68  Matrix &m_matrix;
69  RowIndex const &m_rows;
70  ColIndex const &m_cols;
71 };
72 
73 
88 template <class Matrix, class RowIndex, class ColIndex>
90  block(Matrix &matrix, RowIndex const &rows, ColIndex const &cols)
91 {
92  return matrix_block<Matrix, RowIndex, ColIndex>(matrix, rows, cols);
93 }
94 
95 } // end of namespace NiHu
96 
97 #endif /* MATRIX_BLOCK_HPP_INCLUDED */
NiHu::matrix_block::m_matrix
Matrix & m_matrix
the matrix to be indexed
Definition: matrix_block.hpp:68
NiHu::block
matrix_block< Matrix, RowIndex, ColIndex > block(Matrix &matrix, RowIndex const &rows, ColIndex const &cols)
Factory function of matrix_block.
Definition: matrix_block.hpp:90
NiHu::matrix_block
Proxy class to represent a block of a matrix.
Definition: matrix_block.hpp:40
NiHu::matrix_block::operator+=
void operator+=(SubMatrix const &rhs) const
increment the block with a submatrix
Definition: matrix_block.hpp:60
NiHu::matrix_block::m_rows
const RowIndex & m_rows
the row index vector
Definition: matrix_block.hpp:69
NiHu::matrix_block::m_cols
const ColIndex & m_cols
the column index vector
Definition: matrix_block.hpp:70
NiHu::matrix_block::matrix_block
matrix_block(Matrix &m, RowIndex const &rows, ColIndex const &cols)
constructor from a matrix and two index vectors
Definition: matrix_block.hpp:49