From 81107a36132b2dbeeac189b22e022cf87ce4baf0 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Tue, 27 May 2014 15:51:37 +0200
Subject: [PATCH] Assert that the input vectors match the matrix size

Otherwise, if the matrix is smaller than the vectors, you may never find
out that you are computing wrong results.
---
 dune/solvers/norms/h1seminorm.hh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/dune/solvers/norms/h1seminorm.hh b/dune/solvers/norms/h1seminorm.hh
index 449dd1f3..b30bfacd 100644
--- a/dune/solvers/norms/h1seminorm.hh
+++ b/dune/solvers/norms/h1seminorm.hh
@@ -17,11 +17,16 @@ public:
 
     H1SemiNorm(const Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> >& matrix)
         : matrix_(&matrix)
-    {}
+    {
+      assert(matrix.N() == matrix.M());
+    }
 
     //! Compute the norm of the difference of two vectors
     double diff(const VectorType& u1, const VectorType& u2) const
 	{
+          assert(u1.size()==u2.size());
+          assert(u1.size()==matrix_->N());
+
 		double sum = 0;
 
 		for (size_t i=0; i<matrix_->N(); i++)
@@ -42,6 +47,9 @@ public:
     {
         if (matrix_ == NULL)
             DUNE_THROW(Dune::Exception, "You have not supplied neither a matrix nor an IterationStep to the EnergyNorm routine!");
+
+        assert(u.size()==matrix_->N());
+
         // we compute sqrt{uAu^t}.  We have implemented this by hand because the matrix is
         // always scalar but the vectors may not be
         double sum = 0;
-- 
GitLab