]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Facilitate casting between tensors of AD numbers to floats.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Fri, 2 Feb 2018 06:14:16 +0000 (07:14 +0100)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Fri, 2 Feb 2018 06:14:16 +0000 (07:14 +0100)
include/deal.II/base/numbers.h

index e99397ba9ff5148d28471a23268b4dbeeced9743..057baf07ea22d4ab37d55182db68e261da203c3b 100644 (file)
@@ -385,6 +385,27 @@ namespace numbers
 
 }
 
+
+// Forward declarations
+namespace Differentiation
+{
+  namespace AD
+  {
+
+    namespace internal
+    {
+      // Defined in differentiation/ad/ad_number_traits.h
+      template <typename T>
+      struct NumberType;
+    }
+
+    // Defined in differentiation/ad/ad_number_traits.h
+    template <typename NumberType>
+    struct is_ad_number;
+  }
+}
+
+
 namespace internal
 {
   /**
@@ -466,6 +487,24 @@ namespace internal
     {
       return static_cast<T>(f);
     }
+
+    // Sacado doesn't provide any conversion operators, so we have
+    // to extract the value and perform further conversions from there.
+    // To be safe, we extend this to other possible AD numbers that
+    // might fall into the same category.
+    template<typename F>
+    static T
+    value (const F &f,
+           typename std::enable_if<
+           !std::is_same<typename std::decay<T>::type,typename std::decay<F>::type>::value &&
+           !std::is_constructible<T,F>::value &&
+           !is_explicitly_convertible<const F,T>::value &&
+           Differentiation::AD::is_ad_number<F>::value
+           >::type * = nullptr)
+    {
+      return Differentiation::AD::internal::NumberType<T>::value(f);
+    }
+
   };
 
   template <typename T>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.