1#ifndef INCG_LF_COOMATRIX_H
2#define INCG_LF_COOMATRIX_H
17#include "assembly_types.h"
19#include <Eigen/Sparse>
51template <
typename SCALAR>
108 template <
typename PREDICATE>
140 template <
typename VECTOR>
162 template <
typename VECTOR,
typename RESULTVECTOR>
173 Eigen::SparseMatrix<Scalar> result;
176 "matrix has zero rows or columns, this is probably an error.");
187 [[
nodiscard]] Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
189 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
mat(
rows_,
cols_);
194 "Illegal triplet index (" <<
trp.col() <<
',' <<
trp.row() <<
")");
206 o <<
rows_ <<
" x " <<
cols_ <<
" COO matrix" <<
'\n';
208 o <<
"(" <<
trp.row() <<
',' <<
trp.col() <<
") -> " <<
trp.value()
218 template <
typename SCALARTYPE>
228template <
typename SCALARTYPE>
234template <
typename SCALAR>
235template <
typename VECTOR>
238 LF_ASSERT_MSG(
vec.size() >= cols_,
239 "size mismatch: " << cols_ <<
" <-> " <<
vec.size());
240 Eigen::VectorXd result(rows_);
248template <
typename SCALAR>
249template <
typename VECTOR,
typename RESULTVECTOR>
252 LF_ASSERT_MSG(
vec.size() >= cols_,
253 "Vector vec size mismatch: " << cols_ <<
" <-> " <<
vec.size());
256 "Vector result size mismatch: " << cols_ <<
" <-> " <<
resvec.size());
269template<
class SCALAR>
A temporary data structure for matrix in COO format.
void PrintInfo(std::ostream &o) const
Ouput of triplet list describing COO matrix.
void setZero()
Erase all entries of the matrix.
Index cols() const
return number of column
void setZero(PREDICATE &&pred)
Erase specific entries of the COO matrix, that is, set them to zero.
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > MatVecMult(SCALAR alpha, const VECTOR &vec) const
Computes the product of a (scaled) vector with the matrix in COO format.
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > makeDense() const
Create an Eigen::MatrixX from the COO format.
COOMatrix(COOMatrix &&) noexcept=default
const TripletVec & triplets() const
std::vector< Triplet > TripletVec
Eigen::SparseMatrix< Scalar > makeSparse() const
Create an Eigen::SparseMatrix out of the COO format.
Eigen::Triplet< SCALAR > Triplet
COOMatrix(const COOMatrix &)=default
COOMatrix(size_type num_rows, size_type num_cols)
TripletVec & triplets()
Gives access to the vector of triplets.
Index rows() const
return number of rows
void AddToEntry(gdof_idx_t i, gdof_idx_t j, SCALAR increment)
Add a value to the specified entry.
friend std::ostream & operator<<(std::ostream &o, const COOMatrix< SCALARTYPE > &mat)
Output operator for COO matrix.
void AssembleMatrixLocally(dim_t codim, const DofHandler &dof_handler_trial, const DofHandler &dof_handler_test, ENTITY_MATRIX_PROVIDER &entity_matrix_provider, TMPMATRIX &matrix)
Assembly function for standard assembly of finite element matrices.
D.o.f. index mapping and assembly facilities.
lf::base::size_type size_type
std::ostream & operator<<(std::ostream &o, const COOMatrix< SCALARTYPE > &mat)