16 #ifndef dealii_differentiation_ad_ad_drivers_h 17 #define dealii_differentiation_ad_ad_drivers_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/types.h> 24 #include <deal.II/differentiation/ad/ad_number_traits.h> 25 #include <deal.II/differentiation/ad/ad_number_types.h> 27 #include <deal.II/lac/full_matrix.h> 28 #include <deal.II/lac/vector.h> 30 #ifdef DEAL_II_WITH_ADOLC 32 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
33 # include <adolc/internal/usrparms.h> 34 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
36 #endif // DEAL_II_WITH_ADOLC 41 DEAL_II_NAMESPACE_OPEN
59 "This function is called in a class that is expected to be specialized " 60 "for auto-differentiable numbers.");
67 "This function is only available if deal.II is compiled with ADOL-C.");
81 <<
"The number of derivative levels that this auto-differentiable number type supports is " 83 <<
", but to perform the intended operation the number must support at least " 84 << arg2 <<
" levels.");
93 template <
typename ADNumberType,
typename T =
void>
112 template <
typename ADNumberType,
typename T =
void>
128 std::numeric_limits<typename Types<ADNumberType>::tape_index>::max();
149 template <
typename ADNumberType,
typename ScalarType,
typename T =
void>
253 const bool write_tapes_to_file);
258 std::vector<typename Types<ADNumberType>::tape_index>
368 reset(
const bool clear_registered_tapes);
379 print(std::ostream &stream)
const;
391 std::ostream & stream)
const;
412 const std::vector<ScalarType> &independent_variables)
const;
429 const std::vector<ScalarType> &independent_variables,
430 Vector<ScalarType> &
gradient)
const;
447 const std::vector<ScalarType> &independent_variables,
471 const unsigned int n_dependent_variables,
472 const std::vector<ScalarType> &independent_variables,
473 Vector<ScalarType> &
values)
const;
495 const unsigned int n_dependent_variables,
496 const std::vector<ScalarType> &independent_variables,
521 template <
typename ADNumberType,
typename ScalarType,
typename T =
void>
597 value(
const std::vector<ADNumberType> &dependent_variables)
const;
613 gradient(
const std::vector<ADNumberType> &independent_variables,
614 const std::vector<ADNumberType> &dependent_variables,
615 Vector<ScalarType> &
gradient)
const;
631 hessian(
const std::vector<ADNumberType> &independent_variables,
632 const std::vector<ADNumberType> &dependent_variables,
652 values(
const std::vector<ADNumberType> &dependent_variables,
653 Vector<ScalarType> &
values)
const;
673 jacobian(
const std::vector<ADNumberType> &independent_variables,
674 const std::vector<ADNumberType> &dependent_variables,
694 # ifdef DEAL_II_WITH_ADOLC 699 template <
typename ADNumberType>
702 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
703 NumberTypes::adolc_taped>::type>
721 template <
typename ADNumberType>
724 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
725 NumberTypes::adolc_taped>::type>
768 template <
typename ADNumberType>
772 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
773 NumberTypes::adolc_taped>::type>
775 using scalar_type = double;
815 const bool write_tapes_to_file);
817 std::vector<typename Types<ADNumberType>::tape_index>
834 reset(
const bool clear_registered_tapes);
837 print(std::ostream &stream)
const;
842 std::ostream & stream)
const;
853 const std::vector<scalar_type> &independent_variables)
const;
857 const std::vector<scalar_type> &independent_variables,
858 Vector<scalar_type> &
gradient)
const;
862 const std::vector<scalar_type> &independent_variables,
874 const unsigned int n_dependent_variables,
875 const std::vector<scalar_type> &independent_variables,
876 Vector<scalar_type> &
values)
const;
880 const unsigned int n_dependent_variables,
881 const std::vector<scalar_type> &independent_variables,
905 bool is_recording_flag;
934 mutable std::map<typename Types<ADNumberType>::tape_index,
int> status;
942 bool use_stored_taped_buffer_sizes;
975 template <
typename ADNumberType>
979 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
980 NumberTypes::adolc_taped>::type>
982 using scalar_type = double;
1015 std::vector<typename Types<ADNumberType>::tape_index>
1034 print(std::ostream &stream)
const;
1038 std::ostream &)
const;
1049 const std::vector<scalar_type> &)
const;
1053 const std::vector<scalar_type> &,
1054 Vector<scalar_type> &)
const;
1058 const std::vector<scalar_type> &,
1071 const std::vector<scalar_type> &,
1072 Vector<scalar_type> &)
const;
1077 const std::vector<scalar_type> &,
1083 # endif // DEAL_II_WITH_ADOLC 1093 template <
typename ADNumberType>
1094 struct TapedDrivers<
1097 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
1098 NumberTypes::adolc_taped>::type>
1100 using scalar_type = float;
1134 const bool write_tapes_to_file);
1136 std::vector<typename Types<ADNumberType>::tape_index>
1153 reset(
const bool clear_registered_tapes);
1156 print(std::ostream &stream)
const;
1161 std::ostream & stream)
const;
1172 const std::vector<scalar_type> &independent_variables)
const;
1176 const std::vector<scalar_type> &independent_variables,
1177 Vector<scalar_type> &
gradient)
const;
1181 const std::vector<scalar_type> &independent_variables,
1193 const unsigned int n_dependent_variables,
1194 const std::vector<scalar_type> &independent_variables,
1195 Vector<scalar_type> &
values)
const;
1199 const unsigned int n_dependent_variables,
1200 const std::vector<scalar_type> &independent_variables,
1210 vector_float_to_double(
const std::vector<float> &in)
const;
1215 TapedDrivers<ADNumberType, double> taped_driver;
1227 template <
typename ADNumberType,
typename ScalarType>
1228 struct TapelessDrivers<
1231 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
1232 NumberTypes::sacado_rad ||
1233 ADNumberTraits<ADNumberType>::type_code ==
1234 NumberTypes::sacado_rad_dfad>::type>
1273 value(
const std::vector<ADNumberType> &dependent_variables)
const;
1276 gradient(
const std::vector<ADNumberType> &independent_variables,
1277 const std::vector<ADNumberType> &dependent_variables,
1278 Vector<ScalarType> &
gradient)
const;
1281 hessian(
const std::vector<ADNumberType> &independent_variables,
1282 const std::vector<ADNumberType> &dependent_variables,
1293 values(
const std::vector<ADNumberType> &dependent_variables,
1294 Vector<ScalarType> &
values)
const;
1297 jacobian(
const std::vector<ADNumberType> &independent_variables,
1298 const std::vector<ADNumberType> &dependent_variables,
1308 bool dependent_variable_marking_safe;
1317 template <
typename ADNumberType,
typename ScalarType>
1318 struct TapelessDrivers<
1321 typename
std::enable_if<ADNumberTraits<ADNumberType>::type_code ==
1322 NumberTypes::adolc_tapeless ||
1323 ADNumberTraits<ADNumberType>::type_code ==
1324 NumberTypes::sacado_dfad ||
1325 ADNumberTraits<ADNumberType>::type_code ==
1326 NumberTypes::sacado_dfad_dfad>::type>
1365 value(
const std::vector<ADNumberType> &dependent_variables)
const;
1368 gradient(
const std::vector<ADNumberType> &independent_variables,
1369 const std::vector<ADNumberType> &dependent_variables,
1370 Vector<ScalarType> &
gradient)
const;
1373 hessian(
const std::vector<ADNumberType> &independent_variables,
1374 const std::vector<ADNumberType> &dependent_variables,
1385 values(
const std::vector<ADNumberType> &dependent_variables,
1386 Vector<ScalarType> &
values)
const;
1389 jacobian(
const std::vector<ADNumberType> &independent_variables,
1390 const std::vector<ADNumberType> &dependent_variables,
1400 bool dependent_variable_marking_safe;
1409 DEAL_II_NAMESPACE_CLOSE
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
static ::ExceptionBase & ExcRequiresADNumberSpecialization()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcSupportedDerivativeLevels(std::size_t arg1, std::size_t arg2)
void values(const std::vector< ADNumberType > &dependent_variables, Vector< ScalarType > &values) const
Types< ADNumberType >::tape_index active_tape_index() const
static ::ExceptionBase & ExcRequiresADOLC()
ScalarType value(const typename Types< ADNumberType >::tape_index active_tape_index, const std::vector< ScalarType > &independent_variables) const
void jacobian(const std::vector< ADNumberType > &independent_variables, const std::vector< ADNumberType > &dependent_variables, FullMatrix< ScalarType > &jacobian) const
unsigned int tape_buffer_sizes
void activate_tape(const typename Types< ADNumberType >::tape_index tape_index)
bool is_dependent_variable_marking_allowed() 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 hessian(const typename Types< ADNumberType >::tape_index active_tape_index, const std::vector< ScalarType > &independent_variables, FullMatrix< ScalarType > &hessian) const
bool keep_independent_values() const
static const Types< ADNumberType >::tape_index invalid_tape_index
bool requires_retaping(const typename Types< ADNumberType >::tape_index tape_index) const
void print_tape_stats(const typename Types< ADNumberType >::tape_index tape_index, std::ostream &stream) const
#define DeclExceptionMsg(Exception, defaulttext)
void start_taping(const typename Types< ADNumberType >::tape_index tape_index, const bool keep_independent_values)
ScalarType value(const std::vector< ADNumberType > &dependent_variables) const
bool is_recording() const
std::vector< typename Types< ADNumberType >::tape_index > get_registered_tape_indices() 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 print(std::ostream &stream) const
void gradient(const typename Types< ADNumberType >::tape_index active_tape_index, const std::vector< ScalarType > &independent_variables, Vector< ScalarType > &gradient) const
bool is_registered_tape(const typename Types< ADNumberType >::tape_index tape_index) const
static void initialize_global_environment(const unsigned int n_independent_variables)
void reset(const bool clear_registered_tapes)
static const Types< ADNumberType >::tape_index max_tape_index
void prevent_dependent_variable_marking()
void gradient(const std::vector< ADNumberType > &independent_variables, const std::vector< ADNumberType > &dependent_variables, Vector< ScalarType > &gradient) const
void stop_taping(const typename Types< ADNumberType >::tape_index active_tape_index, const bool write_tapes_to_file)
void hessian(const std::vector< ADNumberType > &independent_variables, const std::vector< ADNumberType > &dependent_variables, FullMatrix< ScalarType > &hessian) const
bool last_action_requires_retaping() const
void allow_dependent_variable_marking()
void remove_tape(const typename Types< ADNumberType >::tape_index tape_index)