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;
92 template <
class T_DENSE_MATRIX>
93 void add(std::vector<IndexType>
const& row_pos,
94 const T_DENSE_MATRIX& sub_matrix,
97 this->
add(row_pos, row_pos, sub_matrix, fkt);
102 template <
class T_DENSE_MATRIX>
104 const T_DENSE_MATRIX& sub_matrix,
122 template <
class T_DENSE_MATRIX>
123 void add(std::vector<IndexType>
const& row_pos,
124 std::vector<IndexType>
const& col_pos,
125 const T_DENSE_MATRIX& sub_matrix,
double fkt = 1.0);
130 return mat_.coeff(row, col);
137 void write(
const std::string& filename)
const;
140 void write(std::ostream& os)
const;
149template <
class T_DENSE_MATRIX>
151 std::vector<IndexType>
const& col_pos,
152 const T_DENSE_MATRIX& sub_matrix,
double fkt)
154 auto const n_rows = row_pos.size();
155 auto const n_cols = col_pos.size();
156 for (
auto i =
decltype(n_rows){0}; i < n_rows; i++)
158 auto const row = row_pos[i];
159 for (
auto j =
decltype(n_cols){0}; j < n_cols; j++)
161 auto const col = col_pos[j];
162 add(row, col, fkt * sub_matrix(i, j));
168template <
typename SPARSITY_PATTERN>
174 SPARSITY_PATTERN
const& sparsity_pattern)
const
176 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
177 "Set matrix sparsity relies on the EigenMatrix to be in "
178 "row-major storage order.");
182 sparsity_pattern.numberOfRows()));
185 sparsity_pattern.number_non_zeros_per_row);
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
void addToDiagonal(double const value)
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