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> 21 #include <type_traits> 23 DEAL_II_NAMESPACE_OPEN
37 template <
typename NumberType,
typename =
void>
49 template <
typename NumberType,
typename =
void>
61 template <
typename NumberType,
typename =
void>
68 DEAL_II_NAMESPACE_CLOSE
71 #ifdef DEAL_II_WITH_ADOLC 73 # include <deal.II/base/exceptions.h> 74 # include <deal.II/base/numbers.h> 76 # include <deal.II/differentiation/ad/ad_number_traits.h> 77 # include <deal.II/differentiation/ad/ad_number_types.h> 79 # include <adolc/adouble.h> 80 # include <adolc/adtl.h> 81 # include <adolc/internal/adolc_settings.h> 82 # include <adolc/internal/adubfunc.h> 85 # include <type_traits> 87 DEAL_II_NAMESPACE_OPEN
96 "This function has not yet been implemented for taped ADOL-C " 97 "numbers when the advanced branching feature is activated.");
116 template <
typename ScalarType>
117 struct ADNumberInfoFromEnum<
120 typename std::enable_if<
121 std::is_floating_point<ScalarType>::value>::type>
123 static const bool is_taped =
true;
124 using real_type = adouble;
125 using derivative_type = double;
126 static const unsigned int n_supported_derivative_levels =
127 std::numeric_limits<unsigned int>::max();
135 template <
typename ScalarType>
136 struct ADNumberInfoFromEnum<
139 typename std::enable_if<
140 std::is_floating_point<ScalarType>::value>::type>
142 static const bool is_taped =
false;
143 using real_type = adtl::adouble;
144 using derivative_type = double;
145 static const unsigned int n_supported_derivative_levels = 1;
149 template <
typename ADNumberType>
152 typename
std::enable_if<
153 ADNumberTraits<ADNumberType>::type_code == NumberTypes::adolc_taped &&
154 ADNumberTraits<ADNumberType>::is_real_valued>::type>
156 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
162 independent_variable(
const scalar_type &in,
177 dependent_variable(ADNumberType &out, ADNumberType func)
180 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
187 template <
typename ADNumberType>
188 struct Marking<ADNumberType,
189 typename
std::enable_if<
190 ADNumberTraits<ADNumberType>::type_code ==
191 NumberTypes::adolc_tapeless &&
192 ADNumberTraits<ADNumberType>::is_real_valued>::type>
194 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
200 independent_variable(
const scalar_type &in,
201 const unsigned int index,
214 "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,
const ADNumberType &func)
240 struct ExtractData<adouble>
246 value(
const adouble &x)
259 n_directional_derivatives(
const adouble &)
273 directional_derivative(
const adouble &,
const unsigned int)
277 "The derivative values for taped ADOL-C numbers must be" 278 "computed through the ::gradient function."));
291 struct ExtractData<adtl::adouble>
297 value(
const adtl::adouble &x)
307 n_directional_derivatives(
const adtl::adouble &)
310 return adtl::getNumDir();
318 directional_derivative(
const adtl::adouble &x,
319 const unsigned int direction)
322 direction < n_directional_derivatives(x),
324 "Requested directional derivative is greater than the number " 325 "registered by ADOL-C."));
326 return x.getADValue(direction);
344 template <
typename ADNumberType>
345 struct ADNumberTraits<
347 typename
std::enable_if<std::is_same<ADNumberType, adouble>::value>::type>
348 : NumberTraits<double, NumberTypes::adolc_taped>
350 static_assert(std::is_same<ad_type, adouble>::value,
351 "Incorrect template type selected for taped ad_type");
352 static_assert(is_taped ==
true,
"Incorrect setting for taping");
368 template <
typename ADNumberType>
369 struct ADNumberTraits<
371 typename
std::enable_if<
372 std::is_same<ADNumberType, std::complex<adouble>>::value>::type>
373 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
375 static_assert(std::is_same<ad_type, std::complex<adouble>>::value,
376 "Incorrect template type selected for taped ad_type");
377 static_assert(is_taped ==
true,
"Incorrect setting for taping");
392 template <
typename ADNumberType>
393 struct ADNumberTraits<
395 typename
std::enable_if<
396 std::is_same<ADNumberType, adtl::adouble>::value>::type>
397 : NumberTraits<double, NumberTypes::adolc_tapeless>
399 static_assert(std::is_same<ad_type, adtl::adouble>::value,
400 "Incorrect template type selected for tapeless ad_type");
401 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
417 template <
typename ADNumberType>
418 struct ADNumberTraits<
420 typename
std::enable_if<
421 std::is_same<ADNumberType, std::complex<adtl::adouble>>::value>::type>
422 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
424 static_assert(std::is_same<ad_type, std::complex<adtl::adouble>>::value,
425 "Incorrect template type selected for tapeless ad_type");
426 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
437 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
438 NumberTypes::adolc_taped>
449 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
450 NumberTypes::adolc_taped>
460 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
461 NumberTypes::adolc_tapeless>
470 struct NumberTraits<
std::complex<adtl::adouble>,
473 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
474 NumberTypes::adolc_tapeless>
482 template <
typename NumberType>
483 struct is_adolc_taped_number<
485 typename
std::enable_if<
486 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
487 NumberTypes::adolc_taped>::type> : std::true_type
495 template <
typename NumberType>
496 struct is_adolc_tapeless_number<
498 typename
std::enable_if<
499 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
500 NumberTypes::adolc_tapeless>::type> : std::true_type
508 template <
typename NumberType>
509 struct is_adolc_number<NumberType,
510 typename
std::enable_if<
511 is_adolc_taped_number<NumberType>::value ||
512 is_adolc_tapeless_number<NumberType>::value>::type>
523 DEAL_II_NAMESPACE_CLOSE
526 #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)