OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
bem::EigenSparseMatrix< T, StorageOrder > Class Template Reference

Eigen-based sparse matrix wrapper. More...

#include <eigen_sparse.hpp>

+ Inheritance diagram for bem::EigenSparseMatrix< T, StorageOrder >:

Detailed Description

template<typename T, int StorageOrder = Eigen::ColMajor>
class bem::EigenSparseMatrix< T, StorageOrder >

Eigen-based sparse matrix wrapper.

Template Parameters
T- Data type to be stored in the matrix (e.g., float, double, std::complex).
StorageOrder- Storage order of the matrix, either Eigen::ColMajor or Eigen::RowMajor.

Definition at line 51 of file eigen_sparse.hpp.

Member Function Documentation

◆ preallocate() [1/2]

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::preallocate ( const std::vector< Index > &  nnz)
inlineoverridevirtual

Preallocates memory for a given number of non-zero values per row.

Parameters
[in]nnz- Vector containing the number of non-zero values for each row.
Note
This preallocates a cache for storing matrix values and their indices, not the actual matrix. One must call assemble() to actually assemble the matrix from the cached values, before using the matrix.

Reimplemented from bem::MatrixBase< T >.

Definition at line 69 of file eigen_sparse.hpp.

◆ preallocate() [2/2]

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::preallocate ( Index  num_entries)
inlineoverridevirtual

Preallocates memory for a given total number of non-zero values.

Parameters
[in]num_entries- Total number of non-zero values.
Note
This preallocates a cache for storing matrix values and their indices, not the actual matrix. One must call assemble() to actually assemble the matrix from the cached values, before using the matrix.

Reimplemented from bem::MatrixBase< T >.

Definition at line 83 of file eigen_sparse.hpp.

◆ preallocate_directly()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::preallocate_directly ( const std::vector< Index > &  nnz)
inline

Preallocates memory for a given number of non-zero values per row.

Parameters
[in]nnz- Vector containing the number of non-zero values for each row.
Note
This preallocates memory directly for the underlying raw matrix values, but assemble() must still be called before using the matrix.

Definition at line 97 of file eigen_sparse.hpp.

◆ assemble()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::assemble ( )
inlineoverridevirtual

Assembles cached data into the matrix.

Reimplemented from bem::MatrixBase< T >.

Definition at line 108 of file eigen_sparse.hpp.

◆ value()

template<typename T , int StorageOrder = Eigen::ColMajor>
T bem::EigenSparseMatrix< T, StorageOrder >::value ( Index  row,
Index  col 
) const
inlineoverridevirtual

Returns the matrix value at the specified row and column.

Parameters
[in]row- Row index.
[in]col- Column index.
Returns
Value at the specified position in the matrix.

Implements bem::MatrixBase< T >.

Definition at line 134 of file eigen_sparse.hpp.

◆ set_value()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::set_value ( Index  row,
Index  col,
const T a 
)
inlineoverridevirtual

Sets the matrix value at the specified row and column.

Parameters
[in]row- Row index.
[in]col- Column index.
[in]a- Value to set.
Note
This sets the value in a cache, not directly in the underlying raw matrix. One must call assemble() to actually assemble the matrix from all cached values. It is recommended to call set_value() for all values one wants to set, and then call assemble() once to create the matrix.

Implements bem::MatrixBase< T >.

Definition at line 149 of file eigen_sparse.hpp.

◆ set_value_directly()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::set_value_directly ( Index  row,
Index  col,
const T a 
)
inline

Sets the matrix value at the specified row and column directly, without using a cache.

Parameters
[in]row- Row index.
[in]col- Column index.
[in]a- Value to set.

Definition at line 164 of file eigen_sparse.hpp.

◆ add_value()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::add_value ( Index  row,
Index  col,
const T a 
)
inlineoverridevirtual

Adds to the matrix value at the specified row and column.

Parameters
[in]row- Row index.
[in]col- Column index.
[in]a- Value to add.
Note
This adds the value to a cache, not directly in the underlying raw matrix. One must call assemble() to actually assemble the matrix from all cached values. It is recommended to call set_value() or add_value() for all values one wants to set or add, and then call assemble() once to create the matrix.

Reimplemented from bem::MatrixBase< T >.

Definition at line 182 of file eigen_sparse.hpp.

◆ add_value_directly()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::add_value_directly ( Index  row,
Index  col,
const T a 
)
inline

Adds to the matrix value at the specified row and column directly, without using a cache.

Parameters
[in]row- Row index.
[in]col- Column index.
[in]a- Value to add.

Definition at line 197 of file eigen_sparse.hpp.

◆ scale()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::scale ( const T a)
inlineoverridevirtual

