From 4ae3c4a8e70cca46de9a08619ed12eec2b291b69 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Fri, 2 Feb 2018 07:14:16 +0100 Subject: [PATCH] Facilitate casting between tensors of AD numbers to floats. --- include/deal.II/base/numbers.h | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/deal.II/base/numbers.h b/include/deal.II/base/numbers.h index e99397ba9f..057baf07ea 100644 --- a/include/deal.II/base/numbers.h +++ b/include/deal.II/base/numbers.h @@ -385,6 +385,27 @@ namespace numbers } + +// Forward declarations +namespace Differentiation +{ + namespace AD + { + + namespace internal + { + // Defined in differentiation/ad/ad_number_traits.h + template + struct NumberType; + } + + // Defined in differentiation/ad/ad_number_traits.h + template + struct is_ad_number; + } +} + + namespace internal { /** @@ -466,6 +487,24 @@ namespace internal { return static_cast(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 + static T + value (const F &f, + typename std::enable_if< + !std::is_same::type,typename std::decay::type>::value && + !std::is_constructible::value && + !is_explicitly_convertible::value && + Differentiation::AD::is_ad_number::value + >::type * = nullptr) + { + return Differentiation::AD::internal::NumberType::value(f); + } + }; template -- 2.39.5