From dc329fb55586ffe3474332630ab102d9140af8b9 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Tue, 3 Sep 2013 16:29:32 +0000
Subject: [PATCH] Add rebinding to another field type, and assignment with
 operator <<=

This is needed to use the ADOL-C automatic differentiation library.

[[Imported from SVN: r9398]]
---
 dune/gfe/realtuple.hh       | 15 +++++++++++++++
 dune/gfe/rigidbodymotion.hh | 16 ++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/dune/gfe/realtuple.hh b/dune/gfe/realtuple.hh
index 200fe060..a67b71d5 100644
--- a/dune/gfe/realtuple.hh
+++ b/dune/gfe/realtuple.hh
@@ -59,6 +59,21 @@ public:
         return *this;
     }
 
+    /** \brief Assigment from RealTuple with different type -- used for automatic differentiation with ADOL-C */
+    template <class T2>
+    RealTuple& operator <<= (const RealTuple<T2,N>& other) {
+        for (size_t i=0; i<N; i++)
+            data_[i] <<= other.data_[i];
+        return *this;
+    }
+
+     /** \brief Rebind the RealTuple to another coordinate type */
+    template<class U>
+    struct rebind
+    {
+      typedef RealTuple<U,N> other;
+    };
+
     /** \brief The exponention map */
     static RealTuple exp(const RealTuple& p, const TangentVector& v) {
         return RealTuple(p.data_+v);
diff --git a/dune/gfe/rigidbodymotion.hh b/dune/gfe/rigidbodymotion.hh
index 85fbb7ba..e51f6e49 100644
--- a/dune/gfe/rigidbodymotion.hh
+++ b/dune/gfe/rigidbodymotion.hh
@@ -55,6 +55,22 @@ public:
         q.normalize();
     }
 
+    /** \brief Assigment from RigidBodyMotion with different type -- used for automatic differentiation with ADOL-C */
+    template <class T2>
+    RigidBodyMotion& operator <<= (const RigidBodyMotion<T2,N>& other) {
+        for (int i=0; i<N; i++)
+            r[i] <<= other.r[i];
+        q <<= other.q;
+        return *this;
+    }
+
+     /** \brief Rebind the RigidBodyMotion to another coordinate type */
+    template<class U>
+    struct rebind
+    {
+      typedef RigidBodyMotion<U,N> other;
+    };
+
     /** \brief The exponential map from a given point $p \in SE(d)$.
 
      Why the template parameter?  Well, it should work with both TangentVector and EmbeddedTangentVector.
-- 
GitLab