16 #ifndef dealii_differentiation_ad_adolc_number_types_h
17 #define dealii_differentiation_ad_adolc_number_types_h
21 #include <type_traits>
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_v<ScalarType>>>
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 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
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_v<ADNumberType, adouble>>>
334 : NumberTraits<double, NumberTypes::adolc_taped>
336 static_assert(std::is_same_v<ad_type, adouble>,
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<
355 std::enable_if_t<std::is_same_v<ADNumberType, std::complex<adouble>>>>
356 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
358 static_assert(std::is_same_v<ad_type, std::complex<adouble>>,
359 "Incorrect template type selected for taped ad_type");
360 static_assert(is_taped ==
true,
"Incorrect setting for taping");
373 template <
typename ADNumberType>
374 struct ADNumberTraits<
376 std::enable_if_t<std::is_same_v<ADNumberType, adtl::adouble>>>
377 : NumberTraits<double, NumberTypes::adolc_tapeless>
379 static_assert(std::is_same_v<ad_type, adtl::adouble>,
380 "Incorrect template type selected for tapeless ad_type");
381 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
395 template <
typename ADNumberType>
396 struct ADNumberTraits<
399 std::is_same_v<ADNumberType, std::complex<adtl::adouble>>>>
400 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
402 static_assert(std::is_same_v<ad_type, std::complex<adtl::adouble>>,
403 "Incorrect template type selected for tapeless ad_type");
404 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
415 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
416 NumberTypes::adolc_taped>
427 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
428 NumberTypes::adolc_taped>
438 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
439 NumberTypes::adolc_tapeless>
448 struct NumberTraits<std::complex<adtl::adouble>,
451 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
452 NumberTypes::adolc_tapeless>
460 template <
typename NumberType>
461 struct is_adolc_taped_number<
463 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
464 NumberTypes::adolc_taped>> : std::true_type
472 template <
typename NumberType>
473 struct is_adolc_tapeless_number<
475 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
476 NumberTypes::adolc_tapeless>> : std::true_type
484 template <
typename NumberType>
485 struct is_adolc_number<
487 std::enable_if_t<is_adolc_taped_number<NumberType>::value ||
488 is_adolc_tapeless_number<NumberType>::value>>
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcADOLCAdvancedBranching()
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)