Scales all matrix entries by a given value.

Parameters
[in]a- Value by which to scale.

Implements bem::MatrixBase< T >.

Definition at line 208 of file eigen_sparse.hpp.

◆ factorize()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::factorize ( )
inline

Computes and stores the LU factors using sparse factorization. The original matrix is not modified.

Definition at line 221 of file eigen_sparse.hpp.

◆ mat_solve()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::mat_solve ( MatrixBase< T > &  x,
const MatrixBase< T > &  b 
)
inlineoverridevirtual

Solves \( \mathbf{M}\mathbf{X} = \mathbf{B} \) for matrix \( \mathbf{X} \) with a direct solver, where \( \mathbf{M} \) is this matrix, and \( \mathbf{B} \) is a given right-hand side matrix.

Parameters
[out]x- Solution.
[in]b- Right-hand side matrix, must have the same number of rows as this matrix.

Implements bem::MatrixBase< T >.

Definition at line 238 of file eigen_sparse.hpp.

◆ set_block()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::set_block ( const MatrixBase< T > &  x,
Index  row_start,
Index  col_start,
const T a = T(1) 
)
inlineoverridevirtual

Sets a block of values in this matrix to the values of a given matrix, starting at a given position.

Parameters
[in]x- Matrix to insert.
[in]row_start- Starting row index for the block.
[in]col_start- Starting column index for the block.
[in]a- Scalar to multiply the values of x before inserting (optional).

Implements bem::EigenMatrixBase< T, MatrixType >.

Definition at line 262 of file eigen_sparse.hpp.

◆ add_block()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::add_block ( const MatrixBase< T > &  x,
Index  row_start,
Index  col_start,
const T a = T(1) 
)
inlineoverridevirtual

Adds a block of values to this matrix from the values of a given matrix, starting at a given position.

Parameters
[in]x- Matrix whose values should be added to a block of this matrix.
[in]row_start- Starting row index for the block.
[in]col_start- Starting column index for the block.
[in]a- Scalar to multiply the values of x before adding (optional).

Implements bem::EigenMatrixBase< T, MatrixType >.

Definition at line 296 of file eigen_sparse.hpp.

◆ get_block()

template<typename T , int StorageOrder = Eigen::ColMajor>
void bem::EigenSparseMatrix< T, StorageOrder >::get_block ( MatrixBase< T > &  x,
Index  row_start,
Index  col_start,
Index  b_rows,
Index  b_cols 
) const
inlineoverridevirtual

Retrieves a block of values from this matrix.

Parameters
[out]x- Matrix to store the retrieved block of values.
[in]row_start- Starting row index for the block.
[in]col_start- Starting column index for the block.
[in]b_rows- Number of rows in the block to retrieve.
[in]b_cols- Number of columns in the block to retrieve.

Implements bem::EigenMatrixBase< T, MatrixType >.

Definition at line 326 of file eigen_sparse.hpp.

◆ data() [1/2]

template<typename T , int StorageOrder = Eigen::ColMajor>
virtual const T * bem::EigenSparseMatrix< T, StorageOrder >::data ( ) const
inlineoverridevirtual

Returns a read-only pointer to the underlying raw data.

Returns
Read-only pointer to the raw data.

Implements bem::MatrixBase< T >.

Definition at line 345 of file eigen_sparse.hpp.

◆ data() [2/2]

template<typename T , int StorageOrder = Eigen::ColMajor>
virtual T * bem::EigenSparseMatrix< T, StorageOrder >::data ( )
inlineoverridevirtual

Returns a writable pointer to the underlying raw data - use with care.

Returns
Writable pointer to the raw data.

Implements bem::MatrixBase< T >.

Definition at line 353 of file eigen_sparse.hpp.

◆ raw_matrix() [1/2]

template<typename T , int StorageOrder = Eigen::ColMajor>
MatrixType & bem::EigenMatrixBase< T, MatrixType >::raw_matrix ( )
inline

Returns a writable reference to the underlying raw matrix - use with caution.

Definition at line 120 of file eigen_base.hpp.

◆ raw_matrix() [2/2]

template<typename T , int StorageOrder = Eigen::ColMajor>
const MatrixType & bem::EigenMatrixBase< T, MatrixType >::raw_matrix ( ) const
inline

Returns a read-only reference to the underlying raw matrix.

Definition at line 129 of file eigen_base.hpp.

◆ set_raw_matrix()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::set_raw_matrix ( const MatrixType &  matrix)
inlineinherited

Sets the underlying raw matrix by copying over data from a given matrix.

Parameters
[in]matrix- The raw matrix to set.

Definition at line 139 of file eigen_base.hpp.

