Bembel
GenericMatrix.hpp
1 // This file is part of Bembel, the higher order C++ boundary element library.
2 //
3 // Copyright (C) 2022 see <http://www.bembel.eu>
4 //
5 // It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz,
6 // M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt,
7 // Universitaet Basel, and Universita della Svizzera italiana, Lugano. This
8 // source code is subject to the GNU General Public License version 3 and
9 // provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further
10 // information.
11 #ifndef BEMBEL_SRC_UTIL_GENERICMATRIX_HPP_
12 #define BEMBEL_SRC_UTIL_GENERICMATRIX_HPP_
13 
14 #include <vector>
15 
16 namespace Bembel {
17 template <typename T>
19  public:
20  typedef typename std::vector<std::vector<T> >::size_type colIndex;
21  typedef typename std::vector<T>::size_type rowIndex;
23  // constructors
25  GenericMatrix() : rows_(0), cols_(0) {}
26 
27  GenericMatrix(rowIndex rows, colIndex cols) { resize(rows, cols); }
28 
29  GenericMatrix(const GenericMatrix& other) {
30  rows_ = other.rows_;
31  cols_ = other.cols_;
32  m_data_ = other.m_data_;
33  }
34 
35  GenericMatrix(GenericMatrix&& other) {
36  rows_ = other.rows_;
37  cols_ = other.cols_;
38  m_data_ = std::move(other.m_data_);
39  }
41  // methods
43  void resize(rowIndex rows, colIndex cols) {
44  m_data_.resize(cols);
45  for (auto it = m_data_.begin(); it != m_data_.end(); ++it) it->resize(rows);
46  rows_ = rows;
47  cols_ = cols;
48  return;
49  }
50 
51  colIndex cols() const { return cols_; }
52 
53  rowIndex rows() const { return rows_; }
55  // operators
57  const T& operator()(rowIndex row, colIndex col) const {
58  return m_data_[col][row];
59  }
60 
61  T& operator()(rowIndex row, colIndex col) { return m_data_[col][row]; }
62 
63  GenericMatrix& operator=(GenericMatrix other) {
64  rows_ = other.rows_;
65  cols_ = other.cols_;
66  std::swap(m_data_, other.m_data_);
67  return *this;
68  }
70  // private members
72  private:
73  std::vector<std::vector<T> > m_data_;
74  colIndex cols_;
75  rowIndex rows_;
76 };
77 } // namespace Bembel
78 #endif // BEMBEL_SRC_UTIL_GENERICMATRIX_HPP_
Routines for the evalutation of pointwise errors.
Definition: AnsatzSpace.hpp:14