From: Jean-Paul Pelteret Date: Fri, 2 Feb 2018 06:14:16 +0000 (+0100) Subject: Facilitate casting between tensors of AD numbers to floats. X-Git-Tag: v9.0.0-rc1~481^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ae3c4a8e70cca46de9a08619ed12eec2b291b69;p=dealii.git Facilitate casting between tensors of AD numbers to floats. --- 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