From dd62361e7ffc2a3a88327c9759183f9939ccd06f Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Wed, 18 Dec 2013 20:30:00 +0000
Subject: [PATCH] Make TwoNorm work for FieldVectors

[[Imported from SVN: r12469]]
---
 dune/solvers/norms/twonorm.hh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/dune/solvers/norms/twonorm.hh b/dune/solvers/norms/twonorm.hh
index c21f8e44..7e58a993 100644
--- a/dune/solvers/norms/twonorm.hh
+++ b/dune/solvers/norms/twonorm.hh
@@ -4,6 +4,8 @@
 #include <cmath>
 #include <cstring> // For size_t
 
+#include <dune/common/fvector.hh>
+
 #include "norm.hh"
 
 //! Wrapper around the two_norm() method of a vector class
@@ -46,4 +48,36 @@ class TwoNorm : public Norm<VectorType>
 
 };
 
+template <typename T, int dimension>
+class TwoNorm<Dune::FieldVector<T, dimension> >
+  : public Norm<Dune::FieldVector<T, dimension> >
+{
+    typedef Dune::FieldVector<T, dimension> VectorType;
+
+    public:
+
+        /** \brief Destructor, doing nothing */
+        virtual ~TwoNorm() {};
+
+        //! Compute the norm of the given vector
+        virtual double operator()(const VectorType& f) const
+        {
+            return f.two_norm();
+        }
+
+        //! Compute the square of the norm of the given vector
+        virtual double normSquared(const VectorType& f) const
+        {
+            return f.two_norm2();
+        }
+
+        //! Compute the norm of the difference of two vectors
+        virtual double diff(const VectorType& f1, const VectorType& f2) const
+        {
+          VectorType tmp = f1;
+          tmp -= f2;
+          return tmp.two_norm();
+        }
+};
+
 #endif
-- 
GitLab