28 std::vector<double>
const vals(values);
29 std::vector<PETScVector::IndexType> idcs(vals.size());
30 std::iota(idcs.begin(), idcs.end(), 0);
52 auto const rows = tmp.rows();
53 auto const cols = tmp.cols();
58 std::vector<IndexType> row_idcs(rows);
59 std::vector<IndexType> col_idcs(cols);
61 std::iota(row_idcs.begin(), row_idcs.end(), 0);
62 std::iota(col_idcs.begin(), col_idcs.end(), 0);
65 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
68 m.
add(row_idcs, col_idcs, tmp_);
78 assert((IndexType)values.size() == rows * cols);
80 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp(
83 auto it = values.begin();
84 for (IndexType
r = 0;
r < rows; ++
r)
86 for (IndexType c = 0; c < cols; ++c)
92 std::vector<IndexType> row_idcs(rows);
93 std::vector<IndexType> col_idcs(cols);
95 std::iota(row_idcs.begin(), row_idcs.end(), 0);
96 std::iota(col_idcs.begin(), col_idcs.end(), 0);
98 m.
add(row_idcs, col_idcs, tmp);
113void setVector(EigenVector&
v, std::initializer_list<double> values)
115 auto& w =
v.getRawVector();
116 assert((std::size_t)
v.size() == values.size());
117 auto it = values.begin();
118 for (std::size_t i = 0; i < values.size(); ++i)
125 MatrixVectorTraits<EigenVector>::Index
const index,
128 v.getRawVector()[index] = value;
131void setMatrix(EigenMatrix& m, std::initializer_list<double> values)
133 auto const rows = m.getNumberOfRows();
134 auto const cols = m.getNumberOfColumns();
137 Eigen::MatrixXd tmp(rows, cols);
139 auto it = values.begin();
148 m.getRawMatrix() = tmp.sparseView();
151void setMatrix(EigenMatrix& m, Eigen::MatrixXd
const& tmp)
153 m.getRawMatrix() = tmp.sparseView();
156void addToMatrix(EigenMatrix& m, std::initializer_list<double> values)
158 auto const rows = m.getNumberOfRows();
159 auto const cols = m.getNumberOfColumns();
162 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp(
165 auto it = values.begin();
174 m.getRawMatrix() += tmp.sparseView();
GlobalMatrix::IndexType GlobalIndexType
Declaration of class PETScMatrix, which provides an interface to PETSc matrix routines.
Declaration of class PETScVector, which provides an interface to PETSc vector routines.
RawMatrixType::Index IndexType
Wrapper class for PETSc matrix routines for matrix.
PetscInt getNumberOfColumns() const
Get the number of columns.
void setZero()
Set all entries to zero.
void add(const PetscInt i, const PetscInt j, const PetscScalar value)
Add value to a single entry.
PetscInt getNumberOfRows() const
Get the number of rows.
Wrapper class for PETSc vector.
void addToMatrix(PETScMatrix &m, std::initializer_list< double > values)
void setVector(PETScVector &v, std::initializer_list< double > values)
void setMatrix(PETScMatrix &m, std::initializer_list< double > values)