From a5e55e5ce461c448105760a65b81ce49fb293560 Mon Sep 17 00:00:00 2001
From: Patrick Jaap <patrick.jaap@tu-dresden.de>
Date: Wed, 24 Jun 2020 19:31:37 +0200
Subject: [PATCH] Fix: Implement std::numeric_limits and
 Dune::MathematicalConstants for hyperdual numbers

This is simply done by forwarding to the `double` implementation.
This is safe since `hyperdual` numbers can be constructed from `double` numbers.
---
 dune/elasticity/common/hyperdual.hh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dune/elasticity/common/hyperdual.hh b/dune/elasticity/common/hyperdual.hh
index 524b785..7c97fbb 100644
--- a/dune/elasticity/common/hyperdual.hh
+++ b/dune/elasticity/common/hyperdual.hh
@@ -605,6 +605,15 @@ bool operator!= (hyperdual lhs, double rhs)
 }
 
 
+namespace std
+{
+  // Register the type hyperdual for std::numeric_limits by forwarding to std::numeric_limits<double>
+  template<>
+  struct numeric_limits<hyperdual> : std::numeric_limits<double>
+  {};
+}
+
+
 // Dune related definitions with hyperdual numbers
 namespace Dune
 {
@@ -628,6 +637,15 @@ namespace Dune
   {
     using PromotedType = hyperdual;
   };
+
+
+  /* Generate constants like "pi", "e", etc. directly from double values
+   * since calls like "pi = acos(-1)" are not differentiable
+   */
+  template <>
+  struct MathematicalConstants<hyperdual>
+    : MathematicalConstants<double>
+  {};
 }
 
 
-- 
GitLab