16 #ifndef dealii_differentiation_ad_adolc_number_types_h 17 #define dealii_differentiation_ad_adolc_number_types_h 19 #include <deal.II/base/config.h> 20 #include <type_traits> 22 DEAL_II_NAMESPACE_OPEN
36 template <
typename NumberType,
typename =
void>
49 template <
typename NumberType,
typename =
void>
62 template <
typename NumberType,
typename =
void>
70 DEAL_II_NAMESPACE_CLOSE
73 #ifdef DEAL_II_WITH_ADOLC 75 #include <adolc/internal/adolc_settings.h> 76 #include <adolc/internal/adubfunc.h> 78 #include <adolc/adouble.h> 79 #include <adolc/adtl.h> 81 #include <deal.II/base/numbers.h> 82 #include <deal.II/base/exceptions.h> 84 #include <deal.II/differentiation/ad/ad_number_types.h> 85 #include <deal.II/differentiation/ad/ad_number_traits.h> 88 #include <type_traits> 90 DEAL_II_NAMESPACE_OPEN
99 "This function has not yet been implemented for taped Adol-C " 100 "numbers when the advanced branching feature is activated.");
121 template<
typename ScalarType>
123 typename std::enable_if<std::is_floating_point<ScalarType>::value>::type
126 static const bool is_taped =
true;
127 typedef adouble real_type;
128 typedef double derivative_type;
129 static const unsigned int n_supported_derivative_levels
130 = std::numeric_limits<unsigned int>::max();
138 template<
typename ScalarType>
140 typename std::enable_if<std::is_floating_point<ScalarType>::value>::type
143 static const bool is_taped =
false;
144 typedef adtl::adouble real_type;
145 typedef double derivative_type;
146 static const unsigned int n_supported_derivative_levels = 1;
150 template<
typename ADNumberType>
151 struct Marking<ADNumberType, typename
std::enable_if<
152 ADNumberTraits<ADNumberType>::type_code == NumberTypes::adolc_taped &&
153 ADNumberTraits<ADNumberType>::is_real_valued
157 typedef typename ADNumberTraits<ADNumberType>::scalar_type scalar_type;
163 independent_variable(
const scalar_type &in,
178 dependent_variable(ADNumberType &out,
182 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
189 template<
typename ADNumberType>
190 struct Marking<ADNumberType, typename
std::enable_if<
191 ADNumberTraits<ADNumberType>::type_code == NumberTypes::adolc_tapeless &&
192 ADNumberTraits<ADNumberType>::is_real_valued
195 typedef typename ADNumberTraits<ADNumberType>::scalar_type scalar_type;
201 independent_variable(
const scalar_type &in,
202 const unsigned int index,
214 ExcMessage(
"The index number of the independent variable being " 215 "marked is greater than the number of independent " 216 "variables that have been declared."));
217 out.setADValue(index, 1 );
224 dependent_variable(ADNumberType &out,
225 const ADNumberType &func)
241 struct ExtractData<adouble>
247 value (
const adouble &x)
260 n_directional_derivatives (
const adouble &)
274 directional_derivative (
const adouble &,
278 ExcMessage(
"The derivative values for taped Adol-C numbers must be" 279 "computed through the ::gradient function."));
292 struct ExtractData<adtl::adouble>
298 value (
const adtl::adouble &x)
308 n_directional_derivatives (
const adtl::adouble &)
311 return adtl::getNumDir();
319 directional_derivative (
const adtl::adouble &x,
320 const unsigned int direction)
322 Assert(direction < n_directional_derivatives(x),
323 ExcMessage(
"Requested directional derivative is greater than the number " 324 "registered by Adol-C."));
325 return x.getADValue(direction);
343 template<
typename ADNumberType>
344 struct ADNumberTraits<ADNumberType,
345 typename
std::enable_if<
346 std::is_same<ADNumberType, adouble>::value
348 : NumberTraits<double, NumberTypes::adolc_taped>
351 std::is_same<ad_type,adouble>::value,
352 "Incorrect template type selected for taped ad_type");
355 "Incorrect setting for taping");
371 template<
typename ADNumberType>
372 struct ADNumberTraits<ADNumberType,
373 typename
std::enable_if<
374 std::is_same<ADNumberType, std::complex<adouble> >::value
376 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
379 std::is_same<ad_type,std::complex<adouble> >::value,
380 "Incorrect template type selected for taped ad_type");
383 "Incorrect setting for taping");
398 template<
typename ADNumberType>
399 struct ADNumberTraits<ADNumberType,
400 typename
std::enable_if<
401 std::is_same<ADNumberType, adtl::adouble>::value
403 : NumberTraits<double, NumberTypes::adolc_tapeless>
406 std::is_same<ad_type,adtl::adouble>::value,
407 "Incorrect template type selected for tapeless ad_type");
410 "Incorrect setting for taping");
426 template<
typename ADNumberType>
427 struct ADNumberTraits<ADNumberType,
428 typename
std::enable_if<
429 std::is_same<ADNumberType, std::complex<adtl::adouble> >::value
431 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
434 std::is_same<ad_type,std::complex<adtl::adouble> >::value,
435 "Incorrect template type selected for tapeless ad_type");
438 "Incorrect setting for taping");
449 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,NumberTypes::adolc_taped>
459 : NumberTraits<typename ADNumberTraits<std::complex<adouble> >::scalar_type,NumberTypes::adolc_taped>
469 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,NumberTypes::adolc_tapeless>
479 : NumberTraits<typename ADNumberTraits<std::complex<adtl::adouble> >::scalar_type,NumberTypes::adolc_tapeless>
487 template <
typename NumberType>
488 struct is_adolc_taped_number<NumberType, typename
std::enable_if<
489 ADNumberTraits<typename std::decay<NumberType>::type>::type_code == NumberTypes::adolc_taped
499 template <
typename NumberType>
500 struct is_adolc_tapeless_number<NumberType, typename
std::enable_if<
501 ADNumberTraits<typename std::decay<NumberType>::type>::type_code == NumberTypes::adolc_tapeless
511 template <
typename NumberType>
512 struct is_adolc_number<NumberType, typename
std::enable_if<
513 is_adolc_taped_number<NumberType>::value ||
514 is_adolc_tapeless_number<NumberType>::value
526 DEAL_II_NAMESPACE_CLOSE
529 #endif // DEAL_II_WITH_ADOLC
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcADOLCAdvancedBranching()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)