◆ bind_raw_matrix()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::bind_raw_matrix ( std::shared_ptr< MatrixType >  matrix)
inlineinherited

Binds the underlying raw matrix to the data pointed at by a given matrix pointer.

Parameters
[in]matrix- Pointer to the raw matrix to be bound.

The purpose of this method is to allow creating an external Eigen matrix of type MatrixType, and then transferring ownership of that matrix to this object, but without copying over the underlying data, unlike set_raw_matrix().

Definition at line 154 of file eigen_base.hpp.

◆ num_rows()

template<typename T , typename MatrixType >
Index bem::EigenMatrixBase< T, MatrixType >::num_rows ( ) const
inlineoverridevirtualinherited

Returns the total number of rows in the matrix.

Returns
Number of rows.

Implements bem::MatrixBase< T >.

Definition at line 165 of file eigen_base.hpp.

◆ num_cols()

template<typename T , typename MatrixType >
Index bem::EigenMatrixBase< T, MatrixType >::num_cols ( ) const
inlineoverridevirtualinherited

Returns the total number of rows in the matrix.

Returns
Number of rows.

Implements bem::MatrixBase< T >.

Definition at line 175 of file eigen_base.hpp.

◆ size()

template<typename T , typename MatrixType >
Index bem::EigenMatrixBase< T, MatrixType >::size ( ) const
inlineoverridevirtualinherited

Returns the size (rows * cols) of the matrix.

Returns
Size (rows * cols).

Reimplemented from bem::MatrixBase< T >.

Definition at line 185 of file eigen_base.hpp.

◆ resize()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::resize ( Index  rows,
Index  cols 
)
inlineoverridevirtualinherited

Resizes the matrix to a new number of rows and columns.

Parameters
[in]rows- New number of rows.
[in]cols- New number of columns.

Implements bem::MatrixBase< T >.

Definition at line 196 of file eigen_base.hpp.

◆ clear()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::clear ( )
inlineoverridevirtualinherited

Clears all data in the matrix and sets its size to 0.

Implements bem::MatrixBase< T >.

Definition at line 207 of file eigen_base.hpp.

◆ set_zero()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::set_zero ( )
inlineoverridevirtualinherited

Sets all matrix entries to zero.

Implements bem::MatrixBase< T >.

Definition at line 217 of file eigen_base.hpp.

◆ set_identity()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::set_identity ( )
inlineoverridevirtualinherited

Sets the matrix to identity (ones along the diagonal).

Reimplemented from bem::MatrixBase< T >.

Definition at line 227 of file eigen_base.hpp.

◆ set_transpose()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::set_transpose ( const MatrixBase< T > &  x)
inlineinherited

Computes \( \mathbf{M} = \mathbf{X}^T \) where \( \mathbf{M} \) is this matrix, \( \mathbf{X} \) is a given matrix, and \( \mathbf{X}^T \) is its transpose.

Parameters
[in]x- Matrix to transpose.

Definition at line 240 of file eigen_base.hpp.

◆ get_diagonal()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::get_diagonal ( MatrixBase< T > &  x) const
inlineinherited

Retrieves matrix values on the diagonal, zeroing out all other entries.

Parameters
[out]x- Diagonal matrix.

Definition at line 252 of file eigen_base.hpp.

◆ add_ax()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::add_ax ( const MatrixBase< T > &  x,
const T a = T(1) 
)
inlineoverridevirtualinherited

Computes \( \mathbf{M} = \mathbf{M} + a\mathbf{X} \) where \( \mathbf{M} \) is this matrix, \( a \) is a scalar, and \( \mathbf{X} \) is a matrix.

Parameters
[in]x- Matrix to scale and add, must have the same dimensions as this matrix.
[in]a- Scalar which which to scale x.

Implements bem::MatrixBase< T >.

Definition at line 266 of file eigen_base.hpp.

◆ set_axpby()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::set_axpby ( const MatrixBase< T > &  x,
const MatrixBase< T > &  y,
const T a = T(1),
const T b = T(1) 
)
inlineinherited

Computes \( \mathbf{M} = a\mathbf{X} + b\mathbf{Y} \) where \( \mathbf{M} \) is this matrix, \( a \) and \( b \) are scalars, and \( \mathbf{X} \) and \( \mathbf{Y} \) are matrices.

Parameters
[in]x- First matrix to scale and add, must have the same dimensions as y.
[in]y- Second matrix to scale and add, must have the same dimensions as x.
[in]a- Scalar which which to scale x.
[in]b- Scalar which which to scale y.

Definition at line 282 of file eigen_base.hpp.

