16 #ifndef dealii_differentiation_ad_adolc_number_types_h 17 #define dealii_differentiation_ad_adolc_number_types_h 21 #include <type_traits> 37 template <
typename NumberType,
typename =
void>
49 template <
typename NumberType,
typename =
void>
61 template <
typename NumberType,
typename =
void>
71 #ifdef DEAL_II_WITH_ADOLC 79 # include <adolc/adouble.h> 80 # include <adolc/adtl.h> 81 # include <adolc/internal/adolc_settings.h> 82 # include <adolc/internal/adubfunc.h> 95 "This function has not yet been implemented for taped ADOL-C " 96 "numbers when the advanced branching feature is activated.");
115 template <
typename ScalarType>
116 struct ADNumberInfoFromEnum<
119 typename std::enable_if<
120 std::is_floating_point<ScalarType>::value>::type>
122 static const bool is_taped =
true;
123 using real_type = adouble;
124 using derivative_type =
double;
125 static const unsigned int n_supported_derivative_levels =
134 template <
typename ScalarType>
135 struct ADNumberInfoFromEnum<
138 typename std::enable_if<
139 std::is_floating_point<ScalarType>::value>::type>
141 static const bool is_taped =
false;
142 using real_type = adtl::adouble;
143 using derivative_type =
double;
144 static const unsigned int n_supported_derivative_levels = 1;
148 template <
typename ADNumberType>
151 typename std::enable_if<
152 ADNumberTraits<ADNumberType>::type_code == NumberTypes::adolc_taped &&
153 ADNumberTraits<ADNumberType>::is_real_valued>::type>
161 independent_variable(
const scalar_type &in,
176 dependent_variable(ADNumberType &out, ADNumberType func)
186 template <
typename ADNumberType>
187 struct Marking<ADNumberType,
188 typename std::enable_if<
189 ADNumberTraits<ADNumberType>::type_code ==
190 NumberTypes::adolc_tapeless &&
191 ADNumberTraits<ADNumberType>::is_real_valued>::type>
199 independent_variable(
const scalar_type &in,
200 const unsigned int index,
213 "The index number of the independent variable being " 214 "marked is greater than the number of independent " 215 "variables that have been declared."));
216 out.setADValue(index, 1 );
223 dependent_variable(ADNumberType &out,
const ADNumberType &func)
239 struct ExtractData<adouble>
245 value(
const adouble &x)
258 n_directional_derivatives(
const adouble &)
272 directional_derivative(
const adouble &,
const unsigned int)
276 "The derivative values for taped ADOL-C numbers must be" 277 " computed through the ::gradient function."));
290 struct ExtractData<adtl::adouble>
296 value(
const adtl::adouble &x)
306 n_directional_derivatives(
const adtl::adouble &)
309 return adtl::getNumDir();
317 directional_derivative(
const adtl::adouble &x,
318 const unsigned int direction)
321 direction < n_directional_derivatives(x),
323 "Requested directional derivative is greater than the number " 324 "registered by ADOL-C."));
325 return x.getADValue(direction);
343 template <
typename ADNumberType>
346 typename std::enable_if<std::is_same<ADNumberType, adouble>::value>::type>
350 "Incorrect template type selected for taped ad_type");
351 static_assert(is_taped ==
true,
"Incorrect setting for taping");
367 template <
typename ADNumberType>
370 typename std::enable_if<
371 std::is_same<ADNumberType, std::complex<adouble>>::value>::type>
372 :
NumberTraits<std::complex<double>, NumberTypes::adolc_taped>
374 static_assert(std::is_same<ad_type, std::complex<adouble>>::
value,
375 "Incorrect template type selected for taped ad_type");
376 static_assert(is_taped ==
true,
"Incorrect setting for taping");
391 template <
typename ADNumberType>
394 typename std::enable_if<
395 std::is_same<ADNumberType, adtl::adouble>::value>::type>
399 "Incorrect template type selected for tapeless ad_type");
400 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
416 template <
typename ADNumberType>
419 typename std::enable_if<
420 std::is_same<ADNumberType, std::complex<adtl::adouble>>::value>::type>
421 :
NumberTraits<std::complex<double>, NumberTypes::adolc_tapeless>
423 static_assert(std::is_same<ad_type, std::complex<adtl::adouble>>::
value,
424 "Incorrect template type selected for tapeless ad_type");
425 static_assert(is_tapeless ==
true,
"Incorrect setting for taping");
436 :
NumberTraits<typename ADNumberTraits<adouble>::scalar_type,
437 NumberTypes::adolc_taped>
448 typename ADNumberTraits<std::complex<adouble>>::scalar_type,
449 NumberTypes::adolc_taped>
459 :
NumberTraits<typename ADNumberTraits<adtl::adouble>::scalar_type,
460 NumberTypes::adolc_tapeless>
472 typename ADNumberTraits<std::complex<adtl::adouble>>::scalar_type,
473 NumberTypes::adolc_tapeless>
481 template <
typename NumberType>
484 typename std::enable_if<
485 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
486 NumberTypes::adolc_taped>::type> : std::true_type
494 template <
typename NumberType>
497 typename std::enable_if<
498 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
499 NumberTypes::adolc_tapeless>::type> : std::true_type
507 template <
typename NumberType>
509 typename std::enable_if<
510 is_adolc_taped_number<NumberType>::value ||
511 is_adolc_tapeless_number<NumberType>::value>::type>
525 #endif // DEAL_II_WITH_ADOLC
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcADOLCAdvancedBranching()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_OPEN
T max(const T &t, const MPI_Comm &mpi_communicator)