47 PETScMatrix(
const PetscInt nrows,
const PetscInt ncols,
62 MatAssemblyBegin(
A_, asm_type);
63 MatAssemblyEnd(
A_, asm_type);
112 void set(
const PetscInt i,
const PetscInt j,
const PetscScalar value)
114 PetscCallAbort(PETSC_COMM_WORLD,
115 MatSetValue(
A_, i, j, value, INSERT_VALUES));
124 void add(
const PetscInt i,
const PetscInt j,
const PetscScalar value)
126 PetscCallAbort(PETSC_COMM_WORLD,
127 MatSetValue(
A_, i, j, value, ADD_VALUES));
153 template <
class T_DENSE_MATRIX>
155 const T_DENSE_MATRIX& sub_matrix)
161 std::vector<PetscInt> cols;
162 cols.reserve(indices.
columns.size());
163 for (
auto col : indices.
columns)
172 cols.push_back(std::abs(col));
176 add(indices.
rows, cols, sub_matrix);
187 template <
class T_DENSE_MATRIX>
188 void add(std::vector<PetscInt>
const& row_pos,
189 std::vector<PetscInt>
const& col_pos,
190 const T_DENSE_MATRIX& sub_mat);
221 void viewer(
const std::string& file_name,
222 const PetscViewerFormat vw_format = PETSC_VIEWER_ASCII_MATLAB);
229 PetscCallAbort(PETSC_COMM_WORLD, MatDestroy(&
A_));
279 const MatAssemblyType asm_type);
282template <
class T_DENSE_MATRIX>
284 std::vector<PetscInt>
const& col_pos,
285 const T_DENSE_MATRIX& sub_mat)
287 const PetscInt nrows =
static_cast<PetscInt
>(row_pos.size());
288 const PetscInt ncols =
static_cast<PetscInt
>(col_pos.size());
290 PetscCallAbort(PETSC_COMM_WORLD,
291 MatSetValues(
A_, nrows, &row_pos[0], ncols, &col_pos[0],
292 sub_mat.data(), ADD_VALUES));
302 PETScMatrix& mat,
const MatAssemblyType asm_type = MAT_FINAL_ASSEMBLY);
315 std::vector<PetscInt>
const& col_b);
325template <
typename SPARSITY_PATTERN>
329 SPARSITY_PATTERN
const& sparsity_pattern)
const
332 !sparsity_pattern.col_idx.empty());
Wrapper class for PETSc matrix routines for matrix.
PetscInt n_loc_cols_
Number of the local columns.
Mat const & getRawMatrix() const
PetscInt getNumberOfLocalRows() const
Get the number of local rows.
friend bool finalizeMatrixAssembly(PETScMatrix &mat, const MatAssemblyType asm_type)
General interface for the matrix assembly.
PETScMatrix & operator=(PETScMatrix const &A)
Mat & getRawMatrix()
Get matrix reference.
PetscInt getNumberOfColumns() const
Get the number of columns.
void add(RowColumnIndices< PetscInt > const &indices, const T_DENSE_MATRIX &sub_matrix)
Add sub-matrix at positions given by global indices, in which negative index indicates ghost entry.
void setZero()
Set all entries to zero.
PetscInt getRangeEnd() const
Get the end global index of the rows in the same rank.
void set(const PetscInt i, const PetscInt j, const PetscScalar value)
Set a single entry with a value.
PetscInt end_rank_
Ending index in a rank.
PetscInt getRangeBegin() const
Get the start global index of the rows of the same rank.
void finalizeAssembly(const MatAssemblyType asm_type=MAT_FINAL_ASSEMBLY)
Perform MPI collection of assembled entries in buffer.
PetscInt n_loc_rows_
Number of the local rows.
void preallocateFromSparsityPattern(const PETScSparsityPattern &sparsity_pattern)
Preallocate the matrix storage from an exact sparsity pattern.
PetscInt nrows_
Number of the global rows.
void setRowsColumnsZero(std::vector< PetscInt > const &row_pos)
Set the specified rows to zero except diagonal entries, i.e. , where This function must be called...
PetscInt ncols_
Number of the global columns.
void viewer(const std::string &file_name, const PetscViewerFormat vw_format=PETSC_VIEWER_ASCII_MATLAB)
void add(const PetscInt i, const PetscInt j, const PetscScalar value)
Add value to a single entry.
void create(const PETScSparsityPattern &sparsity_pattern)
Create the matrix, configure memory allocation and set the related member data.
void addToDiagonal(const PetscScalar value)
Add a constant value to all diagonal entries of the matrix.
PetscInt getNumberOfRows() const
Get the number of rows.
PetscInt start_rank_
Starting index in a rank.
std::vector< PetscInt > sparsity_col_idx_
Column indices from preallocation (empty when fallback path was used).
std::vector< PetscInt > const & getSparsityColumnIndices() const
Column indices cached at preallocation (empty on the fallback path).
PetscInt getNumberOfLocalColumns() const
Get the number of local columns.
void setPreallocationNonzeroOption(PETScMatrix &matrix, bool const has_col_idx)
MatStructure nonzeroPatternStructure(std::vector< PetscInt > const &col_a, std::vector< PetscInt > const &col_b)
bool finalizeMatrixAssembly(MAT_T &)
LineIndex const & columns
void operator()(PETScMatrix &matrix, SPARSITY_PATTERN const &sparsity_pattern) const