44 #include "Teuchos_ParameterList.hpp" 45 #include "Teuchos_XMLParameterListHelpers.hpp" 46 #include "Teuchos_oblackholestream.hpp" 47 #include "Teuchos_LAPACK.hpp" 48 #include "Teuchos_GlobalMPISession.hpp" 49 #include "Teuchos_Comm.hpp" 50 #include "Teuchos_DefaultComm.hpp" 51 #include "Teuchos_CommHelpers.hpp" 80 return std::sqrt(
dot(r,r));
83 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y) {
85 Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
86 for (
unsigned i=0; i<x.size(); i++) {
88 ip += dx_/6.0*(c*x[i] + x[i+1])*y[i];
90 else if ( i == x.size()-1 ) {
91 ip += dx_/6.0*(x[i-1] + c*x[i])*y[i];
94 ip += dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
100 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0) {
101 for (
unsigned i=0; i<u.size(); i++) {
106 void scale(std::vector<Real> &u,
const Real alpha=0.0) {
107 for (
unsigned i=0; i<u.size(); i++) {
113 const std::vector<Real> &z) {
114 r.clear(); r.resize(nx_,0.0);
115 const std::vector<Real> param =
117 Real nu = std::pow(10.0,param[0]-2.0);
118 Real f = param[1]/100.0;
119 Real u0 = 1.0+param[2]/1000.0;
120 Real u1 = param[3]/1000.0;
121 for (
int i=0; i<
nx_; i++) {
124 r[i] = nu/dx_*(2.0*u[i]-u[i+1]);
127 r[i] = nu/dx_*(2.0*u[i]-u[i-1]);
130 r[i] = nu/dx_*(2.0*u[i]-u[i-1]-u[i+1]);
134 r[i] += u[i+1]*(u[i]+u[i+1])/6.0;
137 r[i] -= u[i-1]*(u[i-1]+u[i])/6.0;
140 r[i] -= dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
145 r[ 0] -= u0*u[ 0]/6.0 + u0*u0/6.0 + nu*u0/
dx_;
146 r[nx_-1] += u1*u[nx_-1]/6.0 + u1*u1/6.0 - nu*u1/
dx_;
150 const std::vector<Real> &u) {
151 const std::vector<Real> param =
153 Real nu = std::pow(10.0,param[0]-2.0);
154 Real u0 = 1.0+param[2]/1000.0;
155 Real u1 = param[3]/1000.0;
157 d.clear(); d.resize(nx_,nu*2.0/dx_);
158 dl.clear(); dl.resize(nx_-1,-nu/dx_);
159 du.clear(); du.resize(nx_-1,-nu/dx_);
161 for (
int i=0; i<
nx_; i++) {
163 dl[i] += (-2.0*u[i]-u[i+1])/6.0;
168 du[i-1] += (u[i-1]+2.0*u[i])/6.0;
176 void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
177 const std::vector<Real> &r,
const bool transpose =
false) {
178 u.assign(r.begin(),r.end());
180 Teuchos::LAPACK<int,Real> lp;
181 std::vector<Real> du2(nx_-2,0.0);
182 std::vector<int> ipiv(nx_,0);
186 lp.GTTRF(nx_,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
191 lp.GTTRS(trans,nx_,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
200 Teuchos::RCP<std::vector<Real> > cp =
201 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(c)).getVector());
202 Teuchos::RCP<const std::vector<Real> > up =
204 Teuchos::RCP<const std::vector<Real> > zp =
210 Teuchos::RCP<std::vector<Real> > up =
211 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(u)).getVector());
212 up->assign(up->size(),z.
norm()/up->size());
213 Teuchos::RCP<const std::vector<Real> > zp =
216 std::vector<Real> r(up->size(),0.0);
223 std::vector<Real> d(nx_,0.0);
224 std::vector<Real> dl(nx_-1,0.0);
225 std::vector<Real> du(nx_-1,0.0);
227 Real alpha = 1.0, tmp = 0.0;
228 std::vector<Real> s(nx_,0.0);
229 std::vector<Real> utmp(nx_,0.0);
230 for (
int i=0; i<maxit; i++) {
239 utmp.assign(up->begin(),up->end());
243 while ( rnorm > (1.0-1.e-4*alpha)*tmp && alpha > std::sqrt(
ROL::ROL_EPSILON) ) {
245 utmp.assign(up->begin(),up->end());
251 up->assign(utmp.begin(),utmp.end());
252 if ( rnorm < rtol ) {
260 Teuchos::RCP<std::vector<Real> > jvp =
261 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(jv)).getVector());
262 Teuchos::RCP<const std::vector<Real> > vp =
264 Teuchos::RCP<const std::vector<Real> > up =
266 Teuchos::RCP<const std::vector<Real> > zp =
268 const std::vector<Real> param =
270 Real nu = std::pow(10.0,param[0]-2.0);
271 Real u0 = 1.0+param[2]/1000.0;
272 Real u1 = param[3]/1000.0;
274 for (
int i = 0; i <
nx_; i++) {
275 (*jvp)[i] = nu/dx_*2.0*(*vp)[i];
277 (*jvp)[i] += -nu/dx_*(*vp)[i-1]
278 -(*up)[i-1]/6.0*(*vp)[i]
279 -((*up)[i]+2.0*(*up)[i-1])/6.0*(*vp)[i-1];
282 (*jvp)[i] += -nu/dx_*(*vp)[i+1]
283 +(*up)[i+1]/6.0*(*vp)[i]
284 +((*up)[i]+2.0*(*up)[i+1])/6.0*(*vp)[i+1];
287 (*jvp)[ 0] -= u0/6.0*(*vp)[0];
288 (*jvp)[nx_-1] += u1/6.0*(*vp)[nx_-1];
293 Teuchos::RCP<std::vector<Real> > jvp =
294 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(jv)).getVector());
295 Teuchos::RCP<const std::vector<Real> > vp =
297 Teuchos::RCP<const std::vector<Real> > up =
299 Teuchos::RCP<const std::vector<Real> > zp =
301 for (
int i=0; i<
nx_; i++) {
303 (*jvp)[i] = -dx_/6.0*((*vp)[i]+4.0*(*vp)[i+1]+(*vp)[i+2]);
309 Teuchos::RCP<std::vector<Real> > ijvp =
310 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(ijv)).getVector());
311 Teuchos::RCP<const std::vector<Real> > vp =
313 Teuchos::RCP<const std::vector<Real> > up =
315 Teuchos::RCP<const std::vector<Real> > zp =
318 std::vector<Real> d(nx_,0.0);
319 std::vector<Real> dl(nx_-1,0.0);
320 std::vector<Real> du(nx_-1,0.0);
328 Teuchos::RCP<std::vector<Real> > jvp =
329 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(ajv)).getVector());
330 Teuchos::RCP<const std::vector<Real> > vp =
332 Teuchos::RCP<const std::vector<Real> > up =
334 Teuchos::RCP<const std::vector<Real> > zp =
336 const std::vector<Real> param =
338 Real nu = std::pow(10.0,param[0]-2.0);
339 Real u0 = 1.0+param[2]/1000.0;
340 Real u1 = param[3]/1000.0;
342 for (
int i = 0; i <
nx_; i++) {
343 (*jvp)[i] = nu/dx_*2.0*(*vp)[i];
345 (*jvp)[i] += -nu/dx_*(*vp)[i-1]
346 -(*up)[i-1]/6.0*(*vp)[i]
347 +((*up)[i-1]+2.0*(*up)[i])/6.0*(*vp)[i-1];
350 (*jvp)[i] += -nu/dx_*(*vp)[i+1]
351 +(*up)[i+1]/6.0*(*vp)[i]
352 -((*up)[i+1]+2.0*(*up)[i])/6.0*(*vp)[i+1];
355 (*jvp)[ 0] -= u0/6.0*(*vp)[0];
356 (*jvp)[nx_-1] += u1/6.0*(*vp)[nx_-1];
361 Teuchos::RCP<std::vector<Real> > jvp =
362 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(jv)).getVector());
363 Teuchos::RCP<const std::vector<Real> > vp =
365 Teuchos::RCP<const std::vector<Real> > up =
367 Teuchos::RCP<const std::vector<Real> > zp =
369 for (
int i=0; i<nx_+2; i++) {
371 (*jvp)[i] = -dx_/6.0*(*vp)[i];
374 (*jvp)[i] = -dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i]);
376 else if ( i == nx_ ) {
377 (*jvp)[i] = -dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i-2]);
379 else if ( i == nx_+1 ) {
380 (*jvp)[i] = -dx_/6.0*(*vp)[i-2];
383 (*jvp)[i] = -dx_/6.0*((*vp)[i-2]+4.0*(*vp)[i-1]+(*vp)[i]);
390 Teuchos::RCP<std::vector<Real> > iajvp =
391 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(iajv)).getVector());
392 Teuchos::RCP<const std::vector<Real> > vp =
394 Teuchos::RCP<const std::vector<Real> > up =
397 std::vector<Real> d(nx_,0.0);
398 std::vector<Real> du(nx_-1,0.0);
399 std::vector<Real> dl(nx_-1,0.0);
407 Teuchos::RCP<std::vector<Real> > ahwvp =
408 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(ahwv)).getVector());
409 Teuchos::RCP<const std::vector<Real> > wp =
411 Teuchos::RCP<const std::vector<Real> > vp =
413 Teuchos::RCP<const std::vector<Real> > up =
415 Teuchos::RCP<const std::vector<Real> > zp =
417 for (
int i=0; i<
nx_; i++) {
421 (*ahwvp)[i] += ((*wp)[i]*(*vp)[i+1] - (*wp)[i+1]*(2.0*(*vp)[i]+(*vp)[i+1]))/6.0;
424 (*ahwvp)[i] += ((*wp)[i-1]*((*vp)[i-1]+2.0*(*vp)[i]) - (*wp)[i]*(*vp)[i-1])/6.0;
458 case 1: val = ((x<0.5) ? 1.0 : 0.0);
break;
459 case 2: val = 1.0;
break;
460 case 3: val = std::abs(std::sin(8.0*M_PI*x));
break;
461 case 4: val = std::exp(-0.5*(x-0.5)*(x-0.5));
break;
466 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y) {
468 Real c = (((int)x.size()==
nx_) ? 4.0 : 2.0);
469 for (
unsigned i=0; i<x.size(); i++) {
471 ip += dx_/6.0*(c*x[i] + x[i+1])*y[i];
473 else if ( i == x.size()-1 ) {
474 ip += dx_/6.0*(x[i-1] + c*x[i])*y[i];
477 ip += dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
483 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u ) {
484 Mu.resize(u.size(),0.0);
485 Real c = (((int)u.size()==
nx_) ? 4.0 : 2.0);
486 for (
unsigned i=0; i<u.size(); i++) {
488 Mu[i] = dx_/6.0*(c*u[i] + u[i+1]);
490 else if ( i == u.size()-1 ) {
491 Mu[i] = dx_/6.0*(u[i-1] + c*u[i]);
494 Mu[i] = dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
505 dx_ = 1.0/((Real)nx+1.0);
509 Teuchos::RCP<const std::vector<Real> > up =
511 Teuchos::RCP<const std::vector<Real> > zp =
514 Real res1 = 0.0, res2 = 0.0, res3 = 0.0;
515 Real valu = 0.0, valz =
dot(*zp,*zp);
516 for (
int i=0; i<
nx_; i++) {
518 res1 = (*up)[i]-evaluate_target((Real)(i+1)*dx_);
519 res2 = (*up)[i+1]-evaluate_target((Real)(i+2)*dx_);
520 valu += dx_/6.0*(4.0*res1 + res2)*res1;
522 else if ( i == nx_-1 ) {
523 res1 = (*up)[i-1]-evaluate_target((Real)i*dx_);
524 res2 = (*up)[i]-evaluate_target((Real)(i+1)*dx_);
525 valu += dx_/6.0*(res1 + 4.0*res2)*res2;
528 res1 = (*up)[i-1]-evaluate_target((Real)i*dx_);
529 res2 = (*up)[i]-evaluate_target((Real)(i+1)*dx_);
530 res3 = (*up)[i+1]-evaluate_target((Real)(i+2)*dx_);
531 valu += dx_/6.0*(res1 + 4.0*res2 + res3)*res2;
534 return 0.5*(valu + alpha_*valz);
539 Teuchos::RCP<std::vector<Real> > gup = Teuchos::rcp_const_cast<std::vector<Real> >(
542 Teuchos::RCP<const std::vector<Real> > up =
544 Teuchos::RCP<const std::vector<Real> > zp =
547 std::vector<Real> diff(nx_,0.0);
548 for (
int i=0; i<
nx_; i++) {
549 diff[i] = ((*up)[i]-evaluate_target((Real)(i+1)*dx_));
551 apply_mass(*gup,diff);
556 Teuchos::RCP<std::vector<Real> > gzp = Teuchos::rcp_const_cast<std::vector<Real> >(
559 Teuchos::RCP<const std::vector<Real> > up =
561 Teuchos::RCP<const std::vector<Real> > zp =
564 for (
int i=0; i<nx_+2; i++) {
566 (*gzp)[i] = alpha_*dx_/6.0*(2.0*(*zp)[i]+(*zp)[i+1]);
569 (*gzp)[i] = alpha_*dx_/6.0*(2.0*(*zp)[i]+(*zp)[i-1]);
572 (*gzp)[i] = alpha_*dx_/6.0*((*zp)[i-1]+4.0*(*zp)[i]+(*zp)[i+1]);
579 Teuchos::RCP<std::vector<Real> > hvup = Teuchos::rcp_const_cast<std::vector<Real> >(
582 Teuchos::RCP<const std::vector<Real> > vup =
585 apply_mass(*hvup,*vup);
600 Teuchos::RCP<std::vector<Real> > hvzp = Teuchos::rcp_const_cast<std::vector<Real> >(
603 Teuchos::RCP<const std::vector<Real> > vzp =
606 for (
int i=0; i<nx_+2; i++) {
608 (*hvzp)[i] = alpha_*dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i+1]);
611 (*hvzp)[i] = alpha_*dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i-1]);
614 (*hvzp)[i] = alpha_*dx_/6.0*((*vzp)[i-1]+4.0*(*vzp)[i]+(*vzp)[i+1]);
void compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u)
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 adjoint of the partial constraint Hessian at , , to vector in direction ...
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)
Real evaluate_target(Real x)
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 adjoint of the partial constraint Hessian at , , to vector in direction ...
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 .
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
Contains definitions of custom data types in ROL.
Real compute_norm(const std::vector< Real > &r)
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
void compute_residual(std::vector< Real > &r, const std::vector< Real > &u, const std::vector< Real > &z)
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 adjoint of the partial constraint Hessian at , , to vector in direction ...
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 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 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 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...
Provides the std::vector implementation of the ROL::Vector interface.
void applyJacobian_1(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
Objective_BurgersControl(Real alpha=1.e-4, int nx=128)
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)
EqualityConstraint_BurgersControl(int nx=128)
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 solve(ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve for .
const std::vector< Real > getParameter(void) const
void scale(std::vector< Real > &u, const Real alpha=0.0)
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 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 value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
void apply_mass(std::vector< Real > &Mu, const std::vector< Real > &u)
virtual Real norm() const =0
Returns where .
void update(std::vector< Real > &u, const std::vector< Real > &s, const Real alpha=1.0)
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 adjoint of the partial constraint Hessian at , , to vector in direction ...
static const double ROL_EPSILON
Platform-dependent machine epsilon.