From b5abd515786fec0bfde75367d292495aa6ad074c Mon Sep 17 00:00:00 2001
From: Oliver Sander <oliver.sander@tu-dresden.de>
Date: Sat, 30 Jan 2016 07:11:14 +0100
Subject: [PATCH] Add specializations of the PromotionTraits class from
 dune-common for the adouble type

This is needed, e.g., to be able to use the FieldVector implementation of dot products
between a FieldVector<double> and a FieldVector<adouble>.  The standard C++ return type
 deduction mechanism doesn't help here, because the product of a double and an adouble
is actually a proxy class called 'adub', which is not to be used outside of the ADOL-C
library.
---
 .../utilities/adolcnamespaceinjections.hh     | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/dune/fufem/utilities/adolcnamespaceinjections.hh b/dune/fufem/utilities/adolcnamespaceinjections.hh
index 212d70d0..1ee8d837 100644
--- a/dune/fufem/utilities/adolcnamespaceinjections.hh
+++ b/dune/fufem/utilities/adolcnamespaceinjections.hh
@@ -3,6 +3,8 @@
 
 #include <limits>
 
+#include <dune/common/promotiontraits.hh>
+
 #ifdef HAVE_ADOLC
 #include <adolc/adouble.h>
 
@@ -111,6 +113,29 @@ namespace std
    };
 }
 
+/* Specializations of the PromotionTraits class from dune-common for the adouble type.
+ * This is needed, e.g., to be able to use the FieldVector implementation of dot products
+ * between a FieldVector<double> and a FieldVector<adouble>.  The standard C++ return type
+ * deduction mechanism doesn't help here, because the product of a double and an adouble
+ * is actually a proxy class called 'adub', which is not to be used outside of the ADOL-C
+ * library.
+ */
+namespace Dune
+{
+  template <>
+  struct PromotionTraits<double,adouble>
+  {
+    typedef adouble PromotedType;
+  };
+
+  template <>
+  struct PromotionTraits<adouble,double>
+  {
+    typedef adouble PromotedType;
+  };
+}
+
+
 #endif
 
 #endif
-- 
GitLab