16#ifndef dealii_differentiation_ad_ad_drivers_h
17#define dealii_differentiation_ad_ad_drivers_h
30#ifdef DEAL_II_WITH_ADOLC
32# include <adolc/internal/usrparms.h>
58 "This function is called in a class that is expected to be specialized "
59 "for auto-differentiable numbers.");
66 "This function is only available if deal.II is compiled with ADOL-C.");
80 <<
"The number of derivative levels that this auto-differentiable number type supports is "
82 <<
", but to perform the intended operation the number must support at least "
83 << arg2 <<
" levels.");
92 template <
typename ADNumberType,
typename T =
void>
111 template <
typename ADNumberType,
typename T =
void>
127 std::numeric_limits<typename Types<ADNumberType>::tape_index>::max();
146 template <
typename ADNumberType,
typename ScalarType,
typename T =
void>
250 const bool write_tapes_to_file);
255 std::vector<typename Types<ADNumberType>::tape_index>
365 reset(
const bool clear_registered_tapes);
376 print(std::ostream &stream)
const;
388 std::ostream & stream)
const;
409 const std::vector<ScalarType> &independent_variables)
const;
426 const std::vector<ScalarType> &independent_variables,
444 const std::vector<ScalarType> &independent_variables,
468 const unsigned int n_dependent_variables,
469 const std::vector<ScalarType> &independent_variables,
492 const unsigned int n_dependent_variables,
493 const std::vector<ScalarType> &independent_variables,
516 template <
typename ADNumberType,
typename ScalarType,
typename T =
void>
592 value(
const std::vector<ADNumberType> &dependent_variables)
const;
608 gradient(
const std::vector<ADNumberType> &independent_variables,
609 const std::vector<ADNumberType> &dependent_variables,
626 hessian(
const std::vector<ADNumberType> &independent_variables,
627 const std::vector<ADNumberType> &dependent_variables,
647 values(
const std::vector<ADNumberType> &dependent_variables,
668 jacobian(
const std::vector<ADNumberType> &independent_variables,
669 const std::vector<ADNumberType> &dependent_variables,
689# ifdef DEAL_II_WITH_ADOLC
694 template <
typename ADNumberType>
695 struct Types<ADNumberType,
696 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
697 NumberTypes::adolc_taped>>
715 template <
typename ADNumberType>
716 struct Numbers<ADNumberType,
717 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
718 NumberTypes::adolc_taped>>
761 template <
typename ADNumberType>
765 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
766 NumberTypes::adolc_taped>>
768 using scalar_type = double;
808 const bool write_tapes_to_file);
810 std::vector<typename Types<ADNumberType>::tape_index>
827 reset(
const bool clear_registered_tapes);
830 print(std::ostream &stream)
const;
835 std::ostream & stream)
const;
846 const std::vector<scalar_type> &independent_variables)
const;
850 const std::vector<scalar_type> &independent_variables,
855 const std::vector<scalar_type> &independent_variables,
867 const unsigned int n_dependent_variables,
868 const std::vector<scalar_type> &independent_variables,
873 const unsigned int n_dependent_variables,
874 const std::vector<scalar_type> &independent_variables,
898 bool is_recording_flag;
927 mutable std::map<typename Types<ADNumberType>::tape_index,
int> status;
935 bool use_stored_taped_buffer_sizes;
968 template <
typename ADNumberType>
972 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
973 NumberTypes::adolc_taped>>
975 using scalar_type = double;
1008 std::vector<typename Types<ADNumberType>::tape_index>
1027 print(std::ostream &stream)
const;
1031 std::ostream &)
const;
1042 const std::vector<scalar_type> &)
const;
1046 const std::vector<scalar_type> &,
1051 const std::vector<scalar_type> &,
1064 const std::vector<scalar_type> &,
1070 const std::vector<scalar_type> &,
1086 template <
typename ADNumberType>
1087 struct TapedDrivers<
1090 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1091 NumberTypes::adolc_taped>>
1093 using scalar_type = float;
1127 const bool write_tapes_to_file);
1129 std::vector<typename Types<ADNumberType>::tape_index>
1146 reset(
const bool clear_registered_tapes);
1149 print(std::ostream &stream)
const;
1154 std::ostream & stream)
const;
1165 const std::vector<scalar_type> &independent_variables)
const;
1169 const std::vector<scalar_type> &independent_variables,
1174 const std::vector<scalar_type> &independent_variables,
1186 const unsigned int n_dependent_variables,
1187 const std::vector<scalar_type> &independent_variables,
1192 const unsigned int n_dependent_variables,
1193 const std::vector<scalar_type> &independent_variables,
1203 vector_float_to_double(
const std::vector<float> &in)
const;
1208 TapedDrivers<ADNumberType, double> taped_driver;
1220 template <
typename ADNumberType,
typename ScalarType>
1221 struct TapelessDrivers<
1224 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1225 NumberTypes::sacado_rad ||
1226 ADNumberTraits<ADNumberType>::type_code ==
1227 NumberTypes::sacado_rad_dfad>>
1266 value(
const std::vector<ADNumberType> &dependent_variables)
const;
1269 gradient(
const std::vector<ADNumberType> &independent_variables,
1270 const std::vector<ADNumberType> &dependent_variables,
1274 hessian(
const std::vector<ADNumberType> &independent_variables,
1275 const std::vector<ADNumberType> &dependent_variables,
1286 values(
const std::vector<ADNumberType> &dependent_variables,
1290 jacobian(
const std::vector<ADNumberType> &independent_variables,
1291 const std::vector<ADNumberType> &dependent_variables,
1301 bool dependent_variable_marking_safe;
1310 template <
typename ADNumberType,
typename ScalarType>
1311 struct TapelessDrivers<
1314 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1315 NumberTypes::adolc_tapeless ||
1316 ADNumberTraits<ADNumberType>::type_code ==
1317 NumberTypes::sacado_dfad ||
1318 ADNumberTraits<ADNumberType>::type_code ==
1319 NumberTypes::sacado_dfad_dfad>>
1358 value(
const std::vector<ADNumberType> &dependent_variables)
const;
1361 gradient(
const std::vector<ADNumberType> &independent_variables,
1362 const std::vector<ADNumberType> &dependent_variables,
1366 hessian(
const std::vector<ADNumberType> &independent_variables,
1367 const std::vector<ADNumberType> &dependent_variables,
1378 values(
const std::vector<ADNumberType> &dependent_variables,
1382 jacobian(
const std::vector<ADNumberType> &independent_variables,
1383 const std::vector<ADNumberType> &dependent_variables,
1393 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