13#include <Eigen/Sparse>
44 if (n_nonzero_columns > 0)
46 mat_.reserve(Eigen::Matrix<IndexType, Eigen::Dynamic, 1>::Constant(
47 n, n_nonzero_columns));
66 auto const N =
mat_.nonZeros();
67 for (
auto i =
decltype(N){0}; i < N; i++)
69 mat_.valuePtr()[i] = 0;
80 mat_.coeffRef(row, col) = val;
88 mat_.coeffRef(row, col) += val;
94 template <
class T_DENSE_MATRIX>
95 void add(std::vector<IndexType>
const& row_pos,
96 const T_DENSE_MATRIX& sub_matrix,
99 this->
add(row_pos, row_pos, sub_matrix, fkt);
104 template <
class T_DENSE_MATRIX>
106 const T_DENSE_MATRIX& sub_matrix,
124 template <
class T_DENSE_MATRIX>
125 void add(std::vector<IndexType>
const& row_pos,
126 std::vector<IndexType>
const& col_pos,
127 const T_DENSE_MATRIX& sub_matrix,
double fkt = 1.0);
132 return mat_.coeff(row, col);
139 void write(
const std::string& filename)
const;
142 void write(std::ostream& os)
const;
151template <
class T_DENSE_MATRIX>
153 std::vector<IndexType>
const& col_pos,
154 const T_DENSE_MATRIX& sub_matrix,
double fkt)
156 auto const n_rows = row_pos.size();
157 auto const n_cols = col_pos.size();
158 for (
auto i =
decltype(n_rows){0}; i < n_rows; i++)
160 auto const row = row_pos[i];
161 for (
auto j =
decltype(n_cols){0}; j < n_cols; j++)
163 auto const col = col_pos[j];
164 add(row, col, fkt * sub_matrix(i, j));
170template <
typename SPARSITY_PATTERN>
176 SPARSITY_PATTERN
const& sparsity_pattern)
const
178 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
179 "Set matrix sparsity relies on the EigenMatrix to be in "
180 "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