From 5ea679d37e2eb943989a7067558faa8846d83e33 Mon Sep 17 00:00:00 2001
From: Oliver Sander <oliver.sander@tu-dresden.de>
Date: Mon, 16 Apr 2018 17:20:56 +0200
Subject: [PATCH] Specialize Dune::IsNumber for the 'adouble' type from ADOL-C

Otherwise some dune-common stuff will not work properly,
for example copying of FieldMatrices that use adouble
as their number type.
---
 src/cosserat-continuum.cc       |  9 +++++++++
 src/gradient-flow.cc            |  9 +++++++++
 src/mixed-cosserat-continuum.cc |  9 +++++++++
 test/adolctest.cc               | 11 +++++++++++
 4 files changed, 38 insertions(+)

diff --git a/src/cosserat-continuum.cc b/src/cosserat-continuum.cc
index add2b8ea..6e133670 100644
--- a/src/cosserat-continuum.cc
+++ b/src/cosserat-continuum.cc
@@ -10,6 +10,15 @@
 
 #include <dune/fufem/utilities/adolcnamespaceinjections.hh>
 
+#include <dune/common/typetraits.hh>
+namespace Dune {
+  template <>
+  struct IsNumber<adouble>
+  {
+    constexpr static bool value = true;
+  };
+}
+
 #include <dune/common/bitsetvector.hh>
 #include <dune/common/parametertree.hh>
 #include <dune/common/parametertreeparser.hh>
diff --git a/src/gradient-flow.cc b/src/gradient-flow.cc
index 3d49ced5..aaef1da7 100644
--- a/src/gradient-flow.cc
+++ b/src/gradient-flow.cc
@@ -7,6 +7,15 @@
 #include <adolc/adouble.h>
 #include <dune/fufem/utilities/adolcnamespaceinjections.hh>
 
+#include <dune/common/typetraits.hh>
+namespace Dune {
+  template <>
+  struct IsNumber<adouble>
+  {
+    constexpr static bool value = true;
+  };
+}
+
 #include <array>
 
 #include <dune/common/bitsetvector.hh>
diff --git a/src/mixed-cosserat-continuum.cc b/src/mixed-cosserat-continuum.cc
index 5702b032..6682be6d 100644
--- a/src/mixed-cosserat-continuum.cc
+++ b/src/mixed-cosserat-continuum.cc
@@ -10,6 +10,15 @@
 
 #include <dune/fufem/utilities/adolcnamespaceinjections.hh>
 
+
+#include <dune/common/typetraits.hh>
+namespace Dune {
+  template <>
+  struct IsNumber<adouble>
+  {
+    constexpr static bool value = true;
+  };
+}
 #include <array>
 
 #include <dune/common/bitsetvector.hh>
diff --git a/test/adolctest.cc b/test/adolctest.cc
index 603db78f..238e12b2 100644
--- a/test/adolctest.cc
+++ b/test/adolctest.cc
@@ -25,6 +25,17 @@ typedef double FDType;
 #include <adolc/taping.h>
 
 #include <dune/fufem/utilities/adolcnamespaceinjections.hh>
+
+#include <dune/common/typetraits.hh>
+// This specialization is needed (in particular) to make copying of FieldMatrices work.
+namespace Dune {
+  template <>
+  struct IsNumber<adouble>
+  {
+    constexpr static bool value = true;
+  };
+}
+
 #include <dune/common/fmatrix.hh>
 
 #include <dune/geometry/quadraturerules.hh>
-- 
GitLab