15#ifndef dealii_differentiation_ad_adolc_number_types_h
16#define dealii_differentiation_ad_adolc_number_types_h
26#ifdef DEAL_II_WITH_ADOLC
27# include <adolc/adouble.h>
28# include <adolc/adtl.h>
29# include <adolc/internal/adolc_settings.h>
30# include <adolc/internal/adubfunc.h>
50 template <
typename NumberType,
typename =
void>
60 template <
typename NumberType,
typename =
void>
70 template <
typename NumberType,
typename =
void>
78#ifdef DEAL_II_WITH_ADOLC
87 "This function has not yet been implemented for taped ADOL-C "
88 "numbers when the advanced branching feature is activated.");
107 template <
typename ScalarType>
108 struct ADNumberInfoFromEnum<
111 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
113 static const bool is_taped =
true;
114 using real_type = adouble;
115 using derivative_type = double;
116 static const unsigned int n_supported_derivative_levels =
117 std::numeric_limits<unsigned int>::max();
125 template <
typename ScalarType>
126 struct ADNumberInfoFromEnum<
129 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
131 static const bool is_taped =
false;
132 using real_type = adtl::adouble;
133 using derivative_type = double;
134 static const unsigned int n_supported_derivative_levels = 1;
138 template <
typename ADNumberType>
141 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
142 NumberTypes::adolc_taped &&
143 ADNumberTraits<ADNumberType>::is_real_valued>>
145 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
151 independent_variable(
const scalar_type &in,
166 dependent_variable(ADNumberType &out, ADNumberType func)
169 out = ADNumberTraits<ADNumberType>::get_scalar_value(func);
176 template <
typename ADNumberType>
179 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
180 NumberTypes::adolc_tapeless &&
181 ADNumberTraits<ADNumberType>::is_real_valued>>
183 using scalar_type =
typename ADNumberTraits<ADNumberType>::scalar_type;
189 independent_variable(
const scalar_type &in,
190 const unsigned int index,
203 "The index number of the independent variable being "
204 "marked is greater than the number of independent "
205 "variables that have been declared."));
206 out.setADValue(index, 1 );
213 dependent_variable(ADNumberType &out,
const ADNumberType &func)
227 struct ExtractData<adouble>
233 value(
const adouble &x)
246 n_directional_derivatives(
const adouble &)
260 directional_derivative(
const adouble &,
const unsigned int)
264 "The derivative values for taped ADOL-C numbers must be"
265 " computed through the ::gradient function."));
276 struct ExtractData<
adtl::adouble>
282 value(
const adtl::adouble &x)
292 n_directional_derivatives(
const adtl::adouble &)
295 return adtl::getNumDir();
303 directional_derivative(
const adtl::adouble &x,
304 const unsigned int direction)
307 direction < n_directional_derivatives(x),
309 "Requested directional derivative is greater than the number "
310 "registered by ADOL-C."));
311 return x.getADValue(direction);
327 template <
typename ADNumberType>
328 struct ADNumberTraits<
330 std::enable_if_t<std::is_same_v<ADNumberType, adouble>>>
331 : NumberTraits<double, NumberTypes::adolc_taped>
333 static_assert(std::is_same_v<ad_type, adouble>,
334 "Incorrect template type selected for taped ad_type");
335 static_assert(is_taped ==
true,
"Incorrect setting for taping");
349 template <
typename ADNumberType>
350 struct ADNumberTraits<
352 std::enable_if_t<std::is_same_v<ADNumberType, std::complex<adouble>>>>
353 : NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
355 static_assert(std::is_same_v<ad_type, std::complex<adouble>>,
356 "Incorrect template type selected for taped ad_type");
357 static_assert(is_taped ==
true,
"Incorrect setting for taping");
370 template <
typename ADNumberType>
371 struct ADNumberTraits<
373 std::enable_if_t<std::is_same_v<ADNumberType, adtl::adouble>>>
374 : NumberTraits<double, NumberTypes::adolc_tapeless>
376 static_assert(std::is_same_v<ad_type, adtl::adouble>,
377 "Incorrect template type selected for tapeless ad_type");
378 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
392 template <
typename ADNumberType>
393 struct ADNumberTraits<
396 std::is_same_v<ADNumberType, std::complex<adtl::adouble>>>>
397 : NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
399 static_assert(std::is_same_v<ad_type, std::complex<adtl::adouble>>,
400 "Incorrect template type selected for tapeless ad_type");
401 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
412 : NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
413 NumberTypes::adolc_taped>
424 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
425 NumberTypes::adolc_taped>
435 : NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
436 NumberTypes::adolc_tapeless>
445 struct NumberTraits<
std::complex<adtl::adouble>,
448 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
449 NumberTypes::adolc_tapeless>
457 template <
typename NumberType>
458 struct is_adolc_taped_number<
460 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
461 NumberTypes::adolc_taped>> : std::true_type
469 template <
typename NumberType>
470 struct is_adolc_tapeless_number<
472 std::enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
473 NumberTypes::adolc_tapeless>> : std::true_type
481 template <
typename NumberType>
482 struct is_adolc_number<
484 std::enable_if_t<is_adolc_taped_number<NumberType>::value ||
485 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()