26 template <
typename ScalarT>
27 ScalarT
func(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c) {
34 double& drda,
double& drdb,
35 double& d2rda2,
double& d2rdb2,
double& d2rdadb)
46 template <
typename ScalarT>
48 ScalarT& r, ScalarT& drda, ScalarT& drdb) {
50 FadType a_fad(2, 0, a);
51 FadType b_fad(2, 1, b);
54 FadType r_fad =
func(a_fad, b_fad, c_fad);
70 template <
typename ScalarT>
72 const ScalarT& v_a,
const ScalarT& v_b,
73 ScalarT& r, ScalarT& drda, ScalarT& drdb,
74 ScalarT& z_a, ScalarT& z_b) {
81 FadType a_fad(1, a); a_fad.fastAccessDx(0) = v_a;
82 FadType b_fad(1, b); b_fad.fastAccessDx(0) = v_b;
85 FadType r_fad, drda_fad, drdb_fad;
89 drda = drda_fad.val();
90 drdb = drdb_fad.val();
95 int main(
int argc,
char **argv)
109 double r_ad, drda_ad, drdb_ad, z_a_ad, z_b_ad;
110 func_and_deriv2(a, b, c, v_a, v_b, r_ad, drda_ad, drdb_ad, z_a_ad, z_b_ad);
113 double r =
func(a, b, c);
116 double drda, drdb, d2rda2, d2rdb2, d2rdadb;
118 double z_a = d2rda2*v_a + d2rdadb*v_b;
119 double z_b = d2rdadb*v_a + d2rdb2*v_b;
124 std::cout.setf(std::ios::scientific);
125 std::cout.precision(p);
126 std::cout <<
" r = " << std::setw(w) << r <<
" (original) == "
127 << std::setw(w) << r_ad <<
" (AD) Error = " << std::setw(w)
128 << r - r_ad << std::endl
129 <<
"dr/da = " << std::setw(w) << drda <<
" (analytic) == "
130 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
131 << drda - drda_ad << std::endl
132 <<
"dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
133 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
134 << drdb - drdb_ad << std::endl
135 <<
"z_a = " << std::setw(w) << z_a <<
" (analytic) == "
136 << std::setw(w) << z_a_ad <<
" (AD) Error = " << std::setw(w)
137 << z_a - z_a_ad << std::endl
138 <<
"z_b = " << std::setw(w) << z_b <<
" (analytic) == "
139 << std::setw(w) << z_b_ad <<
" (AD) Error = " << std::setw(w)
140 << z_b - z_b_ad << std::endl;
142 double tol = 1.0e-14;
148 std::cout <<
"\nExample passed!" << std::endl;
152 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
Sacado::Fad::DFad< double > FadType
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
void func_and_deriv2(const ScalarT &a, const ScalarT &b, const ScalarT &c, const ScalarT &v_a, const ScalarT &v_b, ScalarT &r, ScalarT &drda, ScalarT &drdb, ScalarT &z_a, ScalarT &z_b)
void analytic_deriv(double a, double b, double c, double &drda, double &drdb, double &d2rda2, double &d2rdb2, double &d2rdadb)
const T func(int n, T *x)
SACADO_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
void func_and_deriv(const ScalarT &a, const ScalarT &b, const ScalarT &c, ScalarT &r, ScalarT &drda, ScalarT &drdb)