]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add print() for PETSc matrices
authorTimo Heister <timo.heister@gmail.com>
Sun, 16 Jun 2013 20:10:24 +0000 (20:10 +0000)
committerTimo Heister <timo.heister@gmail.com>
Sun, 16 Jun 2013 20:10:24 +0000 (20:10 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_unify_linear_algebra@29828 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/petsc_matrix_base.h
deal.II/source/lac/petsc_matrix_base.cc

index 2049138aa73040c06f9f71907e593b1325c0fd2a..f2c059a978ecbc60654e1ee952536cd10187decc 100644 (file)
@@ -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.
index f78c5b3f677151cfa5026e9ec93d95930bf0d0a0..fa8fa75ea9d8e55cbabc46755d8d1aadcd0cb4bd 100644 (file)
@@ -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<MatrixBase::size_type, MatrixBase::size_type>
+    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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.