From 80ab3e2683e440c2087cea9ab6baff0820b482fb Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@dune-project.org>
Date: Wed, 4 Jul 2012 21:18:24 +0000
Subject: [PATCH] Implement writeMatrixToMatlab if the inner type is a
 ScaledIdMatrix or a DiagonalMatrix.

Patch by Uli Sack

[[Imported from SVN: r1636]]
---
 dune/istl/io.hh | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/dune/istl/io.hh b/dune/istl/io.hh
index 6d611b926..85b6644a9 100644
--- a/dune/istl/io.hh
+++ b/dune/istl/io.hh
@@ -17,6 +17,8 @@
 #include <dune/common/fmatrix.hh>
 
 #include <dune/istl/matrix.hh>
+#include <dune/istl/diagonalmatrix.hh>
+#include <dune/istl/scaledidmatrix.hh>
 #include "bcrsmatrix.hh"
 
 
@@ -391,6 +393,44 @@ namespace Dune {
     };
   } // anonymous namespace
 
+  //! Helper method for the writeMatrixToMatlab routine.
+  /**
+   * \code
+   *#include <dune/istl/io.hh>
+   * \endcode
+   *
+   * This specialization for DiagonalMatrices ends the recursion
+   */
+  template <class FieldType, int dim>
+  void writeMatrixToMatlabHelper(const ScaledIdentityMatrix<FieldType,dim>& matrix, int rowOffset, int colOffset, std::ostream& s)
+  {
+    for (int i=0; i<dim; i++)
+    {
+      //+1 for Matlab numbering
+      s << rowOffset + i + 1 << " " << colOffset + i + 1 << " ";
+      MatlabPODWriter<FieldType>::write(matrix.scalar(), s)<< std::endl;
+    }
+  }
+
+  //! Helper method for the writeMatrixToMatlab routine.
+  /**
+   * \code
+   *#include <dune/istl/io.hh>
+   * \endcode
+   *
+   * This specialization for DiagonalMatrices ends the recursion
+   */
+  template <class FieldType, int dim>
+  void writeMatrixToMatlabHelper(const DiagonalMatrix<FieldType,dim>& matrix, int rowOffset, int colOffset, std::ostream& s)
+  {
+    for (int i=0; i<dim; i++)
+    {
+      //+1 for Matlab numbering
+      s << rowOffset + i + 1 << " " << colOffset + i + 1 << " ";
+      MatlabPODWriter<FieldType>::write(matrix.diagonal(i), s)<< std::endl;
+    }
+  }
+
   //! Helper method for the writeMatrixToMatlab routine.
   /**
    * \code
-- 
GitLab