20 #include "ROL_TeuchosBatchManager.hpp"
22 #include "Teuchos_LAPACK.hpp"
50 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0)
const {
51 for (
unsigned i=0; i<u.size(); i++) {
56 void axpy(std::vector<Real> &out,
const Real a,
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
57 for (
unsigned i=0; i < x.size(); i++) {
58 out[i] = a*x[i] + y[i];
62 void scale(std::vector<Real> &u,
const Real alpha=0.0)
const {
63 for (
unsigned i=0; i<u.size(); i++) {
68 void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
69 const std::vector<Real> &r,
const bool transpose =
false)
const {
70 if ( r.size() == 1 ) {
71 u.resize(1,r[0]/d[0]);
73 else if ( r.size() == 2 ) {
75 Real det = d[0]*d[1] - dl[0]*du[0];
76 u[0] = (d[1]*r[0] - du[0]*r[1])/det;
77 u[1] = (d[0]*r[1] - dl[0]*r[0])/det;
80 u.assign(r.begin(),r.end());
82 Teuchos::LAPACK<int,Real> lp;
83 std::vector<Real> du2(r.size()-2,0.0);
84 std::vector<int> ipiv(r.size(),0);
89 lp.GTTRF(dim,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
94 lp.GTTRS(trans,dim,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
99 BurgersFEM(
int nx = 128, Real nl = 1.0, Real cH1 = 1.0, Real cL2 = 1.0)
103 nu_ = std::pow(10.0,nu-2.0);
121 Real
compute_L2_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
123 Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
124 for (
unsigned i=0; i<x.size(); i++) {
126 ip +=
dx_/6.0*(c*x[i] + x[i+1])*y[i];
128 else if ( i == x.size()-1 ) {
129 ip +=
dx_/6.0*(x[i-1] + c*x[i])*y[i];
132 ip +=
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
144 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
145 Mu.resize(u.size(),0.0);
146 Real c = (((int)u.size()==
nx_) ? 4.0 : 2.0);
147 for (
unsigned i=0; i<u.size(); i++) {
149 Mu[i] =
dx_/6.0*(c*u[i] + u[i+1]);
151 else if ( i == u.size()-1 ) {
152 Mu[i] =
dx_/6.0*(u[i-1] + c*u[i]);
155 Mu[i] =
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
162 unsigned nx = u.size();
164 std::vector<Real> dl(nx-1,
dx_/6.0);
165 std::vector<Real> d(nx,2.0*
dx_/3.0);
166 std::vector<Real> du(nx-1,
dx_/6.0);
167 if ( (
int)nx !=
nx_ ) {
176 std::vector<Real> u(
nx_,0.0), Mu(
nx_,0.0), iMMu(
nx_,0.0), diff(
nx_,0.0);
177 for (
int i = 0; i <
nx_; i++) {
178 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
182 axpy(diff,-1.0,iMMu,u);
185 outStream <<
"Test Inverse State Mass Matrix\n";
186 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
187 outStream <<
" ||u|| = " << normu <<
"\n";
188 outStream <<
" Relative Error = " << error/normu <<
"\n";
191 u.resize(nx_+2,0.0); Mu.resize(nx_+2,0.0); iMMu.resize(nx_+2,0.0); diff.resize(nx_+2,0.0);
192 for (
int i = 0; i < nx_+2; i++) {
193 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
197 axpy(diff,-1.0,iMMu,u);
200 outStream <<
"Test Inverse Control Mass Matrix\n";
201 outStream <<
" ||z - inv(M)Mz|| = " << error <<
"\n";
202 outStream <<
" ||z|| = " << normu <<
"\n";
203 outStream <<
" Relative Error = " << error/normu <<
"\n";
211 Real
compute_H1_dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
213 for (
int i=0; i<
nx_; i++) {
215 ip +=
cL2_*
dx_/6.0*(4.0*x[i] + x[i+1])*y[i];
216 ip +=
cH1_*(2.0*x[i] - x[i+1])/
dx_*y[i];
218 else if ( i == nx_-1 ) {
219 ip +=
cL2_*
dx_/6.0*(x[i-1] + 4.0*x[i])*y[i];
220 ip +=
cH1_*(2.0*x[i] - x[i-1])/
dx_*y[i];
223 ip +=
cL2_*
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
224 ip +=
cH1_*(2.0*x[i] - x[i-1] - x[i+1])/
dx_*y[i];
236 void apply_H1(std::vector<Real> &Mu,
const std::vector<Real> &u )
const {
238 for (
int i=0; i<
nx_; i++) {
240 Mu[i] =
cL2_*
dx_/6.0*(4.0*u[i] + u[i+1])
241 +
cH1_*(2.0*u[i] - u[i+1])/
dx_;
243 else if ( i == nx_-1 ) {
244 Mu[i] =
cL2_*
dx_/6.0*(u[i-1] + 4.0*u[i])
245 +
cH1_*(2.0*u[i] - u[i-1])/
dx_;
248 Mu[i] =
cL2_*
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1])
249 +
cH1_*(2.0*u[i] - u[i-1] - u[i+1])/
dx_;
264 std::vector<Real> u(
nx_,0.0), Mu(
nx_,0.0), iMMu(
nx_,0.0), diff(
nx_,0.0);
265 for (
int i = 0; i <
nx_; i++) {
266 u[i] = 2.0*(Real)rand()/(Real)RAND_MAX - 1.0;
270 axpy(diff,-1.0,iMMu,u);
273 outStream <<
"Test Inverse State H1 Matrix\n";
274 outStream <<
" ||u - inv(M)Mu|| = " << error <<
"\n";
275 outStream <<
" ||u|| = " << normu <<
"\n";
276 outStream <<
" Relative Error = " << error/normu <<
"\n";
285 const std::vector<Real> &z)
const {
288 for (
int i=0; i<
nx_; i++) {
291 r[i] =
nu_/
dx_*(2.0*u[i]-u[i+1]);
294 r[i] =
nu_/
dx_*(2.0*u[i]-u[i-1]);
297 r[i] =
nu_/
dx_*(2.0*u[i]-u[i-1]-u[i+1]);
301 r[i] +=
nl_*u[i+1]*(u[i]+u[i+1])/6.0;
304 r[i] -=
nl_*u[i-1]*(u[i-1]+u[i])/6.0;
307 r[i] -=
dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
321 std::vector<Real> &d,
322 std::vector<Real> &du,
323 const std::vector<Real> &u)
const {
332 for (
int i=0; i<
nx_; i++) {
334 dl[i] +=
nl_*(-2.0*u[i]-u[i+1])/6.0;
335 d[i] +=
nl_*u[i+1]/6.0;
338 d[i] -=
nl_*u[i-1]/6.0;
339 du[i-1] +=
nl_*(u[i-1]+2.0*u[i])/6.0;
349 const std::vector<Real> &v,
350 const std::vector<Real> &u,
351 const std::vector<Real> &z)
const {
353 for (
int i = 0; i <
nx_; i++) {
356 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]);
359 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]);
362 jv[ 0] -=
nl_*
u0_/6.0*v[0];
363 jv[nx_-1] +=
nl_*
u1_/6.0*v[nx_-1];
368 const std::vector<Real> &v,
369 const std::vector<Real> &u,
370 const std::vector<Real> &z)
const {
372 std::vector<Real> d(
nx_,0.0);
373 std::vector<Real> dl(
nx_-1,0.0);
374 std::vector<Real> du(
nx_-1,0.0);
382 const std::vector<Real> &v,
383 const std::vector<Real> &u,
384 const std::vector<Real> &z)
const {
386 for (
int i = 0; i <
nx_; i++) {
387 ajv[i] =
nu_/
dx_*2.0*v[i];
389 ajv[i] += -
nu_/
dx_*v[i-1]-
nl_*(u[i-1]/6.0*v[i]
390 -(u[i-1]+2.0*u[i])/6.0*v[i-1]);
393 ajv[i] += -
nu_/
dx_*v[i+1]+
nl_*(u[i+1]/6.0*v[i]
394 -(u[i+1]+2.0*u[i])/6.0*v[i+1]);
397 ajv[ 0] -=
nl_*
u0_/6.0*v[0];
398 ajv[nx_-1] +=
nl_*
u1_/6.0*v[nx_-1];
403 const std::vector<Real> &v,
404 const std::vector<Real> &u,
405 const std::vector<Real> &z)
const {
407 std::vector<Real> d(
nx_,0.0);
408 std::vector<Real> du(
nx_-1,0.0);
409 std::vector<Real> dl(
nx_-1,0.0);
420 const std::vector<Real> &v,
421 const std::vector<Real> &u,
422 const std::vector<Real> &z)
const {
423 for (
int i=0; i<
nx_; i++) {
425 jv[i] = -
dx_/6.0*(v[i]+4.0*v[i+1]+v[i+2]);
431 const std::vector<Real> &v,
432 const std::vector<Real> &u,
433 const std::vector<Real> &z)
const {
434 for (
int i=0; i<
nx_+2; i++) {
436 jv[i] = -
dx_/6.0*v[i];
439 jv[i] = -
dx_/6.0*(4.0*v[i-1]+v[i]);
441 else if ( i == nx_ ) {
442 jv[i] = -
dx_/6.0*(4.0*v[i-1]+v[i-2]);
444 else if ( i == nx_+1 ) {
445 jv[i] = -
dx_/6.0*v[i-2];
448 jv[i] = -
dx_/6.0*(v[i-2]+4.0*v[i-1]+v[i]);
457 const std::vector<Real> &w,
458 const std::vector<Real> &v,
459 const std::vector<Real> &u,
460 const std::vector<Real> &z)
const {
461 for (
int i=0; i<
nx_; i++) {
465 ahwv[i] += (w[i]*v[i+1] - w[i+1]*(2.0*v[i]+v[i+1]))/6.0;
468 ahwv[i] += (w[i-1]*(v[i-1]+2.0*v[i]) - w[i]*v[i-1])/6.0;
474 const std::vector<Real> &w,
475 const std::vector<Real> &v,
476 const std::vector<Real> &u,
477 const std::vector<Real> &z) {
478 ahwv.assign(u.size(),0.0);
481 const std::vector<Real> &w,
482 const std::vector<Real> &v,
483 const std::vector<Real> &u,
484 const std::vector<Real> &z) {
485 ahwv.assign(z.size(),0.0);
488 const std::vector<Real> &w,
489 const std::vector<Real> &v,
490 const std::vector<Real> &u,
491 const std::vector<Real> &z) {
492 ahwv.assign(z.size(),0.0);
499 ROL::Ptr<std::vector<Real> >
vec_;
500 ROL::Ptr<BurgersFEM<Real> >
fem_;
502 mutable ROL::Ptr<L2VectorDual<Real> >
dual_vec_;
511 const std::vector<Real>& xval = *ex.
getVector();
512 std::copy(xval.begin(),xval.end(),
vec_->begin());
517 const std::vector<Real>& xval = *ex.
getVector();
520 (*vec_)[i] += xval[i];
533 const std::vector<Real>& xval = *ex.
getVector();
534 return fem_->compute_L2_dot(xval,*
vec_);
539 val = std::sqrt(
dot(*
this) );
543 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
544 return ROL::makePtr<L2VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
555 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
556 ROL::Ptr<L2VectorPrimal> e
557 = ROL::makePtr<L2VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
558 (*e->getVector())[i] = 1.0;
567 dual_vec_ = ROL::makePtr<L2VectorDual<Real>>(
568 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
570 fem_->apply_mass(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
576 const std::vector<Real>& xval = *ex.
getVector();
577 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
585 ROL::Ptr<std::vector<Real> >
vec_;
586 ROL::Ptr<BurgersFEM<Real> >
fem_;
588 mutable ROL::Ptr<L2VectorPrimal<Real> >
dual_vec_;
597 const std::vector<Real>& xval = *ex.
getVector();
598 std::copy(xval.begin(),xval.end(),
vec_->begin());
603 const std::vector<Real>& xval = *ex.
getVector();
606 (*vec_)[i] += xval[i];
619 const std::vector<Real>& xval = *ex.
getVector();
621 std::vector<Real> Mx(dimension,0.0);
622 fem_->apply_inverse_mass(Mx,xval);
624 for (
unsigned i = 0; i <
dimension; i++) {
625 val += Mx[i]*(*vec_)[i];
632 val = std::sqrt(
dot(*
this) );
636 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
637 return ROL::makePtr<L2VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
648 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
649 ROL::Ptr<L2VectorDual> e
650 = ROL::makePtr<L2VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
651 (*e->getVector())[i] = 1.0;
660 dual_vec_ = ROL::makePtr<L2VectorPrimal<Real>>(
661 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
663 fem_->apply_inverse_mass(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
669 const std::vector<Real>& xval = *ex.
getVector();
670 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
678 ROL::Ptr<std::vector<Real> >
vec_;
679 ROL::Ptr<BurgersFEM<Real> >
fem_;
681 mutable ROL::Ptr<H1VectorDual<Real> >
dual_vec_;
690 const std::vector<Real>& xval = *ex.
getVector();
691 std::copy(xval.begin(),xval.end(),
vec_->begin());
696 const std::vector<Real>& xval = *ex.
getVector();
699 (*vec_)[i] += xval[i];
712 const std::vector<Real>& xval = *ex.
getVector();
713 return fem_->compute_H1_dot(xval,*
vec_);
718 val = std::sqrt(
dot(*
this) );
722 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
723 return ROL::makePtr<H1VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
734 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
735 ROL::Ptr<H1VectorPrimal> e
736 = ROL::makePtr<H1VectorPrimal>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
737 (*e->getVector())[i] = 1.0;
746 dual_vec_ = ROL::makePtr<H1VectorDual<Real>>(
747 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
749 fem_->apply_H1(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
755 const std::vector<Real>& xval = *ex.
getVector();
756 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
764 ROL::Ptr<std::vector<Real> >
vec_;
765 ROL::Ptr<BurgersFEM<Real> >
fem_;
767 mutable ROL::Ptr<H1VectorPrimal<Real> >
dual_vec_;
776 const std::vector<Real>& xval = *ex.
getVector();
777 std::copy(xval.begin(),xval.end(),
vec_->begin());
782 const std::vector<Real>& xval = *ex.
getVector();
785 (*vec_)[i] += xval[i];
798 const std::vector<Real>& xval = *ex.
getVector();
800 std::vector<Real> Mx(dimension,0.0);
801 fem_->apply_inverse_H1(Mx,xval);
803 for (
unsigned i = 0; i <
dimension; i++) {
804 val += Mx[i]*(*vec_)[i];
811 val = std::sqrt(
dot(*
this) );
815 ROL::Ptr<ROL::Vector<Real> >
clone()
const {
816 return ROL::makePtr<H1VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
827 ROL::Ptr<ROL::Vector<Real> >
basis(
const int i )
const {
828 ROL::Ptr<H1VectorDual> e
829 = ROL::makePtr<H1VectorDual>( ROL::makePtr<std::vector<Real>>(
vec_->size(),0.0),
fem_);
830 (*e->getVector())[i] = 1.0;
839 dual_vec_ = ROL::makePtr<H1VectorPrimal<Real>>(
840 ROL::makePtr<std::vector<Real>>(*vec_),
fem_);
842 fem_->apply_inverse_H1(*(ROL::constPtrCast<std::vector<Real> >(
dual_vec_->getVector())),*
vec_);
848 const std::vector<Real>& xval = *ex.
getVector();
849 return std::inner_product(
vec_->begin(),
vec_->end(), xval.begin(), Real(0));
867 ROL::Ptr<BurgersFEM<Real> >
fem_;
876 ROL::Ptr<std::vector<Real> > cp =
878 ROL::Ptr<const std::vector<Real> > up =
880 ROL::Ptr<const std::vector<Real> > zp =
883 const std::vector<Real> param
885 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
887 fem_->compute_residual(*cp,*up,*zp);
892 ROL::Ptr<std::vector<Real> > jvp =
894 ROL::Ptr<const std::vector<Real> > vp =
896 ROL::Ptr<const std::vector<Real> > up =
898 ROL::Ptr<const std::vector<Real> > zp =
901 const std::vector<Real> param
903 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
905 fem_->apply_pde_jacobian(*jvp,*vp,*up,*zp);
910 ROL::Ptr<std::vector<Real> > jvp =
912 ROL::Ptr<const std::vector<Real> > vp =
914 ROL::Ptr<const std::vector<Real> > up =
916 ROL::Ptr<const std::vector<Real> > zp =
919 const std::vector<Real> param
921 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
923 fem_->apply_control_jacobian(*jvp,*vp,*up,*zp);
928 ROL::Ptr<std::vector<Real> > ijvp =
930 ROL::Ptr<const std::vector<Real> > vp =
932 ROL::Ptr<const std::vector<Real> > up =
934 ROL::Ptr<const std::vector<Real> > zp =
937 const std::vector<Real> param
939 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
941 fem_->apply_inverse_pde_jacobian(*ijvp,*vp,*up,*zp);
946 ROL::Ptr<std::vector<Real> > jvp =
948 ROL::Ptr<const std::vector<Real> > vp =
950 ROL::Ptr<const std::vector<Real> > up =
952 ROL::Ptr<const std::vector<Real> > zp =
955 const std::vector<Real> param
957 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
959 fem_->apply_adjoint_pde_jacobian(*jvp,*vp,*up,*zp);
964 ROL::Ptr<std::vector<Real> > jvp =
966 ROL::Ptr<const std::vector<Real> > vp =
968 ROL::Ptr<const std::vector<Real> > up =
970 ROL::Ptr<const std::vector<Real> > zp =
973 const std::vector<Real> param
975 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
977 fem_->apply_adjoint_control_jacobian(*jvp,*vp,*up,*zp);
982 ROL::Ptr<std::vector<Real> > iajvp =
984 ROL::Ptr<const std::vector<Real> > vp =
986 ROL::Ptr<const std::vector<Real> > up =
988 ROL::Ptr<const std::vector<Real> > zp =
991 const std::vector<Real> param
993 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
995 fem_->apply_inverse_adjoint_pde_jacobian(*iajvp,*vp,*up,*zp);
1001 ROL::Ptr<std::vector<Real> > ahwvp =
1003 ROL::Ptr<const std::vector<Real> > wp =
1005 ROL::Ptr<const std::vector<Real> > vp =
1007 ROL::Ptr<const std::vector<Real> > up =
1009 ROL::Ptr<const std::vector<Real> > zp =
1012 const std::vector<Real> param
1014 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
1016 fem_->apply_adjoint_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
1026 ROL::Ptr<std::vector<Real> > ahwvp =
1028 ROL::Ptr<const std::vector<Real> > wp =
1030 ROL::Ptr<const std::vector<Real> > vp =
1032 ROL::Ptr<const std::vector<Real> > up =
1034 ROL::Ptr<const std::vector<Real> > zp =
1037 const std::vector<Real> param
1039 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
1041 fem_->apply_adjoint_control_pde_hessian(*ahwvp,*wp,*vp,*up,*zp);
1050 ROL::Ptr<std::vector<Real> > ahwvp =
1052 ROL::Ptr<const std::vector<Real> > wp =
1054 ROL::Ptr<const std::vector<Real> > vp =
1056 ROL::Ptr<const std::vector<Real> > up =
1058 ROL::Ptr<const std::vector<Real> > zp =
1061 const std::vector<Real> param
1063 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
1065 fem_->apply_adjoint_pde_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
1074 ROL::Ptr<std::vector<Real> > ahwvp =
1076 ROL::Ptr<const std::vector<Real> > wp =
1078 ROL::Ptr<const std::vector<Real> > vp =
1080 ROL::Ptr<const std::vector<Real> > up =
1082 ROL::Ptr<const std::vector<Real> > zp =
1085 const std::vector<Real> param
1087 fem_->set_problem_data(param[0],param[1],param[2],param[3]);
1089 fem_->apply_adjoint_control_hessian(*ahwvp,*wp,*vp,*up,*zp);
1097 template<
class Real>
1108 ROL::Ptr<BurgersFEM<Real> >
fem_;
1109 ROL::Ptr<ROL::Vector<Real> >
ud_;
1110 ROL::Ptr<ROL::Vector<Real> >
diff_;
1122 ROL::Ptr<const std::vector<Real> > up =
1124 ROL::Ptr<const std::vector<Real> > zp =
1126 ROL::Ptr<const std::vector<Real> > udp =
1129 std::vector<Real> diff(udp->size(),0.0);
1130 for (
unsigned i = 0; i < udp->size(); i++) {
1131 diff[i] = (*up)[i] - (*udp)[i];
1133 return 0.5*(
fem_->compute_L2_dot(diff,diff) +
alpha_*
fem_->compute_L2_dot(*zp,*zp));
1137 ROL::Ptr<std::vector<Real> > gp =
1139 ROL::Ptr<const std::vector<Real> > up =
1141 ROL::Ptr<const std::vector<Real> > udp =
1144 std::vector<Real> diff(udp->size(),0.0);
1145 for (
unsigned i = 0; i < udp->size(); i++) {
1146 diff[i] = (*up)[i] - (*udp)[i];
1148 fem_->apply_mass(*gp,diff);
1152 ROL::Ptr<std::vector<Real> > gp =
1154 ROL::Ptr<const std::vector<Real> > zp =
1157 fem_->apply_mass(*gp,*zp);
1158 for (
unsigned i = 0; i < zp->size(); i++) {
1165 ROL::Ptr<std::vector<Real> > hvp =
1167 ROL::Ptr<const std::vector<Real> > vp =
1170 fem_->apply_mass(*hvp,*vp);
1185 ROL::Ptr<std::vector<Real> > hvp =
1187 ROL::Ptr<const std::vector<Real> > vp =
1190 fem_->apply_mass(*hvp,*vp);
1191 for (
unsigned i = 0; i < vp->size(); i++) {
1197 template<
class Real,
class Ordinal>
1205 catch (std::exception &e) {
1212 : ROL::TeuchosBatchManager<Real,Ordinal>(comm) {}
1214 ROL::Ptr<std::vector<Real> > input_ptr;
1216 int dim_i = input_ptr->size();
1217 ROL::Ptr<std::vector<Real> > output_ptr;
1219 int dim_o = output_ptr->size();
1220 if ( dim_i != dim_o ) {
1221 std::cout <<
"L2VectorBatchManager: DIMENSION MISMATCH ON RANK "
1222 << ROL::TeuchosBatchManager<Real,Ordinal>::batchID() <<
"\n";
1225 ROL::TeuchosBatchManager<Real,Ordinal>::sumAll(&(*input_ptr)[0],&(*output_ptr)[0],dim_i);
1230 template<
class Real,
class Ordinal>
1238 catch (std::exception &e) {
1245 : ROL::TeuchosBatchManager<Real,Ordinal>(comm) {}
1247 ROL::Ptr<std::vector<Real> > input_ptr;
1249 int dim_i = input_ptr->size();
1250 ROL::Ptr<std::vector<Real> > output_ptr;
1252 int dim_o = output_ptr->size();
1253 if ( dim_i != dim_o ) {
1254 std::cout <<
"H1VectorBatchManager: DIMENSION MISMATCH ON RANK "
1255 << ROL::TeuchosBatchManager<Real,Ordinal>::batchID() <<
"\n";
1258 ROL::TeuchosBatchManager<Real,Ordinal>::sumAll(&(*input_ptr)[0],&(*output_ptr)[0],dim_i);
1263 template<
class Real>
1264 Real
random(
const ROL::Ptr<
const Teuchos::Comm<int> > &comm) {
1266 if ( Teuchos::rank<int>(*comm)==0 ) {
1267 val = (Real)rand()/(Real)RAND_MAX;
1269 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)
ROL::Ptr< std::vector< Real > > vec_
Provides the interface to evaluate simulation-based objective functions.
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
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.
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 .
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 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
void plus(const ROL::Vector< Real > &x)
Compute , where .
ROL::Ptr< BurgersFEM< Real > > fem_
const std::vector< Real > getParameter(void) const
Real compute_H1_norm(const std::vector< Real > &r) const
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_
H1VectorDual(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BurgersFEM< Real > > &fem)
virtual void zero()
Set to zero vector.
ROL::Ptr< std::vector< Real > > getVector()
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
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 .
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.
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_
ROL::Ptr< ROL::Vector< Real > > ud_
L2VectorBatchManager(const ROL::Ptr< const Teuchos::Comm< int > > &comm)
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...
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
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
ROL::Ptr< std::vector< Real > > getVector()
L2VectorPrimal< Real > PrimalControlVector
void apply_inverse_mass(std::vector< Real > &Mu, const std::vector< Real > &u) 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 scale(const Real alpha)
Compute where .
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)
void set(const ROL::Vector< Real > &x)
Set where .
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 .
void compute_residual(std::vector< Real > &r, const std::vector< Real > &u, const std::vector< Real > &z) const
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
H1VectorBatchManager(const ROL::Ptr< const Teuchos::Comm< int > > &comm)
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
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 .
void cast_vector(ROL::Ptr< std::vector< Real > > &xvec, ROL::Vector< Real > &x) const
L2VectorPrimal< Real > PrimalControlVector
H1VectorPrimal< Real > PrimalStateVector
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
L2VectorDual< Real > DualControlVector
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 .
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 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 .
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 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 sumAll(ROL::Vector< Real > &input, ROL::Vector< Real > &output)
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)
Real dot(const ROL::Vector< Real > &x) const override
Compute where .
ROL::Ptr< std::vector< Real > > getVector()
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_