54 #include "ROL_TeuchosBatchManager.hpp"
56 #include "Teuchos_LAPACK.hpp"
84 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0)
const {
85 for (
unsigned i=0; i<u.size(); i++) {
90 void axpy(std::vector<Real> &out,
const Real a,
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
91 for (
unsigned i=0; i < x.size(); i++) {
92 out[i] = a*x[i] + y[i];
96 void scale(std::vector<Real> &u,
const Real alpha=0.0)
const {
97 for (
unsigned i=0; i<u.size(); i++) {
102 void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
103 const std::vector<Real> &r,
const bool transpose =
false)
const {
104 if ( r.size() == 1 ) {
105 u.resize(1,r[0]/d[0]);
107 else if ( r.size() == 2 ) {
109 Real det = d[0]*d[1] - dl[0]*du[0];
110 u[0] = (d[1]*r[0] - du[0]*r[1])/det;
111 u[1] = (d[0]*r[1] - dl[0]*r[0])/det;
114 u.assign(r.begin(),r.end());
116 Teuchos::LAPACK<int,Real> lp;
117 std::vector<Real> du2(r.size()-2,0.0);
118 std::vector<int> ipiv(r.size(),0);
123 lp.GTTRF(dim,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
128 lp.GTTRS(trans,dim,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
133 BurgersFEM(
int nx = 128, Real nl = 1.0, Real cH1 = 1.0, Real cL2 = 1.0)
137 nu_ = std::pow(10.0,nu-2.0);
155 Real
compute_L2_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
157 Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
158 for (
unsigned i=0; i<x.size(); i++) {
160 ip +=
dx_/6.0*(c*x[i] + x[i+1])*y[i];
162 else if ( i == x.size()-1 ) {
163 ip +=
dx_/6.0*(x[i-1] + c*x[i])*y[i];
166 ip +=
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
178 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
179 Mu.resize(u.size(),0.0);
180 Real c = (((int)u.size()==
nx_) ? 4.0 : 2.0);
181 for (
unsigned i=0; i<u.size(); i++) {
183 Mu[i] =
dx_/6.0*(c*u[i] + u[i+1]);
185 else if ( i == u.size()-1 ) {
186 Mu[i] =
dx_/6.0*(u[i-1] + c*u[i]);
189 Mu[i] =
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
196 unsigned nx = u.size();
198 std::vector<Real> dl(nx-1,
dx_/6.0);
199 std::vector<Real> d(nx,2.0*
dx_/3.0);
200 std::vector<Real> du(nx-1,
dx_/6.0);
201 if ( (
int)nx !=
nx_ ) {
210 std::vector<Real> u(
nx_,0.0), Mu(
nx_,0.0), iMMu(
nx_,0.0), diff(
nx_,0.0);
211 for (
int i = 0; i <
nx_; i++) {
212 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
216 axpy(diff,-1.0,iMMu,u);
219 outStream <<
"Test Inverse State Mass Matrix\n";
220 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
221 outStream <<
" ||u|| = " << normu <<
"\n";
222 outStream <<
" Relative Error = " << error/normu <<
"\n";
225 u.resize(nx_+2,0.0); Mu.resize(nx_+2,0.0); iMMu.resize(nx_+2,0.0); diff.resize(nx_+2,0.0);
226 for (
int i = 0; i < nx_+2; i++) {
227 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
231 axpy(diff,-1.0,iMMu,u);
234 outStream <<
"Test Inverse Control Mass Matrix\n";
235 outStream <<
" ||z - inv(M)Mz|| = " << error <<
"\n";
236 outStream <<
" ||z|| = " << normu <<
"\n";
237 outStream <<
" Relative Error = " << error/normu <<
"\n";
245 Real
compute_H1_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
247 for (
int i=0; i<
nx_; i++) {
249 ip +=
cL2_*
dx_/6.0*(4.0*x[i] + x[i+1])*y[i];
250 ip +=
cH1_*(2.0*x[i] - x[i+1])/
dx_*y[i];
252 else if ( i == nx_-1 ) {
253 ip +=
cL2_*
dx_/6.0*(x[i-1] + 4.0*x[i])*y[i];
254 ip +=
cH1_*(2.0*x[i] - x[i-1])/
dx_*y[i];
257 ip +=
cL2_*
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
258 ip +=
cH1_*(2.0*x[i] - x[i-1] - x[i+1])/
dx_*y[i];
270 void apply_H1(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
272 for (
int i=0; i<
nx_; i++) {
274 Mu[i] =
cL2_*
dx_/6.0*(4.0*u[i] + u[i+1])
275 +
cH1_*(2.0*u[i] - u[i+1])/
dx_;
277 else if ( i == nx_-1 ) {
278 Mu[i] =
cL2_*
dx_/6.0*(u[i-1] + 4.0*u[i])
279 +
cH1_*(2.0*u[i] - u[i-1])/
dx_;
282 Mu[i] =
cL2_*
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1])
283 +
cH1_*(2.0*u[i] - u[i-1] - u[i+1])/
dx_;
298 std::vector<Real> u(
nx_,0.0), Mu(
nx_,0.0), iMMu(
nx_,0.0), diff(
nx_,0.0);
299 for (
int i = 0; i <
nx_; i++) {
300 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
304 axpy(diff,-1.0,iMMu,u);
307 outStream <<
"Test Inverse State H1 Matrix\n";
308 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
309 outStream <<
" ||u|| = " << normu <<
"\n";
310 outStream <<
" Relative Error = " << error/normu <<
"\n";
319 const std::vector<Real> &z)
const {
322 for (
int i=0; i<
nx_; i++) {
325 r[i] =
nu_/
dx_*(2.0*u[i]-u[i+1]);
328 r[i] =
nu_/
dx_*(2.0*u[i]-u[i-1]);
331 r[i] =
nu_/
dx_*(2.0*u[i]-u[i-1]-u[i+1]);
335 r[i] +=
nl_*u[i+1]*(u[i]+u[i+1])/6.0;
338 r[i] -=
nl_*u[i-1]*(u[i-1]+u[i])/6.0;
341 r[i] -=
dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
355 std::vector<Real> &d,
356 std::vector<Real> &du,
357 const std::vector<Real> &u)
const {
366 for (
int i=0; i<
nx_; i++) {
368 dl[i] +=
nl_*(-2.0*u[i]-u[i+1])/6.0;
369 d[i] +=
nl_*u[i+1]/6.0;
372 d[i] -=
nl_*u[i-1]/6.0;
373 du[i-1] +=
nl_*(u[i-1]+2.0*u[i])/6.0;
383 const std::vector<Real> &v,
384 const std::vector<Real> &u,
385 const std::vector<Real> &z)
const {
387 for (
int i = 0; i <
nx_; i++) {
390 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]);
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[ 0] -=
nl_*
u0_/6.0*v[0];
397 jv[nx_-1] +=
nl_*
u1_/6.0*v[nx_-1];
402 const std::vector<Real> &v,
403 const std::vector<Real> &u,
404 const std::vector<Real> &z)
const {
406 std::vector<Real> d(
nx_,0.0);
407 std::vector<Real> dl(
nx_-1,0.0);
408 std::vector<Real> du(
nx_-1,0.0);
416 const std::vector<Real> &v,
417 const std::vector<Real> &u,
418 const std::vector<Real> &z)
const {
420 for (
int i = 0; i <
nx_; i++) {
421 ajv[i] =
nu_/
dx_*2.0*v[i];
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[i] += -
nu_/
dx_*v[i+1]+
nl_*(u[i+1]/6.0*v[i]
428 -(u[i+1]+2.0*u[i])/6.0*v[i+1]);
431 ajv[ 0] -=
nl_*
u0_/6.0*v[0];
432 ajv[nx_-1] +=
nl_*
u1_/6.0*v[nx_-1];
437 const std::vector<Real> &v,
438 const std::vector<Real> &u,
439 const std::vector<Real> &z)
const {
441 std::vector<Real> d(
nx_,0.0);
442 std::vector<Real> du(
nx_-1,0.0);
443 std::vector<Real> dl(
nx_-1,0.0);
454 const std::vector<Real> &v,
455 const std::vector<Real> &u,
456 const std::vector<Real> &z)
const {
457 for (
int i=0; i<
nx_; i++) {
459 jv[i] = -
dx_/6.0*(v[i]+4.0*v[i+1]+v[i+2]);
465 const std::vector<Real> &v,
466 const std::vector<Real> &u,
467 const std::vector<Real> &z)
const {
468 for (
int i=0; i<
nx_+2; i++) {
470 jv[i] = -
dx_/6.0*v[i];
473 jv[i] = -
dx_/6.0*(4.0*v[i-1]+v[i]);
475 else if ( i == nx_ ) {
476 jv[i] = -
dx_/6.0*(4.0*v[i-1]+v[i-2]);
478 else if ( i == nx_+1 ) {
479 jv[i] = -
dx_/6.0*v[i-2];
482 jv[i] = -
dx_/6.0*(v[i-2]+4.0*v[i-1]+v[i]);
491 const std::vector<Real> &w,
492 const std::vector<Real> &v,
493 const std::vector<Real> &u,
494 const std::vector<Real> &z)
const {
495 for (
int i=0; i<
nx_; i++) {
499 ahwv[i] += (w[i]*v[i+1] - w[i+1]*(2.0*v[i]+v[i+1]))/6.0;
502 ahwv[i] += (w[i-1]*(v[i-1]+2.0*v[i]) - w[i]*v[i-1])/6.0;
508 const std::vector<Real> &w,
509 const std::vector<Real> &v,
510 const std::vector<Real> &u,
511 const std::vector<Real> &z) {
512 ahwv.assign(u.size(),0.0);
515 const std::vector<Real> &w,
516 const std::vector<Real> &v,
517 const std::vector<Real> &u,
518 const std::vector<Real> &z) {
519 ahwv.assign(z.size(),0.0);
522 const std::vector<Real> &w,
523 const std::vector<Real> &v,
524 const std::vector<Real> &u,
525 const std::vector<Real> &z) {
526 ahwv.assign(z.size(),0.0);
533 ROL::Ptr<BurgersFEM<Real> >
fem_;
534 mutable ROL::Ptr<L2VectorDual<Real> >
dual_vec_;
545 const std::vector<Real>& xval = *ex.
getVector();
547 return fem_->compute_L2_dot(xval,yval);
550 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
551 return ROL::makePtr<L2VectorPrimal>(
557 dual_vec_ = ROL::makePtr<L2VectorDual<Real>>(
570 ROL::Ptr<BurgersFEM<Real> >
fem_;
582 const std::vector<Real>& xval = *ex.
getVector();
585 std::vector<Real> Mx(dimension,0.0);
586 fem_->apply_inverse_mass(Mx,xval);
588 for (
unsigned i = 0; i <
dimension; i++) {
589 val += Mx[i]*yval[i];
594 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
595 return ROL::makePtr<L2VectorDual>(
601 prim_vec_ = ROL::makePtr<L2VectorPrimal<Real>>(
614 ROL::Ptr<BurgersFEM<Real> >
fem_;
615 mutable ROL::Ptr<H1VectorDual<Real> >
dual_vec_;
626 const std::vector<Real>& xval = *ex.
getVector();
628 return fem_->compute_H1_dot(xval,yval);
631 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
632 return ROL::makePtr<H1VectorPrimal>(
638 dual_vec_ = ROL::makePtr<H1VectorDual<Real>>(
651 ROL::Ptr<BurgersFEM<Real> >
fem_;
663 const std::vector<Real>& xval = *ex.
getVector();
666 std::vector<Real> Mx(dimension,0.0);
667 fem_->apply_inverse_H1(Mx,xval);
669 for (
unsigned i = 0; i <
dimension; i++) {
670 val += Mx[i]*yval[i];
675 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
676 return ROL::makePtr<H1VectorDual>(
682 prim_vec_ = ROL::makePtr<H1VectorPrimal<Real>>(
705 ROL::Ptr<BurgersFEM<Real> >
fem_;
714 ROL::Ptr<std::vector<Real> > cp =
716 ROL::Ptr<const std::vector<Real> > up =
718 ROL::Ptr<const std::vector<Real> > zp =
721 const std::vector<Real> param
723 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
725 fem_->compute_residual(*cp,*up,*zp);
730 ROL::Ptr<std::vector<Real> > jvp =
732 ROL::Ptr<const std::vector<Real> > vp =
734 ROL::Ptr<const std::vector<Real> > up =
736 ROL::Ptr<const std::vector<Real> > zp =
739 const std::vector<Real> param
741 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
743 fem_->apply_pde_jacobian(*jvp,*vp,*up,*zp);
748 ROL::Ptr<std::vector<Real> > jvp =
750 ROL::Ptr<const std::vector<Real> > vp =
752 ROL::Ptr<const std::vector<Real> > up =
754 ROL::Ptr<const std::vector<Real> > zp =
757 const std::vector<Real> param
759 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
761 fem_->apply_control_jacobian(*jvp,*vp,*up,*zp);
766 ROL::Ptr<std::vector<Real> > ijvp =
768 ROL::Ptr<const std::vector<Real> > vp =
770 ROL::Ptr<const std::vector<Real> > up =
772 ROL::Ptr<const std::vector<Real> > zp =
775 const std::vector<Real> param
777 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
779 fem_->apply_inverse_pde_jacobian(*ijvp,*vp,*up,*zp);
784 ROL::Ptr<std::vector<Real> > jvp =
786 ROL::Ptr<const std::vector<Real> > vp =
788 ROL::Ptr<const std::vector<Real> > up =
790 ROL::Ptr<const std::vector<Real> > zp =
793 const std::vector<Real> param
795 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
797 fem_->apply_adjoint_pde_jacobian(*jvp,*vp,*up,*zp);
802 ROL::Ptr<std::vector<Real> > jvp =
804 ROL::Ptr<const std::vector<Real> > vp =
806 ROL::Ptr<const std::vector<Real> > up =
808 ROL::Ptr<const std::vector<Real> > zp =
811 const std::vector<Real> param
813 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
815 fem_->apply_adjoint_control_jacobian(*jvp,*vp,*up,*zp);
820 ROL::Ptr<std::vector<Real> > iajvp =
822 ROL::Ptr<const std::vector<Real> > vp =
824 ROL::Ptr<const std::vector<Real> > up =
826 ROL::Ptr<const std::vector<Real> > zp =
829 const std::vector<Real> param
831 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
833 fem_->apply_inverse_adjoint_pde_jacobian(*iajvp,*vp,*up,*zp);
839 ROL::Ptr<std::vector<Real> > ahwvp =
841 ROL::Ptr<const std::vector<Real> > wp =
843 ROL::Ptr<const std::vector<Real> > vp =
845 ROL::Ptr<const std::vector<Real> > up =
847 ROL::Ptr<const std::vector<Real> > zp =
850 const std::vector<Real> param
852 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
854 fem_->apply_adjoint_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
864 ROL::Ptr<std::vector<Real> > ahwvp =
866 ROL::Ptr<const std::vector<Real> > wp =
868 ROL::Ptr<const std::vector<Real> > vp =
870 ROL::Ptr<const std::vector<Real> > up =
872 ROL::Ptr<const std::vector<Real> > zp =
875 const std::vector<Real> param
877 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
879 fem_->apply_adjoint_control_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
888 ROL::Ptr<std::vector<Real> > ahwvp =
890 ROL::Ptr<const std::vector<Real> > wp =
892 ROL::Ptr<const std::vector<Real> > vp =
894 ROL::Ptr<const std::vector<Real> > up =
896 ROL::Ptr<const std::vector<Real> > zp =
899 const std::vector<Real> param
901 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
903 fem_->apply_adjoint_pde_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
912 ROL::Ptr<std::vector<Real> > ahwvp =
914 ROL::Ptr<const std::vector<Real> > wp =
916 ROL::Ptr<const std::vector<Real> > vp =
918 ROL::Ptr<const std::vector<Real> > up =
920 ROL::Ptr<const std::vector<Real> > zp =
923 const std::vector<Real> param
925 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
927 fem_->apply_adjoint_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
946 ROL::Ptr<BurgersFEM<Real> >
fem_;
947 ROL::Ptr<ROL::Vector<Real> >
ud_;
948 ROL::Ptr<ROL::Vector<Real> >
diff_;
960 ROL::Ptr<const std::vector<Real> > up =
962 ROL::Ptr<const std::vector<Real> > zp =
964 ROL::Ptr<const std::vector<Real> > udp =
967 std::vector<Real> diff(udp->size(),0.0);
968 for (
unsigned i = 0; i < udp->size(); i++) {
969 diff[i] = (*up)[i] - (*udp)[i];
971 return 0.5*(
fem_->compute_L2_dot(diff,diff) +
alpha_*
fem_->compute_L2_dot(*zp,*zp));
975 ROL::Ptr<std::vector<Real> > gp =
977 ROL::Ptr<const std::vector<Real> > up =
979 ROL::Ptr<const std::vector<Real> > udp =
982 std::vector<Real> diff(udp->size(),0.0);
983 for (
unsigned i = 0; i < udp->size(); i++) {
984 diff[i] = (*up)[i] - (*udp)[i];
986 fem_->apply_mass(*gp,diff);
990 ROL::Ptr<std::vector<Real> > gp =
992 ROL::Ptr<const std::vector<Real> > zp =
995 fem_->apply_mass(*gp,*zp);
996 for (
unsigned i = 0; i < zp->size(); i++) {
1003 ROL::Ptr<std::vector<Real> > hvp =
1005 ROL::Ptr<const std::vector<Real> > vp =
1008 fem_->apply_mass(*hvp,*vp);
1023 ROL::Ptr<std::vector<Real> > hvp =
1025 ROL::Ptr<const std::vector<Real> > vp =
1028 fem_->apply_mass(*hvp,*vp);
1029 for (
unsigned i = 0; i < vp->size(); i++) {
1035 template<
class Real>
1039 std::vector<Real>
x_lo_;
1040 std::vector<Real>
x_up_;
1043 ROL::Ptr<BurgersFEM<Real> >
fem_;
1044 ROL::Ptr<ROL::Vector<Real> >
l_;
1045 ROL::Ptr<ROL::Vector<Real> >
u_;
1052 catch (std::exception &e) {
1062 catch (std::exception &e) {
1067 void axpy(std::vector<Real> &out,
const Real a,
1068 const std::vector<Real> &x,
const std::vector<Real> &y)
const{
1069 out.resize(
dim_,0.0);
1070 for (
unsigned i = 0; i <
dim_; i++) {
1071 out[i] = a*x[i] + y[i];
1076 for (
int i = 0; i <
dim_; i++ ) {
1077 x[i] = std::max(
x_lo_[i],std::min(
x_up_[i],x[i]));
1086 for (
int i = 0; i <
dim_; i++ ) {
1095 l_ = ROL::makePtr<L2VectorPrimal<Real>>(
1096 ROL::makePtr<std::vector<Real>>(l), fem);
1097 u_ = ROL::makePtr<L2VectorPrimal<Real>>(
1098 ROL::makePtr<std::vector<Real>>(u), fem);
1105 for (
int i = 0; i <
dim_; i++ ) {
1106 if ( (*ex)[i] >=
x_lo_[i] && (*ex)[i] <=
x_up_[i] ) { cnt *= 1; }
1109 if ( cnt == 0 ) { val =
false; }
1114 ROL::Ptr<std::vector<Real> > ex;
cast_vector(ex,x);
1120 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1122 for (
int i = 0; i <
dim_; i++ ) {
1123 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ) {
1131 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1133 for (
int i = 0; i <
dim_; i++ ) {
1134 if ( ((*ex)[i] >=
x_up_[i]-epsn) ) {
1142 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1144 for (
int i = 0; i <
dim_; i++ ) {
1145 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ||
1146 ((*ex)[i] >=
x_up_[i]-epsn) ) {
1155 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1157 for (
int i = 0; i <
dim_; i++ ) {
1158 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > 0.0) ) {
1167 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1169 for (
int i = 0; i <
dim_; i++ ) {
1170 if ( ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < 0.0) ) {
1179 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1181 for (
int i = 0; i <
dim_; i++ ) {
1182 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > 0.0) ||
1183 ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < 0.0) ) {
1198 template<
class Real>
1202 std::vector<Real>
x_lo_;
1203 std::vector<Real>
x_up_;
1206 ROL::Ptr<BurgersFEM<Real> >
fem_;
1207 ROL::Ptr<ROL::Vector<Real> >
l_;
1208 ROL::Ptr<ROL::Vector<Real> >
u_;
1213 xvec = ROL::constPtrCast<std::vector<Real> >(
1216 catch (std::exception &e) {
1217 xvec = ROL::constPtrCast<std::vector<Real> >(
1227 catch (std::exception &e) {
1232 void axpy(std::vector<Real> &out,
const Real a,
1233 const std::vector<Real> &x,
const std::vector<Real> &y)
const{
1234 out.resize(
dim_,0.0);
1235 for (
unsigned i = 0; i <
dim_; i++) {
1236 out[i] = a*x[i] + y[i];
1241 for (
int i = 0; i <
dim_; i++ ) {
1242 x[i] = std::max(
x_lo_[i],std::min(
x_up_[i],x[i]));
1251 for (
int i = 0; i <
dim_; i++ ) {
1260 l_ = ROL::makePtr<H1VectorPrimal<Real>>(
1261 ROL::makePtr<std::vector<Real>>(l), fem);
1262 u_ = ROL::makePtr<H1VectorPrimal<Real>>(
1263 ROL::makePtr<std::vector<Real>>(u), fem);
1270 for (
int i = 0; i <
dim_; i++ ) {
1271 if ( (*ex)[i] >=
x_lo_[i] && (*ex)[i] <=
x_up_[i] ) { cnt *= 1; }
1274 if ( cnt == 0 ) { val =
false; }
1279 ROL::Ptr<std::vector<Real> > ex;
cast_vector(ex,x);
1285 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1287 for (
int i = 0; i <
dim_; i++ ) {
1288 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ) {
1296 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1298 for (
int i = 0; i <
dim_; i++ ) {
1299 if ( ((*ex)[i] >=
x_up_[i]-epsn) ) {
1307 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1309 for (
int i = 0; i <
dim_; i++ ) {
1310 if ( ((*ex)[i] <=
x_lo_[i]+epsn) ||
1311 ((*ex)[i] >=
x_up_[i]-epsn) ) {
1320 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1322 for (
int i = 0; i <
dim_; i++ ) {
1323 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > 0.0) ) {
1332 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1334 for (
int i = 0; i <
dim_; i++ ) {
1335 if ( ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < 0.0) ) {
1344 ROL::Ptr<std::vector<Real> > ev;
cast_vector(ev,v);
1346 for (
int i = 0; i <
dim_; i++ ) {
1347 if ( ((*ex)[i] <=
x_lo_[i]+epsn && (*eg)[i] > 0.0) ||
1348 ((*ex)[i] >=
x_up_[i]-epsn && (*eg)[i] < 0.0) ) {
1363 template<
class Real,
class Ordinal>
1371 catch (std::exception &e) {
1378 : ROL::TeuchosBatchManager<Real,Ordinal>(comm) {}
1380 ROL::Ptr<std::vector<Real> > input_ptr;
1382 int dim_i = input_ptr->size();
1383 ROL::Ptr<std::vector<Real> > output_ptr;
1385 int dim_o = output_ptr->size();
1386 if ( dim_i != dim_o ) {
1387 std::cout <<
"L2VectorBatchManager: DIMENSION MISMATCH ON RANK "
1388 << ROL::TeuchosBatchManager<Real,Ordinal>::batchID() <<
"\n";
1391 ROL::TeuchosBatchManager<Real,Ordinal>::sumAll(&(*input_ptr)[0],&(*output_ptr)[0],dim_i);
1396 template<
class Real,
class Ordinal>
1404 catch (std::exception &e) {
1411 : ROL::TeuchosBatchManager<Real,Ordinal>(comm) {}
1413 ROL::Ptr<std::vector<Real> > input_ptr;
1415 int dim_i = input_ptr->size();
1416 ROL::Ptr<std::vector<Real> > output_ptr;
1418 int dim_o = output_ptr->size();
1419 if ( dim_i != dim_o ) {
1420 std::cout <<
"H1VectorBatchManager: DIMENSION MISMATCH ON RANK "
1421 << ROL::TeuchosBatchManager<Real,Ordinal>::batchID() <<
"\n";
1424 ROL::TeuchosBatchManager<Real,Ordinal>::sumAll(&(*input_ptr)[0],&(*output_ptr)[0],dim_i);
1429 template<
class Real>
1430 Real
random(
const ROL::Ptr<
const Teuchos::Comm<int> > &comm) {
1432 if ( Teuchos::rank<int>(*comm)==0 ) {
1433 val = (Real)rand()/(Real)RAND_MAX;
1435 Teuchos::broadcast<int,Real>(*comm,0,1,&val);
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)
Provides the interface to evaluate simulation-based objective functions.
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -active set.
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...
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 axpy(std::vector< Real > &out, const Real a, const std::vector< Real > &x, const std::vector< Real > &y) const
void cast_vector(ROL::Ptr< std::vector< Real > > &xvec, ROL::Vector< Real > &x) const
ROL::Ptr< L2VectorPrimal< Real > > prim_vec_
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< H1VectorPrimal< Real > > prim_vec_
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...
std::vector< Real > x_up_
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)
void pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Contains definitions of custom data types in ROL.
Ptr< const std::vector< Element > > getVector() const
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 ...
L2VectorBatchManager(const ROL::Ptr< const Teuchos::Comm< Ordinal > > &comm)
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.
ROL::Ptr< BurgersFEM< Real > > fem_
const std::vector< Real > getParameter(void) const
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the lower -active set.
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)
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 ...
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -binding set.
StdVector(const Ptr< std::vector< Real > > &std_vec)
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.
Defines the linear algebra or vector space interface.
void cast_vector(ROL::Ptr< std::vector< Real > > &xvec, ROL::Vector< Real > &x) const
ROL::Ptr< BurgersFEM< Real > > fem_
H1VectorDual< Real > DualStateVector
H1VectorDual< Real > PrimalConstraintVector
L2VectorPrimal(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
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 pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
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.
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_
void pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
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 pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the -binding set.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
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 compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u) const
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 pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the lower -active set.
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_
L2VectorPrimal< Real > PrimalControlVector
ROL::Ptr< ROL::Vector< Real > > u_
void apply_inverse_mass(std::vector< Real > &Mu, const std::vector< Real > &u) const
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< 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 pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the -binding set.
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.
Real random(const ROL::Ptr< const Teuchos::Comm< int > > &comm)
int dimension() const
Return dimension of the vector space.
ROL::Ptr< ROL::Vector< Real > > l_
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
H1VectorBatchManager(const ROL::Ptr< const Teuchos::Comm< Ordinal > > &comm)
ROL::Ptr< ROL::Vector< Real > > l_
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
void set_problem_data(const Real nu, const Real f, const Real u0, const Real u1)
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
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 .
void cast_vector(ROL::Ptr< std::vector< Real > > &xvec, ROL::Vector< Real > &x) const
L2VectorPrimal< Real > PrimalControlVector
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -binding set.
void pruneActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
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
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
const ROL::Ptr< const ROL::Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
void sumAll(ROL::Vector< Real > &input, ROL::Vector< Real > &output)
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
ROL::Ptr< BurgersFEM< Real > > fem_
ROL::Ptr< ROL::Vector< Real > > u_
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 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
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
bool isPrimalInitialized_
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
void sumAll(ROL::Vector< Real > &input, ROL::Vector< Real > &output)
bool isPrimalInitialized_
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.
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -active set.
H1BoundConstraint(std::vector< Real > &l, std::vector< Real > &u, const ROL::Ptr< BurgersFEM< Real > > &fem, Real scale=1.0)
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