◆ set_mat_mul()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::set_mat_mul ( const MatrixBase< T > &  x,
const MatrixBase< T > &  y,
const T a = T(1) 
)
inlineinherited

Computes \( \mathbf{M} = a\mathbf{X}\mathbf{Y} \) where \( \mathbf{M} \) is this matrix, \( a \) is a scalar, and \( \mathbf{X} \) and \( \mathbf{Y} \) are matrices.

Parameters
[in]x- First matrix to multiply, must have the same number of columns as y has rows.
[in]y- Second matrix to multiply , must have the same number of rows as x has columns.
[in]a- Scalar which which to scale the product of x and y.

Definition at line 298 of file eigen_base.hpp.

◆ add_mat_mul()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::add_mat_mul ( const MatrixBase< T > &  x,
const MatrixBase< T > &  y,
const T a = T(1) 
)
inlineinherited

Computes \( \mathbf{M} = \mathbf{M} + a\mathbf{X}\mathbf{Y} \) where \( \mathbf{M} \) is this matrix, \( a \) is a scalar, and \( \mathbf{X} \) and \( \mathbf{Y} \) are matrices.

Parameters
[in]x- First matrix to multiply, must have the same number of columns as y has rows.
[in]y- Second matrix to multiply , must have the same number of rows as x has columns.
[in]a- Scalar which which to scale the product of x and y.

Definition at line 314 of file eigen_base.hpp.

◆ mat_solve_iterative()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::mat_solve_iterative ( MatrixBase< T > &  x,
const MatrixBase< T > &  b,
const Float  tol = 1e-3 
)
inlineinherited

Solves \( \mathbf{M}\mathbf{X} = \mathbf{B} \) for matrix \( \mathbf{X} \) with an iterative solver, where \( \mathbf{M} \) is this matrix, and \( \mathbf{B} \) is a given right-hand side matrix.

Parameters
[out]x- Solution.
[in]b- Right-hand side matrix, must have the same number of rows as this matrix.
[in]tol- Tolerance for convergence (optional).

Definition at line 332 of file eigen_base.hpp.

◆ mat_solve_gmres()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::mat_solve_gmres ( MatrixBase< T > &  x,
const MatrixBase< T > &  b,
const Float  tol = 1e-3,
const Index  restart = 100 
)
inlineinherited

Solves \( \mathbf{M}\mathbf{X} = \mathbf{B} \) for matrix \( \mathbf{X} \) with the GMRES iterative solver, where \( \mathbf{M} \) is this matrix, and \( \mathbf{B} \) is a given right-hand side matrix.

Parameters
[out]x- Solution.
[in]b- Right-hand side matrix, must have the same number of rows as this matrix.
[in]tol- Tolerance for convergence (optional).
[in]restart- Restart iteration at which the Krylov subspace is discarded (optional).

Definition at line 349 of file eigen_base.hpp.

◆ mat_solve_bicgstab()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::mat_solve_bicgstab ( MatrixBase< T > &  x,
const MatrixBase< T > &  b,
const Float  tol = 1e-3 
)
inlineinherited

Solves \( \mathbf{M}\mathbf{X} = \mathbf{B} \) for matrix \( \mathbf{X} \) with the BiCGSTAB iterative solver, where \( \mathbf{M} \) is this matrix, and \( \mathbf{B} \) is a given right-hand side matrix.

Parameters
[out]x- Solution.
[in]b- Right-hand side matrix, must have the same number of rows as this matrix.
[in]tol- Tolerance for convergence (optional).

Definition at line 390 of file eigen_base.hpp.

◆ cond()

template<typename T , typename MatrixType >
Float bem::EigenMatrixBase< T, MatrixType >::cond ( ) const
inlineinherited

Computes the condition number (ratio of largest to smallest singular value) of the matrix.

Returns
Condition number.

Definition at line 424 of file eigen_base.hpp.

◆ print()

template<typename T , typename MatrixType >
void bem::EigenMatrixBase< T, MatrixType >::print ( const std::string  name = "matrix") const
inlineoverridevirtualinherited

Prints the matrix to the terminal in a formatted manner.

Reimplemented from bem::MatrixBase< T >.

Definition at line 440 of file eigen_base.hpp.

◆ write_binary()

template<typename T >
virtual void bem::MatrixBase< T >::write_binary ( const std::string  name = "matrix") const
inlinevirtualinherited

Writes the matrix to a binary file.

Definition at line 196 of file base.hpp.

◆ read_binary()

template<typename T >
virtual void bem::MatrixBase< T >::read_binary ( const std::string  name = "matrix")
inlinevirtualinherited

Reads the matrix from a binary file.

Definition at line 211 of file base.hpp.


The documentation for this class was generated from the following file: