15#ifndef dealii_differentiation_ad_adolc_number_types_h
16#define dealii_differentiation_ad_adolc_number_types_h
34 template <
typename NumberType,
typename =
void>
44 template <
typename NumberType,
typename =
void>
54 template <
typename NumberType,
typename =
void>
64#ifdef DEAL_II_WITH_ADOLC
72# include <adolc/adouble.h>
73# include <adolc/adtl.h>
74# include <adolc/internal/adolc_settings.h>
75# 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 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
115 static const bool is_taped =
true;
116 using real_type = adouble;
117 using derivative_type = double;
118 static const unsigned int n_supported_derivative_levels =
119 std::numeric_limits<unsigned int>::max();
127 template <
typename ScalarType>
128 struct ADNumberInfoFromEnum<
131 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
133 static const bool is_taped =
false;
134 using real_type = adtl::adouble;
135 using derivative_type = double;
136 static const unsigned int n_supported_derivative_levels = 1;
140 template <
typename ADNumberType>
143 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
144 NumberTypes::adolc_taped &&
145 ADNumberTraits<ADNumberType>::is_real_valued>>
147 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
153 independent_variable(
const scalar_type &in,
168 dependent_variable(ADNumberType &out, ADNumberType func)
171 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
178 template <
typename ADNumberType>
181 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
182 NumberTypes::adolc_tapeless &&
183 ADNumberTraits<ADNumberType>::is_real_valued>>
185 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
191 independent_variable(
const scalar_type &in,
192 const unsigned int index,
205 "The index number of the independent variable being "
206 "marked is greater than the number of independent "
207 "variables that have been declared."));
208 out.setADValue(index, 1 );
215 dependent_variable(ADNumberType &out,
const ADNumberType &func)
229 struct ExtractData<adouble>
235 value(
const adouble &x)
248 n_directional_derivatives(
const adouble &)
262 directional_derivative(
const adouble &,
const unsigned int)
266 "The derivative values for taped ADOL-C numbers must be"
267 " computed through the ::gradient function."));
278 struct ExtractData<
adtl::adouble>
284 value(
const adtl::adouble &x)
294 n_directional_derivatives(
const adtl::adouble &)
297 return adtl::getNumDir();
305 directional_derivative(
const adtl::adouble &x,
306 const unsigned int direction)
309 direction < n_directional_derivatives(x),
311 "Requested directional derivative is greater than the number "
312 "registered by ADOL-C."));
313 return x.getADValue(direction);
329 template <
typename ADNumberType>
330 struct ADNumberTraits<
332 std::enable_if_t<std::is_same_v<ADNumberType, adouble>>>
333 : NumberTraits<double, NumberTypes::adolc_taped>
335 static_assert(std::is_same_v<ad_type, adouble>,
336 "Incorrect template type selected for taped ad_type");
337 static_assert(is_taped ==
true,
"Incorrect setting for taping");
351 template <
typename ADNumberType>
352 struct ADNumberTraits<
354 std::enable_if_t<std::is_same_v<ADNumberType, std::complex<adouble>>>>
355 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
357 static_assert(std::is_same_v<ad_type, std::complex<adouble>>,
358 "Incorrect template type selected for taped ad_type");
359 static_assert(is_taped ==
true,
"Incorrect setting for taping");
372 template <
typename ADNumberType>
373 struct ADNumberTraits<
375 std::enable_if_t<std::is_same_v<ADNumberType, adtl::adouble>>>
376 : NumberTraits<double, NumberTypes::adolc_tapeless>
378 static_assert(std::is_same_v<ad_type, adtl::adouble>,
379 "Incorrect template type selected for tapeless ad_type");
380 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
394 template <
typename ADNumberType>
395 struct ADNumberTraits<
398 std::is_same_v<ADNumberType, std::complex<adtl::adouble>>>>
399 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
401 static_assert(std::is_same_v<ad_type, std::complex<adtl::adouble>>,
402 "Incorrect template type selected for tapeless ad_type");
403 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
414 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
415 NumberTypes::adolc_taped>
426 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
427 NumberTypes::adolc_taped>
437 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
438 NumberTypes::adolc_tapeless>
447 struct NumberTraits<
std::complex<adtl::adouble>,
450 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
451 NumberTypes::adolc_tapeless>
459 template <
typename NumberType>
460 struct is_adolc_taped_number<
462 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
463 NumberTypes::adolc_taped>> : std::true_type
471 template <
typename NumberType>
472 struct is_adolc_tapeless_number<
474 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
475 NumberTypes::adolc_tapeless>> : std::true_type
483 template <
typename NumberType>
484 struct is_adolc_number<
486 std::enable_if_t<is_adolc_taped_number<NumberType>::value ||
487 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()