diff --git a/dune/solvers/norms/twonorm.hh b/dune/solvers/norms/twonorm.hh index c21f8e4462059c31c1667673f24ba536e6c8d53f..7e58a993e2e7526e0aaedfd870284659d90a9566 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