31 return std::sqrt(this->
dot(r,r));
34 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y) {
36 Real c = (((int)x.size()==this->
nx_) ? 4.0 : 2.0);
37 for (
unsigned i=0; i<x.size(); i++) {
39 ip += this->
dx_/6.0*(c*x[i] + x[i+1])*y[i];
41 else if ( i == x.size()-1 ) {
42 ip += this->
dx_/6.0*(x[i-1] + c*x[i])*y[i];
45 ip += this->
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
53 void update(std::vector<Real> &u,
const std::vector<Real> &s,
const Real alpha=1.0) {
54 for (
unsigned i=0; i<u.size(); i++) {
59 void scale(std::vector<Real> &u,
const Real alpha=0.0) {
60 for (
unsigned i=0; i<u.size(); i++) {
66 const std::vector<Real> &z) {
68 r.resize(this->
nx_,0.0);
69 for (
int i=0; i<this->
nx_; i++) {
72 r[i] = this->
nu_/this->
dx_*(2.0*u[i]-u[i+1]);
74 else if (i==this->nx_-1) {
75 r[i] = this->
nu_/this->
dx_*(2.0*u[i]-u[i-1]);
78 r[i] = this->
nu_/this->
dx_*(2.0*u[i]-u[i-1]-u[i+1]);
82 r[i] += u[i+1]*(u[i]+u[i+1])/6.0;
85 r[i] -= u[i-1]*(u[i-1]+u[i])/6.0;
88 r[i] -= this->
dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
90 r[i] -= this->
dx_*this->
f_;
94 r[this->nx_-1] += this->
u1_*u[this->nx_-1]/6.0 + this->
u1_*this->
u1_/6.0 - this->
nu_*this->
u1_/this->
dx_;
98 const std::vector<Real> &u) {
101 d.resize(this->
nx_,this->
nu_*2.0/this->
dx_);
103 dl.resize(this->
nx_-1,-this->
nu_/this->
dx_);
105 du.resize(this->
nx_-1,-this->
nu_/this->
dx_);
107 for (
int i=0; i<this->
nx_; i++) {
109 dl[i] += (-2.0*u[i]-u[i+1])/6.0;
114 du[i-1] += (u[i-1]+2.0*u[i])/6.0;
118 d[0] -= this->
u0_/6.0;
119 d[this->nx_-1] += this->
u1_/6.0;
122 void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
123 const std::vector<Real> &r,
const bool transpose =
false) {
124 u.assign(r.begin(),r.end());
126 Teuchos::LAPACK<int,Real> lp;
127 std::vector<Real> du2(this->
nx_-2,0.0);
128 std::vector<int> ipiv(this->
nx_,0);
132 lp.GTTRF(this->
nx_,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
137 lp.GTTRS(trans,this->
nx_,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
144 dx_ = 1.0/((Real)nx+1.0);
149 ROL::Ptr<std::vector<Real> > cp =
151 ROL::Ptr<const std::vector<Real> > up =
153 ROL::Ptr<const std::vector<Real> > zp =
160 ROL::Ptr<std::vector<Real> > jvp =
162 ROL::Ptr<const std::vector<Real> > vp =
164 ROL::Ptr<const std::vector<Real> > up =
166 ROL::Ptr<const std::vector<Real> > zp =
169 for (
int i = 0; i < this->
nx_; i++) {
170 (*jvp)[i] = this->
nu_/this->
dx_*2.0*(*vp)[i];
172 (*jvp)[i] += -this->
nu_/this->
dx_*(*vp)[i-1]
173 -(*up)[i-1]/6.0*(*vp)[i]
174 -((*up)[i]+2.0*(*up)[i-1])/6.0*(*vp)[i-1];
176 if ( i < this->nx_-1 ) {
177 (*jvp)[i] += -this->
nu_/this->
dx_*(*vp)[i+1]
178 +(*up)[i+1]/6.0*(*vp)[i]
179 +((*up)[i]+2.0*(*up)[i+1])/6.0*(*vp)[i+1];
182 (*jvp)[0] -= this->
u0_/6.0*(*vp)[0];
183 (*jvp)[this->nx_-1] += this->
u1_/6.0*(*vp)[this->nx_-1];
188 ROL::Ptr<std::vector<Real> > jvp =
190 ROL::Ptr<const std::vector<Real> > vp =
192 ROL::Ptr<const std::vector<Real> > up =
194 ROL::Ptr<const std::vector<Real> > zp =
196 for (
int i=0; i<this->
nx_; i++) {
198 (*jvp)[i] = -this->
dx_/6.0*((*vp)[i]+4.0*(*vp)[i+1]+(*vp)[i+2]);
204 ROL::Ptr<std::vector<Real> > ijvp =
206 ROL::Ptr<const std::vector<Real> > vp =
208 ROL::Ptr<const std::vector<Real> > up =
210 ROL::Ptr<const std::vector<Real> > zp =
213 std::vector<Real> d(this->
nx_,0.0);
214 std::vector<Real> dl(this->
nx_-1,0.0);
215 std::vector<Real> du(this->
nx_-1,0.0);
223 ROL::Ptr<std::vector<Real> > jvp =
225 ROL::Ptr<const std::vector<Real> > vp =
227 ROL::Ptr<const std::vector<Real> > up =
229 ROL::Ptr<const std::vector<Real> > zp =
232 for (
int i = 0; i < this->
nx_; i++) {
233 (*jvp)[i] = this->
nu_/this->
dx_*2.0*(*vp)[i];
235 (*jvp)[i] += -this->
nu_/this->
dx_*(*vp)[i-1]
236 -(*up)[i-1]/6.0*(*vp)[i]
237 +((*up)[i-1]+2.0*(*up)[i])/6.0*(*vp)[i-1];
239 if ( i < this->nx_-1 ) {
240 (*jvp)[i] += -this->
nu_/this->
dx_*(*vp)[i+1]
241 +(*up)[i+1]/6.0*(*vp)[i]
242 -((*up)[i+1]+2.0*(*up)[i])/6.0*(*vp)[i+1];
245 (*jvp)[0] -= this->
u0_/6.0*(*vp)[0];
246 (*jvp)[this->nx_-1] += this->
u1_/6.0*(*vp)[this->nx_-1];
251 ROL::Ptr<std::vector<Real> > jvp =
253 ROL::Ptr<const std::vector<Real> > vp =
255 ROL::Ptr<const std::vector<Real> > up =
257 ROL::Ptr<const std::vector<Real> > zp =
259 for (
int i=0; i<this->
nx_+2; i++) {
261 (*jvp)[i] = -this->
dx_/6.0*(*vp)[i];
264 (*jvp)[i] = -this->
dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i]);
266 else if ( i == this->nx_ ) {
267 (*jvp)[i] = -this->
dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i-2]);
269 else if ( i == this->nx_+1 ) {
270 (*jvp)[i] = -this->
dx_/6.0*(*vp)[i-2];
273 (*jvp)[i] = -this->
dx_/6.0*((*vp)[i-2]+4.0*(*vp)[i-1]+(*vp)[i]);
280 ROL::Ptr<std::vector<Real> > iajvp =
282 ROL::Ptr<const std::vector<Real> > vp =
284 ROL::Ptr<const std::vector<Real> > up =
287 std::vector<Real> d(this->
nx_,0.0);
288 std::vector<Real> du(this->
nx_-1,0.0);
289 std::vector<Real> dl(this->
nx_-1,0.0);
297 ROL::Ptr<std::vector<Real> > ahwvp =
299 ROL::Ptr<const std::vector<Real> > wp =
301 ROL::Ptr<const std::vector<Real> > vp =
303 ROL::Ptr<const std::vector<Real> > up =
305 ROL::Ptr<const std::vector<Real> > zp =
307 for (
int i=0; i<this->
nx_; i++) {
311 (*ahwvp)[i] += ((*wp)[i]*(*vp)[i+1] - (*wp)[i+1]*(2.0*(*vp)[i]+(*vp)[i+1]))/6.0;
314 (*ahwvp)[i] += ((*wp)[i-1]*((*vp)[i-1]+2.0*(*vp)[i]) - (*wp)[i]*(*vp)[i-1])/6.0;
351 case 1: val = ((x<0.5) ? 1.0 : 0.0);
break;
352 case 2: val = 1.0;
break;
353 case 3: val = std::abs(std::sin(8.0*M_PI*x));
break;
354 case 4: val = std::exp(-0.5*(x-0.5)*(x-0.5));
break;
359 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y) {
361 Real c = (((int)x.size()==this->
nx_) ? 4.0 : 2.0);
362 for (
unsigned i=0; i<x.size(); i++) {
364 ip += this->
dx_/6.0*(c*x[i] + x[i+1])*y[i];
366 else if ( i == x.size()-1 ) {
367 ip += this->
dx_/6.0*(x[i-1] + c*x[i])*y[i];
370 ip += this->
dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
376 void apply_mass(std::vector<Real> &Mu,
const std::vector<Real> &u ) {
377 Mu.resize(u.size(),0.0);
378 Real c = (((int)u.size()==this->
nx_) ? 4.0 : 2.0);
379 for (
unsigned i=0; i<u.size(); i++) {
381 Mu[i] = this->
dx_/6.0*(c*u[i] + u[i+1]);
383 else if ( i == u.size()-1 ) {
384 Mu[i] = this->
dx_/6.0*(u[i-1] + c*u[i]);
387 Mu[i] = this->
dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
398 dx_ = 1.0/((Real)nx+1.0);
402 ROL::Ptr<const std::vector<Real> > up =
404 ROL::Ptr<const std::vector<Real> > zp =
407 Real res1 = 0.0, res2 = 0.0, res3 = 0.0;
408 Real valu = 0.0, valz = this->
dot(*zp,*zp);
409 for (
int i=0; i<this->
nx_; i++) {
413 valu += this->
dx_/6.0*(4.0*res1 + res2)*res1;
415 else if ( i == this->nx_-1 ) {
418 valu += this->dx_/6.0*(res1 + 4.0*res2)*res2;
424 valu += this->dx_/6.0*(res1 + 4.0*res2 + res3)*res2;
427 return 0.5*(valu + this->
alpha_*valz);
432 ROL::Ptr<std::vector<Real> > gup = ROL::constPtrCast<std::vector<Real> >(
435 ROL::Ptr<const std::vector<Real> > up =
437 ROL::Ptr<const std::vector<Real> > zp =
440 std::vector<Real> diff(this->
nx_,0.0);
441 for (
int i=0; i<this->
nx_; i++) {
449 ROL::Ptr<std::vector<Real> > gzp = ROL::constPtrCast<std::vector<Real> >(
452 ROL::Ptr<const std::vector<Real> > up =
454 ROL::Ptr<const std::vector<Real> > zp =
457 for (
int i=0; i<this->
nx_+2; i++) {
459 (*gzp)[i] = this->
alpha_*this->
dx_/6.0*(2.0*(*zp)[i]+(*zp)[i+1]);
461 else if (i==this->nx_+1) {
462 (*gzp)[i] = this->
alpha_*this->
dx_/6.0*(2.0*(*zp)[i]+(*zp)[i-1]);
465 (*gzp)[i] = this->
alpha_*this->
dx_/6.0*((*zp)[i-1]+4.0*(*zp)[i]+(*zp)[i+1]);
472 ROL::Ptr<std::vector<Real> > hvup =
475 ROL::Ptr<const std::vector<Real> > vup =
493 ROL::Ptr<std::vector<Real> > hvzp =
496 ROL::Ptr<const std::vector<Real> > vzp =
499 for (
int i=0; i<this->
nx_+2; i++) {
501 (*hvzp)[i] = this->
alpha_*this->
dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i+1]);
503 else if (i==this->nx_+1) {
504 (*hvzp)[i] = this->
alpha_*this->
dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i-1]);
507 (*hvzp)[i] = this->
alpha_*this->
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 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 ...
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.
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)
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)
Constraint_BurgersControl(int nx=128, Real nu=1.e-2, Real u0=1.0, Real u1=0.0, Real f=0.0)
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 .
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)