54 #include "Teuchos_LAPACK.hpp" 82 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0)
const {
83 for (
unsigned i=0; i<u.size(); i++) {
88 void axpy(std::vector<Real> &out,
const Real a,
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
89 for (
unsigned i=0; i < x.size(); i++) {
90 out[i] = a*x[i] + y[i];
94 void scale(std::vector<Real> &u,
const Real alpha=0.0)
const {
95 for (
unsigned i=0; i<u.size(); i++) {
100 void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
101 const std::vector<Real> &r,
const bool transpose =
false)
const {
102 if ( r.size() == 1 ) {
103 u.resize(1,r[0]/d[0]);
105 else if ( r.size() == 2 ) {
107 Real det = d[0]*d[1] - dl[0]*du[0];
108 u[0] = (d[1]*r[0] - du[0]*r[1])/det;
109 u[1] = (d[0]*r[1] - dl[0]*r[0])/det;
112 u.assign(r.begin(),r.end());
114 Teuchos::LAPACK<int,Real> lp;
115 std::vector<Real> du2(r.size()-2,0.0);
116 std::vector<int> ipiv(r.size(),0);
121 lp.GTTRF(dim,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
126 lp.GTTRS(trans,dim,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
131 BurgersFEM(
int nx = 128, Real nl = 1.0, Real cH1 = 1.0, Real cL2 = 1.0)
132 : nx_(nx), dx_(1.0/((Real)nx+1.0)), nl_(nl), cH1_(cH1), cL2_(cL2) {
140 nu_ = std::pow(10.0,nu-2.0);
158 Real
compute_L2_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
160 Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
161 for (
unsigned i=0; i<x.size(); i++) {
163 ip += dx_/6.0*(c*x[i] + x[i+1])*y[i];
165 else if ( i == x.size()-1 ) {
166 ip += dx_/6.0*(x[i-1] + c*x[i])*y[i];
169 ip += dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
181 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
182 Mu.resize(u.size(),0.0);
183 Real c = (((int)u.size()==
nx_) ? 4.0 : 2.0);
184 for (
unsigned i=0; i<u.size(); i++) {
186 Mu[i] = dx_/6.0*(c*u[i] + u[i+1]);
188 else if ( i == u.size()-1 ) {
189 Mu[i] = dx_/6.0*(u[i-1] + c*u[i]);
192 Mu[i] = dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
199 unsigned nx = u.size();
201 std::vector<Real> dl(nx-1,dx_/6.0);
202 std::vector<Real> d(nx,2.0*dx_/3.0);
203 std::vector<Real> du(nx-1,dx_/6.0);
204 if ( (
int)nx != nx_ ) {
213 std::vector<Real> u(nx_,0.0), Mu(nx_,0.0), iMMu(nx_,0.0), diff(nx_,0.0);
214 for (
int i = 0; i <
nx_; i++) {
215 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
219 axpy(diff,-1.0,iMMu,u);
222 outStream <<
"\nTest Inverse State Mass Matrix\n";
223 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
224 outStream <<
" ||u|| = " << normu <<
"\n";
225 outStream <<
" Relative Error = " << error/normu <<
"\n";
228 u.resize(nx_+2,0.0); Mu.resize(nx_+2,0.0); iMMu.resize(nx_+2,0.0); diff.resize(nx_+2,0.0);
229 for (
int i = 0; i < nx_+2; i++) {
230 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
234 axpy(diff,-1.0,iMMu,u);
237 outStream <<
"\nTest Inverse Control Mass Matrix\n";
238 outStream <<
" ||z - inv(M)Mz|| = " << error <<
"\n";
239 outStream <<
" ||z|| = " << normu <<
"\n";
240 outStream <<
" Relative Error = " << error/normu <<
"\n";
248 Real
compute_H1_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
250 for (
int i=0; i<
nx_; i++) {
252 ip += cL2_*dx_/6.0*(4.0*x[i] + x[i+1])*y[i];
253 ip += cH1_*(2.0*x[i] - x[i+1])/dx_*y[i];
255 else if ( i == nx_-1 ) {
256 ip += cL2_*dx_/6.0*(x[i-1] + 4.0*x[i])*y[i];
257 ip += cH1_*(2.0*x[i] - x[i-1])/dx_*y[i];
260 ip += cL2_*dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
261 ip += cH1_*(2.0*x[i] - x[i-1] - x[i+1])/dx_*y[i];
273 void apply_H1(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
275 for (
int i=0; i<
nx_; i++) {
277 Mu[i] = cL2_*dx_/6.0*(4.0*u[i] + u[i+1])
278 + cH1_*(2.0*u[i] - u[i+1])/
dx_;
280 else if ( i == nx_-1 ) {
281 Mu[i] = cL2_*dx_/6.0*(u[i-1] + 4.0*u[i])
282 + cH1_*(2.0*u[i] - u[i-1])/
dx_;
285 Mu[i] = cL2_*dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1])
286 + cH1_*(2.0*u[i] - u[i-1] - u[i+1])/
dx_;
294 std::vector<Real> dl(nx_-1,cL2_*dx_/6.0 - cH1_/dx_);
295 std::vector<Real> d(nx_,2.0*(cL2_*dx_/3.0 + cH1_/dx_));
296 std::vector<Real> du(nx_-1,cL2_*dx_/6.0 - cH1_/dx_);
301 std::vector<Real> u(nx_,0.0), Mu(nx_,0.0), iMMu(nx_,0.0), diff(nx_,0.0);
302 for (
int i = 0; i <
nx_; i++) {
303 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
307 axpy(diff,-1.0,iMMu,u);
310 outStream <<
"\nTest Inverse State H1 Matrix\n";
311 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
312 outStream <<
" ||u|| = " << normu <<
"\n";
313 outStream <<
" Relative Error = " << error/normu <<
"\n";
322 const std::vector<Real> &z)
const {
325 for (
int i=0; i<
nx_; i++) {
328 r[i] = nu_/dx_*(2.0*u[i]-u[i+1]);
331 r[i] = nu_/dx_*(2.0*u[i]-u[i-1]);
334 r[i] = nu_/dx_*(2.0*u[i]-u[i-1]-u[i+1]);
338 r[i] += nl_*u[i+1]*(u[i]+u[i+1])/6.0;
341 r[i] -= nl_*u[i-1]*(u[i-1]+u[i])/6.0;
344 r[i] -= dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
349 r[0] -= nl_*(u0_*u[ 0]/6.0 + u0_*u0_/6.0) + nu_*u0_/
dx_;
350 r[nx_-1] += nl_*(u1_*u[nx_-1]/6.0 + u1_*u1_/6.0) - nu_*u1_/
dx_;
358 std::vector<Real> &d,
359 std::vector<Real> &du,
360 const std::vector<Real> &u)
const {
363 d.resize(nx_,nu_*2.0/dx_);
365 dl.resize(nx_-1,-nu_/dx_);
367 du.resize(nx_-1,-nu_/dx_);
369 for (
int i=0; i<
nx_; i++) {
371 dl[i] += nl_*(-2.0*u[i]-u[i+1])/6.0;
372 d[i] += nl_*u[i+1]/6.0;
375 d[i] -= nl_*u[i-1]/6.0;
376 du[i-1] += nl_*(u[i-1]+2.0*u[i])/6.0;
380 d[ 0] -= nl_*u0_/6.0;
381 d[nx_-1] += nl_*u1_/6.0;
386 const std::vector<Real> &v,
387 const std::vector<Real> &u,
388 const std::vector<Real> &z)
const {
390 for (
int i = 0; i <
nx_; i++) {
391 jv[i] = nu_/dx_*2.0*v[i];
393 jv[i] += -nu_/dx_*v[i-1]-nl_*(u[i-1]/6.0*v[i]+(u[i]+2.0*u[i-1])/6.0*v[i-1]);
396 jv[i] += -nu_/dx_*v[i+1]+nl_*(u[i+1]/6.0*v[i]+(u[i]+2.0*u[i+1])/6.0*v[i+1]);
399 jv[ 0] -= nl_*u0_/6.0*v[0];
400 jv[nx_-1] += nl_*u1_/6.0*v[nx_-1];
405 const std::vector<Real> &v,
406 const std::vector<Real> &u,
407 const std::vector<Real> &z)
const {
409 std::vector<Real> d(nx_,0.0);
410 std::vector<Real> dl(nx_-1,0.0);
411 std::vector<Real> du(nx_-1,0.0);
419 const std::vector<Real> &v,
420 const std::vector<Real> &u,
421 const std::vector<Real> &z)
const {
423 for (
int i = 0; i <
nx_; i++) {
424 ajv[i] = nu_/dx_*2.0*v[i];
426 ajv[i] += -nu_/dx_*v[i-1]-nl_*(u[i-1]/6.0*v[i]
427 -(u[i-1]+2.0*u[i])/6.0*v[i-1]);
430 ajv[i] += -nu_/dx_*v[i+1]+nl_*(u[i+1]/6.0*v[i]
431 -(u[i+1]+2.0*u[i])/6.0*v[i+1]);
434 ajv[ 0] -= nl_*u0_/6.0*v[0];
435 ajv[nx_-1] += nl_*u1_/6.0*v[nx_-1];
440 const std::vector<Real> &v,
441 const std::vector<Real> &u,
442 const std::vector<Real> &z)
const {
444 std::vector<Real> d(nx_,0.0);
445 std::vector<Real> du(nx_-1,0.0);
446 std::vector<Real> dl(nx_-1,0.0);
457 const std::vector<Real> &v,
458 const std::vector<Real> &u,
459 const std::vector<Real> &z)
const {
460 for (
int i=0; i<
nx_; i++) {
462 jv[i] = -dx_/6.0*(v[i]+4.0*v[i+1]+v[i+2]);
468 const std::vector<Real> &v,
469 const std::vector<Real> &u,
470 const std::vector<Real> &z)
const {
471 for (
int i=0; i<nx_+2; i++) {
473 jv[i] = -dx_/6.0*v[i];
476 jv[i] = -dx_/6.0*(4.0*v[i-1]+v[i]);
478 else if ( i == nx_ ) {
479 jv[i] = -dx_/6.0*(4.0*v[i-1]+v[i-2]);
481 else if ( i == nx_+1 ) {
482 jv[i] = -dx_/6.0*v[i-2];
485 jv[i] = -dx_/6.0*(v[i-2]+4.0*v[i-1]+v[i]);
494 const std::vector<Real> &w,
495 const std::vector<Real> &v,
496 const std::vector<Real> &u,
497 const std::vector<Real> &z)
const {
498 for (
int i=0; i<
nx_; i++) {
502 ahwv[i] += (w[i]*v[i+1] - w[i+1]*(2.0*v[i]+v[i+1]))/6.0;
505 ahwv[i] += (w[i-1]*(v[i-1]+2.0*v[i]) - w[i]*v[i-1])/6.0;
511 const std::vector<Real> &w,
512 const std::vector<Real> &v,
513 const std::vector<Real> &u,
514 const std::vector<Real> &z) {
515 ahwv.assign(u.size(),0.0);
518 const std::vector<Real> &w,
519 const std::vector<Real> &v,
520 const std::vector<Real> &u,
521 const std::vector<Real> &z) {
522 ahwv.assign(z.size(),0.0);
525 const std::vector<Real> &w,
526 const std::vector<Real> &v,
527 const std::vector<Real> &u,
528 const std::vector<Real> &z) {
529 ahwv.assign(z.size(),0.0);
536 ROL::Ptr<std::vector<Real> >
vec_;
537 ROL::Ptr<BurgersFEM<Real> >
fem_;
544 : vec_(vec), fem_(fem), dual_vec_(
ROL::nullPtr) {}
548 const std::vector<Real>& xval = *ex.
getVector();
549 std::copy(xval.begin(),xval.end(),vec_->begin());
554 const std::vector<Real>& xval = *ex.
getVector();
555 unsigned dimension = vec_->size();
556 for (
unsigned i=0; i<dimension; i++) {
557 (*vec_)[i] += xval[i];
562 unsigned dimension = vec_->size();
563 for (
unsigned i=0; i<dimension; i++) {
570 const std::vector<Real>& xval = *ex.
getVector();
571 return fem_->compute_L2_dot(xval,*vec_);
576 val = std::sqrt( dot(*
this) );
580 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
581 return ROL::makePtr<L2VectorPrimal>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
592 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
593 ROL::Ptr<L2VectorPrimal> e
594 = ROL::makePtr<L2VectorPrimal>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
595 (*e->getVector())[i] = 1.0;
604 dual_vec_ = ROL::makePtr<L2VectorDual<Real>>(
605 ROL::makePtr<std::vector<Real>>(*vec_),fem_);
607 fem_->apply_mass(*(ROL::constPtrCast<std::vector<Real> >(dual_vec_->getVector())),*vec_);
616 ROL::Ptr<std::vector<Real> >
vec_;
617 ROL::Ptr<BurgersFEM<Real> >
fem_;
624 : vec_(vec), fem_(fem), dual_vec_(
ROL::nullPtr) {}
628 const std::vector<Real>& xval = *ex.
getVector();
629 std::copy(xval.begin(),xval.end(),vec_->begin());
634 const std::vector<Real>& xval = *ex.
getVector();
635 unsigned dimension = vec_->size();
636 for (
unsigned i=0; i<dimension; i++) {
637 (*vec_)[i] += xval[i];
642 unsigned dimension = vec_->size();
643 for (
unsigned i=0; i<dimension; i++) {
650 const std::vector<Real>& xval = *ex.
getVector();
651 unsigned dimension = vec_->size();
652 std::vector<Real> Mx(dimension,0.0);
653 fem_->apply_inverse_mass(Mx,xval);
655 for (
unsigned i = 0; i < dimension; i++) {
656 val += Mx[i]*(*vec_)[i];
663 val = std::sqrt( dot(*
this) );
667 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
668 return ROL::makePtr<L2VectorDual>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
679 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
680 ROL::Ptr<L2VectorDual> e
681 = ROL::makePtr<L2VectorDual>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
682 (*e->getVector())[i] = 1.0;
691 dual_vec_ = ROL::makePtr<L2VectorPrimal<Real>>(
692 ROL::makePtr<std::vector<Real>>(*vec_),fem_);
694 fem_->apply_inverse_mass(*(ROL::constPtrCast<std::vector<Real> >(dual_vec_->getVector())),*vec_);
703 ROL::Ptr<std::vector<Real> >
vec_;
704 ROL::Ptr<BurgersFEM<Real> >
fem_;
711 : vec_(vec), fem_(fem), dual_vec_(
ROL::nullPtr) {}
715 const std::vector<Real>& xval = *ex.
getVector();
716 std::copy(xval.begin(),xval.end(),vec_->begin());
721 const std::vector<Real>& xval = *ex.
getVector();
722 unsigned dimension = vec_->size();
723 for (
unsigned i=0; i<dimension; i++) {
724 (*vec_)[i] += xval[i];
729 unsigned dimension = vec_->size();
730 for (
unsigned i=0; i<dimension; i++) {
737 const std::vector<Real>& xval = *ex.
getVector();
738 return fem_->compute_H1_dot(xval,*vec_);
743 val = std::sqrt( dot(*
this) );
747 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
748 return ROL::makePtr<H1VectorPrimal>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
759 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
760 ROL::Ptr<H1VectorPrimal> e
761 = ROL::makePtr<H1VectorPrimal>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
762 (*e->getVector())[i] = 1.0;
771 dual_vec_ = ROL::makePtr<H1VectorDual<Real>>(
772 ROL::makePtr<std::vector<Real>>(*vec_),fem_);
774 fem_->apply_H1(*(ROL::constPtrCast<std::vector<Real> >(dual_vec_->getVector())),*vec_);
783 ROL::Ptr<std::vector<Real> >
vec_;
784 ROL::Ptr<BurgersFEM<Real> >
fem_;
791 : vec_(vec), fem_(fem), dual_vec_(
ROL::nullPtr) {}
795 const std::vector<Real>& xval = *ex.
getVector();
796 std::copy(xval.begin(),xval.end(),vec_->begin());
801 const std::vector<Real>& xval = *ex.
getVector();
802 unsigned dimension = vec_->size();
803 for (
unsigned i=0; i<dimension; i++) {
804 (*vec_)[i] += xval[i];
809 unsigned dimension = vec_->size();
810 for (
unsigned i=0; i<dimension; i++) {
817 const std::vector<Real>& xval = *ex.
getVector();
818 unsigned dimension = vec_->size();
819 std::vector<Real> Mx(dimension,0.0);
820 fem_->apply_inverse_H1(Mx,xval);
822 for (
unsigned i = 0; i < dimension; i++) {
823 val += Mx[i]*(*vec_)[i];
830 val = std::sqrt( dot(*
this) );
834 ROL::Ptr<ROL::Vector<Real>>
clone()
const {
835 return ROL::makePtr<H1VectorDual>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
846 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
847 ROL::Ptr<H1VectorDual> e
848 = ROL::makePtr<H1VectorDual>( ROL::makePtr<std::vector<Real>>(vec_->size(),0.0),fem_);
849 (*e->getVector())[i] = 1.0;
858 dual_vec_ = ROL::makePtr<H1VectorPrimal<Real>>(
859 ROL::makePtr<std::vector<Real>>(*vec_),fem_);
861 fem_->apply_inverse_H1(*(ROL::constPtrCast<std::vector<Real> >(dual_vec_->getVector())),*vec_);
880 ROL::Ptr<BurgersFEM<Real> >
fem_;
885 const bool useHessian =
true)
886 : fem_(fem), useHessian_(useHessian) {}
890 ROL::Ptr<std::vector<Real> > cp =
891 dynamic_cast<PrimalConstraintVector&
>(c).getVector();
892 ROL::Ptr<const std::vector<Real> > up =
893 dynamic_cast<const PrimalStateVector&
>(u).getVector();
894 ROL::Ptr<const std::vector<Real> > zp =
895 dynamic_cast<const PrimalControlVector&
>(z).getVector();
897 fem_->compute_residual(*cp,*up,*zp);
902 ROL::Ptr<std::vector<Real> > jvp =
903 dynamic_cast<PrimalConstraintVector&
>(jv).getVector();
904 ROL::Ptr<const std::vector<Real> > vp =
905 dynamic_cast<const PrimalStateVector&
>(v).getVector();
906 ROL::Ptr<const std::vector<Real> > up =
907 dynamic_cast<const PrimalStateVector&
>(u).getVector();
908 ROL::Ptr<const std::vector<Real> > zp =
909 dynamic_cast<const PrimalControlVector&
>(z).getVector();
911 fem_->apply_pde_jacobian(*jvp,*vp,*up,*zp);
916 ROL::Ptr<std::vector<Real> > jvp =
917 dynamic_cast<PrimalConstraintVector&
>(jv).getVector();
918 ROL::Ptr<const std::vector<Real> > vp =
919 dynamic_cast<const PrimalControlVector&
>(v).getVector();
920 ROL::Ptr<const std::vector<Real> > up =
921 dynamic_cast<const PrimalStateVector&
>(u).getVector();
922 ROL::Ptr<const std::vector<Real> > zp =
923 dynamic_cast<const PrimalControlVector&
>(z).getVector();
925 fem_->apply_control_jacobian(*jvp,*vp,*up,*zp);
930 ROL::Ptr<std::vector<Real> > ijvp =
931 dynamic_cast<PrimalStateVector&
>(ijv).getVector();
932 ROL::Ptr<const std::vector<Real> > vp =
933 dynamic_cast<const PrimalConstraintVector&
>(v).getVector();
934 ROL::Ptr<const std::vector<Real> > up =
935 dynamic_cast<const PrimalStateVector&
>(u).getVector();
936 ROL::Ptr<const std::vector<Real> > zp =
937 dynamic_cast<const PrimalControlVector&
>(z).getVector();
939 fem_->apply_inverse_pde_jacobian(*ijvp,*vp,*up,*zp);
944 ROL::Ptr<std::vector<Real> > jvp =
945 dynamic_cast<DualStateVector&
>(ajv).getVector();
946 ROL::Ptr<const std::vector<Real> > vp =
947 dynamic_cast<const DualConstraintVector&
>(v).getVector();
948 ROL::Ptr<const std::vector<Real> > up =
949 dynamic_cast<const PrimalStateVector&
>(u).getVector();
950 ROL::Ptr<const std::vector<Real> > zp =
951 dynamic_cast<const PrimalControlVector&
>(z).getVector();
953 fem_->apply_adjoint_pde_jacobian(*jvp,*vp,*up,*zp);
958 ROL::Ptr<std::vector<Real> > jvp =
959 dynamic_cast<DualControlVector&
>(jv).getVector();
960 ROL::Ptr<const std::vector<Real> > vp =
961 dynamic_cast<const DualConstraintVector&
>(v).getVector();
962 ROL::Ptr<const std::vector<Real> > up =
963 dynamic_cast<const PrimalStateVector&
>(u).getVector();
964 ROL::Ptr<const std::vector<Real> > zp =
965 dynamic_cast<const PrimalControlVector&
>(z).getVector();
967 fem_->apply_adjoint_control_jacobian(*jvp,*vp,*up,*zp);
972 ROL::Ptr<std::vector<Real> > iajvp =
973 dynamic_cast<DualConstraintVector&
>(iajv).getVector();
974 ROL::Ptr<const std::vector<Real> > vp =
975 dynamic_cast<const DualStateVector&
>(v).getVector();
976 ROL::Ptr<const std::vector<Real> > up =
977 dynamic_cast<const PrimalStateVector&
>(u).getVector();
978 ROL::Ptr<const std::vector<Real> > zp =
979 dynamic_cast<const PrimalControlVector&
>(z).getVector();
981 fem_->apply_inverse_adjoint_pde_jacobian(*iajvp,*vp,*up,*zp);
987 ROL::Ptr<std::vector<Real> > ahwvp =
988 dynamic_cast<DualStateVector&
>(ahwv).getVector();
989 ROL::Ptr<const std::vector<Real> > wp =
990 dynamic_cast<const DualConstraintVector&
>(w).getVector();
991 ROL::Ptr<const std::vector<Real> > vp =
992 dynamic_cast<const PrimalStateVector&
>(v).getVector();
993 ROL::Ptr<const std::vector<Real> > up =
994 dynamic_cast<const PrimalStateVector&
>(u).getVector();
995 ROL::Ptr<const std::vector<Real> > zp =
996 dynamic_cast<const PrimalControlVector&
>(z).getVector();
998 fem_->apply_adjoint_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
1007 if ( useHessian_ ) {
1008 ROL::Ptr<std::vector<Real> > ahwvp =
1009 dynamic_cast<DualControlVector&
>(ahwv).getVector();
1010 ROL::Ptr<const std::vector<Real> > wp =
1011 dynamic_cast<const DualConstraintVector&
>(w).getVector();
1012 ROL::Ptr<const std::vector<Real> > vp =
1013 dynamic_cast<const PrimalStateVector&
>(v).getVector();
1014 ROL::Ptr<const std::vector<Real> > up =
1015 dynamic_cast<const PrimalStateVector&
>(u).getVector();
1016 ROL::Ptr<const std::vector<Real> > zp =
1017 dynamic_cast<const PrimalControlVector&
>(z).getVector();
1019 fem_->apply_adjoint_control_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
1027 if ( useHessian_ ) {
1028 ROL::Ptr<std::vector<Real> > ahwvp =
1029 dynamic_cast<DualStateVector&
>(ahwv).getVector();
1030 ROL::Ptr<const std::vector<Real> > wp =
1031 dynamic_cast<const DualConstraintVector&
>(w).getVector();
1032 ROL::Ptr<const std::vector<Real> > vp =
1033 dynamic_cast<const PrimalControlVector&
>(v).getVector();
1034 ROL::Ptr<const std::vector<Real> > up =
1035 dynamic_cast<const PrimalStateVector&
>(u).getVector();
1036 ROL::Ptr<const std::vector<Real> > zp =
1037 dynamic_cast<const PrimalControlVector&
>(z).getVector();
1039 fem_->apply_adjoint_pde_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
1047 if ( useHessian_ ) {
1048 ROL::Ptr<std::vector<Real> > ahwvp =
1049 dynamic_cast<DualControlVector&
>(ahwv).getVector();
1050 ROL::Ptr<const std::vector<Real> > wp =
1051 dynamic_cast<const DualConstraintVector&
>(w).getVector();
1052 ROL::Ptr<const std::vector<Real> > vp =
1053 dynamic_cast<const PrimalControlVector&
>(v).getVector();
1054 ROL::Ptr<const std::vector<Real> > up =
1055 dynamic_cast<const PrimalStateVector&
>(u).getVector();
1056 ROL::Ptr<const std::vector<Real> > zp =
1057 dynamic_cast<const PrimalControlVector&
>(z).getVector();
1059 fem_->apply_adjoint_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
H1VectorPrimal< Real > DualConstraintVector
BurgersFEM(int nx=128, Real nl=1.0, Real cH1=1.0, Real cL2=1.0)
L2VectorDual(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
ROL::Ptr< std::vector< Real > > vec_
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
void apply_pde_jacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
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...
Real norm() const
Returns where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
void compute_residual(std::vector< Real > &r, const std::vector< Real > &u, const std::vector< Real > &z) const
ROL::Ptr< const std::vector< Real > > getVector() const
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void apply_adjoint_pde_control_hessian(std::vector< Real > &ahwv, const std::vector< Real > &w, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z)
ROL::Ptr< std::vector< Real > > vec_
ROL::Ptr< const std::vector< Real > > getVector() const
ROL::Ptr< L2VectorDual< Real > > dual_vec_
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 plus(const ROL::Vector< Real > &x)
Compute , where .
void axpy(std::vector< Real > &out, const Real a, const std::vector< Real > &x, const std::vector< Real > &y) const
Constraint_BurgersControl(const ROL::Ptr< BurgersFEM< Real > > &fem, const bool useHessian=true)
void apply_inverse_H1(std::vector< Real > &Mu, const std::vector< Real > &u) const
ROL::Ptr< BurgersFEM< Real > > fem_
H1VectorPrimal(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Contains definitions of custom data types in ROL.
int dimension() const
Return dimension of the vector space.
void applyAdjointHessian_11(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 simulation-space Jacobian at ...
void plus(const ROL::Vector< Real > &x)
Compute , where .
ROL::Ptr< BurgersFEM< Real > > fem_
void applyInverseAdjointJacobian_1(ROL::Vector< Real > &iajv, 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 ...
ROL::Ptr< std::vector< Real > > vec_
H1VectorDual(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
int dimension() const
Return dimension of the vector space.
void compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u) const
Real compute_H1_dot(const std::vector< Real > &x, const std::vector< Real > &y) const
void apply_control_jacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
virtual void zero()
Set to zero vector.
void scale(std::vector< Real > &u, const Real alpha=0.0) const
ROL::Ptr< std::vector< Real > > getVector()
Defines the linear algebra or vector space interface.
H1VectorDual< Real > PrimalConstraintVector
void scale(const Real alpha)
Compute where .
ROL::Ptr< const std::vector< Real > > getVector() const
L2VectorPrimal(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
H1VectorPrimal< Real > PrimalStateVector
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
void plus(const ROL::Vector< Real > &x)
Compute , where .
void apply_inverse_pde_jacobian(std::vector< Real > &ijv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
ROL::Ptr< std::vector< Real > > vec_
void test_inverse_mass(std::ostream &outStream=std::cout)
void apply_adjoint_pde_hessian(std::vector< Real > &ahwv, const std::vector< Real > &w, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
ROL::Ptr< BurgersFEM< Real > > fem_
void apply_mass(std::vector< Real > &Mu, const std::vector< Real > &u) const
void apply_H1(std::vector< Real > &Mu, const std::vector< Real > &u) const
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...
Real norm() const
Returns where .
Real compute_L2_dot(const std::vector< Real > &x, const std::vector< Real > &y) const
void scale(const Real alpha)
Compute where .
Real mesh_spacing(void) const
void apply_adjoint_pde_jacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
int dimension() const
Return dimension of the vector space.
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Real norm() const
Returns where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
void apply_adjoint_control_jacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
Real norm() const
Returns where .
H1VectorDual< Real > DualStateVector
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 ROL::Vector< Real > &x) const
Compute where .
Real compute_H1_norm(const std::vector< Real > &r) const
ROL::Ptr< std::vector< Real > > getVector()
L2VectorPrimal< Real > PrimalControlVector
ROL::Ptr< std::vector< Real > > getVector()
ROL::Ptr< BurgersFEM< Real > > fem_
ROL::Ptr< BurgersFEM< Real > > fem_
void scale(const Real alpha)
Compute where .
void apply_adjoint_control_hessian(std::vector< Real > &ahwv, const std::vector< Real > &w, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z)
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 .
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void apply_inverse_mass(std::vector< Real > &Mu, const std::vector< Real > &u) const
void set_problem_data(const Real nu, const Real f, const Real u0, const Real u1)
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 test_inverse_H1(std::ostream &outStream=std::cout)
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
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) const
void apply_inverse_adjoint_pde_jacobian(std::vector< Real > &iajv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
L2VectorDual< Real > DualControlVector
Real compute_L2_norm(const std::vector< Real > &r) const
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 plus(const ROL::Vector< Real > &x)
Compute , where .
int dimension() const
Return dimension of the vector space.
void update(std::vector< Real > &u, const std::vector< Real > &s, const Real alpha=1.0) const
void apply_adjoint_control_pde_hessian(std::vector< Real > &ahwv, const std::vector< Real > &w, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z)
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...
Defines the constraint operator interface for simulation-based optimization.
ROL::Ptr< H1VectorPrimal< Real > > dual_vec_
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
ROL::Ptr< H1VectorDual< Real > > dual_vec_
ROL::Ptr< const std::vector< Real > > getVector() const
ROL::Ptr< std::vector< Real > > getVector()
void scale(const Real alpha)
Compute where .
ROL::Ptr< L2VectorPrimal< Real > > dual_vec_