17#ifdef DEAL_II_WITH_PETSC
29 namespace MatrixIterators
33 MatrixBase::const_iterator::Accessor::visit_present_row()
38 if (
matrix->in_local_range(this->a_row) ==
false)
48 const PetscInt *colnums;
52 MatGetRow(*matrix, this->a_row, &ncols, &colnums, &values);
63 for (PetscInt j = 0; j < ncols; ++j)
65 const auto column =
static_cast<PetscInt
>(colnums[j]);
70 std::make_shared<std::vector<size_type>>(colnums, colnums + ncols);
72 std::make_shared<std::vector<PetscScalar>>(
values,
values + ncols);
75 ierr = MatRestoreRow(*matrix, this->a_row, &ncols, &colnums, &values);
93 const PetscErrorCode ierr =
94 PetscObjectReference(
reinterpret_cast<PetscObject
>(
matrix));
103 PetscErrorCode ierr =
104 PetscObjectReference(
reinterpret_cast<PetscObject
>(A));
106 ierr = MatDestroy(&
matrix);
113 PetscErrorCode ierr = MatDestroy(&
matrix);
123 const PetscErrorCode ierr = MatDestroy(&
matrix);
129 const int m = 0,
n = 0, n_nonzero_per_row = 0;
130 const PetscErrorCode ierr = MatCreateSeqAIJ(
131 PETSC_COMM_SELF,
m,
n, n_nonzero_per_row,
nullptr, &
matrix);
145 const PetscErrorCode ierr = MatZeroEntries(
matrix);
163 const PetscScalar new_diag_value)
169 for (
const auto &row : rows)
172 const std::vector<PetscInt> petsc_rows(rows.
begin(), rows.
end());
187 ierr = MatZeroRowsIS(
matrix, index_set, new_diag_value,
nullptr,
nullptr);
189 ierr = ISDestroy(&index_set);
195 const PetscScalar new_diag_value)
201 for (
const auto &row : rows)
204 const std::vector<PetscInt> petsc_rows(rows.begin(), rows.end());
220 MatZeroRowsColumnsIS(
matrix, index_set, new_diag_value,
nullptr,
nullptr);
222 ierr = ISDestroy(&index_set);
231 const auto petsc_i =
static_cast<PetscInt
>(i);
233 const auto petsc_j =
static_cast<PetscInt
>(j);
238 const PetscErrorCode ierr =
239 MatGetValues(
matrix, 1, &petsc_i, 1, &petsc_j, &value);
267 int all_int_last_action;
269 const int ierr = MPI_Allreduce(&my_int_last_action,
270 &all_int_last_action,
279 ExcMessage(
"Error: not all processors agree on the last "
280 "VectorOperation before this compress() call."));
287 "Missing compress() or calling with wrong VectorOperation argument."));
290 PetscErrorCode ierr = MatAssemblyBegin(
matrix, MAT_FINAL_ASSEMBLY);
293 ierr = MatAssemblyEnd(
matrix, MAT_FINAL_ASSEMBLY);
304 PetscInt n_rows, n_cols;
306 const PetscErrorCode ierr = MatGetSize(
matrix, &n_rows, &n_cols);
317 PetscInt n_rows, n_cols;
319 const PetscErrorCode ierr = MatGetSize(
matrix, &n_rows, &n_cols);
332 const PetscErrorCode ierr = MatGetLocalSize(
matrix, &n_rows,
nullptr);
340 std::pair<MatrixBase::size_type, MatrixBase::size_type>
345 const PetscErrorCode ierr =
346 MatGetOwnershipRange(
static_cast<const Mat &
>(
matrix), &
begin, &
end);
359 const PetscErrorCode ierr = MatGetLocalSize(
matrix,
nullptr, &n_cols);
367 std::pair<MatrixBase::size_type, MatrixBase::size_type>
372 const PetscErrorCode ierr =
373 MatGetOwnershipRangeColumn(
static_cast<const Mat &
>(
matrix),
387 const PetscErrorCode ierr = MatGetInfo(
matrix, MAT_GLOBAL_SUM, &mat_info);
392 return static_cast<std::uint64_t
>(mat_info.nz_used);
412 const PetscInt *colnums;
413 const PetscScalar *values;
417 PetscErrorCode ierr = MatGetRow(*
this, row, &ncols, &colnums, &values);
425 const PetscInt ncols_saved = ncols;
426 ierr = MatRestoreRow(*
this, row, &ncols, &colnums, &values);
438 const PetscErrorCode ierr = MatNorm(
matrix, NORM_1, &result);
451 const PetscErrorCode ierr = MatNorm(
matrix, NORM_INFINITY, &result);
464 const PetscErrorCode ierr = MatNorm(
matrix, NORM_FROBENIUS, &result);
500 const PetscErrorCode ierr = MatGetTrace(
matrix, &result);
511 const PetscErrorCode ierr = MatScale(
matrix, a);
522 const PetscScalar factor = 1. / a;
523 const PetscErrorCode ierr = MatScale(
matrix, factor);
534 const PetscErrorCode ierr =
535 MatAXPY(
matrix, factor, other, DIFFERENT_NONZERO_PATTERN);
547 const PetscErrorCode ierr = MatMult(
matrix, src, dst);
558 const PetscErrorCode ierr = MatMultTranspose(
matrix, src, dst);
569 const PetscErrorCode ierr = MatMultAdd(
matrix, src, dst, dst);
580 const PetscErrorCode ierr = MatMultTransposeAdd(
matrix, src, dst, dst);
592 const bool transpose_left)
594 const bool use_vector = (V.
size() == inputright.
m() ? true :
false);
595 if (transpose_left ==
false)
597 Assert(inputleft.
n() == inputright.
m(),
602 Assert(inputleft.
m() == inputright.
m(),
610 if (use_vector ==
false)
614 ierr = MatTransposeMatMult(inputleft,
623 ierr = MatMatMult(inputleft,
634 ierr = MatDuplicate(inputleft, MAT_COPY_VALUES, &tmp);
638# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
639 ierr = MatTranspose(tmp, MAT_REUSE_MATRIX, &tmp);
641 ierr = MatTranspose(tmp, MAT_INPLACE_MATRIX, &tmp);
645 ierr = MatDiagonalScale(tmp,
nullptr, V);
647 ierr = MatMatMult(tmp,
653 ierr = MatDestroy(&tmp);
692 MatrixBase::operator Mat()
const
706# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
707 const PetscErrorCode ierr = MatTranspose(
matrix, MAT_REUSE_MATRIX, &
matrix);
709 const PetscErrorCode ierr =
720 const PetscErrorCode ierr = MatIsSymmetric(
matrix, tolerance, &truth);
731 const PetscErrorCode ierr = MatIsHermitian(
matrix, tolerance, &truth);
744 PetscErrorCode ierr =
745 PetscViewerPushFormat(PETSC_VIEWER_STDOUT_(
comm), format);
749 ierr = MatView(
matrix, PETSC_VIEWER_STDOUT_(
comm));
751 ierr = PetscViewerPopFormat(PETSC_VIEWER_STDOUT_(
comm));
760 PetscErrorCode ierr = MatHasOperation(
matrix, MATOP_GET_ROW, &has);
766 ierr = MatConvert(
matrix, MATAIJ, MAT_INITIAL_MATRIX, &vmatrix);
770 std::pair<MatrixBase::size_type, MatrixBase::size_type> loc_range =
774 const PetscInt *colnums;
775 const PetscScalar *values;
778 for (row = loc_range.first; row < loc_range.second; ++row)
780 ierr = MatGetRow(vmatrix, row, &ncols, &colnums, &values);
783 for (PetscInt col = 0; col < ncols; ++col)
785 out <<
"(" << row <<
"," << colnums[col] <<
") " << values[col]
789 ierr = MatRestoreRow(vmatrix, row, &ncols, &colnums, &values);
794 ierr = MatDestroy(&vmatrix);
806 const PetscErrorCode ierr = MatGetInfo(
matrix, MAT_LOCAL, &info);
809 return sizeof(*this) +
static_cast<size_type>(info.memory);
void add(const size_type i, const size_type j, const PetscScalar value)
size_type row_length(const size_type row) const
std::size_t memory_consumption() const
PetscReal l1_norm() const
VectorOperation::values last_action
void vmult(VectorBase &dst, const VectorBase &src) const
MPI_Comm get_mpi_communicator() const
PetscScalar diag_element(const size_type i) const
size_type local_domain_size() const
const_iterator begin() const
MatrixBase & operator/=(const PetscScalar factor)
void mmult(MatrixBase &C, const MatrixBase &B, const VectorBase &V) const
PetscBool is_symmetric(const double tolerance=1.e-12)
PetscReal frobenius_norm() const
virtual ~MatrixBase() override
std::pair< size_type, size_type > local_domain() const
const_iterator end() const
void Tvmult_add(VectorBase &dst, const VectorBase &src) const
void print(std::ostream &out, const bool alternative_output=false) const
PetscScalar el(const size_type i, const size_type j) const
size_type local_size() const
MatrixBase & operator=(const MatrixBase &)=delete
PetscScalar trace() const
PetscBool is_hermitian(const double tolerance=1.e-12)
PetscScalar matrix_scalar_product(const VectorBase &u, const VectorBase &v) const
void assert_is_compressed()
void Tvmult(VectorBase &dst, const VectorBase &src) const
void clear_rows_columns(const std::vector< size_type > &row_and_column_indices, const PetscScalar new_diag_value=0)
MatrixBase & operator*=(const PetscScalar factor)
PetscScalar residual(VectorBase &dst, const VectorBase &x, const VectorBase &b) const
void Tmmult(MatrixBase &C, const MatrixBase &B, const VectorBase &V) const
void write_ascii(const PetscViewerFormat format=PETSC_VIEWER_DEFAULT)
void vmult_add(VectorBase &dst, const VectorBase &src) const
std::pair< size_type, size_type > local_range() const
void compress(const VectorOperation::values operation)
PetscScalar matrix_norm_square(const VectorBase &v) const
void clear_rows(const ArrayView< const size_type > &rows, const PetscScalar new_diag_value=0)
std::uint64_t n_nonzero_elements() const
void clear_row(const size_type row, const PetscScalar new_diag_value=0)
PetscReal linfty_norm() const
real_type l2_norm() const
size_type size() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertNothrow(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcSourceEqualsDestination()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define AssertIntegerConversion(index1, index2)
@ matrix
Contents is actually a matrix.
void perform_mmult(const MatrixBase &inputleft, const MatrixBase &inputright, MatrixBase &result, const VectorBase &V, const bool transpose_left)
*braid_SplitCommworld & comm