OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
eigen_dense.hpp
Go to the documentation of this file.
1// OpenBEM - Copyright (C) 2026 Shashwat Sharma
2
3// This file is part of OpenBEM.
4
5// OpenBEM is free software: you can redistribute it and/or modify it under the terms of the
6// GNU General Public License as published by the Free Software Foundation, either version 3
7// of the License, or (at your option) any later version.
8
9// You should have received a copy of the GNU General Public License along with OpenBEM.
10// If not, see <https://www.gnu.org/licenses/>.
11
12
18#ifndef EIGEN_DENSE_MATRIX_HPP
19#define EIGEN_DENSE_MATRIX_HPP
20
21#include <external/Eigen/Dense>
22#include <external/Eigen/IterativeLinearSolvers>
23#include <external/EigenUnsupported/Eigen/IterativeSolvers>
24
25#include "types.hpp"
26#include "matrix/base.hpp"
27#include "matrix/eigen_base.hpp"
28
29
30namespace bem
31{
32
43template <typename T, int StorageOrder = Eigen::ColMajor>
44class EigenDenseMatrix: public EigenMatrixBase<T, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, StorageOrder>>
45{
46
47 using MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, StorageOrder>;
49 using base::base;
50 using base::matrix_;
51
52public:
53
54
61 T value(Index row, Index col) const override
62 {
63 return (*matrix_)(row, col);
64 };
65
66
73 void set_value(Index row, Index col, const T& a) override
74 {
75 (*matrix_)(row, col) = a;
76 return;
77 };
78
79
86 void add_value(Index row, Index col, const T& a) override
87 {
88 (*matrix_)(row, col) += a;
89 return;
90 };
91
92
97 void scale(const T& a) override
98 {
99 (*matrix_) *= a;
100 return;
101 };
102
103
108 void set_constant(const T& a)
109 {
110 matrix_->setConstant(a);
111 return;
112 };
113
114
122 void mat_solve(MatrixBase<T>& x, const MatrixBase<T>& b) override
123 {
124 const EigenDenseMatrix<T>& bd = dynamic_cast<const EigenDenseMatrix<T>&> (b);
125 EigenDenseMatrix<T>& xd = dynamic_cast<EigenDenseMatrix<T>&> (x);
126 // xd.raw_matrix() = matrix_->householderQr().solve(bd.raw_matrix());
127 // xd.raw_matrix() = matrix_->colPivHouseholderQr().solve(bd.raw_matrix());
128 // xd.raw_matrix() = matrix_->fullPivHouseholderQr().solve(bd.raw_matrix());
129 xd.raw_matrix() = matrix_->partialPivLu().solve(bd.raw_matrix());
130 // xd.raw_matrix() = matrix_->fullPivLu().solve(bd.raw_matrix());
131 return;
132 };
133
134
143 const MatrixBase<T>& x,
146 const T& a = T(1)
147 ) override
148 {
149 const EigenDenseMatrix<T>& xd = dynamic_cast<const EigenDenseMatrix<T>&> (x);
150 matrix_->block(row_start, col_start, xd.num_rows(), xd.num_cols()) = xd.raw_matrix() * a;
151 return;
152 };
153
154
164 const MatrixBase<T>& x,
167 const T& a = T(1)
168 ) override
169 {
170 const EigenDenseMatrix<T>& xd = dynamic_cast<const EigenDenseMatrix<T>&> (x);
171 matrix_->block(row_start, col_start, xd.num_rows(), xd.num_cols()) += a * xd.raw_matrix();
172 return;
173 };
174
175
190 ) const override
191 {
192 EigenDenseMatrix<T>& xd = dynamic_cast<EigenDenseMatrix<T>&> (x);
193 xd.resize(b_rows, b_cols);
194 xd.raw_matrix() = matrix_->block(row_start, col_start, b_rows, b_cols);
195 return;
196 };
197
198
203 virtual const T* data() const override
204 { return matrix_->data(); };
205
206
211 virtual T* data() override
212 { return matrix_->data(); };
213
214
221 {
222 return matrix_->norm();
223 };
224
225
231 T one_norm() const
232 {
233 return matrix_->colwise().sum().array().abs().maxCoeff();
234 };
235
236
243 {
244 return matrix_->rowwise().sum().array().abs().maxCoeff();
245 };
246
247
252 Index rank() const
253 {
254 return matrix_->fullPivLu().rank();
255 };
256
257};
258
263}
264
265#endif
Eigen-based dense matrix wrapper.
void add_block(const MatrixBase< T > &x, Index row_start, Index col_start, const T &a=T(1)) override
Adds a block of values to this matrix from the values of a given matrix, starting at a given position...
void mat_solve(MatrixBase< T > &x, const MatrixBase< T > &b) override
Solves for matrix with a direct solver, where is this matrix, and is a given right-hand side matr...
T frobenius_norm() const
Returns the Frobenius norm of the matrix, defined as the square root of the sum of the squares of all...
void set_value(Index row, Index col, const T &a) override
Sets the matrix value at the specified row and column.
virtual T * data() override
Returns a writable pointer to the underlying raw data - use with care.
void get_block(MatrixBase< T > &x, Index row_start, Index col_start, Index b_rows, Index b_cols) const override
Retrieves a block of values from this matrix.
Index rank() const
Computes the rank of the matrix.
void add_value(Index row, Index col, const T &a) override
Adds to the matrix value at the specified row and column.
void scale(const T &a) override
Scales all matrix entries by a given value.
void set_block(const MatrixBase< T > &x, Index row_start, Index col_start, const T &a=T(1)) override
Sets a block of values in this matrix to the values of a given matrix, starting at a given position.
T value(Index row, Index col) const override
Returns the matrix value at the specified row and column.
virtual const T * data() const override
Returns a read-only pointer to the underlying raw data.
void set_constant(const T &a)
Sets all matrix entries to a given constant value.
T infinity_norm() const
Returns the infinity-norm of the matrix, computed by taking the sum of absolute values of all columns...
T one_norm() const
Returns the one-norm of the matrix, computed by taking the sum of absolute values of all rows for eac...
Base class for Eigen-based matrices.
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Definition types.hpp:86
std::size_t Index
Unsigned integer type for indices and container sizes.
Definition types.hpp:54
Primary namespace for the OpenBEM library.
Definition constants.hpp:31