13#ifndef dealii_differentiation_ad_adolc_number_types_h
14#define dealii_differentiation_ad_adolc_number_types_h
24#ifdef DEAL_II_WITH_ADOLC
25# include <adolc/adouble.h>
26# include <adolc/adtl.h>
27# include <adolc/internal/adolc_settings.h>
28# include <adolc/internal/adubfunc.h>
48 template <
typename NumberType,
typename =
void>
58 template <
typename NumberType,
typename =
void>
68 template <
typename NumberType,
typename =
void>
76#ifdef DEAL_II_WITH_ADOLC
85 "This function has not yet been implemented for taped ADOL-C "
86 "numbers when the advanced branching feature is activated.");
105 template <
typename ScalarType>
106 struct ADNumberInfoFromEnum<
109 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
111 static const bool is_taped =
true;
112 using real_type = adouble;
113 using derivative_type = double;
114 static const unsigned int n_supported_derivative_levels =
115 std::numeric_limits<unsigned int>::max();
123 template <
typename ScalarType>
124 struct ADNumberInfoFromEnum<
127 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
129 static const bool is_taped =
false;
130 using real_type = adtl::adouble;
131 using derivative_type = double;
132 static const unsigned int n_supported_derivative_levels = 1;
136 template <
typename ADNumberType>
139 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
140 NumberTypes::adolc_taped &&
141 ADNumberTraits<ADNumberType>::is_real_valued>>
143 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
149 independent_variable(
const scalar_type &in,
164 dependent_variable(ADNumberType &out, ADNumberType func)
167 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
174 template <
typename ADNumberType>
177 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
178 NumberTypes::adolc_tapeless &&
179 ADNumberTraits<ADNumberType>::is_real_valued>>
181 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
187 independent_variable(
const scalar_type &in,
188 const unsigned int index,
201 "The index number of the independent variable being "
202 "marked is greater than the number of independent "
203 "variables that have been declared."));
204 out.setADValue(index, 1 );
211 dependent_variable(ADNumberType &out,
const ADNumberType &func)
225 struct ExtractData<adouble>
231 value(
const adouble &x)
244 n_directional_derivatives(
const adouble &)
258 directional_derivative(
const adouble &,
const unsigned int)
262 "The derivative values for taped ADOL-C numbers must be"
263 " computed through the ::gradient function."));
274 struct ExtractData<
adtl::adouble>
280 value(
const adtl::adouble &x)
290 n_directional_derivatives(
const adtl::adouble &)
293 return adtl::getNumDir();
301 directional_derivative(
const adtl::adouble &x,
302 const unsigned int direction)
305 direction < n_directional_derivatives(x),
307 "Requested directional derivative is greater than the number "
308 "registered by ADOL-C."));
309 return x.getADValue(direction);
325 template <
typename ADNumberType>
326 struct ADNumberTraits<
328 std::enable_if_t<std::is_same_v<ADNumberType, adouble>>>
329 : NumberTraits<double, NumberTypes::adolc_taped>
331 static_assert(std::is_same_v<ad_type, adouble>,
332 "Incorrect template type selected for taped ad_type");
333 static_assert(is_taped,
"Incorrect setting for taping");
347 template <
typename ADNumberType>
348 struct ADNumberTraits<
350 std::enable_if_t<std::is_same_v<ADNumberType, std::complex<adouble>>>>
351 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
353 static_assert(std::is_same_v<ad_type, std::complex<adouble>>,
354 "Incorrect template type selected for taped ad_type");
355 static_assert(is_taped,
"Incorrect setting for taping");
368 template <
typename ADNumberType>
369 struct ADNumberTraits<
371 std::enable_if_t<std::is_same_v<ADNumberType, adtl::adouble>>>
372 : NumberTraits<double, NumberTypes::adolc_tapeless>
374 static_assert(std::is_same_v<ad_type, adtl::adouble>,
375 "Incorrect template type selected for tapeless ad_type");
376 static_assert(is_tapeless,
"Incorrect setting for taping");
390 template <
typename ADNumberType>
391 struct ADNumberTraits<
394 std::is_same_v<ADNumberType, std::complex<adtl::adouble>>>>
395 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
397 static_assert(std::is_same_v<ad_type, std::complex<adtl::adouble>>,
398 "Incorrect template type selected for tapeless ad_type");
399 static_assert(is_tapeless,
"Incorrect setting for taping");
410 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
411 NumberTypes::adolc_taped>
422 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
423 NumberTypes::adolc_taped>
433 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
434 NumberTypes::adolc_tapeless>
443 struct NumberTraits<
std::complex<adtl::adouble>,
446 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
447 NumberTypes::adolc_tapeless>
455 template <
typename NumberType>
456 struct is_adolc_taped_number<
458 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
459 NumberTypes::adolc_taped>> : std::true_type
467 template <
typename NumberType>
468 struct is_adolc_tapeless_number<
470 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
471 NumberTypes::adolc_tapeless>> : std::true_type
479 template <
typename NumberType>
480 struct is_adolc_number<
482 std::enable_if_t<is_adolc_taped_number<NumberType>::value ||
483 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()