24 #ifdef PACKAGE_BUGREPORT
25 #undef PACKAGE_BUGREPORT
30 #ifdef PACKAGE_TARNAME
31 #undef PACKAGE_TARNAME
33 #ifdef PACKAGE_VERSION
34 #undef PACKAGE_VERSION
39 #include "adolc/adouble.h"
40 #include "adolc/drivers/drivers.h"
41 #include "adolc/interfaces.h"
42 #include "adolc/taping.h"
52 static const unsigned int nqp = 2;
53 static const unsigned int nnode = 2;
63 for (
unsigned int i=0;
i<
nqp;
i++) {
68 jac[
i] = 0.5*mesh_spacing;
71 phi[
i][0] = 0.5*(1.0 - xi[
i]);
72 phi[
i][1] = 0.5*(1.0 + xi[
i]);
79 template <
class FadType>
82 const std::vector<double>&
x,
83 const std::vector< std::vector<double> >& w,
84 std::vector<FadType>& x_fad,
85 std::vector< std::vector<double> >& w_local) {
86 for (
unsigned int node=0; node<e.
nnode; node++)
87 for (
unsigned int eqn=0; eqn<neqn; eqn++)
88 x_fad[node*neqn+eqn] =
FadType(e.
nnode*neqn, node*neqn+eqn,
89 x[e.
gid[node]*neqn+eqn]);
91 for (
unsigned int col=0; col<w.size(); col++)
92 for (
unsigned int node=0; node<e.
nnode; node++)
93 for (
unsigned int eqn=0; eqn<neqn; eqn++)
94 w_local[col][node*neqn+eqn] = w[col][e.
gid[node]*neqn+eqn];
99 const std::vector<double>&
x,
100 const std::vector< std::vector<double> >& w,
101 std::vector<RadType>& x_rad,
102 std::vector< std::vector<double> >& w_local) {
103 for (
unsigned int node=0; node<e.
nnode; node++)
104 for (
unsigned int eqn=0; eqn<neqn; eqn++)
105 x_rad[node*neqn+eqn] = x[e.
gid[node]*neqn+eqn];
107 for (
unsigned int col=0; col<w.size(); col++)
108 for (
unsigned int node=0; node<e.
nnode; node++)
109 for (
unsigned int eqn=0; eqn<neqn; eqn++)
110 w_local[col][node*neqn+eqn] = w[col][e.
gid[node]*neqn+eqn];
115 const std::vector<double>&
x,
116 const std::vector< std::vector<double> >& w,
117 std::vector<VRadType>& x_rad,
119 for (
unsigned int node=0; node<e.
nnode; node++)
120 for (
unsigned int eqn=0; eqn<neqn; eqn++)
121 x_rad[node*neqn+eqn] = x[e.
gid[node]*neqn+eqn];
123 for (
unsigned int col=0; col<w.size(); col++)
124 for (
unsigned int node=0; node<e.
nnode; node++)
125 for (
unsigned int eqn=0; eqn<neqn; eqn++)
126 w_local[col][node*neqn+eqn] = w[col][e.
gid[node]*neqn+eqn];
130 void adolc_init_fill(
bool retape,
134 const std::vector<double>&
x,
135 const std::vector< std::vector<double> >& w,
136 std::vector<double>& x_local,
137 std::vector<adouble>& x_ad,
141 for (
unsigned int node=0; node<e.
nnode; node++)
142 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
143 x_local[node*neqn+eqn] = x[e.
gid[node]*neqn+eqn];
145 x_ad[node*neqn+eqn] <<= x_local[node*neqn+eqn];
148 for (
unsigned int col=0; col<w.size(); col++)
149 for (
unsigned int node=0; node<e.
nnode; node++)
150 for (
unsigned int eqn=0; eqn<neqn; eqn++)
151 w_local[col][node*neqn+eqn] = w[col][e.
gid[node]*neqn+eqn];
157 const std::vector<double>& x,
158 const std::vector< std::vector<double> >& w,
159 std::vector<double>& x_local,
160 std::vector< std::vector<double> >& w_local) {
161 for (
unsigned int node=0; node<e.
nnode; node++)
162 for (
unsigned int eqn=0; eqn<neqn; eqn++)
163 x_local[node*neqn+eqn] = x[e.
gid[node]*neqn+eqn];
165 for (
unsigned int node=0; node<e.
nnode; node++)
166 for (
unsigned int eqn=0; eqn<neqn; eqn++)
167 for (
unsigned int col=0; col<w.size(); col++)
168 w_local[col][node*neqn+eqn] = w[col][e.
gid[node]*neqn+eqn];
174 const std::vector<T>& x,
179 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
180 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
181 u[qp*neqn+eqn] = 0.0;
182 du[qp*neqn+eqn] = 0.0;
183 for (
unsigned int node=0; node<e.
nnode; node++) {
184 u[qp*neqn+eqn] += x[node*neqn+eqn] * e.
phi[qp][node];
185 du[qp*neqn+eqn] += x[node*neqn+eqn] * e.
dphi[qp][node];
191 std::vector<T> s(e.
nqp*neqn);
192 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
193 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
194 s[qp*neqn+eqn] = 0.0;
195 for (
unsigned int j=0; j<neqn; j++) {
197 s[qp*neqn+eqn] += u[qp*neqn+j];
203 for (
unsigned int node=0; node<e.
nnode; node++) {
204 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
205 unsigned int row = node*neqn+eqn;
207 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
209 e.
w[qp]*e.
jac[qp]*(-(1.0/(e.
jac[qp]*e.
jac[qp]))*
210 du[qp*neqn+eqn]*e.
dphi[qp][node] +
211 e.
phi[qp][node]*(
exp(u[qp*neqn+eqn]) +
212 u[qp*neqn+eqn]*s[qp*neqn+eqn]));
220 const std::vector<double>& x,
221 std::vector< std::vector<double> >& w,
222 std::vector<double>& u,
223 std::vector<double>& du,
224 std::vector<double>& f,
225 std::vector< std::vector<double> >& adj) {
227 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
228 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
229 u[qp*neqn+eqn] = 0.0;
230 du[qp*neqn+eqn] = 0.0;
231 for (
unsigned int node=0; node<e.
nnode; node++) {
232 u[qp*neqn+eqn] += x[node*neqn+eqn] * e.
phi[qp][node];
233 du[qp*neqn+eqn] += x[node*neqn+eqn] * e.
dphi[qp][node];
239 std::vector<double> s(e.
nqp*neqn);
240 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
241 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
242 s[qp*neqn+eqn] = 0.0;
243 for (
unsigned int j=0; j<neqn; j++) {
245 s[qp*neqn+eqn] += u[qp*neqn+j];
250 for (
unsigned int col=0; col<w.size(); col++)
251 for (
unsigned int node=0; node<e.
nnode; node++)
252 for (
unsigned int eqn=0; eqn<neqn; eqn++)
253 adj[col][node*neqn+eqn] = 0.0;
256 for (
unsigned int node=0; node<e.
nnode; node++) {
257 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
258 unsigned int row = node*neqn+eqn;
260 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
261 double c1 = e.
w[qp]*e.
jac[qp];
262 double c2 = -(1.0/(e.
jac[qp]*e.
jac[qp]))*e.
dphi[qp][node];
263 double c3 = e.
phi[qp][node]*(
exp(u[qp*neqn+eqn]));
264 double c4 = e.
phi[qp][node]*u[qp*neqn+eqn];
265 double c5 = e.
phi[qp][node]*s[qp*neqn+eqn];
268 f[row] += c1*(c2*du[qp*neqn+eqn] + c3 + c4*s[qp*neqn+eqn]);
269 for (
unsigned int col=0; col<w.size(); col++) {
270 for (
unsigned int node_col=0; node_col<e.
nnode; node_col++) {
271 adj[col][node_col*neqn+eqn] +=
272 c1*(c2*e.
dphi[qp][node_col] + c35*e.
phi[qp][node_col])*w[col][row];
273 for (
unsigned int eqn_col=0; eqn_col<neqn; eqn_col++) {
275 adj[col][node_col*neqn+eqn_col] += c14*e.
phi[qp][node_col]*w[col][row];
284 template <
class FadType>
287 const std::vector< std::vector<double> >& w_local,
288 const std::vector<FadType>& f_fad,
289 std::vector<double>& f,
290 std::vector< std::vector<double> >& adj) {
292 for (
unsigned int node=0; node<e.
nnode; node++)
293 for (
unsigned int eqn=0; eqn<neqn; eqn++)
294 f[e.
gid[node]*neqn+eqn] += f_fad[node*neqn+eqn].val();
297 for (
unsigned int col=0; col<w_local.size(); col++) {
299 for (
unsigned int node=0; node<e.
nnode; node++)
300 for (
unsigned int eqn=0; eqn<neqn; eqn++)
301 z += f_fad[node*neqn+eqn]*w_local[col][node*neqn+eqn];
303 for (
unsigned int node=0; node<e.
nnode; node++)
304 for (
unsigned int eqn=0; eqn<neqn; eqn++)
305 adj[col][e.
gid[node]*neqn+eqn] += z.fastAccessDx(node*neqn+eqn);
311 std::vector< std::vector<double> >& w_local,
312 std::vector<RadType>& x_rad,
313 std::vector<RadType>& f_rad,
314 std::vector<RadType*>& ff_rad,
315 std::vector<double>& f,
316 std::vector< std::vector<double> >& adj) {
318 for (
unsigned int node=0; node<e.
nnode; node++)
319 for (
unsigned int eqn=0; eqn<neqn; eqn++)
320 f[e.
gid[node]*neqn+eqn] += f_rad[node*neqn+eqn].val();
323 for (
unsigned int col=0; col<w_local.size(); col++) {
327 for (
unsigned int node=0; node<e.
nnode; node++)
328 for (
unsigned int eqn=0; eqn<neqn; eqn++)
329 adj[col][e.
gid[node]*neqn+eqn] += x_rad[node*neqn+eqn].adj();
336 std::vector<std::size_t>& vn,
338 std::vector<VRadType>& x_rad,
339 std::vector<VRadType>& f_rad,
341 std::vector<double>& f,
342 std::vector< std::vector<double> >& adj) {
344 for (
unsigned int node=0; node<e.
nnode; node++)
345 for (
unsigned int eqn=0; eqn<neqn; eqn++)
346 f[e.
gid[node]*neqn+eqn] += f_rad[node*neqn+eqn].val();
353 for (
unsigned int col=0; col<ncol; col++)
354 for (
unsigned int node=0; node<e.
nnode; node++)
355 for (
unsigned int eqn=0; eqn<neqn; eqn++)
356 adj[col][e.
gid[node]*neqn+eqn] += x_rad[node*neqn+eqn].adj(col);
360 void adolc_process_fill(
bool retape,
365 std::vector<double>& x_local,
367 std::vector<adouble>& f_ad,
368 std::vector<double>& f_local,
369 std::vector<double>& f,
371 std::vector< std::vector<double> >& adj) {
373 for (
unsigned int node=0; node<e.
nnode; node++)
374 for (
unsigned int eqn=0; eqn<neqn; eqn++)
375 f_ad[node*neqn+eqn] >>= f_local[node*neqn+eqn];
379 zos_forward(tag, neqn*e.
nnode, neqn*e.
nnode, 1, &x_local[0], &f_local[0]);
381 fov_reverse(tag, neqn*e.
nnode, neqn*e.
nnode, ncol, w_local, adj_local);
383 for (
unsigned int node=0; node<e.
nnode; node++)
384 for (
unsigned int eqn=0; eqn<neqn; eqn++)
385 f[e.
gid[node]*neqn+eqn] += f_local[node*neqn+eqn];
387 for (
unsigned int col=0; col<ncol; col++)
388 for (
unsigned int node=0; node<e.
nnode; node++)
389 for (
unsigned int eqn=0; eqn<neqn; eqn++)
390 adj[col][e.
gid[node]*neqn+eqn] += adj_local[col][node*neqn+eqn];
396 const std::vector<double>& f_local,
397 const std::vector< std::vector<double> >& adj_local,
398 std::vector<double>& f,
399 std::vector< std::vector<double> >& adj) {
400 for (
unsigned int node=0; node<e.
nnode; node++)
401 for (
unsigned int eqn=0; eqn<neqn; eqn++)
402 f[e.
gid[node]*neqn+eqn] += f_local[node*neqn+eqn];
404 for (
unsigned int col=0; col<adj.size(); col++)
405 for (
unsigned int node=0; node<e.
nnode; node++)
406 for (
unsigned int eqn=0; eqn<neqn; eqn++)
407 adj[col][e.
gid[node]*neqn+eqn] += adj_local[col][node*neqn+eqn];
412 const std::vector<double>& f_local,
413 std::vector<double>& f) {
414 for (
unsigned int node=0; node<e.
nnode; node++)
415 for (
unsigned int eqn=0; eqn<neqn; eqn++)
416 f[e.
gid[node]*neqn+eqn] += f_local[node*neqn+eqn];
419 template <
typename FadType>
421 unsigned int num_cols,
double mesh_spacing) {
425 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
426 std::vector< std::vector<double> > w(num_cols), w_local(num_cols);
427 std::vector< std::vector<double> > adj(num_cols);
428 for (
unsigned int node=0; node<num_nodes; node++)
429 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
430 x[node*num_eqns+eqn] =
431 (mesh_spacing*node - 0.5)*(mesh_spacing*node - 0.5);
432 f[node*num_eqns+eqn] = 0.0;
435 for (
unsigned int col=0; col<num_cols; col++) {
436 w[col] = std::vector<double>(num_nodes*num_eqns);
437 w_local[col] = std::vector<double>(e.
nnode*num_eqns);
438 adj[col] = std::vector<double>(num_nodes*num_eqns);
439 for (
unsigned int node=0; node<num_nodes; node++)
440 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
441 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
442 adj[col][node*num_eqns+eqn] = 0.0;
448 std::vector<FadType> x_fad(e.
nnode*num_eqns), f_fad(e.
nnode*num_eqns);
449 std::vector<FadType> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
450 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
477 unsigned int num_cols,
double mesh_spacing) {
481 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
482 std::vector< std::vector<double> > w(num_cols), w_local(num_cols);
483 std::vector< std::vector<double> > adj(num_cols);
484 for (
unsigned int node=0; node<num_nodes; node++)
485 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
486 x[node*num_eqns+eqn] =
487 (mesh_spacing*node - 0.5)*(mesh_spacing*node - 0.5);
488 f[node*num_eqns+eqn] = 0.0;
491 for (
unsigned int col=0; col<num_cols; col++) {
492 w[col] = std::vector<double>(num_nodes*num_eqns);
493 w_local[col] = std::vector<double>(e.
nnode*num_eqns);
494 adj[col] = std::vector<double>(num_nodes*num_eqns);
495 for (
unsigned int node=0; node<num_nodes; node++)
496 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
497 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
498 adj[col][node*num_eqns+eqn] = 0.0;
504 std::vector<RadType> x_rad(e.
nnode*num_eqns), f_rad(e.
nnode*num_eqns);
505 std::vector<RadType> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
506 std::vector<RadType*> ff_rad(f_rad.size());
507 for (
unsigned int i=0;
i<f_rad.size();
i++)
508 ff_rad[
i] = &f_rad[
i];
509 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
536 unsigned int num_cols,
double mesh_spacing) {
540 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
541 std::vector< std::vector<double> > w(num_cols);
542 double **w_local =
new double*[num_cols];
543 std::vector< std::vector<double> > adj(num_cols);
544 for (
unsigned int node=0; node<num_nodes; node++)
545 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
546 x[node*num_eqns+eqn] =
547 (mesh_spacing*node - 0.5)*(mesh_spacing*node - 0.5);
548 f[node*num_eqns+eqn] = 0.0;
551 for (
unsigned int col=0; col<num_cols; col++) {
552 w[col] = std::vector<double>(num_nodes*num_eqns);
553 w_local[col] =
new double[e.
nnode*num_eqns];
554 adj[col] = std::vector<double>(num_nodes*num_eqns);
555 for (
unsigned int node=0; node<num_nodes; node++)
556 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
557 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
558 adj[col][node*num_eqns+eqn] = 0.0;
564 std::vector<VRadType> x_rad(e.
nnode*num_eqns), f_rad(e.
nnode*num_eqns);
565 std::vector<VRadType> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
567 std::vector<std::size_t> vn(num_cols);
568 for (
unsigned int i=0;
i<num_cols;
i++) {
571 for (
unsigned int j=0; j<num_eqns*e.
nnode; j++)
572 vf_rad[
i][j] = &f_rad[j];
574 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
583 for (
unsigned int col=0; col<num_cols; col++) {
584 delete [] w_local[col];
585 delete [] vf_rad[col];
608 double adolc_adj_fill(
unsigned int num_nodes,
unsigned int num_eqns,
609 unsigned int num_cols,
double mesh_spacing) {
613 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
614 std::vector< std::vector<double> > w(num_cols);
615 std::vector< std::vector<double> > adj(num_cols);
616 for (
unsigned int node=0; node<num_nodes; node++)
617 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
618 x[node*num_eqns+eqn] =
619 (mesh_spacing*node - 0.5)*(mesh_spacing*node - 0.5);
620 f[node*num_eqns+eqn] = 0.0;
623 for (
unsigned int col=0; col<num_cols; col++) {
624 w[col] = std::vector<double>(num_nodes*num_eqns);
625 adj[col] = std::vector<double>(num_nodes*num_eqns);
626 for (
unsigned int node=0; node<num_nodes; node++)
627 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
628 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
629 adj[col][node*num_eqns+eqn] = 0.0;
635 std::vector<adouble> x_ad(e.
nnode*num_eqns), f_ad(e.
nnode*num_eqns);
636 std::vector<adouble> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
637 std::vector<double> x_local(e.
nnode*num_eqns);
638 std::vector<double> f_local(e.
nnode*num_eqns);
639 double **adj_local =
new double*[num_cols];
640 double **w_local =
new double*[num_cols];
641 for (
unsigned int i=0;
i<num_cols;
i++) {
642 adj_local[
i] =
new double[e.
nnode*num_eqns];
643 w_local[
i] =
new double[e.
nnode*num_eqns];
649 adolc_init_fill(
true, 0, e, num_eqns, x, w, x_local, x_ad, w_local);
651 adolc_process_fill(
true, 0, e, num_eqns, num_cols, x_local, w_local, f_ad,
652 f_local, f, adj_local, adj);
655 for (
unsigned int i=1;
i<num_nodes-1;
i++) {
659 adolc_init_fill(
false, 0, e, num_eqns, x, w, x_local, x_ad, w_local);
660 adolc_process_fill(
false, 0, e, num_eqns, num_cols, x_local, w_local, f_ad,
661 f_local, f, adj_local, adj);
663 for (
unsigned int i=0;
i<num_cols;
i++) {
664 delete [] adj_local[
i];
665 delete [] w_local[
i];
684 return timer.totalElapsedTime();
687 double adolc_retape_adj_fill(
unsigned int num_nodes,
unsigned int num_eqns,
688 unsigned int num_cols,
double mesh_spacing) {
692 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
693 std::vector< std::vector<double> > w(num_cols);
694 std::vector< std::vector<double> > adj(num_cols);
695 for (
unsigned int node=0; node<num_nodes; node++)
696 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
697 x[node*num_eqns+eqn] =
698 (mesh_spacing*node - 0.5)*(mesh_spacing*node - 0.5);
699 f[node*num_eqns+eqn] = 0.0;
702 for (
unsigned int col=0; col<num_cols; col++) {
703 w[col] = std::vector<double>(num_nodes*num_eqns);
704 adj[col] = std::vector<double>(num_nodes*num_eqns);
705 for (
unsigned int node=0; node<num_nodes; node++)
706 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
707 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
708 adj[col][node*num_eqns+eqn] = 0.0;
714 std::vector<adouble> x_ad(e.
nnode*num_eqns), f_ad(e.
nnode*num_eqns);
715 std::vector<adouble> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
716 std::vector<double> x_local(e.
nnode*num_eqns);
717 std::vector<double> f_local(e.
nnode*num_eqns);
718 double **adj_local =
new double*[num_cols];
719 double **w_local =
new double*[num_cols];
720 for (
unsigned int i=0;
i<num_cols;
i++) {
721 adj_local[
i] =
new double[e.
nnode*num_eqns];
722 w_local[
i] =
new double[e.
nnode*num_eqns];
725 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
729 adolc_init_fill(
true, 1, e, num_eqns, x, w, x_local, x_ad, w_local);
731 adolc_process_fill(
true, 1, e, num_eqns, num_cols, x_local, w_local, f_ad,
732 f_local, f, adj_local, adj);
734 for (
unsigned int i=0;
i<num_cols;
i++) {
735 delete [] adj_local[
i];
736 delete [] w_local[
i];
755 return timer.totalElapsedTime();
760 unsigned int num_cols,
double mesh_spacing) {
764 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
765 std::vector< std::vector<double> > w(num_cols), w_local(num_cols);
766 std::vector< std::vector<double> > adj(num_cols);
767 for (
unsigned int node=0; node<num_nodes; node++)
768 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
769 x[node*num_eqns+eqn] =
770 (mesh_spacing*node - 0.5)*(mesh_spacing*node - 0.5);
771 f[node*num_eqns+eqn] = 0.0;
774 for (
unsigned int col=0; col<num_cols; col++) {
775 w[col] = std::vector<double>(num_nodes*num_eqns);
776 w_local[col] = std::vector<double>(e.
nnode*num_eqns);
777 adj[col] = std::vector<double>(num_nodes*num_eqns);
778 for (
unsigned int node=0; node<num_nodes; node++)
779 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
780 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
781 adj[col][node*num_eqns+eqn] = 0.0;
787 std::vector<double> x_local(e.
nnode*num_eqns), f_local(e.
nnode*num_eqns);
788 std::vector< std::vector<double> > adj_local(num_cols);
789 std::vector<double> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
790 for (
unsigned int i=0;
i<num_cols;
i++)
791 adj_local[
i] = std::vector<double>(e.
nnode*num_eqns);
792 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
821 unsigned int num_cols,
double mesh_spacing) {
825 std::vector<double>
x(num_nodes*num_eqns), f(num_nodes*num_eqns);
826 std::vector< std::vector<double> > w(num_cols), w_local(num_cols);
827 for (
unsigned int node_row=0; node_row<num_nodes; node_row++) {
828 for (
unsigned int eqn_row=0; eqn_row<num_eqns; eqn_row++) {
829 unsigned int row = node_row*num_eqns + eqn_row;
830 x[row] = (mesh_spacing*node_row - 0.5)*(mesh_spacing*node_row - 0.5);
835 for (
unsigned int col=0; col<num_cols; col++) {
836 w[col] = std::vector<double>(num_nodes*num_eqns);
837 w_local[col] = std::vector<double>(e.
nnode*num_eqns);
838 for (
unsigned int node=0; node<num_nodes; node++)
839 for (
unsigned int eqn=0; eqn<num_eqns; eqn++) {
840 w[col][node*num_eqns+eqn] = x[node*num_eqns+eqn];
846 std::vector<double> x_local(e.
nnode*num_eqns), f_local(e.
nnode*num_eqns);
847 std::vector<double> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
848 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
866 int main(
int argc,
char* argv[]) {
876 clp.
setDocString(
"This program tests the speed of various forward mode AD implementations for a finite-element-like Jacobian fill");
877 int num_nodes = 100000;
881 clp.
setOption(
"n", &num_nodes,
"Number of nodes");
882 clp.
setOption(
"p", &num_eqns,
"Number of equations");
883 clp.
setOption(
"q", &num_cols,
"Number of adjoint directions");
884 clp.
setOption(
"rt", &rt,
"Include ADOL-C retaping test");
888 parseReturn= clp.
parse(argc, argv);
892 double mesh_spacing = 1.0 /
static_cast<double>(num_nodes - 1);
894 std::cout.setf(std::ios::scientific);
895 std::cout.precision(p);
896 std::cout <<
"num_nodes = " << num_nodes
897 <<
", num_eqns = " << num_eqns
898 <<
", num_cols = " << num_cols <<
": " << std::endl
899 <<
" " <<
" Time" <<
"\t"<<
"Time/Analytic" <<
"\t"
900 <<
"Time/Residual" << std::endl;
905 tr =
residual_fill(num_nodes, num_eqns, num_cols, mesh_spacing);
908 std::cout <<
"Analytic: " << std::setw(w) << ta <<
"\t" << std::setw(w) << ta/ta <<
"\t" << std::setw(w) << ta/tr << std::endl;
911 t = adolc_adj_fill(num_nodes, num_eqns, num_cols, mesh_spacing);
912 std::cout <<
"ADOL-C: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/tr << std::endl;
915 t = adolc_retape_adj_fill(num_nodes, num_eqns, num_cols, mesh_spacing);
916 std::cout <<
"ADOL-C(rt):" << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/tr << std::endl;
920 t = fad_adj_fill< Sacado::Fad::DFad<double> >(num_nodes, num_eqns, num_cols, mesh_spacing);
921 std::cout <<
"DFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/tr << std::endl;
923 t = fad_adj_fill< Sacado::ELRFad::DFad<double> >(num_nodes, num_eqns, num_cols, mesh_spacing);
924 std::cout <<
"ELRDFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/tr << std::endl;
926 t =
rad_adj_fill(num_nodes, num_eqns, num_cols, mesh_spacing);
927 std::cout <<
"Rad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/tr << std::endl;
929 t =
vrad_adj_fill(num_nodes, num_eqns, num_cols, mesh_spacing);
930 std::cout <<
"Vector Rad:" << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/tr << std::endl;
933 catch (std::exception& e) {
934 std::cout << e.what() << std::endl;
937 catch (
const char *s) {
938 std::cout << s << std::endl;
942 std::cout <<
"Caught unknown exception!" << std::endl;
void rad_init_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &x, const std::vector< std::vector< double > > &w, std::vector< RadType > &x_rad, std::vector< std::vector< double > > &w_local)
double residual_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing)
void template_element_fill(const ElemData &e, unsigned int neqn, const std::vector< T > &x, std::vector< T > &u, std::vector< T > &du, std::vector< T > &f)
void analytic_element_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &x, std::vector< double > &u, std::vector< double > &du, std::vector< double > &f, std::vector< std::vector< double > > &jac)
Sacado::Fad::DFad< double > FadType
void analytic_process_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &f_local, const std::vector< std::vector< double > > &jac_local, std::vector< double > &f, std::vector< std::vector< double > > &jac)
ElemData(double mesh_spacing)
double analytic_adj_fill(unsigned int num_nodes, unsigned int num_eqns, unsigned int num_cols, double mesh_spacing)
void fad_init_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &x, std::vector< FadType > &x_fad)
static void Weighted_Gradcomp(size_t, ADVar **, Double *)
void start(bool reset=false)
Sacado::RadVec::ADvar< double > VRadType
void rad_process_fill(const ElemData &e, unsigned int neqn, std::vector< std::vector< double > > &w_local, std::vector< RadType > &x_rad, std::vector< RadType > &f_rad, std::vector< RadType * > &ff_rad, std::vector< double > &f, std::vector< std::vector< double > > &adj)
void analytic_init_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &x, std::vector< double > &x_local)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
static void Weighted_GradcompVec(size_t, size_t *, ADVar ***, Double **)
void vrad_process_fill(const ElemData &e, unsigned int neqn, unsigned int ncol, std::vector< std::size_t > &vn, double **w_local, std::vector< VRadType > &x_rad, std::vector< VRadType > &f_rad, VRadType ***vf_rad, std::vector< double > &f, std::vector< std::vector< double > > &adj)
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
void residual_process_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &f_local, std::vector< double > &f)
double rad_adj_fill(unsigned int num_nodes, unsigned int num_eqns, unsigned int num_cols, double mesh_spacing)
void setDocString(const char doc_string[])
void fad_process_fill(const ElemData &e, unsigned int neqn, const std::vector< FadType > &f_fad, std::vector< double > &f, std::vector< std::vector< double > > &jac)
double totalElapsedTime(bool readCurrentTime=false) const
Sacado::Rad::ADvar< double > RadType
double vrad_adj_fill(unsigned int num_nodes, unsigned int num_eqns, unsigned int num_cols, double mesh_spacing)
double fad_adj_fill(unsigned int num_nodes, unsigned int num_eqns, unsigned int num_cols, double mesh_spacing)
void vrad_init_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &x, const std::vector< std::vector< double > > &w, std::vector< VRadType > &x_rad, double **w_local)