From: Timo Heister Date: Sun, 16 Jun 2013 20:10:24 +0000 (+0000) Subject: add print() for PETSc matrices X-Git-Tag: v8.0.0~120^2~8 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9529a6a3ce08be5a612abe23a87ca3c02791429;p=dealii.git add print() for PETSc matrices git-svn-id: https://svn.dealii.org/branches/branch_unify_linear_algebra@29828 0785d39b-7218-0410-832d-ea1e28bc413d --- 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