16#ifndef dealii_differentiation_ad_adolc_number_types_h
17#define dealii_differentiation_ad_adolc_number_types_h
35 template <
typename NumberType,
typename =
void>
45 template <
typename NumberType,
typename =
void>
55 template <
typename NumberType,
typename =
void>
65#ifdef DEAL_II_WITH_ADOLC
73# include <adolc/adouble.h>
74# include <adolc/adtl.h>
75# include <adolc/internal/adolc_settings.h>
76# include <adolc/internal/adubfunc.h>
89 "This function has not yet been implemented for taped ADOL-C "
90 "numbers when the advanced branching feature is activated.");
109 template <
typename ScalarType>
110 struct ADNumberInfoFromEnum<
113 typename std::enable_if<
114 std::is_floating_point<ScalarType>::value>::type>
116 static const bool is_taped =
true;
117 using real_type = adouble;
118 using derivative_type = double;
119 static const unsigned int n_supported_derivative_levels =
128 template <
typename ScalarType>
129 struct ADNumberInfoFromEnum<
132 typename std::enable_if<
133 std::is_floating_point<ScalarType>::value>::type>
135 static const bool is_taped =
false;
136 using real_type = adtl::adouble;
137 using derivative_type = double;
138 static const unsigned int n_supported_derivative_levels = 1;
142 template <
typename ADNumberType>
145 typename
std::enable_if<
146 ADNumberTraits<ADNumberType>::type_code == NumberTypes::adolc_taped &&
147 ADNumberTraits<ADNumberType>::is_real_valued>::type>
149 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
155 independent_variable(
const scalar_type &in,
170 dependent_variable(ADNumberType &out, ADNumberType func)
173 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
180 template <
typename ADNumberType>
181 struct Marking<ADNumberType,
182 typename
std::enable_if<
183 ADNumberTraits<ADNumberType>::type_code ==
184 NumberTypes::adolc_tapeless &&
185 ADNumberTraits<ADNumberType>::is_real_valued>::type>
187 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
193 independent_variable(
const scalar_type &in,
194 const unsigned int index,
207 "The index number of the independent variable being "
208 "marked is greater than the number of independent "
209 "variables that have been declared."));
210 out.setADValue(index, 1 );
217 dependent_variable(ADNumberType &out,
const ADNumberType &func)
231 struct ExtractData<adouble>
237 value(
const adouble &x)
250 n_directional_derivatives(
const adouble &)
264 directional_derivative(
const adouble &,
const unsigned int)
268 "The derivative values for taped ADOL-C numbers must be"
269 " computed through the ::gradient function."));
280 struct ExtractData<adtl::adouble>
286 value(
const adtl::adouble &x)
296 n_directional_derivatives(
const adtl::adouble &)
299 return adtl::getNumDir();
307 directional_derivative(
const adtl::adouble &x,
308 const unsigned int direction)
311 direction < n_directional_derivatives(x),
313 "Requested directional derivative is greater than the number "
314 "registered by ADOL-C."));
315 return x.getADValue(direction);
331 template <
typename ADNumberType>
332 struct ADNumberTraits<
334 typename
std::enable_if<std::is_same<ADNumberType, adouble>::value>::type>
335 : NumberTraits<double, NumberTypes::adolc_taped>
337 static_assert(std::is_same<ad_type, adouble>::value,
338 "Incorrect template type selected for taped ad_type");
339 static_assert(is_taped ==
true,
"Incorrect setting for taping");
353 template <
typename ADNumberType>
354 struct ADNumberTraits<
356 typename
std::enable_if<
357 std::is_same<ADNumberType, std::complex<adouble>>::value>::type>
358 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
360 static_assert(std::is_same<ad_type, std::complex<adouble>>::value,
361 "Incorrect template type selected for taped ad_type");
362 static_assert(is_taped ==
true,
"Incorrect setting for taping");
375 template <
typename ADNumberType>
376 struct ADNumberTraits<
378 typename
std::enable_if<
379 std::is_same<ADNumberType, adtl::adouble>::value>::type>
380 : NumberTraits<double, NumberTypes::adolc_tapeless>
382 static_assert(std::is_same<ad_type, adtl::adouble>::value,
383 "Incorrect template type selected for tapeless ad_type");
384 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
398 template <
typename ADNumberType>
399 struct ADNumberTraits<
401 typename
std::enable_if<
402 std::is_same<ADNumberType, std::complex<adtl::adouble>>::value>::type>
403 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
405 static_assert(std::is_same<ad_type, std::complex<adtl::adouble>>::value,
406 "Incorrect template type selected for tapeless ad_type");
407 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
418 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
419 NumberTypes::adolc_taped>
430 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
431 NumberTypes::adolc_taped>
441 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
442 NumberTypes::adolc_tapeless>
451 struct NumberTraits<
std::complex<adtl::adouble>,
454 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
455 NumberTypes::adolc_tapeless>
463 template <
typename NumberType>
464 struct is_adolc_taped_number<
466 typename
std::enable_if<
467 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
468 NumberTypes::adolc_taped>::type> : std::true_type
476 template <
typename NumberType>
477 struct is_adolc_tapeless_number<
479 typename
std::enable_if<
480 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
481 NumberTypes::adolc_tapeless>::type> : std::true_type
489 template <
typename NumberType>
490 struct is_adolc_number<NumberType,
491 typename
std::enable_if<
492 is_adolc_taped_number<NumberType>::value ||
493 is_adolc_tapeless_number<NumberType>::value>::type>
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcADOLCAdvancedBranching()