45 #include "Teuchos_LAPACK.hpp" 
   46 #include "Teuchos_GlobalMPISession.hpp" 
   47 #include "Teuchos_Comm.hpp" 
   48 #include "Teuchos_DefaultComm.hpp" 
   49 #include "Teuchos_CommHelpers.hpp" 
   51 #include "ROL_ParameterList.hpp" 
   63 #include "ROL_StdTeuchosBatchManager.hpp" 
   72     return std::sqrt(
dot(r,r));
 
   75   Real 
dot(
const std::vector<Real> &x, 
const std::vector<Real> &y) {
 
   77     Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
 
   78     for (
unsigned i=0; i<x.size(); i++) {
 
   80         ip += 
dx_/6.0*(c*x[i] + x[i+1])*y[i];
 
   82       else if ( i == x.size()-1 ) {
 
   83         ip += 
dx_/6.0*(x[i-1] + c*x[i])*y[i];
 
   86         ip += 
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
 
   94   void update(std::vector<Real> &u, 
const std::vector<Real> &s, 
const Real alpha=1.0) {
 
   95     for (
unsigned i=0; i<u.size(); i++) {
 
  100   void scale(std::vector<Real> &u, 
const Real alpha=0.0) {
 
  101     for (
unsigned i=0; i<u.size(); i++) {
 
  107                   const std::vector<Real> &z) {
 
  108     r.clear(); r.resize(
nx_,0.0);
 
  109     const std::vector<Real> param =
 
  111     Real nu = std::pow(10.0,param[0]-2.0);
 
  112     Real f  = param[1]/100.0;
 
  113     Real u0 = 1.0+param[2]/1000.0;
 
  114     Real u1 = param[3]/1000.0;
 
  115     for (
int i=0; i<
nx_; i++) {
 
  118         r[i] = nu/
dx_*(2.0*u[i]-u[i+1]);
 
  121         r[i] = nu/
dx_*(2.0*u[i]-u[i-1]);
 
  124         r[i] = nu/
dx_*(2.0*u[i]-u[i-1]-u[i+1]);
 
  128         r[i] += u[i+1]*(u[i]+u[i+1])/6.0;
 
  131         r[i] -= u[i-1]*(u[i-1]+u[i])/6.0;
 
  134       r[i] -= 
dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
 
  139     r[    0] -= u0*u[    0]/6.0 + u0*u0/6.0 + nu*u0/
dx_;
 
  140     r[nx_-1] += u1*u[nx_-1]/6.0 + u1*u1/6.0 - nu*u1/
dx_;
 
  144                       const std::vector<Real> &u) {
 
  145     const std::vector<Real> param =
 
  147     Real nu = std::pow(10.0,param[0]-2.0);
 
  148     Real u0 = 1.0+param[2]/1000.0;
 
  149     Real u1 = param[3]/1000.0;
 
  151     d.clear();  d.resize(
nx_,nu*2.0/
dx_);
 
  152     dl.clear(); dl.resize(
nx_-1,-nu/
dx_);
 
  153     du.clear(); du.resize(
nx_-1,-nu/
dx_);
 
  155     for (
int i=0; i<
nx_; i++) {
 
  157         dl[i] += (-2.0*u[i]-u[i+1])/6.0;
 
  162         du[i-1] += (u[i-1]+2.0*u[i])/6.0;
 
  170   void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du, 
 
  171               const std::vector<Real> &r, 
const bool transpose = 
false) {
 
  172     u.assign(r.begin(),r.end());
 
  174     Teuchos::LAPACK<int,Real> lp;
 
  175     std::vector<Real> du2(
nx_-2,0.0);
 
  176     std::vector<int> ipiv(
nx_,0);
 
  180     lp.GTTRF(
nx_,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
 
  185     lp.GTTRS(trans,
nx_,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
 
  194     ROL::Ptr<std::vector<Real> > cp =
 
  196     ROL::Ptr<const std::vector<Real> > up =
 
  198     ROL::Ptr<const std::vector<Real> > zp =
 
  204     ROL::Ptr<std::vector<Real> > up =
 
  206     up->assign(up->size(),
static_cast<Real
>(1));
 
  212     ROL::Ptr<std::vector<Real> > jvp =
 
  214     ROL::Ptr<const std::vector<Real> > vp =
 
  216     ROL::Ptr<const std::vector<Real> > up =
 
  218     ROL::Ptr<const std::vector<Real> > zp =
 
  220     const std::vector<Real> param =
 
  222     Real nu = std::pow(10.0,param[0]-2.0);
 
  223     Real u0 = 1.0+param[2]/1000.0;
 
  224     Real u1 = param[3]/1000.0;
 
  226     for (
int i = 0; i < 
nx_; i++) {
 
  227       (*jvp)[i] = nu/
dx_*2.0*(*vp)[i];
 
  229         (*jvp)[i] += -nu/
dx_*(*vp)[i-1]
 
  230                      -(*up)[i-1]/6.0*(*vp)[i] 
 
  231                      -((*up)[i]+2.0*(*up)[i-1])/6.0*(*vp)[i-1];
 
  234         (*jvp)[i] += -nu/
dx_*(*vp)[i+1]
 
  235                      +(*up)[i+1]/6.0*(*vp)[i] 
 
  236                      +((*up)[i]+2.0*(*up)[i+1])/6.0*(*vp)[i+1];
 
  239     (*jvp)[    0] -= u0/6.0*(*vp)[0];
 
  240     (*jvp)[nx_-1] += u1/6.0*(*vp)[nx_-1];
 
  245     ROL::Ptr<std::vector<Real> > jvp =
 
  247     ROL::Ptr<const std::vector<Real>> vp =
 
  249     ROL::Ptr<const std::vector<Real>> up =
 
  251     ROL::Ptr<const std::vector<Real>> zp =
 
  253     for (
int i=0; i<
nx_; i++) {
 
  255       (*jvp)[i] = -
dx_/6.0*((*vp)[i]+4.0*(*vp)[i+1]+(*vp)[i+2]);
 
  261     ROL::Ptr<std::vector<Real> > ijvp =
 
  263     ROL::Ptr<const std::vector<Real> > vp =
 
  265     ROL::Ptr<const std::vector<Real> > up =
 
  267     ROL::Ptr<const std::vector<Real> > zp =
 
  270     std::vector<Real> d(
nx_,0.0);
 
  271     std::vector<Real> dl(
nx_-1,0.0);
 
  272     std::vector<Real> du(
nx_-1,0.0);
 
  280     ROL::Ptr<std::vector<Real> > jvp =
 
  282     ROL::Ptr<const std::vector<Real> > vp =
 
  284     ROL::Ptr<const std::vector<Real> > up =
 
  286     ROL::Ptr<const std::vector<Real> > zp =
 
  288     const std::vector<Real> param =
 
  290     Real nu = std::pow(10.0,param[0]-2.0);
 
  291     Real u0 = 1.0+param[2]/1000.0;
 
  292     Real u1 = param[3]/1000.0;
 
  294     for (
int i = 0; i < 
nx_; i++) {
 
  295       (*jvp)[i] = nu/
dx_*2.0*(*vp)[i];
 
  297         (*jvp)[i] += -nu/
dx_*(*vp)[i-1] 
 
  298                      -(*up)[i-1]/6.0*(*vp)[i] 
 
  299                      +((*up)[i-1]+2.0*(*up)[i])/6.0*(*vp)[i-1];
 
  302         (*jvp)[i] += -nu/
dx_*(*vp)[i+1] 
 
  303                      +(*up)[i+1]/6.0*(*vp)[i]
 
  304                      -((*up)[i+1]+2.0*(*up)[i])/6.0*(*vp)[i+1];
 
  307     (*jvp)[    0] -= u0/6.0*(*vp)[0];
 
  308     (*jvp)[nx_-1] += u1/6.0*(*vp)[nx_-1];
 
  313     ROL::Ptr<std::vector<Real> > jvp =
 
  315     ROL::Ptr<const std::vector<Real> > vp =
 
  317     ROL::Ptr<const std::vector<Real> > up =
 
  319     ROL::Ptr<const std::vector<Real> > zp =
 
  321     for (
int i=0; i<
nx_+2; i++) {
 
  323         (*jvp)[i] = -
dx_/6.0*(*vp)[i];
 
  326         (*jvp)[i] = -
dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i]);
 
  328       else if ( i == nx_ ) {
 
  329         (*jvp)[i] = -
dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i-2]);
 
  331       else if ( i == nx_+1 ) {
 
  332         (*jvp)[i] = -
dx_/6.0*(*vp)[i-2];
 
  335         (*jvp)[i] = -
dx_/6.0*((*vp)[i-2]+4.0*(*vp)[i-1]+(*vp)[i]);
 
  342     ROL::Ptr<std::vector<Real> > iajvp =
 
  344     ROL::Ptr<const std::vector<Real> > vp =
 
  346     ROL::Ptr<const std::vector<Real>> up =
 
  349     std::vector<Real> d(
nx_,0.0);
 
  350     std::vector<Real> du(
nx_-1,0.0);
 
  351     std::vector<Real> dl(
nx_-1,0.0);
 
  359     ROL::Ptr<std::vector<Real> > ahwvp =
 
  361     ROL::Ptr<const std::vector<Real> > wp =
 
  363     ROL::Ptr<const std::vector<Real> > vp =
 
  365     ROL::Ptr<const std::vector<Real> > up =
 
  367     ROL::Ptr<const std::vector<Real> > zp =
 
  369     for (
int i=0; i<
nx_; i++) {
 
  373         (*ahwvp)[i] += ((*wp)[i]*(*vp)[i+1] - (*wp)[i+1]*(2.0*(*vp)[i]+(*vp)[i+1]))/6.0;
 
  376         (*ahwvp)[i] += ((*wp)[i-1]*((*vp)[i-1]+2.0*(*vp)[i]) - (*wp)[i]*(*vp)[i-1])/6.0;
 
  410       case 1:  val = ((x<0.5) ? 1.0 : 0.0);          
break;
 
  411       case 2:  val = 1.0;                            
break;
 
  412       case 3:  val = std::abs(std::sin(8.0*M_PI*x)); 
break;
 
  413       case 4:  val = std::exp(-0.5*(x-0.5)*(x-0.5)); 
break;
 
  418   Real 
dot(
const std::vector<Real> &x, 
const std::vector<Real> &y) {
 
  420     Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
 
  421     for (
unsigned i=0; i<x.size(); i++) {
 
  423         ip += 
dx_/6.0*(c*x[i] + x[i+1])*y[i];
 
  425       else if ( i == x.size()-1 ) {
 
  426         ip += 
dx_/6.0*(x[i-1] + c*x[i])*y[i];
 
  429         ip += 
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
 
  435   void apply_mass(std::vector<Real> &Mu, 
const std::vector<Real> &u ) {
 
  436     Mu.resize(u.size(),0.0);
 
  437     Real c = (((int)u.size()==
nx_) ? 4.0 : 2.0);
 
  438     for (
unsigned i=0; i<u.size(); i++) {
 
  440         Mu[i] = 
dx_/6.0*(c*u[i] + u[i+1]);
 
  442       else if ( i == u.size()-1 ) {
 
  443         Mu[i] = 
dx_/6.0*(u[i-1] + c*u[i]);
 
  446         Mu[i] = 
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
 
  457     dx_ = 1.0/((Real)nx+1.0);
 
  463     ROL::Ptr<const std::vector<Real> > up =
 
  465     ROL::Ptr<const std::vector<Real> > zp =
 
  468     Real res1 = 0.0, res2 = 0.0, res3 = 0.0;
 
  469     Real valu = 0.0, valz = 
dot(*zp,*zp);
 
  470     for (
int i=0; i<
nx_; i++) {
 
  474         valu += 
dx_/6.0*(4.0*res1 + res2)*res1;
 
  476       else if ( i == nx_-1 ) {
 
  479         valu += dx_/6.0*(res1 + 4.0*res2)*res2;
 
  485         valu += dx_/6.0*(res1 + 4.0*res2 + res3)*res2;
 
  488     return 0.5*(valu + 
alpha_*valz);
 
  493     ROL::Ptr<std::vector<Real> > gup = 
 
  496     ROL::Ptr<const std::vector<Real> > up =
 
  498     ROL::Ptr<const std::vector<Real> > zp =
 
  501     std::vector<Real> diff(
nx_,0.0);
 
  502     for (
int i=0; i<
nx_; i++) {
 
  510     ROL::Ptr<std::vector<Real> > gzp = 
 
  513     ROL::Ptr<const std::vector<Real> > up =
 
  515     ROL::Ptr<const std::vector<Real> > zp =
 
  518     for (
int i=0; i<
nx_+2; i++) {
 
  520         (*gzp)[i] = 
alpha_*
dx_/6.0*(2.0*(*zp)[i]+(*zp)[i+1]);
 
  523         (*gzp)[i] = 
alpha_*
dx_/6.0*(2.0*(*zp)[i]+(*zp)[i-1]);
 
  526         (*gzp)[i] = 
alpha_*
dx_/6.0*((*zp)[i-1]+4.0*(*zp)[i]+(*zp)[i+1]);
 
  533     ROL::Ptr<std::vector<Real> > hvup =
 
  536     ROL::Ptr<const std::vector<Real> > vup =
 
  554     ROL::Ptr<std::vector<Real> > hvzp =
 
  557     ROL::Ptr<const std::vector<Real> > vzp =
 
  560     for (
int i=0; i<
nx_+2; i++) {
 
  562         (*hvzp)[i] = 
alpha_*
dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i+1]);
 
  565         (*hvzp)[i] = 
alpha_*
dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i-1]);
 
  568         (*hvzp)[i] = 
alpha_*
dx_/6.0*((*vzp)[i-1]+4.0*(*vzp)[i]+(*vzp)[i+1]);
 
Provides the interface to evaluate simulation-based objective functions. 
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 evaluate_target(Real x)
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 solve(ROL::Vector< Real > &c, ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve  for . 
Contains definitions of custom data types in ROL. 
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  ...
const std::vector< Real > getParameter(void) const 
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 ...
virtual void zero()
Set to zero vector. 
Defines the linear algebra or vector space interface. 
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
void hessVec_22(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Real value(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute value. 
void gradient_1(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to first component. 
void 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 compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u)
Constraint_BurgersControl(int nx=128)
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
Objective_BurgersControl(Real alpha=1.e-4, int nx=128)
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 . 
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 hessVec_12(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void gradient_2(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to second component. 
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
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)
void scale(std::vector< Real > &u, const Real alpha=0.0)
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 . 
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol)
Given , solve  for . 
void apply_mass(std::vector< Real > &Mu, const std::vector< Real > &u)
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 ...
Real compute_norm(const std::vector< Real > &r)
void update(std::vector< Real > &u, const std::vector< Real > &s, const Real alpha=1.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...
Defines the constraint operator interface for simulation-based optimization. 
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator  at . 
void linear_solve(std::vector< Real > &u, std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &r, const bool transpose=false)