58 #include "Teuchos_oblackholestream.hpp" 59 #include "Teuchos_GlobalMPISession.hpp" 60 #include "Teuchos_XMLParameterListHelpers.hpp" 61 #include "Teuchos_LAPACK.hpp" 85 return std::sqrt(
dot(r,r));
88 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y) {
90 Real c = ((x.size()==
nx_) ? 4.0 : 2.0);
91 for (
unsigned i = 0; i < x.size(); i++) {
93 ip +=
dx_/6.0*(c*x[i] + x[i+1])*y[i];
95 else if ( i == x.size()-1 ) {
96 ip +=
dx_/6.0*(x[i-1] + c*x[i])*y[i];
99 ip +=
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
107 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0) {
108 for (
unsigned i = 0; i < u.size(); i++) {
113 void scale(std::vector<Real> &u,
const Real alpha=0.0) {
114 for (
unsigned i = 0; i < u.size(); i++) {
119 void compute_residual(std::vector<Real> &r,
const std::vector<Real> &uold,
const std::vector<Real> &zold,
120 const std::vector<Real> &unew,
const std::vector<Real> &znew) {
123 for (
unsigned n = 0; n <
nx_; n++) {
137 r[n] -= 0.5*
dt_*unew[n-1]*(unew[n-1]+unew[n])/6.0;
138 r[n] -= 0.5*
dt_*uold[n-1]*(uold[n-1]+uold[n])/6.0;
141 r[n] += 0.5*
dt_*unew[n+1]*(unew[n]+unew[n+1])/6.0;
142 r[n] += 0.5*
dt_*uold[n+1]*(uold[n]+uold[n+1])/6.0;
145 r[n] -= 0.5*
dt_*
dx_/6.0*(znew[n]+4.0*znew[n+1]+znew[n+2]);
146 r[n] -= 0.5*
dt_*
dx_/6.0*(zold[n]+4.0*zold[n+1]+zold[n+2]);
156 const std::vector<Real> &u) {
165 for (
unsigned n = 0; n <
nx_; n++) {
167 dl[n] += 0.5*
dt_*(-2.0*u[n]-u[n+1])/6.0;
168 d[n] += 0.5*
dt_*u[n+1]/6.0;
171 d[n] -= 0.5*
dt_*u[n-1]/6.0;
172 du[n-1] += 0.5*
dt_*(u[n-1]+2.0*u[n])/6.0;
181 bool adjoint =
false) {
185 for (
unsigned n = 0; n <
nx_; n++) {
190 jv[n] -= 0.5*
dt_*(u[n-1]/6.0*v[n]-(u[n-1]+2.0*u[n])/6.0*v[n-1]);
193 jv[n] -= 0.5*
dt_*(u[n-1]/6.0*v[n]+(u[n]+2.0*u[n-1])/6.0*v[n-1]);
199 jv[n] += 0.5*
dt_*(u[n+1]/6.0*v[n]-(u[n+1]+2.0*u[n])/6.0*v[n+1]);
202 jv[n] += 0.5*
dt_*(u[n+1]/6.0*v[n]+(u[n]+2.0*u[n+1])/6.0*v[n+1]);
206 jv[0] -= 0.5*
dt_*
u0_/6.0*v[0];
211 bool adjoint =
false) {
215 for (
unsigned n = 0; n <
nx_; n++) {
220 jv[n] -= 0.5*
dt_*(u[n-1]/6.0*v[n]-(u[n-1]+2.0*u[n])/6.0*v[n-1]);
223 jv[n] -= 0.5*
dt_*(u[n-1]/6.0*v[n]+(u[n]+2.0*u[n-1])/6.0*v[n-1]);
229 jv[n] += 0.5*
dt_*(u[n+1]/6.0*v[n]-(u[n+1]+2.0*u[n])/6.0*v[n+1]);
232 jv[n] += 0.5*
dt_*(u[n+1]/6.0*v[n]+(u[n]+2.0*u[n+1])/6.0*v[n+1]);
236 jv[0] -= 0.5*
dt_*
u0_/6.0*v[0];
240 void apply_pde_jacobian(std::vector<Real> &jv,
const std::vector<Real> &vold,
const std::vector<Real> &uold,
241 const std::vector<Real> &vnew,
const std::vector<Real> unew,
bool adjoint =
false) {
245 for (
unsigned n = 0; n <
nx_; n++) {
252 jv[n] -= 0.5*
dt_*(unew[n-1]/6.0*vnew[n]-(unew[n-1]+2.0*unew[n])/6.0*vnew[n-1]);
253 jv[n] -= 0.5*
dt_*(uold[n-1]/6.0*vold[n]-(uold[n-1]+2.0*uold[n])/6.0*vold[n-1]);
256 jv[n] -= 0.5*
dt_*(unew[n-1]/6.0*vnew[n]+(unew[n]+2.0*unew[n-1])/6.0*vnew[n-1]);
257 jv[n] -= 0.5*
dt_*(uold[n-1]/6.0*vold[n]+(uold[n]+2.0*uold[n-1])/6.0*vold[n-1]);
264 jv[n] += 0.5*
dt_*(unew[n+1]/6.0*vnew[n]-(unew[n+1]+2.0*unew[n])/6.0*vnew[n+1]);
265 jv[n] += 0.5*
dt_*(uold[n+1]/6.0*vold[n]-(uold[n+1]+2.0*uold[n])/6.0*vold[n+1]);
268 jv[n] += 0.5*
dt_*(unew[n+1]/6.0*vnew[n]+(unew[n]+2.0*unew[n+1])/6.0*vnew[n+1]);
269 jv[n] += 0.5*
dt_*(uold[n+1]/6.0*vold[n]+(uold[n]+2.0*uold[n+1])/6.0*vold[n+1]);
273 jv[0] -= 0.5*
dt_*
u0_/6.0*vnew[0];
274 jv[0] -= 0.5*
dt_*
u0_/6.0*vold[0];
279 void apply_pde_hessian(std::vector<Real> &hv,
const std::vector<Real> &wold,
const std::vector<Real> &vold,
280 const std::vector<Real> &wnew,
const std::vector<Real> &vnew) {
283 for (
unsigned n = 0; n <
nx_; n++) {
285 hv[n] += 0.5*
dt_*((wnew[n-1]*(vnew[n-1]+2.0*vnew[n]) - wnew[n]*vnew[n-1])/6.0);
286 hv[n] += 0.5*
dt_*((wold[n-1]*(vold[n-1]+2.0*vold[n]) - wold[n]*vold[n-1])/6.0);
289 hv[n] += 0.5*
dt_*((wnew[n]*vnew[n+1] - wnew[n+1]*(2.0*vnew[n]+vnew[n+1]))/6.0);
290 hv[n] += 0.5*
dt_*((wold[n]*vold[n+1] - wold[n+1]*(2.0*vold[n]+vold[n+1]))/6.0);
297 unsigned dim = ((adjoint ==
true) ?
nx_+2 :
nx_);
299 for (
unsigned n = 0; n < dim; n++) {
302 jv[n] = -0.5*
dt_*
dx_/6.0*v[n];
305 jv[n] = -0.5*
dt_*
dx_/6.0*(4.0*v[n-1]+v[n]);
307 else if ( n ==
nx_ ) {
308 jv[n] = -0.5*
dt_*
dx_/6.0*(4.0*v[n-1]+v[n-2]);
310 else if ( n ==
nx_+1 ) {
311 jv[n] = -0.5*
dt_*
dx_/6.0*v[n-2];
314 jv[n] = -0.5*
dt_*
dx_/6.0*(v[n-2]+4.0*v[n-1]+v[n]);
318 jv[n] -= 0.5*
dt_*
dx_/6.0*(v[n]+4.0*v[n+1]+v[n+2]);
323 void run_newton(std::vector<Real> &u,
const std::vector<Real> &znew,
324 const std::vector<Real> &uold,
const std::vector<Real> &zold) {
328 std::vector<Real> r(
nx_,0.0);
332 Real rtol = 1.e2*ROL::ROL_EPSILON<Real>();
333 unsigned maxit = 500;
335 std::vector<Real> d(
nx_,0.0);
336 std::vector<Real> dl(
nx_-1,0.0);
337 std::vector<Real> du(
nx_-1,0.0);
339 Real alpha = 1.0, tmp = 0.0;
340 std::vector<Real> s(
nx_,0.0);
341 std::vector<Real> utmp(
nx_,0.0);
342 for (
unsigned i = 0; i < maxit; i++) {
351 utmp.assign(u.begin(),u.end());
355 while ( rnorm > (1.0-1.e-4*alpha)*tmp && alpha > std::sqrt(ROL::ROL_EPSILON<Real>()) ) {
357 utmp.assign(u.begin(),u.end());
363 u.assign(utmp.begin(),utmp.end());
364 if ( rnorm < rtol ) {
371 const std::vector<Real> &dl,
const std::vector<Real> &d,
const std::vector<Real> &du,
372 const std::vector<Real> &r,
const bool transpose =
false) {
373 bool useLAPACK =
false;
375 u.assign(r.begin(),r.end());
377 std::vector<Real> Dl(dl);
378 std::vector<Real> Du(du);
379 std::vector<Real> D(d);
381 Teuchos::LAPACK<int,Real> lp;
382 std::vector<Real> Du2(
nx_-2,0.0);
383 std::vector<int> ipiv(
nx_,0);
387 lp.GTTRF(
nx_,&Dl[0],&D[0],&Du[0],&Du2[0],&ipiv[0],&info);
388 char trans = ((transpose ==
true) ?
'T' :
'N');
389 lp.GTTRS(trans,
nx_,nhrs,&Dl[0],&D[0],&Du[0],&Du2[0],&ipiv[0],&u[0],ldb,&info);
394 unsigned maxit = 100;
395 Real rtol = std::min(1.e-12,1.e-4*std::sqrt(
dot(r,r)));
397 Real rnorm = 10.0*rtol;
398 for (
unsigned i = 0; i < maxit; i++) {
399 for (
unsigned n = 0; n <
nx_; n++) {
402 u[n] -= ((transpose ==
false) ? du[n] : dl[n])*u[n+1]/d[n];
405 u[n] -= ((transpose ==
false) ? dl[n-1] : du[n-1])*u[n-1]/d[n];
410 for (
unsigned n = 0; n <
nx_; n++) {
411 resid = r[n] - d[n]*u[n];
413 resid -= ((transpose ==
false) ? du[n] : dl[n])*u[n+1];
416 resid -= ((transpose ==
false) ? dl[n-1] : du[n-1])*u[n-1];
418 rnorm += resid*resid;
420 rnorm = std::sqrt(rnorm);
421 if ( rnorm < rtol ) {
432 Real nu = 1.e-2, Real u0 = 0.0, Real u1 = 0.0, Real f = 0.0)
434 dx_ = 1.0/((Real)nx+1.0);
439 for (
unsigned n = 0; n <
nx_; n++) {
441 u_init_[n] = ((x <= 0.5) ? 1.0 : 0.0);
446 Teuchos::RCP<std::vector<Real> > cp =
447 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(c)).getVector());
448 Teuchos::RCP<const std::vector<Real> > up =
450 Teuchos::RCP<const std::vector<Real> > zp =
453 std::vector<Real> C(
nx_,0.0);
454 std::vector<Real> uold(
u_init_);
455 std::vector<Real> unew(
u_init_);
456 std::vector<Real> zold(
nx_+2,0.0);
457 std::vector<Real> znew(
nx_+2,0.0);
459 for (
unsigned n = 0; n <
nx_+2; n++) {
463 for (
unsigned t = 0; t <
nt_; t++) {
465 for (
unsigned n = 0; n <
nx_; n++) {
466 unew[n] = (*up)[t*
nx_+n];
469 for (
unsigned n = 0; n <
nx_+2; n++) {
470 znew[n] = (*zp)[(t+1)*(
nx_+2)+n];
475 for (
unsigned n = 0; n <
nx_; n++) {
476 (*cp)[t*
nx_+n] = C[n];
479 uold.assign(unew.begin(),unew.end());
480 zold.assign(znew.begin(),znew.end());
485 Teuchos::RCP<std::vector<Real> > up =
486 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(u)).getVector());
487 up->assign(up->size(),z.
norm()/up->size());
488 Teuchos::RCP<const std::vector<Real> > zp =
491 std::vector<Real> uold(
u_init_);
492 std::vector<Real> unew(
u_init_);
493 std::vector<Real> zold(
nx_+2,0.0);
494 std::vector<Real> znew(
nx_+2,0.0);
496 for (
unsigned n = 0; n <
nx_+2; n++) {
500 for (
unsigned t = 0; t <
nt_; t++) {
502 for (
unsigned n = 0; n <
nx_+2; n++) {
503 znew[n] = (*zp)[(t+1)*(
nx_+2)+n];
508 for (
unsigned n = 0; n <
nx_; n++) {
509 (*up)[t*
nx_+n] = unew[n];
512 uold.assign(unew.begin(),unew.end());
513 zold.assign(znew.begin(),znew.end());
520 Teuchos::RCP<std::vector<Real> > jvp =
521 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(jv)).getVector());
522 Teuchos::RCP<const std::vector<Real> > vp =
524 Teuchos::RCP<const std::vector<Real> > up =
526 std::vector<Real> J(
nx_,0.0);
527 std::vector<Real> vold(
nx_,0.0);
528 std::vector<Real> vnew(
nx_,0.0);
529 std::vector<Real> uold(
nx_,0.0);
530 std::vector<Real> unew(
nx_,0.0);
531 for (
unsigned t = 0; t <
nt_; t++) {
532 for (
unsigned n = 0; n <
nx_; n++) {
533 unew[n] = (*up)[t*
nx_+n];
534 vnew[n] = (*vp)[t*
nx_+n];
537 for (
unsigned n = 0; n <
nx_; n++) {
538 (*jvp)[t*
nx_+n] = J[n];
540 vold.assign(vnew.begin(),vnew.end());
541 uold.assign(unew.begin(),unew.end());
547 Teuchos::RCP<std::vector<Real> > jvp =
548 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(jv)).getVector());
549 Teuchos::RCP<const std::vector<Real> > vp =
551 Teuchos::RCP<const std::vector<Real> > zp =
553 std::vector<Real> vnew(
nx_+2,0.0);
554 std::vector<Real> vold(
nx_+2,0.0);
555 std::vector<Real> jnew(
nx_,0.0);
556 std::vector<Real> jold(
nx_,0.0);
557 for (
unsigned n = 0; n <
nx_+2; n++) {
561 for (
unsigned t = 0; t <
nt_; t++) {
562 for (
unsigned n = 0; n <
nx_+2; n++) {
563 vnew[n] = (*vp)[(t+1)*(
nx_+2)+n];
566 for (
unsigned n = 0; n <
nx_; n++) {
568 (*jvp)[t*
nx_+n] = jnew[n] + jold[n];
570 jold.assign(jnew.begin(),jnew.end());
576 Teuchos::RCP<std::vector<Real> > ijvp =
577 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(ijv)).getVector());
578 Teuchos::RCP<const std::vector<Real> > vp =
580 Teuchos::RCP<const std::vector<Real> > up =
582 std::vector<Real> J(
nx_,0.0);
583 std::vector<Real> r(
nx_,0.0);
584 std::vector<Real> s(
nx_,0.0);
585 std::vector<Real> uold(
nx_,0.0);
586 std::vector<Real> unew(
nx_,0.0);
587 std::vector<Real> d(
nx_,0.0);
588 std::vector<Real> dl(
nx_-1,0.0);
589 std::vector<Real> du(
nx_-1,0.0);
590 for (
unsigned t = 0; t <
nt_; t++) {
592 for (
unsigned n = 0; n <
nx_; n++) {
593 r[n] = (*vp)[t*
nx_+n];
594 unew[n] = (*up)[t*
nx_+n];
603 for (
unsigned n = 0; n <
nx_; n++) {
604 (*ijvp)[t*
nx_+n] = s[n];
606 uold.assign(unew.begin(),unew.end());
612 Teuchos::RCP<std::vector<Real> > jvp =
613 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(ajv)).getVector());
614 Teuchos::RCP<const std::vector<Real> > vp =
616 Teuchos::RCP<const std::vector<Real> > up =
618 std::vector<Real> J(
nx_,0.0);
619 std::vector<Real> vold(
nx_,0.0);
620 std::vector<Real> vnew(
nx_,0.0);
621 std::vector<Real> unew(
nx_,0.0);
622 for (
unsigned t =
nt_; t > 0; t--) {
623 for (
unsigned n = 0; n <
nx_; n++) {
624 unew[n] = (*up)[(t-1)*
nx_+n];
625 vnew[n] = (*vp)[(t-1)*
nx_+n];
628 for (
unsigned n = 0; n <
nx_; n++) {
629 (*jvp)[(t-1)*
nx_+n] = J[n];
631 vold.assign(vnew.begin(),vnew.end());
637 Teuchos::RCP<std::vector<Real> > jvp =
638 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(jv)).getVector());
639 Teuchos::RCP<const std::vector<Real> > vp =
641 Teuchos::RCP<const std::vector<Real> > zp =
643 std::vector<Real> vnew(
nx_,0.0);
644 std::vector<Real> vold(
nx_,0.0);
645 std::vector<Real> jnew(
nx_+2,0.0);
646 std::vector<Real> jold(
nx_+2,0.0);
647 for (
unsigned t =
nt_+1; t > 0; t--) {
648 for (
unsigned n = 0; n <
nx_; n++) {
650 vnew[n] = (*vp)[(t-2)*
nx_+n];
657 for (
unsigned n = 0; n <
nx_+2; n++) {
659 (*jvp)[(t-1)*(
nx_+2)+n] = jnew[n] + jold[n];
661 jold.assign(jnew.begin(),jnew.end());
667 Teuchos::RCP<std::vector<Real> > ijvp =
668 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(ijv)).getVector());
669 Teuchos::RCP<const std::vector<Real> > vp =
671 Teuchos::RCP<const std::vector<Real> > up =
673 std::vector<Real> J(
nx_,0.0);
674 std::vector<Real> r(
nx_,0.0);
675 std::vector<Real> s(
nx_,0.0);
676 std::vector<Real> unew(
nx_,0.0);
677 std::vector<Real> d(
nx_,0.0);
678 std::vector<Real> dl(
nx_-1,0.0);
679 std::vector<Real> du(
nx_-1,0.0);
680 for (
unsigned t =
nt_; t > 0; t--) {
682 for (
unsigned n = 0; n <
nx_; n++) {
683 r[n] = (*vp)[(t-1)*
nx_+n];
684 unew[n] = (*up)[(t-1)*
nx_+n];
693 for (
unsigned n = 0; n <
nx_; n++) {
694 (*ijvp)[(t-1)*
nx_+n] = s[n];
701 Teuchos::RCP<std::vector<Real> > hwvp =
702 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(hwv)).getVector());
703 Teuchos::RCP<const std::vector<Real> > wp =
705 Teuchos::RCP<const std::vector<Real> > vp =
707 std::vector<Real> snew(
nx_,0.0);
708 std::vector<Real> wnew(
nx_,0.0);
709 std::vector<Real> wold(
nx_,0.0);
710 std::vector<Real> vnew(
nx_,0.0);
711 for (
unsigned t =
nt_; t > 0; t--) {
712 for (
unsigned n = 0; n <
nx_; n++) {
713 vnew[n] = (*vp)[(t-1)*
nx_+n];
714 wnew[n] = (*wp)[(t-1)*
nx_+n];
717 for (
unsigned n = 0; n <
nx_; n++) {
718 (*hwvp)[(t-1)*
nx_+n] = snew[n];
720 wold.assign(wnew.begin(),wnew.end());
756 case 1: val = ((x<=0.5) ? 1.0 : 0.0);
break;
757 case 2: val = 1.0;
break;
758 case 3: val = std::abs(std::sin(8.0*M_PI*x));
break;
759 case 4: val = std::exp(-0.5*(x-0.5)*(x-0.5));
break;
764 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y) {
766 Real c = ((x.size()==
nx_) ? 4.0 : 2.0);
767 for (
unsigned i=0; i<x.size(); i++) {
769 ip +=
dx_/6.0*(c*x[i] + x[i+1])*y[i];
771 else if ( i == x.size()-1 ) {
772 ip +=
dx_/6.0*(x[i-1] + c*x[i])*y[i];
775 ip +=
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
781 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u ) {
782 Mu.resize(u.size(),0.0);
783 Real c = ((u.size()==
nx_) ? 4.0 : 2.0);
784 for (
unsigned i=0; i<u.size(); i++) {
786 Mu[i] =
dx_/6.0*(c*u[i] + u[i+1]);
788 else if ( i == u.size()-1 ) {
789 Mu[i] =
dx_/6.0*(u[i-1] + c*u[i]);
792 Mu[i] =
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
804 dx_ = 1.0/((Real)nx+1.0);
809 Teuchos::RCP<const std::vector<Real> > up =
811 Teuchos::RCP<const std::vector<Real> > zp =
814 std::vector<Real> U(
nx_,0.0);
815 std::vector<Real> Z(
nx_+2,0.0);
816 for (
unsigned n = 0; n <
nx_+2; n++) {
821 for (
unsigned t = 0; t <
nt_; t++) {
823 for (
unsigned n = 0; n <
nx_; n++) {
826 val += 0.5*ss*
dot(U,U);
827 for (
unsigned n = 0; n <
nx_+2; n++) {
828 Z[n] = (*zp)[(t+1)*(
nx_+2)+n];
836 Teuchos::RCP<std::vector<Real> > gp = Teuchos::rcp_const_cast<std::vector<Real> >(
838 Teuchos::RCP<const std::vector<Real> > up =
841 std::vector<Real> U(
nx_,0.0);
842 std::vector<Real> M(
nx_,0.0);
844 for (
unsigned t = 0; t <
nt_; t++) {
846 for (
unsigned n = 0; n <
nx_; n++) {
850 for (
unsigned n = 0; n <
nx_; n++) {
851 (*gp)[t*
nx_+n] = ss*M[n];
857 Teuchos::RCP<std::vector<Real> > gp = Teuchos::rcp_const_cast<std::vector<Real> >(
859 Teuchos::RCP<const std::vector<Real> > zp =
862 std::vector<Real> Z(
nx_+2,0.0);
863 std::vector<Real> M(
nx_+2,0.0);
865 for (
unsigned t = 0; t <
nt_+1; t++) {
866 ss = ((t < nt_ && t > 0) ?
dt_ : 0.5*
dt_);
867 for (
unsigned n = 0; n <
nx_+2; n++) {
868 Z[n] = (*zp)[t*(
nx_+2)+n];
871 for (
unsigned n = 0; n <
nx_+2; n++) {
879 Teuchos::RCP<std::vector<Real> > hvp = Teuchos::rcp_const_cast<std::vector<Real> >(
881 Teuchos::RCP<const std::vector<Real> > vp =
884 std::vector<Real> V(
nx_,0.0);
885 std::vector<Real> M(
nx_,0.0);
887 for (
unsigned t = 0; t <
nt_; t++) {
889 for (
unsigned n = 0; n <
nx_; n++) {
890 V[n] = (*vp)[t*
nx_+n];
893 for (
unsigned n = 0; n <
nx_; n++) {
894 (*hvp)[t*
nx_+n] = ss*M[n];
911 Teuchos::RCP<std::vector<Real> > hvp = Teuchos::rcp_const_cast<std::vector<Real> >(
913 Teuchos::RCP<const std::vector<Real> > vp =
916 std::vector<Real> V(
nx_+2,0.0);
917 std::vector<Real> M(
nx_+2,0.0);
919 for (
unsigned t = 0; t <
nt_+1; t++) {
920 ss = ((t < nt_ && t > 0) ?
dt_ : 0.5*
dt_);
921 for (
unsigned n = 0; n <
nx_+2; n++) {
922 V[n] = (*vp)[t*(
nx_+2)+n];
925 for (
unsigned n = 0; n <
nx_+2; n++) {
Provides the interface to evaluate simulation-based objective functions.
void run_newton(std::vector< Real > &u, const std::vector< Real > &znew, const std::vector< Real > &uold, const std::vector< Real > &zold)
void compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u)
void applyAdjointHessian_21(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint optimization-space Jacobian at...
void linear_solve(std::vector< Real > &u, std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &r, const bool transpose=false)
Real evaluate_target(Real x)
void applyAdjointHessian_22(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint optimization-space Jacobian ...
void applyInverseJacobian_1(ROL::Vector< Real > &ijv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the inverse partial constraint Jacobian at , , to the vector .
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
Contains definitions of custom data types in ROL.
void compute_residual(std::vector< Real > &r, const std::vector< Real > &uold, const std::vector< Real > &zold, const std::vector< Real > &unew, const std::vector< Real > &znew)
Real compute_norm(const std::vector< Real > &r)
EqualityConstraint_BurgersControl(int nx=128, int nt=100, Real T=1, Real nu=1.e-2, Real u0=0.0, Real u1=0.0, Real f=0.0)
void solve(ROL::Vector< Real > &c, ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve for .
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
void apply_control_jacobian(std::vector< Real > &jv, const std::vector< Real > &v, bool adjoint=false)
void compute_residual(std::vector< Real > &r, const std::vector< Real > &u, const std::vector< Real > &z)
void apply_pde_hessian(std::vector< Real > &hv, const std::vector< Real > &wold, const std::vector< Real > &vold, const std::vector< Real > &wnew, const std::vector< Real > &vnew)
Defines the equality constraint operator interface for simulation-based optimization.
void hessVec_22(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Real value(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute value.
void gradient_1(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to first component.
void applyAdjointJacobian_1(ROL::Vector< Real > &ajv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the primary inter...
void apply_pde_jacobian_new(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, bool adjoint=false)
void applyAdjointJacobian_2(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the primary interface...
void applyJacobian_1(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
void hessVec_21(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
std::vector< Real > u_init_
void hessVec_12(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void gradient_2(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to second component.
void scale(std::vector< Real > &u, const Real alpha=0.0)
Objective_BurgersControl(Real alpha=1.e-4, int nx=128, int nt=100, Real T=1.0)
void applyJacobian_2(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
void hessVec_11(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply Hessian approximation to vector.
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
void applyInverseAdjointJacobian_1(ROL::Vector< Real > &ijv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
void apply_mass(std::vector< Real > &Mu, const std::vector< Real > &u)
void linear_solve(std::vector< Real > &u, const std::vector< Real > &dl, const std::vector< Real > &d, const std::vector< Real > &du, const std::vector< Real > &r, const bool transpose=false)
void apply_pde_jacobian(std::vector< Real > &jv, const std::vector< Real > &vold, const std::vector< Real > &uold, const std::vector< Real > &vnew, const std::vector< Real > unew, bool adjoint=false)
virtual Real norm() const =0
Returns where .
void update(std::vector< Real > &u, const std::vector< Real > &s, const Real alpha=1.0)
void applyAdjointHessian_12(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint simulation-space Jacobian at...
void apply_pde_jacobian_old(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, bool adjoint=false)
void applyAdjointHessian_11(ROL::Vector< Real > &hwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint simulation-space Jacobian at ...