From 7708cc67dcdd70e482ce63f38e80b2e1df07ded2 Mon Sep 17 00:00:00 2001 From: heister Date: Sun, 16 Jun 2013 20:10:24 +0000 Subject: [PATCH] add print() for PETSc matrices git-svn-id: https://svn.dealii.org/branches/branch_unify_linear_algebra@29828 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/lac/petsc_matrix_base.h | 7 +++++ deal.II/source/lac/petsc_matrix_base.cc | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/deal.II/include/deal.II/lac/petsc_matrix_base.h b/deal.II/include/deal.II/lac/petsc_matrix_base.h index 2049138aa7..f2c059a978 100644 --- a/deal.II/include/deal.II/lac/petsc_matrix_base.h +++ b/deal.II/include/deal.II/lac/petsc_matrix_base.h @@ -1172,6 +1172,13 @@ namespace PETScWrappers */ void write_ascii (const PetscViewerFormat format = PETSC_VIEWER_DEFAULT); + /** + * print command, similar to write_ascii, but the same format than + * produced by Trilinos + */ + void print (std::ostream &out, + const bool alternative_output = false) const; + /** * Returns the number bytes consumed * by this matrix on this CPU. diff --git a/deal.II/source/lac/petsc_matrix_base.cc b/deal.II/source/lac/petsc_matrix_base.cc index f78c5b3f67..fa8fa75ea9 100644 --- a/deal.II/source/lac/petsc_matrix_base.cc +++ b/deal.II/source/lac/petsc_matrix_base.cc @@ -608,6 +608,36 @@ namespace PETScWrappers MatView (matrix, PETSC_VIEWER_STDOUT_WORLD); } + void + MatrixBase::print (std::ostream &out, + const bool alternative_output) const + { + std::pair + loc_range = local_range(); + + PetscInt ncols; + const PetscInt *colnums; + const PetscScalar *values; + + MatrixBase::size_type row; + for (row = loc_range.first; row < loc_range.second; ++row) + { + int ierr; + ierr = MatGetRow(*this, row, &ncols, &colnums, &values); + AssertThrow (ierr == 0, MatrixBase::ExcPETScError(ierr)); + + for (PetscInt col = 0; col < ncols; ++col) + { + out << "(" << row << "," << colnums[col] << ") " << values[col] << std::endl; + } + + ierr = MatRestoreRow(*this, row, &ncols, &colnums, &values); + AssertThrow (ierr == 0, MatrixBase::ExcPETScError(ierr)); + } + + AssertThrow (out, ExcIO()); + } + std::size_t -- 2.39.5