From 879ae07ba527fea052fd944d6cbdc1f96978511d Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@dune-project.org>
Date: Mon, 25 Jan 2010 08:54:46 +0000
Subject: [PATCH] test the solve() method of BTDMatrix

[[Imported from SVN: r1160]]
---
 dune/istl/test/matrixtest.cc | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/dune/istl/test/matrixtest.cc b/dune/istl/test/matrixtest.cc
index 1770145e6..e6eaa710a 100644
--- a/dune/istl/test/matrixtest.cc
+++ b/dune/istl/test/matrixtest.cc
@@ -239,8 +239,29 @@ void testMatrix(MatrixType& matrix, X& x, Y& y)
 
 }
 
+// ///////////////////////////////////////////////////////////////////
+//   Test the solve()-method for those matrix classes that have it
+// ///////////////////////////////////////////////////////////////////
+template <class MatrixType, class VectorType>
+void testSolve(const MatrixType& matrix)
+{
+  // create some right hand side
+  VectorType b(matrix.N());
+  for (int i=0; i<b.size(); i++)
+    b[i] = i;
+
+  // solution vector
+  VectorType x(matrix.M());
 
+  // Solve the system
+  matrix.solve(x,b);
 
+  // compute residual
+  matrix.mmv(x,b);
+
+  if (b.two_norm() > 1e-10)
+    DUNE_THROW(ISTLError, "Solve() method doesn't appear to produce the solution!");
+}
 
 int main()
 {
@@ -324,6 +345,15 @@ int main()
 
   testSuperMatrix(btdMatrix);
 
+  btdMatrix = 0.0;
+  for (int i=0; i<btdMatrix.N(); i++)    // diagonal
+    btdMatrix[i][i] = 1+i;
+
+  for (int i=0; i<btdMatrix.N()-1; i++)
+    btdMatrix[i][i+1] = 2+i;               // first off-diagonal
+
+  testSolve<BTDMatrix<FieldMatrix<double,1,1> >, BlockVector<FieldVector<double,1> > >(btdMatrix);
+
   // ////////////////////////////////////////////////////////////////////////
   //   Test the FieldMatrix class
   // ////////////////////////////////////////////////////////////////////////
-- 
GitLab