18#ifdef DEAL_II_WITH_PETSC
30 namespace MatrixIterators
34 MatrixBase::const_iterator::Accessor::visit_present_row()
39 if (
matrix->in_local_range(this->a_row) ==
false)
49 const PetscInt * colnums;
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);
298 return static_cast<std::uint64_t
>(mat_info.nz_used);
318 const PetscInt * colnums;
319 const PetscScalar *values;
323 PetscErrorCode ierr = MatGetRow(*
this, row, &ncols, &colnums, &values);
331 const PetscInt ncols_saved = ncols;
332 ierr = MatRestoreRow(*
this, row, &ncols, &colnums, &values);
344 const PetscErrorCode ierr = MatNorm(
matrix, NORM_1, &result);
357 const PetscErrorCode ierr = MatNorm(
matrix, NORM_INFINITY, &result);
370 const PetscErrorCode ierr = MatNorm(
matrix, NORM_FROBENIUS, &result);
401 const PetscErrorCode ierr = MatGetTrace(
matrix, &result);
412 const PetscErrorCode ierr = MatScale(
matrix, a);
423 const PetscScalar factor = 1. / a;
424 const PetscErrorCode ierr = MatScale(
matrix, factor);
434 const PetscErrorCode ierr =
435 MatAXPY(
matrix, factor, other, DIFFERENT_NONZERO_PATTERN);
447 const PetscErrorCode ierr = MatMult(
matrix, src, dst);
458 const PetscErrorCode ierr = MatMultTranspose(
matrix, src, dst);
469 const PetscErrorCode ierr = MatMultAdd(
matrix, src, dst, dst);
480 const PetscErrorCode ierr = MatMultTransposeAdd(
matrix, src, dst, dst);
492 const bool transpose_left)
494 const bool use_vector = (V.
size() == inputright.
m() ? true :
false);
495 if (transpose_left ==
false)
497 Assert(inputleft.
n() == inputright.
m(),
502 Assert(inputleft.
m() == inputright.
m(),
510 if (use_vector ==
false)
514 ierr = MatTransposeMatMult(inputleft,
523 ierr = MatMatMult(inputleft,
534 ierr = MatDuplicate(inputleft, MAT_COPY_VALUES, &tmp);
538# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
539 ierr = MatTranspose(tmp, MAT_REUSE_MATRIX, &tmp);
541 ierr = MatTranspose(tmp, MAT_INPLACE_MATRIX, &tmp);
545 ierr = MatDiagonalScale(tmp,
nullptr, V);
547 ierr = MatMatMult(tmp,
592 MatrixBase::operator Mat()
const
606# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
607 const PetscErrorCode ierr = MatTranspose(
matrix, MAT_REUSE_MATRIX, &
matrix);
609 const PetscErrorCode ierr =
620 const PetscErrorCode ierr = MatIsSymmetric(
matrix, tolerance, &truth);
631 const PetscErrorCode ierr = MatIsHermitian(
matrix, tolerance, &truth);
643 PetscErrorCode ierr =
644 PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD, format);
648 ierr = MatView(
matrix, PETSC_VIEWER_STDOUT_WORLD);
655 std::pair<MatrixBase::size_type, MatrixBase::size_type> loc_range =
659 const PetscInt * colnums;
660 const PetscScalar *values;
663 for (row = loc_range.first; row < loc_range.second; ++row)
665 PetscErrorCode ierr = MatGetRow(*
this, row, &ncols, &colnums, &values);
668 for (PetscInt col = 0; col < ncols; ++col)
670 out <<
"(" << row <<
"," << colnums[col] <<
") " << values[col]
674 ierr = MatRestoreRow(*
this, row, &ncols, &colnums, &values);
687 const PetscErrorCode ierr = MatGetInfo(
matrix, MAT_LOCAL, &info);
690 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
void clear_rows(const std::vector< size_type > &rows, const PetscScalar new_diag_value=0)
PetscScalar diag_element(const size_type i) 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
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
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
virtual const MPI_Comm & get_mpi_communicator() const =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
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
#define Assert(cond, exc)
#define AssertThrowMPI(error_code)
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)
@ matrix
Contents is actually a matrix.
void perform_mmult(const MatrixBase &inputleft, const MatrixBase &inputright, MatrixBase &result, const VectorBase &V, const bool transpose_left)
PetscErrorCode destroy_matrix(Mat &matrix)