18 #ifdef DEAL_II_WITH_PETSC
30 namespace MatrixIterators
39 if (
matrix->in_local_range(this->a_row) ==
false)
49 const PetscInt * colnums;
50 const PetscScalar *values;
53 MatGetRow(*
matrix, this->a_row, &ncols, &colnums, &values);
64 std::make_shared<std::vector<size_type>>(colnums, colnums + ncols);
66 std::make_shared<std::vector<PetscScalar>>(values, values + ncols);
69 ierr = MatRestoreRow(*
matrix, this->a_row, &ncols, &colnums, &values);
102 const int m = 0,
n = 0, n_nonzero_per_row = 0;
103 const PetscErrorCode ierr = MatCreateSeqAIJ(
104 PETSC_COMM_SELF,
m,
n, n_nonzero_per_row,
nullptr, &
matrix);
118 const PetscErrorCode ierr = MatZeroEntries(
matrix);
129 std::vector<size_type> rows(1, row);
137 const PetscScalar new_diag_value)
143 const std::vector<PetscInt> petsc_rows(rows.begin(), rows.end());
156 const PetscErrorCode ierr =
157 MatZeroRowsIS(
matrix, index_set, new_diag_value,
nullptr,
nullptr);
159 ISDestroy(&index_set);
167 PetscInt petsc_i = i, petsc_j = j;
171 const PetscErrorCode ierr =
172 MatGetValues(
matrix, 1, &petsc_i, 1, &petsc_j, &
value);
197 # ifdef DEAL_II_WITH_MPI
201 int all_int_last_action;
203 const int ierr = MPI_Allreduce(&my_int_last_action,
204 &all_int_last_action,
213 ExcMessage(
"Error: not all processors agree on the last "
214 "VectorOperation before this compress() call."));
222 "Missing compress() or calling with wrong VectorOperation argument."));
225 PetscErrorCode ierr = MatAssemblyBegin(
matrix, MAT_FINAL_ASSEMBLY);
228 ierr = MatAssemblyEnd(
matrix, MAT_FINAL_ASSEMBLY);
239 PetscInt n_rows, n_cols;
241 const PetscErrorCode ierr = MatGetSize(
matrix, &n_rows, &n_cols);
252 PetscInt n_rows, n_cols;
254 const PetscErrorCode ierr = MatGetSize(
matrix, &n_rows, &n_cols);
265 PetscInt n_rows, n_cols;
267 const PetscErrorCode ierr = MatGetLocalSize(
matrix, &n_rows, &n_cols);
275 std::pair<MatrixBase::size_type, MatrixBase::size_type>
280 const PetscErrorCode ierr =
281 MatGetOwnershipRange(
static_cast<const Mat &
>(
matrix), &
begin, &
end);
293 const PetscErrorCode ierr = MatGetInfo(
matrix, MAT_GLOBAL_SUM, &mat_info);
296 return static_cast<size_type>(mat_info.nz_used);
316 const PetscInt * colnums;
317 const PetscScalar *values;
321 PetscErrorCode ierr = MatGetRow(*
this, row, &ncols, &colnums, &values);
329 const PetscInt ncols_saved = ncols;
330 ierr = MatRestoreRow(*
this, row, &ncols, &colnums, &values);
342 const PetscErrorCode ierr = MatNorm(
matrix, NORM_1, &result);
355 const PetscErrorCode ierr = MatNorm(
matrix, NORM_INFINITY, &result);
368 const PetscErrorCode ierr = MatNorm(
matrix, NORM_FROBENIUS, &result);
399 const PetscErrorCode ierr = MatGetTrace(
matrix, &result);
410 const PetscErrorCode ierr = MatScale(
matrix, a);
421 const PetscScalar factor = 1. / a;
422 const PetscErrorCode ierr = MatScale(
matrix, factor);
432 const PetscErrorCode ierr =
433 MatAXPY(
matrix, factor, other, DIFFERENT_NONZERO_PATTERN);
444 return add(factor, other);
453 const PetscErrorCode ierr = MatMult(
matrix, src, dst);
464 const PetscErrorCode ierr = MatMultTranspose(
matrix, src, dst);
475 const PetscErrorCode ierr = MatMultAdd(
matrix, src, dst, dst);
486 const PetscErrorCode ierr = MatMultTransposeAdd(
matrix, src, dst, dst);
498 const bool transpose_left)
500 const bool use_vector = (
V.size() == inputright.
m() ? true :
false);
501 if (transpose_left ==
false)
503 Assert(inputleft.
n() == inputright.
m(),
508 Assert(inputleft.
m() == inputright.
m(),
516 if (use_vector ==
false)
520 ierr = MatTransposeMatMult(inputleft,
529 ierr = MatMatMult(inputleft,
540 ierr = MatDuplicate(inputleft, MAT_COPY_VALUES, &tmp);
544 # if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
545 ierr = MatTranspose(tmp, MAT_REUSE_MATRIX, &tmp);
547 ierr = MatTranspose(tmp, MAT_INPLACE_MATRIX, &tmp);
551 ierr = MatDiagonalScale(tmp,
nullptr,
V);
553 ierr = MatMatMult(tmp,
596 MatrixBase::operator Mat()
const
610 # if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
611 const PetscErrorCode ierr = MatTranspose(
matrix, MAT_REUSE_MATRIX, &
matrix);
613 const PetscErrorCode ierr =
624 const PetscErrorCode ierr = MatIsSymmetric(
matrix, tolerance, &truth);
635 const PetscErrorCode ierr = MatIsHermitian(
matrix, tolerance, &truth);
647 PetscErrorCode ierr =
648 PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD, format);
652 ierr = MatView(
matrix, PETSC_VIEWER_STDOUT_WORLD);
659 std::pair<MatrixBase::size_type, MatrixBase::size_type> loc_range =
663 const PetscInt * colnums;
664 const PetscScalar *values;
667 for (row = loc_range.first; row < loc_range.second; ++row)
669 PetscErrorCode ierr = MatGetRow(*
this, row, &ncols, &colnums, &values);
672 for (PetscInt col = 0; col < ncols; ++col)
674 out <<
"(" << row <<
"," << colnums[col] <<
") " << values[col]
678 ierr = MatRestoreRow(*
this, row, &ncols, &colnums, &values);
691 const PetscErrorCode ierr = MatGetInfo(
matrix, MAT_LOCAL, &info);
694 return sizeof(*this) +
static_cast<size_type>(info.memory);
701 #endif // DEAL_II_WITH_PETSC