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
142 std::ofstream of(filename);
152 for (
int k = 0; k <
mat_.outerSize(); ++k)
154 for (RawMatrixType::InnerIterator it(
mat_, k); it; ++it)
156 os << it.row() <<
" " << it.col() <<
": " << it.value() <<
"\n";
169 template <
class T_DENSE_MATRIX>
171 std::vector<IndexType>
const& col_pos,
172 const T_DENSE_MATRIX& sub_matrix,
double fkt)
174 auto const n_rows = row_pos.size();
175 auto const n_cols = col_pos.size();
176 for (
auto i = decltype(n_rows){0}; i < n_rows; i++)
178 auto const row = row_pos[i];
179 for (
auto j = decltype(n_cols){0}; j < n_cols; j++)
181 auto const col = col_pos[j];
182 add(row, col, fkt * sub_matrix(i, j));
188 template <
typename SPARSITY_PATTERN>
194 SPARSITY_PATTERN
const& sparsity_pattern)
const
196 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
197 "Set matrix sparsity relies on the EigenMatrix to be in "
198 "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
void write(std::ostream &os) const
printout this matrix for debugging
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)
const RawMatrixType & getRawMatrix() const
IndexType getNumberOfRows() const
return the number of rows
int setValue(IndexType row, IndexType col, double val)
Eigen::SparseMatrix< double, Eigen::RowMajor > RawMatrixType
RawMatrixType & getRawMatrix()
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
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