Bembel
H2MatrixBase.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_H2MATRIX_H2MATRIXBASE_HPP_
12 #define BEMBEL_SRC_H2MATRIX_H2MATRIXBASE_HPP_
13 
14 namespace Eigen {
15 
16 template <typename Derived>
17 class H2Matrix;
18 
21 template <typename Derived>
22 class H2MatrixBase : public EigenBase<Derived> {
23  public:
24  typedef typename internal::traits<Derived>::Scalar Scalar;
25  typedef typename internal::ref_selector<Derived>::type Nested;
27  typedef Scalar CoeffReturnType;
28 
29  enum {
30  RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
31  ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
32  SizeAtCompileTime = (internal::size_at_compile_time<
33  internal::traits<Derived>::RowsAtCompileTime,
34  internal::traits<Derived>::ColsAtCompileTime>::ret),
35  MaxRowsAtCompileTime = RowsAtCompileTime,
36  MaxColsAtCompileTime = ColsAtCompileTime,
37  MaxSizeAtCompileTime =
38  (internal::size_at_compile_time<MaxRowsAtCompileTime,
39  MaxColsAtCompileTime>::ret),
40  IsVectorAtCompileTime = false
41  };
42 
43  inline const Derived& derived() const {
44  return *static_cast<const Derived*>(this);
45  }
46  inline Derived& derived() { return *static_cast<Derived*>(this); }
47 
48 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::H2MatrixBase
49 #include "Eigen/src/plugins/CommonCwiseBinaryOps.h"
50 
51  // H2 * dense
52  template <typename OtherDerived>
53  const Product<Derived, OtherDerived> operator*(
54  const MatrixBase<OtherDerived>& other) const {
55  return Product<Derived, OtherDerived>(derived(), other.derived());
56  }
57 
58  private:
59  // these operations cannot be performed exactly, so we declare them private
60  template <typename OtherDerived>
61  Derived& operator+=(const SparseMatrixBase<OtherDerived>& other);
62  template <typename OtherDerived>
63  Derived& operator-=(const SparseMatrixBase<OtherDerived>& other);
64  template <typename OtherDerived>
65  Derived& operator+=(const DiagonalBase<OtherDerived>& other);
66  template <typename OtherDerived>
67  Derived& operator-=(const DiagonalBase<OtherDerived>& other);
68  template <typename OtherDerived>
69  Derived& operator+=(const EigenBase<OtherDerived>& other);
70  template <typename OtherDerived>
71  Derived& operator-=(const EigenBase<OtherDerived>& other);
72 
73  Derived& operator*=(const Scalar& other);
74  Derived& operator/=(const Scalar& other);
75 };
76 
77 namespace internal {
78 
79 // adaption from SparseMatrixBase from Eigen
80 template <typename Derived>
81 struct evaluator<H2MatrixBase<Derived>> : evaluator_base<Derived> {
82  typedef typename Derived::Scalar Scalar;
83 
84  enum { CoeffReadCost = NumTraits<Scalar>::ReadCost, Flags = Derived::Flags };
85 
86  evaluator() : m_matrix(0), m_zero(0) {
87  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
88  }
89  explicit evaluator(const Derived& mat) : m_matrix(&mat), m_zero(0) {
90  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
91  }
92 
93  operator Derived&() { return m_matrix->const_cast_derived(); }
94  operator const Derived&() const { return *m_matrix; }
95 
96  const Derived* m_matrix;
97  const Scalar m_zero;
98 };
99 
100 } // end namespace internal
101 
102 } // end namespace Eigen
103 
104 #endif // BEMBEL_SRC_H2MATRIX_H2MATRIXBASE_HPP_
Hierarchical Matrix class, which extends the EigenBase class.