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>
90 "This function has not yet been implemented for taped ADOL-C "
91 "numbers when the advanced branching feature is activated.");
110 template <
typename ScalarType>
111 struct ADNumberInfoFromEnum<
114 std::enable_if_t<std::is_floating_point<ScalarType>::value>>
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 =
120 std::numeric_limits<unsigned int>::max();
128 template <
typename ScalarType>
129 struct ADNumberInfoFromEnum<
132 std::enable_if_t<std::is_floating_point<ScalarType>::value>>
134 static const bool is_taped =
false;
135 using real_type = adtl::adouble;
136 using derivative_type = double;
137 static const unsigned int n_supported_derivative_levels = 1;
141 template <
typename ADNumberType>
144 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
145 NumberTypes::adolc_taped &&
146 ADNumberTraits<ADNumberType>::is_real_valued>>
148 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
154 independent_variable(
const scalar_type &in,
169 dependent_variable(ADNumberType &out, ADNumberType func)
172 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
179 template <
typename ADNumberType>
182 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
183 NumberTypes::adolc_tapeless &&
184 ADNumberTraits<ADNumberType>::is_real_valued>>
186 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
192 independent_variable(
const scalar_type &in,
193 const unsigned int index,
206 "The index number of the independent variable being "
207 "marked is greater than the number of independent "
208 "variables that have been declared."));
209 out.setADValue(index, 1 );
216 dependent_variable(ADNumberType &out,
const ADNumberType &func)
230 struct ExtractData<adouble>
236 value(
const adouble &x)
249 n_directional_derivatives(
const adouble &)
263 directional_derivative(
const adouble &,
const unsigned int)
267 "The derivative values for taped ADOL-C numbers must be"
268 " computed through the ::gradient function."));
279 struct ExtractData<
adtl::adouble>
285 value(
const adtl::adouble &x)
295 n_directional_derivatives(
const adtl::adouble &)
298 return adtl::getNumDir();
306 directional_derivative(
const adtl::adouble &x,
307 const unsigned int direction)
310 direction < n_directional_derivatives(x),
312 "Requested directional derivative is greater than the number "
313 "registered by ADOL-C."));
314 return x.getADValue(direction);
330 template <
typename ADNumberType>
331 struct ADNumberTraits<
333 std::enable_if_t<std::is_same<ADNumberType, adouble>::value>>
334 : NumberTraits<double, NumberTypes::adolc_taped>
336 static_assert(std::is_same<ad_type, adouble>::value,
337 "Incorrect template type selected for taped ad_type");
338 static_assert(is_taped ==
true,
"Incorrect setting for taping");
352 template <
typename ADNumberType>
353 struct ADNumberTraits<
356 std::is_same<ADNumberType, std::complex<adouble>>::value>>
357 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
359 static_assert(std::is_same<ad_type, std::complex<adouble>>::value,
360 "Incorrect template type selected for taped ad_type");
361 static_assert(is_taped ==
true,
"Incorrect setting for taping");
374 template <
typename ADNumberType>
375 struct ADNumberTraits<
377 std::enable_if_t<std::is_same<ADNumberType, adtl::adouble>::value>>
378 : NumberTraits<double, NumberTypes::adolc_tapeless>
380 static_assert(std::is_same<ad_type, adtl::adouble>::value,
381 "Incorrect template type selected for tapeless ad_type");
382 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
396 template <
typename ADNumberType>
397 struct ADNumberTraits<
400 std::is_same<ADNumberType, std::complex<adtl::adouble>>::value>>
401 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
403 static_assert(std::is_same<ad_type, std::complex<adtl::adouble>>::value,
404 "Incorrect template type selected for tapeless ad_type");
405 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
416 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
417 NumberTypes::adolc_taped>
428 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
429 NumberTypes::adolc_taped>
439 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
440 NumberTypes::adolc_tapeless>
449 struct NumberTraits<
std::complex<adtl::adouble>,
452 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
453 NumberTypes::adolc_tapeless>
461 template <
typename NumberType>
462 struct is_adolc_taped_number<
464 std::enable_if_t<ADNumberTraits<typename std::decay<NumberType>::type>::
465 type_code == NumberTypes::adolc_taped>>
474 template <
typename NumberType>
475 struct is_adolc_tapeless_number<
477 std::enable_if_t<ADNumberTraits<typename std::decay<NumberType>::type>::
478 type_code == NumberTypes::adolc_tapeless>>
487 template <
typename NumberType>
488 struct is_adolc_number<
490 std::enable_if_t<is_adolc_taped_number<NumberType>::value ||
491 is_adolc_tapeless_number<NumberType>::value>>
#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()