From ac7139f9a67f285549f30051f3dbadd9f72176b6 Mon Sep 17 00:00:00 2001
From: Christian Engwer <christi@dune-project.org>
Date: Wed, 13 Oct 2010 12:39:30 +0000
Subject: [PATCH] * update FieldVector such that the vector test passes also
 for complex   valued data

[[Imported from SVN: r6177]]
---
 dune/common/fvector.hh | 105 ++++++++++++++++++++++++-----------------
 1 file changed, 62 insertions(+), 43 deletions(-)

diff --git a/dune/common/fvector.hh b/dune/common/fvector.hh
index b6c177de8..882087599 100644
--- a/dune/common/fvector.hh
+++ b/dune/common/fvector.hh
@@ -142,7 +142,6 @@ namespace Dune {
     };
 
     typedef typename Base::size_type size_type;
-    typedef typename Base::value_type value_type;
 
     //===== construction
 
@@ -150,7 +149,7 @@ namespace Dune {
     FieldVector () {}
 
     /** \brief Constructor with a given scalar */
-    FieldVector (const K& k) { (*this)[0] = k; }
+    FieldVector (const K& k) : _data(k) {}
 
     using Base::operator=;
 
@@ -170,69 +169,45 @@ namespace Dune {
     //===== conversion operator
 
     /** \brief Conversion operator */
-    operator K () { return (*this)[0]; }
+    operator K () { return _data; }
 
     /** \brief Const conversion operator */
-    operator K () const { return (*this)[0]; }
+    operator K () const { return _data; }
   };
 
-  //! Binary vector addition
-  template<class K>
-  inline FieldVector<K,1> operator+ (const FieldVector<K,1>& a, const FieldVector<K,1>& b)
-  {
-    return a[0]+b[0];
-  }
-
-  //! Binary vector subtraction
-  template<class K>
-  inline FieldVector<K,1> operator- (const FieldVector<K,1>& a, const FieldVector<K,1>& b)
-  {
-    return a[0]-b[0];
-  }
+  /* ----- FV / FV ----- */
+  /* not necessary as these operations are already covered via the cast operator */
 
-  //! Binary compare, when using FieldVector<K,1> like K
-  template<class K>
-  inline bool operator> (const FieldVector<K,1>& a, const FieldVector<K,1>& b)
-  {
-    return a[0]>b[0];
-  }
+  /* ----- FV / scalar ----- */
 
-  //! Binary compare, when using FieldVector<K,1> like K
-  template<class K>
-  inline bool operator>= (const FieldVector<K,1>& a, const FieldVector<K,1>& b)
-  {
-    return a[0]>=b[0];
-  }
-
-  //! Binary compare, when using FieldVector<K,1> like K
+  //! Binary addition, when using FieldVector<K,1> like K
   template<class K>
-  inline bool operator< (const FieldVector<K,1>& a, const FieldVector<K,1>& b)
+  inline FieldVector<K,1> operator+ (const FieldVector<K,1>& a, const K b)
   {
-    return a[0]<b[0];
+    return a[0]+b;
   }
 
-  //! Binary compare, when using FieldVector<K,1> like K
+  //! Binary subtraction, when using FieldVector<K,1> like K
   template<class K>
-  inline bool operator<= (const FieldVector<K,1>& a, const FieldVector<K,1>& b)
+  inline FieldVector<K,1> operator- (const FieldVector<K,1>& a, const K b)
   {
-    return a[0]<=b[0];
+    return a[0]-b;
   }
 
-  //! Binary addition, when using FieldVector<K,1> like K
+  //! Binary multiplication, when using FieldVector<K,1> like K
   template<class K>
-  inline FieldVector<K,1> operator+ (const FieldVector<K,1>& a, const K b)
+  inline FieldVector<K,1> operator* (const FieldVector<K,1>& a, const K b)
   {
-    return a[0]+b;
+    return a[0]*b;
   }
 
-  //! Binary subtraction, when using FieldVector<K,1> like K
+  //! Binary division, when using FieldVector<K,1> like K
   template<class K>
-  inline FieldVector<K,1> operator- (const FieldVector<K,1>& a, const K b)
+  inline FieldVector<K,1> operator/ (const FieldVector<K,1>& a, const K b)
   {
-    return a[0]-b;
+    return a[0]/b;
   }
 
-
   //! Binary compare, when using FieldVector<K,1> like K
   template<class K>
   inline bool operator> (const FieldVector<K,1>& a, const K b)
@@ -261,6 +236,22 @@ namespace Dune {
     return a[0]<=b;
   }
 
+  //! Binary compare, when using FieldVector<K,1> like K
+  template<class K>
+  inline bool operator== (const FieldVector<K,1>& a, const K b)
+  {
+    return a[0]==b;
+  }
+
+  //! Binary compare, when using FieldVector<K,1> like K
+  template<class K>
+  inline bool operator!= (const FieldVector<K,1>& a, const K b)
+  {
+    return a[0]!=b;
+  }
+
+  /* ----- scalar / FV ------ */
+
   //! Binary addition, when using FieldVector<K,1> like K
   template<class K>
   inline FieldVector<K,1> operator+ (const K a, const FieldVector<K,1>& b)
@@ -275,6 +266,20 @@ namespace Dune {
     return a-b[0];
   }
 
+  //! Binary multiplication, when using FieldVector<K,1> like K
+  template<class K>
+  inline FieldVector<K,1> operator* (const K a, const FieldVector<K,1>& b)
+  {
+    return a*b[0];
+  }
+
+  //! Binary division, when using FieldVector<K,1> like K
+  template<class K>
+  inline FieldVector<K,1> operator/ (const K a, const FieldVector<K,1>& b)
+  {
+    return a/b[0];
+  }
+
   //! Binary compare, when using FieldVector<K,1> like K
   template<class K>
   inline bool operator> (const K a, const FieldVector<K,1>& b)
@@ -302,6 +307,20 @@ namespace Dune {
   {
     return a<=b[0];
   }
+
+  //! Binary compare, when using FieldVector<K,1> like K
+  template<class K>
+  inline bool operator== (const K a, const FieldVector<K,1>& b)
+  {
+    return a==b[0];
+  }
+
+  //! Binary compare, when using FieldVector<K,1> like K
+  template<class K>
+  inline bool operator!= (const K a, const FieldVector<K,1>& b)
+  {
+    return a!=b[0];
+  }
 #endif
 
   /** @} end documentation */
-- 
GitLab