55 #include "Teuchos_LAPACK.hpp"
83 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0)
const {
84 for (
unsigned i=0; i<u.size(); i++) {
89 void axpy(std::vector<Real> &out,
const Real a,
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
90 for (
unsigned i=0; i < x.size(); i++) {
91 out[i] = a*x[i] + y[i];
95 void scale(std::vector<Real> &u,
const Real alpha=0.0)
const {
96 for (
unsigned i=0; i<u.size(); i++) {
101 void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
102 const std::vector<Real> &r,
const bool transpose =
false)
const {
103 if ( r.size() == 1 ) {
104 u.resize(1,r[0]/d[0]);
106 else if ( r.size() == 2 ) {
108 Real det = d[0]*d[1] - dl[0]*du[0];
109 u[0] = (d[1]*r[0] - du[0]*r[1])/det;
110 u[1] = (d[0]*r[1] - dl[0]*r[0])/det;
113 u.assign(r.begin(),r.end());
115 Teuchos::LAPACK<int,Real> lp;
116 std::vector<Real> du2(r.size()-2,0.0);
117 std::vector<int> ipiv(r.size(),0);
122 lp.GTTRF(dim,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
127 lp.GTTRS(trans,dim,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
133 Real u0 = 1.0, Real u1 = 0.0, Real f = 0.0,
134 Real cH1 = 1.0, Real cL2 = 1.0)
135 :
nx_(nx),
dx_(1.0/((Real)nx+1.0)),
151 Real
compute_L2_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
153 Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
154 for (
unsigned i=0; i<x.size(); i++) {
156 ip +=
dx_/6.0*(c*x[i] + x[i+1])*y[i];
158 else if ( i == x.size()-1 ) {
159 ip +=
dx_/6.0*(x[i-1] + c*x[i])*y[i];
162 ip +=
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
174 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
175 Mu.resize(u.size(),0.0);
176 Real c = (((int)u.size()==
nx_) ? 4.0 : 2.0);
177 for (
unsigned i=0; i<u.size(); i++) {
179 Mu[i] =
dx_/6.0*(c*u[i] + u[i+1]);
181 else if ( i == u.size()-1 ) {
182 Mu[i] =
dx_/6.0*(u[i-1] + c*u[i]);
185 Mu[i] =
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
192 unsigned nx = u.size();
194 std::vector<Real> dl(nx-1,
dx_/6.0);
195 std::vector<Real> d(nx,2.0*
dx_/3.0);
196 std::vector<Real> du(nx-1,
dx_/6.0);
197 if ( (
int)nx !=
nx_ ) {
206 std::vector<Real> u(
nx_,0.0), Mu(
nx_,0.0), iMMu(
nx_,0.0), diff(
nx_,0.0);
207 for (
int i = 0; i <
nx_; i++) {
208 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
212 axpy(diff,-1.0,iMMu,u);
215 outStream <<
"Test Inverse State Mass Matrix\n";
216 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
217 outStream <<
" ||u|| = " << normu <<
"\n";
218 outStream <<
" Relative Error = " << error/normu <<
"\n";
221 u.resize(nx_+2,0.0); Mu.resize(nx_+2,0.0); iMMu.resize(nx_+2,0.0); diff.resize(nx_+2,0.0);
222 for (
int i = 0; i < nx_+2; i++) {
223 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
227 axpy(diff,-1.0,iMMu,u);
230 outStream <<
"Test Inverse Control Mass Matrix\n";
231 outStream <<
" ||z - inv(M)Mz|| = " << error <<
"\n";
232 outStream <<
" ||z|| = " << normu <<
"\n";
233 outStream <<
" Relative Error = " << error/normu <<
"\n";
241 Real
compute_H1_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
243 for (
int i=0; i<
nx_; i++) {
245 ip +=
cL2_*
dx_/6.0*(4.0*x[i] + x[i+1])*y[i];
246 ip +=
cH1_*(2.0*x[i] - x[i+1])/
dx_*y[i];
248 else if ( i == nx_-1 ) {
249 ip +=
cL2_*
dx_/6.0*(x[i-1] + 4.0*x[i])*y[i];
250 ip +=
cH1_*(2.0*x[i] - x[i-1])/
dx_*y[i];
253 ip +=
cL2_*
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
254 ip +=
cH1_*(2.0*x[i] - x[i-1] - x[i+1])/
dx_*y[i];
266 void apply_H1(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
268 for (
int i=0; i<
nx_; i++) {
270 Mu[i] =
cL2_*
dx_/6.0*(4.0*u[i] + u[i+1])
271 +
cH1_*(2.0*u[i] - u[i+1])/
dx_;
273 else if ( i == nx_-1 ) {
274 Mu[i] =
cL2_*
dx_/6.0*(u[i-1] + 4.0*u[i])
275 +
cH1_*(2.0*u[i] - u[i-1])/
dx_;
278 Mu[i] =
cL2_*
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1])
279 +
cH1_*(2.0*u[i] - u[i-1] - u[i+1])/
dx_;
294 std::vector<Real> u(
nx_,0.0), Mu(
nx_,0.0), iMMu(
nx_,0.0), diff(
nx_,0.0);
295 for (
int i = 0; i <
nx_; i++) {
296 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
300 axpy(diff,-1.0,iMMu,u);
303 outStream <<
"Test Inverse State H1 Matrix\n";
304 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
305 outStream <<
" ||u|| = " << normu <<
"\n";
306 outStream <<
" Relative Error = " << error/normu <<
"\n";
315 const std::vector<Real> &z)
const {
318 for (
int i=0; i<
nx_; i++) {
321 r[i] =
nu_/
dx_*(2.0*u[i]-u[i+1]);
324 r[i] =
nu_/
dx_*(2.0*u[i]-u[i-1]);
327 r[i] =
nu_/
dx_*(2.0*u[i]-u[i-1]-u[i+1]);
331 r[i] +=
nl_*u[i+1]*(u[i]+u[i+1])/6.0;
334 r[i] -=
nl_*u[i-1]*(u[i-1]+u[i])/6.0;
337 r[i] -=
dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
351 std::vector<Real> &d,
352 std::vector<Real> &du,
353 const std::vector<Real> &u)
const {
362 for (
int i=0; i<
nx_; i++) {
364 dl[i] +=
nl_*(-2.0*u[i]-u[i+1])/6.0;
365 d[i] +=
nl_*u[i+1]/6.0;
368 d[i] -=
nl_*u[i-1]/6.0;
369 du[i-1] +=
nl_*(u[i-1]+2.0*u[i])/6.0;
379 const std::vector<Real> &v,
380 const std::vector<Real> &u,
381 const std::vector<Real> &z)
const {
383 for (
int i = 0; i <
nx_; i++) {
386 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]);
389 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]);
392 jv[ 0] -=
nl_*
u0_/6.0*v[0];
393 jv[nx_-1] +=
nl_*
u1_/6.0*v[nx_-1];
398 const std::vector<Real> &v,
399 const std::vector<Real> &u,
400 const std::vector<Real> &z)
const {
402 std::vector<Real> d(
nx_,0.0);
403 std::vector<Real> dl(
nx_-1,0.0);
404 std::vector<Real> du(
nx_-1,0.0);
412 const std::vector<Real> &v,
413 const std::vector<Real> &u,
414 const std::vector<Real> &z)
const {
416 for (
int i = 0; i <
nx_; i++) {
417 ajv[i] =
nu_/
dx_*2.0*v[i];
419 ajv[i] += -
nu_/
dx_*v[i-1]-
nl_*(u[i-1]/6.0*v[i]
420 -(u[i-1]+2.0*u[i])/6.0*v[i-1]);
423 ajv[i] += -
nu_/
dx_*v[i+1]+
nl_*(u[i+1]/6.0*v[i]
424 -(u[i+1]+2.0*u[i])/6.0*v[i+1]);
427 ajv[ 0] -=
nl_*
u0_/6.0*v[0];
428 ajv[nx_-1] +=
nl_*
u1_/6.0*v[nx_-1];
433 const std::vector<Real> &v,
434 const std::vector<Real> &u,
435 const std::vector<Real> &z)
const {
437 std::vector<Real> d(
nx_,0.0);
438 std::vector<Real> du(
nx_-1,0.0);
439 std::vector<Real> dl(
nx_-1,0.0);
450 const std::vector<Real> &v,
451 const std::vector<Real> &u,
452 const std::vector<Real> &z)
const {
453 for (
int i=0; i<
nx_; i++) {
455 jv[i] = -
dx_/6.0*(v[i]+4.0*v[i+1]+v[i+2]);
461 const std::vector<Real> &v,
462 const std::vector<Real> &u,
463 const std::vector<Real> &z)
const {
464 for (
int i=0; i<
nx_+2; i++) {
466 jv[i] = -
dx_/6.0*v[i];
469 jv[i] = -
dx_/6.0*(4.0*v[i-1]+v[i]);
471 else if ( i == nx_ ) {
472 jv[i] = -
dx_/6.0*(4.0*v[i-1]+v[i-2]);
474 else if ( i == nx_+1 ) {
475 jv[i] = -
dx_/6.0*v[i-2];
478 jv[i] = -
dx_/6.0*(v[i-2]+4.0*v[i-1]+v[i]);
487 const std::vector<Real> &w,
488 const std::vector<Real> &v,
489 const std::vector<Real> &u,
490 const std::vector<Real> &z)
const {
491 for (
int i=0; i<
nx_; i++) {
495 ahwv[i] += (w[i]*v[i+1] - w[i+1]*(2.0*v[i]+v[i+1]))/6.0;
498 ahwv[i] += (w[i-1]*(v[i-1]+2.0*v[i]) - w[i]*v[i-1])/6.0;
504 const std::vector<Real> &w,
505 const std::vector<Real> &v,
506 const std::vector<Real> &u,
507 const std::vector<Real> &z) {
508 ahwv.assign(u.size(),0.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(z.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);
529 ROL::Ptr<std::vector<Real> >
vec_;
530 ROL::Ptr<BurgersFEM<Real> >
fem_;
532 mutable ROL::Ptr<L2VectorDual<Real> >
dual_vec_;
541 const std::vector<Real>& xval = *ex.
getVector();
542 std::copy(xval.begin(),xval.end(),
vec_->begin());
547 const std::vector<Real>& xval = *ex.
getVector();
550 (*vec_)[i] += xval[i];
563 const std::vector<Real>& xval = *ex.
getVector();
564 return fem_->compute_L2_dot(xval,*
vec_);
569 val = std::sqrt(
dot(*
this) );
573 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
574 return ROL::makePtr<L2VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
585 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
586 ROL::Ptr<L2VectorPrimal> e
587 = ROL::makePtr<L2VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
588 (*e->getVector())[i] = 1.0;
597 dual_vec_ = ROL::makePtr<L2VectorDual<Real>>(
598 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
600 fem_->apply_mass(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
606 const std::vector<Real>& xval = *ex.
getVector();
607 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
615 ROL::Ptr<std::vector<Real> >
vec_;
616 ROL::Ptr<BurgersFEM<Real> >
fem_;
618 mutable ROL::Ptr<L2VectorPrimal<Real> >
dual_vec_;
627 const std::vector<Real>& xval = *ex.
getVector();
628 std::copy(xval.begin(),xval.end(),
vec_->begin());
633 const std::vector<Real>& xval = *ex.
getVector();
636 (*vec_)[i] += xval[i];
649 const std::vector<Real>& xval = *ex.
getVector();
651 std::vector<Real> Mx(dimension,0.0);
652 fem_->apply_inverse_mass(Mx,xval);
654 for (
unsigned i = 0; i <
dimension; i++) {
655 val += Mx[i]*(*vec_)[i];
662 val = std::sqrt(
dot(*
this) );
666 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
667 return ROL::makePtr<L2VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
678 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
679 ROL::Ptr<L2VectorDual> e
680 = ROL::makePtr<L2VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
681 (*e->getVector())[i] = 1.0;
690 dual_vec_ = ROL::makePtr<L2VectorPrimal<Real>>(
691 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
693 fem_->apply_inverse_mass(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
699 const std::vector<Real>& xval = *ex.
getVector();
700 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
708 ROL::Ptr<std::vector<Real> >
vec_;
709 ROL::Ptr<BurgersFEM<Real> >
fem_;
711 mutable ROL::Ptr<H1VectorDual<Real> >
dual_vec_;
720 const std::vector<Real>& xval = *ex.
getVector();
721 std::copy(xval.begin(),xval.end(),
vec_->begin());
726 const std::vector<Real>& xval = *ex.
getVector();
729 (*vec_)[i] += xval[i];
742 const std::vector<Real>& xval = *ex.
getVector();
743 return fem_->compute_H1_dot(xval,*
vec_);
748 val = std::sqrt(
dot(*
this) );
752 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
753 return ROL::makePtr<H1VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
764 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
765 ROL::Ptr<H1VectorPrimal> e
766 = ROL::makePtr<H1VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
767 (*e->getVector())[i] = 1.0;
776 dual_vec_ = ROL::makePtr<H1VectorDual<Real>>(
777 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
779 fem_->apply_H1(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
785 const std::vector<Real>& xval = *ex.
getVector();
786 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
794 ROL::Ptr<std::vector<Real> >
vec_;
795 ROL::Ptr<BurgersFEM<Real> >
fem_;
797 mutable ROL::Ptr<H1VectorPrimal<Real> >
dual_vec_;
806 const std::vector<Real>& xval = *ex.
getVector();
807 std::copy(xval.begin(),xval.end(),
vec_->begin());
812 const std::vector<Real>& xval = *ex.
getVector();
815 (*vec_)[i] += xval[i];
828 const std::vector<Real>& xval = *ex.
getVector();
830 std::vector<Real> Mx(dimension,0.0);
831 fem_->apply_inverse_H1(Mx,xval);
833 for (
unsigned i = 0; i <
dimension; i++) {
834 val += Mx[i]*(*vec_)[i];
841 val = std::sqrt(
dot(*
this) );
845 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
846 return ROL::makePtr<H1VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
857 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
858 ROL::Ptr<H1VectorDual> e
859 = ROL::makePtr<H1VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
860 (*e->getVector())[i] = 1.0;
869 dual_vec_ = ROL::makePtr<H1VectorPrimal<Real>>(
870 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
872 fem_->apply_inverse_H1(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
878 const std::vector<Real>& xval = *ex.
getVector();
879 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
897 ROL::Ptr<BurgersFEM<Real> >
fem_;
906 ROL::Ptr<std::vector<Real> > cp =
908 ROL::Ptr<const std::vector<Real> > up =
910 ROL::Ptr<const std::vector<Real> > zp =
912 fem_->compute_residual(*cp,*up,*zp);
919 ROL::Ptr<std::vector<Real> > jvp =
921 ROL::Ptr<const std::vector<Real> > vp =
923 ROL::Ptr<const std::vector<Real> > up =
925 ROL::Ptr<const std::vector<Real> > zp =
927 fem_->apply_pde_jacobian(*jvp,*vp,*up,*zp);
932 ROL::Ptr<std::vector<Real> > jvp =
934 ROL::Ptr<const std::vector<Real> > vp =
936 ROL::Ptr<const std::vector<Real> > up =
938 ROL::Ptr<const std::vector<Real> > zp =
940 fem_->apply_control_jacobian(*jvp,*vp,*up,*zp);
945 ROL::Ptr<std::vector<Real> > ijvp =
947 ROL::Ptr<const std::vector<Real> > vp =
949 ROL::Ptr<const std::vector<Real> > up =
951 ROL::Ptr<const std::vector<Real> > zp =
953 fem_->apply_inverse_pde_jacobian(*ijvp,*vp,*up,*zp);
958 ROL::Ptr<std::vector<Real> > jvp =
960 ROL::Ptr<const std::vector<Real> > vp =
962 ROL::Ptr<const std::vector<Real> > up =
964 ROL::Ptr<const std::vector<Real> > zp =
966 fem_->apply_adjoint_pde_jacobian(*jvp,*vp,*up,*zp);
971 ROL::Ptr<std::vector<Real> > jvp =
973 ROL::Ptr<const std::vector<Real> > vp =
975 ROL::Ptr<const std::vector<Real> > up =
977 ROL::Ptr<const std::vector<Real> > zp =
979 fem_->apply_adjoint_control_jacobian(*jvp,*vp,*up,*zp);
984 ROL::Ptr<std::vector<Real> > iajvp =
986 ROL::Ptr<const std::vector<Real> > vp =
988 ROL::Ptr<const std::vector<Real> > up =
990 ROL::Ptr<const std::vector<Real> > zp =
992 fem_->apply_inverse_adjoint_pde_jacobian(*iajvp,*vp,*up,*zp);
998 ROL::Ptr<std::vector<Real> > ahwvp =
1000 ROL::Ptr<const std::vector<Real> > wp =
1002 ROL::Ptr<const std::vector<Real> > vp =
1004 ROL::Ptr<const std::vector<Real> > up =
1006 ROL::Ptr<const std::vector<Real> > zp =
1008 fem_->apply_adjoint_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
1018 ROL::Ptr<std::vector<Real> > ahwvp =
1020 ROL::Ptr<const std::vector<Real> > wp =
1022 ROL::Ptr<const std::vector<Real> > vp =
1024 ROL::Ptr<const std::vector<Real> > up =
1026 ROL::Ptr<const std::vector<Real> > zp =
1028 fem_->apply_adjoint_control_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
1037 ROL::Ptr<std::vector<Real> > ahwvp =
1039 ROL::Ptr<const std::vector<Real> > wp =
1041 ROL::Ptr<const std::vector<Real> > vp =
1043 ROL::Ptr<const std::vector<Real> > up =
1045 ROL::Ptr<const std::vector<Real> > zp =
1047 fem_->apply_adjoint_pde_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
1056 ROL::Ptr<std::vector<Real> > ahwvp =
1058 ROL::Ptr<const std::vector<Real> > wp =
1060 ROL::Ptr<const std::vector<Real> > vp =
1062 ROL::Ptr<const std::vector<Real> > up =
1064 ROL::Ptr<const std::vector<Real> > zp =
1066 fem_->apply_adjoint_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
1074 template<
class Real>
1086 ROL::Ptr<ROL::Vector<Real> >
ud_;
1097 ROL::Ptr<const std::vector<Real> > up =
1099 ROL::Ptr<const std::vector<Real> > zp =
1101 ROL::Ptr<const std::vector<Real> > udp =
1104 std::vector<Real> diff(udp->size(),0.0);
1105 for (
unsigned i = 0; i < udp->size(); i++) {
1106 diff[i] = (*up)[i] - (*udp)[i];
1108 return 0.5*(
fem_->compute_L2_dot(diff,diff) +
alpha_*
fem_->compute_L2_dot(*zp,*zp));
1112 ROL::Ptr<std::vector<Real> > gp =
1114 ROL::Ptr<const std::vector<Real> > up =
1116 ROL::Ptr<const std::vector<Real> > udp =
1119 std::vector<Real> diff(udp->size(),0.0);
1120 for (
unsigned i = 0; i < udp->size(); i++) {
1121 diff[i] = (*up)[i] - (*udp)[i];
1123 fem_->apply_mass(*gp,diff);
1127 ROL::Ptr<std::vector<Real> > gp =
1129 ROL::Ptr<const std::vector<Real> > zp =
1132 fem_->apply_mass(*gp,*zp);
1133 for (
unsigned i = 0; i < zp->size(); i++) {
1140 ROL::Ptr<std::vector<Real> > hvp =
1142 ROL::Ptr<const std::vector<Real> > vp =
1145 fem_->apply_mass(*hvp,*vp);
1160 ROL::Ptr<std::vector<Real> > hvp =
1162 ROL::Ptr<const std::vector<Real> > vp =
1165 fem_->apply_mass(*hvp,*vp);
1166 for (
unsigned i = 0; i < vp->size(); i++) {
1172 template<
class Real>
1181 ROL::Ptr<ROL::Vector<Real> >
l_;
1182 ROL::Ptr<ROL::Vector<Real> >
u_;
1189 catch (std::exception &e) {
1199 catch (std::exception &e) {
1204 void axpy(std::vector<Real> &out,
const Real a,
1205 const std::vector<Real> &x,
const std::vector<Real> &y)
const{
1206 out.resize(
dim_,0.0);
1207 for (
unsigned i = 0; i <
dim_; i++) {
1208 out[i] = a*x[i] + y[i];
1213 for (
int i = 0; i <
dim_; i++ ) {
1214 x[i] = std::max(
x_lo_[i],std::min(
x_up_[i],x[i]));
1223 for (
int i = 0; i <
dim_; i++ ) {
1232 l_ = ROL::makePtr<L2VectorPrimal<Real>>(
1233 ROL::makePtr<std::vector<Real>>(l), fem);
1234 u_ = ROL::makePtr<L2VectorPrimal<Real>>(
1235 ROL::makePtr<std::vector<Real>>(u), fem);
1242 for (
int i = 0; i <
dim_; i++ ) {
1243 if ( (*ex)[i] >=
x_lo_[i] && (*ex)[i] <=
x_up_[i] ) { cnt *= 1; }
1246 if ( cnt == 0 ) { val =
false; }
1251 ROL::Ptr<std::vector<Real> > ex;
cast_vector(ex,x);
1257 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1259 for (
int i = 0; i <
dim_; i++ ) {
1260 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ) {
1268 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1270 for (
int i = 0; i <
dim_; i++ ) {
1271 if ( ((*ex)[i] >=
x_up_[i]-epsn) ) {
1279 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1281 for (
int i = 0; i <
dim_; i++ ) {
1282 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ||
1283 ((*ex)[i] >=
x_up_[i]-epsn) ) {
1292 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1294 for (
int i = 0; i <
dim_; i++ ) {
1295 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > geps) ) {
1304 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1306 for (
int i = 0; i <
dim_; i++ ) {
1307 if ( ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < geps) ) {
1316 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1318 for (
int i = 0; i <
dim_; i++ ) {
1319 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > geps) ||
1320 ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < -geps) ) {
1335 template<
class Real>
1344 ROL::Ptr<ROL::Vector<Real> >
l_;
1345 ROL::Ptr<ROL::Vector<Real> >
u_;
1352 catch (std::exception &e) {
1362 catch (std::exception &e) {
1367 void axpy(std::vector<Real> &out,
const Real a,
1368 const std::vector<Real> &x,
const std::vector<Real> &y)
const{
1369 out.resize(
dim_,0.0);
1370 for (
unsigned i = 0; i <
dim_; i++) {
1371 out[i] = a*x[i] + y[i];
1376 for (
int i = 0; i <
dim_; i++ ) {
1377 x[i] = std::max(
x_lo_[i],std::min(
x_up_[i],x[i]));
1386 for (
int i = 0; i <
dim_; i++ ) {
1395 l_ = ROL::makePtr<H1VectorPrimal<Real>>(
1396 ROL::makePtr<std::vector<Real>>(l), fem);
1397 u_ = ROL::makePtr<H1VectorPrimal<Real>>(
1398 ROL::makePtr<std::vector<Real>>(u), fem);
1405 for (
int i = 0; i <
dim_; i++ ) {
1406 if ( (*ex)[i] >=
x_lo_[i] && (*ex)[i] <=
x_up_[i] ) { cnt *= 1; }
1409 if ( cnt == 0 ) { val =
false; }
1414 ROL::Ptr<std::vector<Real> > ex;
cast_vector(ex,x);
1420 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1422 for (
int i = 0; i <
dim_; i++ ) {
1423 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ) {
1431 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1433 for (
int i = 0; i <
dim_; i++ ) {
1434 if ( ((*ex)[i] >=
x_up_[i]-epsn) ) {
1442 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1444 for (
int i = 0; i <
dim_; i++ ) {
1445 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ||
1446 ((*ex)[i] >=
x_up_[i]-epsn) ) {
1455 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1457 for (
int i = 0; i <
dim_; i++ ) {
1458 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > geps) ) {
1467 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1469 for (
int i = 0; i <
dim_; i++ ) {
1470 if ( ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < -geps) ) {
1479 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1481 for (
int i = 0; i <
dim_; i++ ) {
1482 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > geps) ||
1483 ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < -geps) ) {
H1VectorPrimal< Real > DualConstraintVector
L2VectorDual(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
ROL::Ptr< std::vector< Real > > vec_
Provides the interface to evaluate simulation-based objective functions.
std::vector< Real > x_up_
ROL::Ptr< ROL::Vector< Real > > diff_
Real compute_H1_dot(const std::vector< Real > &x, const std::vector< Real > &y) const
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 .
void apply_mass(std::vector< Real > &Mu, const std::vector< Real > &u) const
bool isFeasible(const ROL::Vector< Real > &x)
Check if the vector, v, is feasible.
void pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
void axpy(std::vector< Real > &out, const Real a, const std::vector< Real > &x, const std::vector< Real > &y) const
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
void cast_vector(ROL::Ptr< std::vector< Real > > &xvec, ROL::Vector< Real > &x) const
Real dot(const ROL::Vector< Real > &x) const override
Compute where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
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_
int dimension() const
Return dimension of the vector space.
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 .
std::vector< Real > x_up_
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the upper -binding set.
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_
H1VectorPrimal(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
Real norm() const
Returns where .
Contains definitions of custom data types in ROL.
Real dot(const ROL::Vector< Real > &x) const
Compute where .
void cast_vector(ROL::Ptr< std::vector< Real > > &xvec, ROL::Vector< Real > &x) const
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 ...
ROL::Ptr< const std::vector< Real > > getVector() const
const ROL::Ptr< const ROL::Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
void plus(const ROL::Vector< Real > &x)
Compute , where .
ROL::Ptr< BurgersFEM< Real > > fem_
Real compute_H1_norm(const std::vector< Real > &r) const
L2BoundConstraint(std::vector< Real > &l, std::vector< Real > &u, const ROL::Ptr< BurgersFEM< Real > > &fem, Real scale=1.0)
Real norm() const
Returns where .
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
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_
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the lower -active set.
H1VectorDual(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
void project(ROL::Vector< Real > &x)
Project optimization variables onto the bounds.
virtual void zero()
Set to zero vector.
ROL::Ptr< std::vector< Real > > getVector()
Defines the linear algebra or vector space interface.
ROL::Ptr< BurgersFEM< Real > > fem_
H1VectorDual< Real > DualStateVector
H1VectorDual< Real > PrimalConstraintVector
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the lower -active set.
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
void scale(const Real alpha)
Compute where .
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the -binding set.
L2VectorPrimal(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
Real dot(const ROL::Vector< Real > &x) const override
Compute where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
H1VectorPrimal< Real > PrimalStateVector
void hessVec_22(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Constraint_BurgersControl(ROL::Ptr< BurgersFEM< Real > > &fem, bool useHessian=true)
Real value(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute value.
void plus(const ROL::Vector< Real > &x)
Compute , where .
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.
Real mesh_spacing(void) const
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
bool isFeasible(const ROL::Vector< Real > &x)
Check if the vector, v, is feasible.
int dimension() const
Return dimension of the vector space.
ROL::Ptr< std::vector< Real > > vec_
void test_inverse_mass(std::ostream &outStream=std::cout)
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< BurgersFEM< Real > > fem_
const ROL::Ptr< const ROL::Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
ROL::Ptr< ROL::Vector< Real > > ud_
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
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 pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the upper -active set.
ROL::Ptr< const std::vector< Real > > getVector() const
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< const std::vector< Real > > getVector() const
ROL::Ptr< BurgersFEM< Real > > fem_
void set(const ROL::Vector< Real > &x)
Set where .
void scale(const Real alpha)
Compute where .
void compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u) const
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
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 compute_L2_dot(const std::vector< Real > &x, const std::vector< Real > &y) const
void hessVec_21(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
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
std::vector< Real > x_lo_
ROL::Ptr< std::vector< Real > > getVector()
L2VectorPrimal< Real > PrimalControlVector
ROL::Ptr< ROL::Vector< Real > > u_
void apply_inverse_mass(std::vector< Real > &Mu, const std::vector< Real > &u) const
void pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
void axpy(std::vector< Real > &out, const Real a, const std::vector< Real > &x, const std::vector< Real > &y) const
void hessVec_12(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
ROL::Ptr< std::vector< Real > > getVector()
ROL::Ptr< BurgersFEM< Real > > fem_
ROL::Ptr< const std::vector< Real > > getVector() const
ROL::Ptr< BurgersFEM< Real > > fem_
void update(std::vector< Real > &u, const std::vector< Real > &s, const Real alpha=1.0) const
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the upper -active set.
void scale(const Real alpha)
Compute where .
void projection(std::vector< Real > &x)
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 pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps=Real(0))
void set(const ROL::Vector< Real > &x)
Set where .
ROL::Ptr< ROL::Vector< Real > > l_
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
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 .
Provides the interface to apply upper and lower bound constraints.
void compute_residual(std::vector< Real > &r, const std::vector< Real > &u, const std::vector< Real > &z) const
void projection(std::vector< Real > &x)
void cast_const_vector(ROL::Ptr< const std::vector< Real > > &xvec, const ROL::Vector< Real > &x) const
ROL::Ptr< ROL::Vector< Real > > l_
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) 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 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 apply_control_jacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
Real dot(const ROL::Vector< Real > &x) const override
Compute where .
void test_inverse_H1(std::ostream &outStream=std::cout)
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_control_jacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z) const
Real dot(const ROL::Vector< Real > &x) const
Compute where .
L2VectorPrimal< Real > PrimalControlVector
void cast_const_vector(ROL::Ptr< const std::vector< Real > > &xvec, const ROL::Vector< Real > &x) const
H1VectorPrimal< Real > PrimalStateVector
std::vector< Real > x_lo_
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
void axpy(std::vector< Real > &out, const Real a, const std::vector< Real > &x, const std::vector< Real > &y) const
L2VectorDual< Real > DualControlVector
BurgersFEM(int nx=128, Real nu=1.e-2, Real nl=1.0, Real u0=1.0, Real u1=0.0, Real f=0.0, Real cH1=1.0, Real cL2=1.0)
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the -binding set.
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
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 apply_H1(std::vector< Real > &Mu, const std::vector< Real > &u) const
void plus(const ROL::Vector< Real > &x)
Compute , where .
const ROL::Ptr< const ROL::Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
void apply_inverse_H1(std::vector< Real > &Mu, const std::vector< Real > &u) const
void project(ROL::Vector< Real > &x)
Project optimization variables onto the bounds.
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
void set(const ROL::Vector< Real > &x)
Set where .
ROL::Ptr< BurgersFEM< Real > > fem_
ROL::Ptr< ROL::Vector< Real > > u_
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
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
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 pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the upper -binding set.
void pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps=Real(0))
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...
int dimension() const
Return dimension of the vector space.
Defines the constraint operator interface for simulation-based optimization.
L2VectorDual< Real > DualControlVector
ROL::Ptr< H1VectorPrimal< Real > > dual_vec_
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
void set(const ROL::Vector< Real > &x)
Set where .
Real norm() const
Returns where .
void scale(std::vector< Real > &u, const Real alpha=0.0) 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< H1VectorDual< Real > > dual_vec_
Objective_BurgersControl(const ROL::Ptr< BurgersFEM< Real > > &fem, const ROL::Ptr< ROL::Vector< Real > > &ud, Real alpha=1.e-4)
const ROL::Ptr< const ROL::Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
Real dot(const ROL::Vector< Real > &x) const override
Compute where .
ROL::Ptr< std::vector< Real > > getVector()
H1BoundConstraint(std::vector< Real > &l, std::vector< Real > &u, const ROL::Ptr< BurgersFEM< Real > > &fem, Real scale=1.0)
void scale(const Real alpha)
Compute where .
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...
Real compute_L2_norm(const std::vector< Real > &r) const
ROL::Ptr< L2VectorPrimal< Real > > dual_vec_