38 if (n_nonzero_columns > 0)
40 mat_.reserve(Eigen::Matrix<IndexType, Eigen::Dynamic, 1>::Constant(
41 n, n_nonzero_columns));
60 auto const N =
mat_.nonZeros();
61 for (
auto i =
decltype(N){0}; i < N; i++)
63 mat_.valuePtr()[i] = 0;
74 mat_.coeffRef(row, col) = val;
82 mat_.coeffRef(row, col) += val;
88 template <
class T_DENSE_MATRIX>
89 void add(std::vector<IndexType>
const& row_pos,
90 const T_DENSE_MATRIX& sub_matrix,
93 this->
add(row_pos, row_pos, sub_matrix, fkt);
98 template <
class T_DENSE_MATRIX>
100 const T_DENSE_MATRIX& sub_matrix,
118 template <
class T_DENSE_MATRIX>
119 void add(std::vector<IndexType>
const& row_pos,
120 std::vector<IndexType>
const& col_pos,
121 const T_DENSE_MATRIX& sub_matrix,
double fkt = 1.0);
126 return mat_.coeff(row, col);
133 void write(
const std::string& filename)
const;
136 void write(std::ostream& os)
const;
145template <
class T_DENSE_MATRIX>
147 std::vector<IndexType>
const& col_pos,
148 const T_DENSE_MATRIX& sub_matrix,
double fkt)
150 auto const n_rows = row_pos.size();
151 auto const n_cols = col_pos.size();
152 for (
auto i =
decltype(n_rows){0}; i < n_rows; i++)
154 auto const row = row_pos[i];
155 for (
auto j =
decltype(n_cols){0}; j < n_cols; j++)
157 auto const col = col_pos[j];
158 add(row, col, fkt * sub_matrix(i, j));
164template <
typename SPARSITY_PATTERN>
170 SPARSITY_PATTERN
const& sparsity_pattern)
const
172 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
173 "Set matrix sparsity relies on the EigenMatrix to be in "
174 "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