13#include <Eigen/Sparse>
45 if (n_nonzero_columns > 0)
47 mat_.reserve(Eigen::Matrix<IndexType, Eigen::Dynamic, 1>::Constant(
48 n, n_nonzero_columns));
67 auto const N =
mat_.nonZeros();
68 for (
auto i =
decltype(N){0}; i < N; i++)
70 mat_.valuePtr()[i] = 0;
81 mat_.coeffRef(row, col) = val;
89 mat_.coeffRef(row, col) += val;
95 template <
class T_DENSE_MATRIX>
96 void add(std::vector<IndexType>
const& row_pos,
97 const T_DENSE_MATRIX& sub_matrix,
100 this->
add(row_pos, row_pos, sub_matrix, fkt);
105 template <
class T_DENSE_MATRIX>
107 const T_DENSE_MATRIX& sub_matrix,
125 template <
class T_DENSE_MATRIX>
126 void add(std::vector<IndexType>
const& row_pos,
127 std::vector<IndexType>
const& col_pos,
128 const T_DENSE_MATRIX& sub_matrix,
double fkt = 1.0);
133 return mat_.coeff(row, col);
140 void write(
const std::string& filename)
const;
143 void write(std::ostream& os)
const;
152template <
class T_DENSE_MATRIX>
154 std::vector<IndexType>
const& col_pos,
155 const T_DENSE_MATRIX& sub_matrix,
double fkt)
157 auto const n_rows = row_pos.size();
158 auto const n_cols = col_pos.size();
159 for (
auto i =
decltype(n_rows){0}; i < n_rows; i++)
161 auto const row = row_pos[i];
162 for (
auto j =
decltype(n_cols){0}; j < n_cols; j++)
164 auto const col = col_pos[j];
165 add(row, col, fkt * sub_matrix(i, j));
171template <
typename SPARSITY_PATTERN>
177 SPARSITY_PATTERN
const& sparsity_pattern)
const
179 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
180 "Set matrix sparsity relies on the EigenMatrix to be in "
181 "row-major storage order.");
RawMatrixType::Index IndexType
IndexType getNumberOfColumns() const
return the number of columns
void add(std::vector< IndexType > const &row_pos, const T_DENSE_MATRIX &sub_matrix, double fkt=1.0)
static constexpr IndexType getRangeBegin()
return a start index of the active data range
void write(const std::string &filename) const
printout this matrix for debugging
const RawMatrixType & getRawMatrix() const
void add(RowColumnIndices< IndexType > const &indices, const T_DENSE_MATRIX &sub_matrix, double fkt=1.0)
void setZero()
reset data entries to zero.
int add(IndexType row, IndexType col, double val)
IndexType getNumberOfRows() const
return the number of rows
int setValue(IndexType row, IndexType col, double val)
Eigen::SparseMatrix< double, Eigen::RowMajor > RawMatrixType
double get(IndexType row, IndexType col) const
get value. This function returns zero if the element doesn't exist.
EigenMatrix(IndexType const n, IndexType const n_nonzero_columns=0)
IndexType getRangeEnd() const
return an end index of the active data range
RawMatrixType & getRawMatrix()
static constexpr bool isAssembled()
return always true, i.e. the matrix is always ready for use
LineIndex const & columns
void operator()(EigenMatrix &matrix, SPARSITY_PATTERN const &sparsity_pattern) const