646 << counts[15] <<
'\n'
647 <<
"Number of 'abs' calls that can switch branch: " << counts[16]
649 <<
"Number of parameters (doubles) interchangeable without retaping: "
650 << counts[17] <<
'\n'
655 template <
typename ADNumberType>
659 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
663 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
666 const std::vector<scalar_type> &independent_variables)
const
668 Assert(is_registered_tape(active_tape_index),
669 ExcMessage(
"This tape has not yet been recorded."));
671 scalar_type value = 0.0;
673 status[active_tape_index] =
674 ::function(active_tape_index,
676 independent_variables.size(),
677 const_cast<double *
>(independent_variables.data()),
684 template <
typename ADNumberType>
688 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
691 const std::vector<scalar_type> &independent_variables,
699 Assert(gradient.size() == independent_variables.size(),
701 independent_variables.size()));
702 Assert(is_registered_tape(active_tape_index),
703 ExcMessage(
"This tape has not yet been recorded."));
708 status[active_tape_index] =
709 ::gradient(active_tape_index,
710 independent_variables.size(),
711 const_cast<scalar_type *
>(independent_variables.data()),
716 template <
typename ADNumberType>
718 TapedDrivers<ADNumberType,
720 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
723 const std::vector<scalar_type> &independent_variables,
731 Assert(hessian.m() == independent_variables.size(),
733 Assert(hessian.n() == independent_variables.size(),
735 Assert(is_registered_tape(active_tape_index),
736 ExcMessage(
"This tape has not yet been recorded."));
738 const unsigned int n_independent_variables = independent_variables.size();
739 std::vector<scalar_type *> H(n_independent_variables);
740 for (
unsigned int i = 0; i < n_independent_variables; ++i)
741 H[i] = &hessian[i][0];
743 status[active_tape_index] =
744 ::hessian(active_tape_index,
745 n_independent_variables,
746 const_cast<scalar_type *
>(independent_variables.data()),
752 for (
unsigned int i = 0; i < n_independent_variables; ++i)
753 for (
unsigned int j = 0; j < i; ++j)
754 hessian[j][i] = hessian[i][j];
758 template <
typename ADNumberType>
760 TapedDrivers<ADNumberType,
762 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
765 const unsigned int n_dependent_variables,
766 const std::vector<scalar_type> &independent_variables,
769 Assert(values.size() == n_dependent_variables,
771 Assert(is_registered_tape(active_tape_index),
772 ExcMessage(
"This tape has not yet been recorded."));
777 status[active_tape_index] =
778 ::function(active_tape_index,
779 n_dependent_variables,
780 independent_variables.size(),
781 const_cast<scalar_type *
>(independent_variables.data()),
786 template <
typename ADNumberType>
788 TapedDrivers<ADNumberType,
790 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
793 const unsigned int n_dependent_variables,
794 const std::vector<scalar_type> &independent_variables,
797 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
800 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
802 Assert(jacobian.
m() == n_dependent_variables,
804 Assert(jacobian.
n() == independent_variables.size(),
806 Assert(is_registered_tape(active_tape_index),
807 ExcMessage(
"This tape has not yet been recorded."));
809 std::vector<scalar_type *> J(n_dependent_variables);
810 for (
unsigned int i = 0; i < n_dependent_variables; ++i)
811 J[i] = &jacobian[i][0];
813 status[active_tape_index] = ::jacobian(active_tape_index,
814 n_dependent_variables,
815 independent_variables.size(),
816 independent_variables.data(),
824 template <
typename ADNumberType>
826 TapedDrivers<ADNumberType,
828 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
837 template <
typename ADNumberType>
842 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
850 template <
typename ADNumberType>
852 TapedDrivers<ADNumberType,
854 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
856 keep_independent_values()
const
863 template <
typename ADNumberType>
865 TapedDrivers<ADNumberType,
867 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
876 template <
typename ADNumberType>
878 TapedDrivers<ADNumberType,
880 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
882 set_tape_buffer_sizes(
892 template <
typename ADNumberType>
894 TapedDrivers<ADNumberType,
896 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
904 template <
typename ADNumberType>
906 TapedDrivers<ADNumberType,
908 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
916 template <
typename ADNumberType>
917 std::vector<typename Types<ADNumberType>::tape_index>
918 TapedDrivers<ADNumberType,
920 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
922 get_registered_tape_indices()
const
925 return std::vector<typename Types<ADNumberType>::tape_index>();
929 template <
typename ADNumberType>
931 TapedDrivers<ADNumberType,
933 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
941 template <
typename ADNumberType>
943 TapedDrivers<ADNumberType,
945 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
954 template <
typename ADNumberType>
956 TapedDrivers<ADNumberType,
958 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
960 last_action_requires_retaping()
const
967 template <
typename ADNumberType>
969 TapedDrivers<ADNumberType,
971 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
979 template <
typename ADNumberType>
981 TapedDrivers<ADNumberType,
983 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
990 template <
typename ADNumberType>
992 TapedDrivers<ADNumberType,
994 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1002 template <
typename ADNumberType>
1004 TapedDrivers<ADNumberType,
1006 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1009 std::ostream &)
const
1015 template <
typename ADNumberType>
1016 typename TapedDrivers<
1019 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1021 TapedDrivers<ADNumberType,
1023 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1026 const std::vector<scalar_type> &)
const
1033 template <
typename ADNumberType>
1035 TapedDrivers<ADNumberType,
1037 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1040 const std::vector<scalar_type> &,
1047 template <
typename ADNumberType>
1049 TapedDrivers<ADNumberType,
1051 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1054 const std::vector<scalar_type> &,
1061 template <
typename ADNumberType>
1063 TapedDrivers<ADNumberType,
1065 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1069 const std::vector<scalar_type> &,
1076 template <
typename ADNumberType>
1078 TapedDrivers<ADNumberType,
1080 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1084 const std::vector<scalar_type> &,
1096 template <
typename ADNumberType>
1098 TapedDrivers<ADNumberType,
1100 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1106 return taped_driver.is_recording();
1110 template <
typename ADNumberType>
1115 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1120 return taped_driver.active_tape_index();
1124 template <
typename ADNumberType>
1126 TapedDrivers<ADNumberType,
1128 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1130 keep_independent_values()
const
1132 return taped_driver.keep_independent_values();
1136 template <
typename ADNumberType>
1138 TapedDrivers<ADNumberType,
1140 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1147 return taped_driver.is_registered_tape(tape_index);
1151 template <
typename ADNumberType>
1153 TapedDrivers<ADNumberType,
1155 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1157 set_tape_buffer_sizes(
1165 taped_driver.set_tape_buffer_sizes(obufsize,
1172 template <
typename ADNumberType>
1174 TapedDrivers<ADNumberType,
1176 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1179 const bool keep_independent_values)
1183 taped_driver.start_taping(tape_index, keep_independent_values);
1187 template <
typename ADNumberType>
1189 TapedDrivers<ADNumberType,
1191 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1195 const bool write_tapes_to_file)
1199 taped_driver.stop_taping(active_tape_index, write_tapes_to_file);
1203 template <
typename ADNumberType>
1204 std::vector<typename Types<ADNumberType>::tape_index>
1205 TapedDrivers<ADNumberType,
1207 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1209 get_registered_tape_indices()
const
1211 return taped_driver.get_registered_tape_indices();
1215 template <
typename ADNumberType>
1217 TapedDrivers<ADNumberType,
1219 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1223 taped_driver.activate_tape(tape_index);
1227 template <
typename ADNumberType>
1229 TapedDrivers<ADNumberType,
1231 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1236 return taped_driver.requires_retaping(tape_index);
1240 template <
typename ADNumberType>
1242 TapedDrivers<ADNumberType,
1244 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1246 last_action_requires_retaping()
const
1248 return taped_driver.last_action_requires_retaping();
1252 template <
typename ADNumberType>
1254 TapedDrivers<ADNumberType,
1256 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1260 taped_driver.remove_tape(tape_index);
1264 template <
typename ADNumberType>
1266 TapedDrivers<ADNumberType,
1268 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1270 reset(
const bool clear_registered_tapes)
1272 taped_driver.reset(clear_registered_tapes);
1276 template <
typename ADNumberType>
1278 TapedDrivers<ADNumberType,
1280 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1285 taped_driver.print(stream);
1289 template <
typename ADNumberType>
1291 TapedDrivers<ADNumberType,
1293 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1297 std::ostream &stream)
const
1301 taped_driver.print_tape_stats(tape_index, stream);
1305 template <
typename ADNumberType>
1306 typename TapedDrivers<
1309 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1311 TapedDrivers<ADNumberType,
1313 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1316 const std::vector<scalar_type> &independent_variables)
const
1320 return taped_driver.value(active_tape_index,
1321 vector_float_to_double(independent_variables));
1325 template <
typename ADNumberType>
1327 TapedDrivers<ADNumberType,
1329 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1332 const std::vector<scalar_type> &independent_variables,
1338 taped_driver.gradient(active_tape_index,
1339 vector_float_to_double(independent_variables),
1345 template <
typename ADNumberType>
1347 TapedDrivers<ADNumberType,
1349 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1352 const std::vector<scalar_type> &independent_variables,
1358 taped_driver.hessian(active_tape_index,
1359 vector_float_to_double(independent_variables),
1365 template <
typename ADNumberType>
1367 TapedDrivers<ADNumberType,
1369 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1372 const unsigned int n_dependent_variables,
1373 const std::vector<scalar_type> &independent_variables,
1379 taped_driver.values(active_tape_index,
1380 n_dependent_variables,
1381 vector_float_to_double(independent_variables),
1383 values = values_double;
1387 template <
typename ADNumberType>
1389 TapedDrivers<ADNumberType,
1391 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1394 const unsigned int n_dependent_variables,
1395 const std::vector<scalar_type> &independent_variables,
1401 taped_driver.jacobian(active_tape_index,
1402 n_dependent_variables,
1403 vector_float_to_double(independent_variables),
1405 jacobian = jacobian_double;
1410 template <
typename ADNumberType>
1412 TapedDrivers<ADNumberType,
1414 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1416 vector_float_to_double(
const std::vector<float> &in)
const
1418 std::vector<double> out(in.size());
1419 std::copy(in.begin(), in.end(), out.begin());
1428 template <
typename ADNumberType,
typename ScalarType,
typename T>
1436 template <
typename ADNumberType,
typename ScalarType,
typename T>
1444 template <
typename ADNumberType,
typename ScalarType,
typename T>
1452 template <
typename ADNumberType,
typename ScalarType,
typename T>
1462 template <
typename ADNumberType,
typename ScalarType,
typename T>
1465 const std::vector<ADNumberType> &)
const
1468 return ScalarType(0.0);
1472 template <
typename ADNumberType,
typename ScalarType,
typename T>
1475 const std::vector<ADNumberType> &,
1476 const std::vector<ADNumberType> &,
1483 template <
typename ADNumberType,
typename ScalarType,
typename T>
1486 const std::vector<ADNumberType> &,
1487 const std::vector<ADNumberType> &,
1494 template <
typename ADNumberType,
typename ScalarType,
typename T>
1497 const std::vector<ADNumberType> &,
1504 template <
typename ADNumberType,
typename ScalarType,
typename T>
1507 const std::vector<ADNumberType> &,
1508 const std::vector<ADNumberType> &,
1521 template <
typename ADNumberType>
1529# ifdef DEAL_II_TRILINOS_WITH_SACADO
1540 template <
typename ADNumberType>
1545 ADNumberType &dependent_variable)
1555 ADNumberType::Outvar_Gradcomp(dependent_variable);
1565 template <
typename ADNumberType>
1572# ifdef DEAL_II_WITH_ADOLC
1582 template <
typename ADNumberType>
1583 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1587# ifdef DEAL_II_ADOLC_WITH_TAPELESS_REFCOUNTING
1602 const std::size_t n_live_variables = adtl::refcounter::getNumLiveVar();
1603 if (n_live_variables == 0)
1605 adtl::setNumDir(n_directional_derivatives);
1614 const std::size_t n_set_directional_derivatives = adtl::getNumDir();
1615 if (n_directional_derivatives > n_set_directional_derivatives)
1617 n_live_variables == 0,
1619 "There are currently " + std::to_string(n_live_variables) +
1621 "adtl::adouble variables in existence. They currently "
1623 std::to_string(n_set_directional_derivatives) +
1624 " directional derivatives "
1625 "but you wish to increase this to " +
1626 std::to_string(n_directional_derivatives) +
1628 "To safely change (or more specifically in this case, "
1629 "increase) the number of directional derivatives, there "
1630 "must be no tapeless doubles in local/global scope."));
1636 adtl::setNumDir(n_directional_derivatives);
1642 template <
typename ADNumberType>
1643 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1661 template <
typename ADNumberType,
typename ScalarType>
1665 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1667 ADNumberTraits<ADNumberType>::type_code ==
1669 : dependent_variable_marking_safe(false)
1674 template <
typename ADNumberType,
typename ScalarType>
1676 TapelessDrivers<ADNumberType,
1678 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1680 ADNumberTraits<ADNumberType>::type_code ==
1682 initialize_global_environment(
const unsigned int n_independent_variables)
1688 template <
typename ADNumberType,
typename ScalarType>
1695 ADNumberTraits<ADNumberType>::type_code ==
1698 dependent_variable_marking_safe =
true;
1702 template <
typename ADNumberType,
typename ScalarType>
1709 ADNumberTraits<ADNumberType>::type_code ==
1712 dependent_variable_marking_safe =
false;
1716 template <
typename ADNumberType,
typename ScalarType>
1718 TapelessDrivers<ADNumberType,
1720 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1722 ADNumberTraits<ADNumberType>::type_code ==
1724 is_dependent_variable_marking_allowed()
const
1726 return dependent_variable_marking_safe;
1730 template <
typename ADNumberType,
typename ScalarType>
1732 TapelessDrivers<ADNumberType,
1734 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1736 ADNumberTraits<ADNumberType>::type_code ==
1738 value(
const std::vector<ADNumberType> &dependent_variables)
const
1740 Assert(dependent_variables.size() == 1,
1742 return ADNumberTraits<ADNumberType>::get_scalar_value(
1743 dependent_variables[0]);
1747 template <
typename ADNumberType,
typename ScalarType>
1749 TapelessDrivers<ADNumberType,
1751 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1753 ADNumberTraits<ADNumberType>::type_code ==
1755 gradient(
const std::vector<ADNumberType> &independent_variables,
1756 const std::vector<ADNumberType> &dependent_variables,
1759 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
1762 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
1764 Assert(dependent_variables.size() == 1,
1768 independent_variables.size()));
1773 const_cast<ADNumberType &
>(dependent_variables[0]));
1774 const std::size_t n_independent_variables = independent_variables.size();
1775 for (
unsigned int i = 0; i < n_independent_variables; ++i)
1777 ADNumberTraits<ADNumberType>::get_directional_derivative(
1778 independent_variables[i], 0 ));
1782 template <
typename ADNumberType,
typename ScalarType>
1784 TapelessDrivers<ADNumberType,
1786 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1788 ADNumberTraits<ADNumberType>::type_code ==
1790 hessian(
const std::vector<ADNumberType> &independent_variables,
1791 const std::vector<ADNumberType> &dependent_variables,
1794 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
1797 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
1799 Assert(dependent_variables.size() == 1,
1809 const_cast<ADNumberType &
>(dependent_variables[0]));
1810 const std::size_t n_independent_variables = independent_variables.size();
1811 for (
unsigned int i = 0; i < n_independent_variables; ++i)
1813 using derivative_type =
1814 typename ADNumberTraits<ADNumberType>::derivative_type;
1815 const derivative_type gradient_i =
1816 ADNumberTraits<ADNumberType>::get_directional_derivative(
1817 independent_variables[i], i);
1819 for (
unsigned int j = 0; j <= i; ++j)
1824 const ScalarType hessian_ij =
1826 ADNumberTraits<derivative_type>::get_directional_derivative(
1836 template <
typename ADNumberType,
typename ScalarType>
1838 TapelessDrivers<ADNumberType,
1840 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1842 ADNumberTraits<ADNumberType>::type_code ==
1844 values(
const std::vector<ADNumberType> &dependent_variables,
1847 Assert(values.size() == dependent_variables.size(),
1850 const std::size_t n_dependent_variables = dependent_variables.size();
1851 for (
unsigned int i = 0; i < n_dependent_variables; ++i)
1852 values[i] = ADNumberTraits<ADNumberType>::get_scalar_value(
1853 dependent_variables[i]);
1857 template <
typename ADNumberType,
typename ScalarType>
1859 TapelessDrivers<ADNumberType,
1861 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1863 ADNumberTraits<ADNumberType>::type_code ==
1865 jacobian(
const std::vector<ADNumberType> &independent_variables,
1866 const std::vector<ADNumberType> &dependent_variables,
1869 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
1872 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
1874 Assert(jacobian.
m() == dependent_variables.size(),
1876 Assert(jacobian.
n() == independent_variables.size(),
1879 const std::size_t n_independent_variables = independent_variables.size();
1880 const std::size_t n_dependent_variables = dependent_variables.size();
1891 using accumulation_type =
1892 typename ADNumberTraits<ADNumberType>::derivative_type;
1893 std::vector<accumulation_type> rad_accumulation(
1894 n_independent_variables,
1897 for (
unsigned int i = 0; i < n_dependent_variables; ++i)
1900 const_cast<ADNumberType &
>(dependent_variables[i]));
1901 for (
unsigned int j = 0; j < n_independent_variables; ++j)
1903 const accumulation_type df_i_dx_j =
1904 ADNumberTraits<ADNumberType>::get_directional_derivative(
1905 independent_variables[j],
1907 rad_accumulation[j];
1910 rad_accumulation[j] += df_i_dx_j;
1922 template <
typename ADNumberType,
typename ScalarType>
1926 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1928 ADNumberTraits<ADNumberType>::type_code ==
1930 ADNumberTraits<ADNumberType>::type_code ==
1932 : dependent_variable_marking_safe(false)
1937 template <
typename ADNumberType,
typename ScalarType>
1939 TapelessDrivers<ADNumberType,
1941 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1943 ADNumberTraits<ADNumberType>::type_code ==
1945 ADNumberTraits<ADNumberType>::type_code ==
1947 initialize_global_environment(
const unsigned int n_independent_variables)
1953 template <
typename ADNumberType,
typename ScalarType>
1959 ADNumberTraits<ADNumberType>::type_code ==
1962 ADNumberTraits<ADNumberType>::type_code ==
1965 dependent_variable_marking_safe =
true;
1969 template <
typename ADNumberType,
typename ScalarType>
1975 ADNumberTraits<ADNumberType>::type_code ==
1978 ADNumberTraits<ADNumberType>::type_code ==
1981 dependent_variable_marking_safe =
false;
1985 template <
typename ADNumberType,
typename ScalarType>
1987 TapelessDrivers<ADNumberType,
1989 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1991 ADNumberTraits<ADNumberType>::type_code ==
1993 ADNumberTraits<ADNumberType>::type_code ==
1995 is_dependent_variable_marking_allowed()
const
1997 return dependent_variable_marking_safe;
2001 template <
typename ADNumberType,
typename ScalarType>
2003 TapelessDrivers<ADNumberType,
2005 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
2007 ADNumberTraits<ADNumberType>::type_code ==
2009 ADNumberTraits<ADNumberType>::type_code ==
2011 value(
const std::vector<ADNumberType> &dependent_variables)
const
2013 Assert(dependent_variables.size() == 1,
2015 return ADNumberTraits<ADNumberType>::get_scalar_value(
2016 dependent_variables[0]);
2020 template <
typename ADNumberType,
typename ScalarType>
2022 TapelessDrivers<ADNumberType,
2024 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
2026 ADNumberTraits<ADNumberType>::type_code ==
2028 ADNumberTraits<ADNumberType>::type_code ==
2030 gradient(
const std::vector<ADNumberType> &independent_variables,
2031 const std::vector<ADNumberType> &dependent_variables,
2034 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
2037 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
2039 Assert(dependent_variables.size() == 1,
2043 independent_variables.size()));
2047 const std::size_t n_independent_variables = independent_variables.size();
2048 for (
unsigned int i = 0; i < n_independent_variables; ++i)
2050 ADNumberTraits<ADNumberType>::get_directional_derivative(
2051 dependent_variables[0], i));
2055 template <
typename ADNumberType,
typename ScalarType>
2057 TapelessDrivers<ADNumberType,
2059 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
2061 ADNumberTraits<ADNumberType>::type_code ==
2063 ADNumberTraits<ADNumberType>::type_code ==
2065 hessian(
const std::vector<ADNumberType> &independent_variables,
2066 const std::vector<ADNumberType> &dependent_variables,
2069 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
2072 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
2074 Assert(dependent_variables.size() == 1,
2083 const std::size_t n_independent_variables = independent_variables.size();
2084 for (
unsigned int i = 0; i < n_independent_variables; ++i)
2086 using derivative_type =
2087 typename ADNumberTraits<ADNumberType>::derivative_type;
2088 const derivative_type gradient_i =
2089 ADNumberTraits<ADNumberType>::get_directional_derivative(
2090 dependent_variables[0], i);
2092 for (
unsigned int j = 0; j <= i; ++j)
2097 const ScalarType hessian_ij =
2099 ADNumberTraits<derivative_type>::get_directional_derivative(
2109 template <
typename ADNumberType,
typename ScalarType>
2111 TapelessDrivers<ADNumberType,
2113 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
2115 ADNumberTraits<ADNumberType>::type_code ==
2117 ADNumberTraits<ADNumberType>::type_code ==
2119 values(
const std::vector<ADNumberType> &dependent_variables,
2122 Assert(values.size() == dependent_variables.size(),
2125 const std::size_t n_dependent_variables = dependent_variables.size();
2126 for (
unsigned int i = 0; i < n_dependent_variables; ++i)
2127 values[i] = ADNumberTraits<ADNumberType>::get_scalar_value(
2128 dependent_variables[i]);
2132 template <
typename ADNumberType,
typename ScalarType>
2134 TapelessDrivers<ADNumberType,
2136 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
2138 ADNumberTraits<ADNumberType>::type_code ==
2140 ADNumberTraits<ADNumberType>::type_code ==
2142 jacobian(
const std::vector<ADNumberType> &independent_variables,
2143 const std::vector<ADNumberType> &dependent_variables,
2146 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
2149 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
2151 Assert(jacobian.
m() == dependent_variables.size(),
2153 Assert(jacobian.
n() == independent_variables.size(),
2156 const std::size_t n_independent_variables = independent_variables.size();
2157 const std::size_t n_dependent_variables = dependent_variables.size();
2161 for (
unsigned int i = 0; i < n_dependent_variables; ++i)
2162 for (
unsigned int j = 0; j < n_independent_variables; ++j)
2164 ADNumberTraits<ADNumberType>::get_directional_derivative(
2165 dependent_variables[i], j));
2174# include "ad_drivers.inst"
2175# ifdef DEAL_II_WITH_ADOLC
2176# include "ad_drivers.inst1"
2178# ifdef DEAL_II_TRILINOS_WITH_SACADO
2179# include "ad_drivers.inst2"