15#ifndef dealii_differentiation_ad_ad_drivers_h
16#define dealii_differentiation_ad_ad_drivers_h
29#ifdef DEAL_II_WITH_ADOLC
31# include <adolc/internal/usrparms.h>
57 "This function is called in a class that is expected to be specialized "
58 "for auto-differentiable numbers.");
65 "This function is only available if deal.II is compiled with ADOL-C.");
79 <<
"The number of derivative levels that this auto-differentiable number type supports is "
81 <<
", but to perform the intended operation the number must support at least "
82 << arg2 <<
" levels.");
91 template <
typename ADNumberType,
typename T =
void>
110 template <
typename ADNumberType,
typename T =
void>
126 std::numeric_limits<typename Types<ADNumberType>::tape_index>::max();
145 template <
typename ADNumberType,
typename ScalarType,
typename T =
void>
249 const bool write_tapes_to_file);
254 std::vector<typename Types<ADNumberType>::tape_index>
364 reset(
const bool clear_registered_tapes);
375 print(std::ostream &stream)
const;
387 std::ostream &stream)
const;
408 const std::vector<ScalarType> &independent_variables)
const;
425 const std::vector<ScalarType> &independent_variables,
443 const std::vector<ScalarType> &independent_variables,
467 const unsigned int n_dependent_variables,
468 const std::vector<ScalarType> &independent_variables,
491 const unsigned int n_dependent_variables,
492 const std::vector<ScalarType> &independent_variables,
515 template <
typename ADNumberType,
typename ScalarType,
typename T =
void>
591 value(
const std::vector<ADNumberType> &dependent_variables)
const;
607 gradient(
const std::vector<ADNumberType> &independent_variables,
608 const std::vector<ADNumberType> &dependent_variables,
625 hessian(
const std::vector<ADNumberType> &independent_variables,
626 const std::vector<ADNumberType> &dependent_variables,
646 values(
const std::vector<ADNumberType> &dependent_variables,
667 jacobian(
const std::vector<ADNumberType> &independent_variables,
668 const std::vector<ADNumberType> &dependent_variables,
688# ifdef DEAL_II_WITH_ADOLC
693 template <
typename ADNumberType>
694 struct Types<ADNumberType,
695 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
696 NumberTypes::adolc_taped>>
714 template <
typename ADNumberType>
715 struct Numbers<ADNumberType,
716 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
717 NumberTypes::adolc_taped>>
760 template <
typename ADNumberType>
764 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
765 NumberTypes::adolc_taped>>
767 using scalar_type = double;
807 const bool write_tapes_to_file);
809 std::vector<typename Types<ADNumberType>::tape_index>
826 reset(
const bool clear_registered_tapes);
829 print(std::ostream &stream)
const;
834 std::ostream &stream)
const;
845 const std::vector<scalar_type> &independent_variables)
const;
849 const std::vector<scalar_type> &independent_variables,
854 const std::vector<scalar_type> &independent_variables,
866 const unsigned int n_dependent_variables,
867 const std::vector<scalar_type> &independent_variables,
872 const unsigned int n_dependent_variables,
873 const std::vector<scalar_type> &independent_variables,
897 bool is_recording_flag;
926 mutable std::map<typename Types<ADNumberType>::tape_index,
int> status;
934 bool use_stored_taped_buffer_sizes;
967 template <
typename ADNumberType>
971 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
972 NumberTypes::adolc_taped>>
974 using scalar_type = double;
1007 std::vector<typename Types<ADNumberType>::tape_index>
1026 print(std::ostream &stream)
const;
1030 std::ostream &)
const;
1041 const std::vector<scalar_type> &)
const;
1045 const std::vector<scalar_type> &,
1050 const std::vector<scalar_type> &,
1063 const std::vector<scalar_type> &,
1069 const std::vector<scalar_type> &,
1085 template <
typename ADNumberType>
1086 struct TapedDrivers<
1089 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1090 NumberTypes::adolc_taped>>
1092 using scalar_type = float;
1126 const bool write_tapes_to_file);
1128 std::vector<typename Types<ADNumberType>::tape_index>
1145 reset(
const bool clear_registered_tapes);
1148 print(std::ostream &stream)
const;
1153 std::ostream &stream)
const;
1164 const std::vector<scalar_type> &independent_variables)
const;
1168 const std::vector<scalar_type> &independent_variables,
1173 const std::vector<scalar_type> &independent_variables,
1185 const unsigned int n_dependent_variables,
1186 const std::vector<scalar_type> &independent_variables,
1191 const unsigned int n_dependent_variables,
1192 const std::vector<scalar_type> &independent_variables,
1202 vector_float_to_double(
const std::vector<float> &in)
const;
1207 TapedDrivers<ADNumberType, double> taped_driver;
1219 template <
typename ADNumberType,
typename ScalarType>
1220 struct TapelessDrivers<
1223 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1224 NumberTypes::sacado_rad ||
1225 ADNumberTraits<ADNumberType>::type_code ==
1226 NumberTypes::sacado_rad_dfad>>
1265 value(
const std::vector<ADNumberType> &dependent_variables)
const;
1268 gradient(
const std::vector<ADNumberType> &independent_variables,
1269 const std::vector<ADNumberType> &dependent_variables,
1273 hessian(
const std::vector<ADNumberType> &independent_variables,
1274 const std::vector<ADNumberType> &dependent_variables,
1285 values(
const std::vector<ADNumberType> &dependent_variables,
1289 jacobian(
const std::vector<ADNumberType> &independent_variables,
1290 const std::vector<ADNumberType> &dependent_variables,
1300 bool dependent_variable_marking_safe;
1309 template <
typename ADNumberType,
typename ScalarType>
1310 struct TapelessDrivers<
1313 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1314 NumberTypes::adolc_tapeless ||
1315 ADNumberTraits<ADNumberType>::type_code ==
1316 NumberTypes::sacado_dfad ||
1317 ADNumberTraits<ADNumberType>::type_code ==
1318 NumberTypes::sacado_dfad_dfad>>
1357 value(
const std::vector<ADNumberType> &dependent_variables)
const;
1360 gradient(
const std::vector<ADNumberType> &independent_variables,
1361 const std::vector<ADNumberType> &dependent_variables,
1365 hessian(
const std::vector<ADNumberType> &independent_variables,
1366 const std::vector<ADNumberType> &dependent_variables,
1377 values(
const std::vector<ADNumberType> &dependent_variables,
1381 jacobian(
const std::vector<ADNumberType> &independent_variables,
1382 const std::vector<ADNumberType> &dependent_variables,
1392 bool dependent_variable_marking_safe;
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcSupportedDerivativeLevels(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcRequiresADNumberSpecialization()
static ::ExceptionBase & ExcRequiresADOLC()
#define DeclException2(Exception2, type1, type2, outsequence)
#define DeclExceptionMsg(Exception, defaulttext)
static const Types< ADNumberType >::tape_index max_tape_index
static const Types< ADNumberType >::tape_index invalid_tape_index
void gradient(const typename Types< ADNumberType >::tape_index active_tape_index, const std::vector< ScalarType > &independent_variables, Vector< ScalarType > &gradient) const
bool is_recording() const
bool is_registered_tape(const typename Types< ADNumberType >::tape_index tape_index) const
void stop_taping(const typename Types< ADNumberType >::tape_index active_tape_index, const bool write_tapes_to_file)
void remove_tape(const typename Types< ADNumberType >::tape_index tape_index)
void start_taping(const typename Types< ADNumberType >::tape_index tape_index, const bool keep_independent_values)
void hessian(const typename Types< ADNumberType >::tape_index active_tape_index, const std::vector< ScalarType > &independent_variables, FullMatrix< ScalarType > &hessian) const
void set_tape_buffer_sizes(const typename Types< ADNumberType >::tape_buffer_sizes obufsize=64 *1024 *1024, const typename Types< ADNumberType >::tape_buffer_sizes lbufsize=64 *1024 *1024, const typename Types< ADNumberType >::tape_buffer_sizes vbufsize=64 *1024 *1024, const typename Types< ADNumberType >::tape_buffer_sizes tbufsize=64 *1024 *1024)
void activate_tape(const typename Types< ADNumberType >::tape_index tape_index)
bool last_action_requires_retaping() const
bool requires_retaping(const typename Types< ADNumberType >::tape_index tape_index) const
void print(std::ostream &stream) const
void print_tape_stats(const typename Types< ADNumberType >::tape_index tape_index, std::ostream &stream) const
ScalarType value(const typename Types< ADNumberType >::tape_index active_tape_index, const std::vector< ScalarType > &independent_variables) const
bool keep_independent_values() const
Types< ADNumberType >::tape_index active_tape_index() const
void reset(const bool clear_registered_tapes)
std::vector< typename Types< ADNumberType >::tape_index > get_registered_tape_indices() const
void values(const typename Types< ADNumberType >::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector< ScalarType > &independent_variables, Vector< ScalarType > &values) const
void jacobian(const typename Types< ADNumberType >::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector< ScalarType > &independent_variables, FullMatrix< ScalarType > &jacobian) const
void gradient(const std::vector< ADNumberType > &independent_variables, const std::vector< ADNumberType > &dependent_variables, Vector< ScalarType > &gradient) const
void allow_dependent_variable_marking()
void hessian(const std::vector< ADNumberType > &independent_variables, const std::vector< ADNumberType > &dependent_variables, FullMatrix< ScalarType > &hessian) const
void values(const std::vector< ADNumberType > &dependent_variables, Vector< ScalarType > &values) const
void jacobian(const std::vector< ADNumberType > &independent_variables, const std::vector< ADNumberType > &dependent_variables, FullMatrix< ScalarType > &jacobian) const
static void initialize_global_environment(const unsigned int n_independent_variables)
bool is_dependent_variable_marking_allowed() const
ScalarType value(const std::vector< ADNumberType > &dependent_variables) const
void prevent_dependent_variable_marking()
unsigned int tape_buffer_sizes