ROL
example_05.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "ROL_Stream.hpp"
11 #include "Teuchos_LAPACK.hpp"
12 #include "Teuchos_GlobalMPISession.hpp"
13 #include "Teuchos_Comm.hpp"
14 #include "Teuchos_DefaultComm.hpp"
15 #include "Teuchos_CommHelpers.hpp"
16 
17 #include "ROL_ParameterList.hpp"
18 // ROL_Types contains predefined constants and objects
19 #include "ROL_Types.hpp"
20 // ROL vectors
21 #include "ROL_StdVector.hpp"
22 // ROL objective functions and constraints
23 #include "ROL_Objective_SimOpt.hpp"
27 // ROL sample generators
29 #include "ROL_StdTeuchosBatchManager.hpp"
30 
31 template<class Real>
33 private:
34  int nx_;
35  Real dx_;
36 
37  Real compute_norm(const std::vector<Real> &r) {
38  return std::sqrt(dot(r,r));
39  }
40 
41  Real dot(const std::vector<Real> &x, const std::vector<Real> &y) {
42  Real ip = 0.0;
43  Real c = (((int)x.size()==nx_) ? 4.0 : 2.0);
44  for (unsigned i=0; i<x.size(); i++) {
45  if ( i == 0 ) {
46  ip += dx_/6.0*(c*x[i] + x[i+1])*y[i];
47  }
48  else if ( i == x.size()-1 ) {
49  ip += dx_/6.0*(x[i-1] + c*x[i])*y[i];
50  }
51  else {
52  ip += dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
53  }
54  }
55  return ip;
56  }
57 
59 
60  void update(std::vector<Real> &u, const std::vector<Real> &s, const Real alpha=1.0) {
61  for (unsigned i=0; i<u.size(); i++) {
62  u[i] += alpha*s[i];
63  }
64  }
65 
66  void scale(std::vector<Real> &u, const Real alpha=0.0) {
67  for (unsigned i=0; i<u.size(); i++) {
68  u[i] *= alpha;
69  }
70  }
71 
72  void compute_residual(std::vector<Real> &r, const std::vector<Real> &u,
73  const std::vector<Real> &z) {
74  r.clear(); r.resize(nx_,0.0);
75  const std::vector<Real> param =
77  Real nu = std::pow(10.0,param[0]-2.0);
78  Real f = param[1]/100.0;
79  Real u0 = 1.0+param[2]/1000.0;
80  Real u1 = param[3]/1000.0;
81  for (int i=0; i<nx_; i++) {
82  // Contribution from stiffness term
83  if ( i==0 ) {
84  r[i] = nu/dx_*(2.0*u[i]-u[i+1]);
85  }
86  else if (i==nx_-1) {
87  r[i] = nu/dx_*(2.0*u[i]-u[i-1]);
88  }
89  else {
90  r[i] = nu/dx_*(2.0*u[i]-u[i-1]-u[i+1]);
91  }
92  // Contribution from nonlinear term
93  if (i<nx_-1){
94  r[i] += u[i+1]*(u[i]+u[i+1])/6.0;
95  }
96  if (i>0) {
97  r[i] -= u[i-1]*(u[i-1]+u[i])/6.0;
98  }
99  // Contribution from control
100  r[i] -= dx_/6.0*(z[i]+4.0*z[i+1]+z[i+2]);
101  // Contribution from right-hand side
102  r[i] -= dx_*f;
103  }
104  // Contribution from Dirichlet boundary terms
105  r[ 0] -= u0*u[ 0]/6.0 + u0*u0/6.0 + nu*u0/dx_;
106  r[nx_-1] += u1*u[nx_-1]/6.0 + u1*u1/6.0 - nu*u1/dx_;
107  }
108 
109  void compute_pde_jacobian(std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
110  const std::vector<Real> &u) {
111  const std::vector<Real> param =
113  Real nu = std::pow(10.0,param[0]-2.0);
114  Real u0 = 1.0+param[2]/1000.0;
115  Real u1 = param[3]/1000.0;
116  // Get Diagonal and Off-Diagonal Entries of linear PDE Jacobian
117  d.clear(); d.resize(nx_,nu*2.0/dx_);
118  dl.clear(); dl.resize(nx_-1,-nu/dx_);
119  du.clear(); du.resize(nx_-1,-nu/dx_);
120  // Contribution from nonlinearity
121  for (int i=0; i<nx_; i++) {
122  if (i<nx_-1) {
123  dl[i] += (-2.0*u[i]-u[i+1])/6.0;
124  d[i] += u[i+1]/6.0;
125  }
126  if (i>0) {
127  d[i] += -u[i-1]/6.0;
128  du[i-1] += (u[i-1]+2.0*u[i])/6.0;
129  }
130  }
131  // Contribution from Dirichlet boundary conditions
132  d[ 0] -= u0/6.0;
133  d[nx_-1] += u1/6.0;
134  }
135 
136  void linear_solve(std::vector<Real> &u, std::vector<Real> &dl, std::vector<Real> &d, std::vector<Real> &du,
137  const std::vector<Real> &r, const bool transpose = false) {
138  u.assign(r.begin(),r.end());
139  // Perform LDL factorization
140  Teuchos::LAPACK<int,Real> lp;
141  std::vector<Real> du2(nx_-2,0.0);
142  std::vector<int> ipiv(nx_,0);
143  int info;
144  int ldb = nx_;
145  int nhrs = 1;
146  lp.GTTRF(nx_,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
147  char trans = 'N';
148  if ( transpose ) {
149  trans = 'T';
150  }
151  lp.GTTRS(trans,nx_,nhrs,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&u[0],ldb,&info);
152  }
153 
154 public:
155 
156  Constraint_BurgersControl(int nx = 128) : nx_(nx), dx_(1.0/((Real)nx+1.0)) {}
157 
159  const ROL::Vector<Real> &z, Real &tol) {
160  ROL::Ptr<std::vector<Real> > cp =
161  dynamic_cast<ROL::StdVector<Real>&>(c).getVector();
162  ROL::Ptr<const std::vector<Real> > up =
163  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
164  ROL::Ptr<const std::vector<Real> > zp =
165  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
166  compute_residual(*cp,*up,*zp);
167  }
168 
169  void solve(ROL::Vector<Real> &c, ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) {
170  ROL::Ptr<std::vector<Real> > up =
171  ROL::constPtrCast<std::vector<Real> >((dynamic_cast<ROL::StdVector<Real>&>(u)).getVector());
172  up->assign(up->size(),static_cast<Real>(1));
174  }
175 
177  const ROL::Vector<Real> &z, Real &tol) {
178  ROL::Ptr<std::vector<Real> > jvp =
179  dynamic_cast<ROL::StdVector<Real>&>(jv).getVector();
180  ROL::Ptr<const std::vector<Real> > vp =
181  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
182  ROL::Ptr<const std::vector<Real> > up =
183  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
184  ROL::Ptr<const std::vector<Real> > zp =
185  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
186  const std::vector<Real> param =
188  Real nu = std::pow(10.0,param[0]-2.0);
189  Real u0 = 1.0+param[2]/1000.0;
190  Real u1 = param[3]/1000.0;
191  // Fill jvp
192  for (int i = 0; i < nx_; i++) {
193  (*jvp)[i] = nu/dx_*2.0*(*vp)[i];
194  if ( i > 0 ) {
195  (*jvp)[i] += -nu/dx_*(*vp)[i-1]
196  -(*up)[i-1]/6.0*(*vp)[i]
197  -((*up)[i]+2.0*(*up)[i-1])/6.0*(*vp)[i-1];
198  }
199  if ( i < nx_-1 ) {
200  (*jvp)[i] += -nu/dx_*(*vp)[i+1]
201  +(*up)[i+1]/6.0*(*vp)[i]
202  +((*up)[i]+2.0*(*up)[i+1])/6.0*(*vp)[i+1];
203  }
204  }
205  (*jvp)[ 0] -= u0/6.0*(*vp)[0];
206  (*jvp)[nx_-1] += u1/6.0*(*vp)[nx_-1];
207  }
208 
210  const ROL::Vector<Real> &z, Real &tol) {
211  ROL::Ptr<std::vector<Real> > jvp =
212  dynamic_cast<ROL::StdVector<Real>&>(jv).getVector();
213  ROL::Ptr<const std::vector<Real>> vp =
214  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
215  ROL::Ptr<const std::vector<Real>> up =
216  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
217  ROL::Ptr<const std::vector<Real>> zp =
218  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
219  for (int i=0; i<nx_; i++) {
220  // Contribution from control
221  (*jvp)[i] = -dx_/6.0*((*vp)[i]+4.0*(*vp)[i+1]+(*vp)[i+2]);
222  }
223  }
224 
226  const ROL::Vector<Real> &z, Real &tol) {
227  ROL::Ptr<std::vector<Real> > ijvp =
228  dynamic_cast<ROL::StdVector<Real>&>(ijv).getVector();
229  ROL::Ptr<const std::vector<Real> > vp =
230  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
231  ROL::Ptr<const std::vector<Real> > up =
232  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
233  ROL::Ptr<const std::vector<Real> > zp =
234  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
235  // Get PDE Jacobian
236  std::vector<Real> d(nx_,0.0);
237  std::vector<Real> dl(nx_-1,0.0);
238  std::vector<Real> du(nx_-1,0.0);
239  compute_pde_jacobian(dl,d,du,*up);
240  // Solve solve state sensitivity system at current time step
241  linear_solve(*ijvp,dl,d,du,*vp);
242  }
243 
245  const ROL::Vector<Real> &z, Real &tol) {
246  ROL::Ptr<std::vector<Real> > jvp =
247  dynamic_cast<ROL::StdVector<Real>&>(ajv).getVector();
248  ROL::Ptr<const std::vector<Real> > vp =
249  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
250  ROL::Ptr<const std::vector<Real> > up =
251  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
252  ROL::Ptr<const std::vector<Real> > zp =
253  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
254  const std::vector<Real> param =
256  Real nu = std::pow(10.0,param[0]-2.0);
257  Real u0 = 1.0+param[2]/1000.0;
258  Real u1 = param[3]/1000.0;
259  // Fill jvp
260  for (int i = 0; i < nx_; i++) {
261  (*jvp)[i] = nu/dx_*2.0*(*vp)[i];
262  if ( i > 0 ) {
263  (*jvp)[i] += -nu/dx_*(*vp)[i-1]
264  -(*up)[i-1]/6.0*(*vp)[i]
265  +((*up)[i-1]+2.0*(*up)[i])/6.0*(*vp)[i-1];
266  }
267  if ( i < nx_-1 ) {
268  (*jvp)[i] += -nu/dx_*(*vp)[i+1]
269  +(*up)[i+1]/6.0*(*vp)[i]
270  -((*up)[i+1]+2.0*(*up)[i])/6.0*(*vp)[i+1];
271  }
272  }
273  (*jvp)[ 0] -= u0/6.0*(*vp)[0];
274  (*jvp)[nx_-1] += u1/6.0*(*vp)[nx_-1];
275  }
276 
278  const ROL::Vector<Real> &z, Real &tol) {
279  ROL::Ptr<std::vector<Real> > jvp =
280  dynamic_cast<ROL::StdVector<Real>&>(jv).getVector();
281  ROL::Ptr<const std::vector<Real> > vp =
282  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
283  ROL::Ptr<const std::vector<Real> > up =
284  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
285  ROL::Ptr<const std::vector<Real> > zp =
286  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
287  for (int i=0; i<nx_+2; i++) {
288  if ( i == 0 ) {
289  (*jvp)[i] = -dx_/6.0*(*vp)[i];
290  }
291  else if ( i == 1 ) {
292  (*jvp)[i] = -dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i]);
293  }
294  else if ( i == nx_ ) {
295  (*jvp)[i] = -dx_/6.0*(4.0*(*vp)[i-1]+(*vp)[i-2]);
296  }
297  else if ( i == nx_+1 ) {
298  (*jvp)[i] = -dx_/6.0*(*vp)[i-2];
299  }
300  else {
301  (*jvp)[i] = -dx_/6.0*((*vp)[i-2]+4.0*(*vp)[i-1]+(*vp)[i]);
302  }
303  }
304  }
305 
307  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) {
308  ROL::Ptr<std::vector<Real> > iajvp =
309  dynamic_cast<ROL::StdVector<Real>&>(iajv).getVector();
310  ROL::Ptr<const std::vector<Real> > vp =
311  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
312  ROL::Ptr<const std::vector<Real>> up =
313  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
314  // Get PDE Jacobian
315  std::vector<Real> d(nx_,0.0);
316  std::vector<Real> du(nx_-1,0.0);
317  std::vector<Real> dl(nx_-1,0.0);
318  compute_pde_jacobian(dl,d,du,*up);
319  // Solve solve adjoint system at current time step
320  linear_solve(*iajvp,dl,d,du,*vp,true);
321  }
322 
324  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) {
325  ROL::Ptr<std::vector<Real> > ahwvp =
326  dynamic_cast<ROL::StdVector<Real>&>(ahwv).getVector();
327  ROL::Ptr<const std::vector<Real> > wp =
328  dynamic_cast<const ROL::StdVector<Real>&>(w).getVector();
329  ROL::Ptr<const std::vector<Real> > vp =
330  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
331  ROL::Ptr<const std::vector<Real> > up =
332  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
333  ROL::Ptr<const std::vector<Real> > zp =
334  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
335  for (int i=0; i<nx_; i++) {
336  // Contribution from nonlinear term
337  (*ahwvp)[i] = 0.0;
338  if (i<nx_-1){
339  (*ahwvp)[i] += ((*wp)[i]*(*vp)[i+1] - (*wp)[i+1]*(2.0*(*vp)[i]+(*vp)[i+1]))/6.0;
340  }
341  if (i>0) {
342  (*ahwvp)[i] += ((*wp)[i-1]*((*vp)[i-1]+2.0*(*vp)[i]) - (*wp)[i]*(*vp)[i-1])/6.0;
343  }
344  }
345  }
346 
348  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) {
349  ahwv.zero();
350  }
352  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) {
353  ahwv.zero();
354  }
356  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) {
357  ahwv.zero();
358  }
359 };
360 
361 template<class Real>
362 class Objective_BurgersControl : public ROL::Objective_SimOpt<Real> {
363 private:
364  Real alpha_; // Penalty Parameter
365 
366  int nx_; // Number of interior nodes
367  Real dx_; // Mesh spacing (i.e. 1/(nx+1))
368 
369 /***************************************************************/
370 /********** BEGIN PRIVATE MEMBER FUNCTION DECLARATION **********/
371 /***************************************************************/
372  Real evaluate_target(Real x) {
373  Real val = 0.0;
374  int example = 2;
375  switch (example) {
376  case 1: val = ((x<0.5) ? 1.0 : 0.0); break;
377  case 2: val = 1.0; break;
378  case 3: val = std::abs(std::sin(8.0*M_PI*x)); break;
379  case 4: val = std::exp(-0.5*(x-0.5)*(x-0.5)); break;
380  }
381  return val;
382  }
383 
384  Real dot(const std::vector<Real> &x, const std::vector<Real> &y) {
385  Real ip = 0.0;
386  Real c = (((int)x.size()==nx_) ? 4.0 : 2.0);
387  for (unsigned i=0; i<x.size(); i++) {
388  if ( i == 0 ) {
389  ip += dx_/6.0*(c*x[i] + x[i+1])*y[i];
390  }
391  else if ( i == x.size()-1 ) {
392  ip += dx_/6.0*(x[i-1] + c*x[i])*y[i];
393  }
394  else {
395  ip += dx_/6.0*(x[i-1] + 4.0*x[i] + x[i+1])*y[i];
396  }
397  }
398  return ip;
399  }
400 
401  void apply_mass(std::vector<Real> &Mu, const std::vector<Real> &u ) {
402  Mu.resize(u.size(),0.0);
403  Real c = (((int)u.size()==nx_) ? 4.0 : 2.0);
404  for (unsigned i=0; i<u.size(); i++) {
405  if ( i == 0 ) {
406  Mu[i] = dx_/6.0*(c*u[i] + u[i+1]);
407  }
408  else if ( i == u.size()-1 ) {
409  Mu[i] = dx_/6.0*(u[i-1] + c*u[i]);
410  }
411  else {
412  Mu[i] = dx_/6.0*(u[i-1] + 4.0*u[i] + u[i+1]);
413  }
414  }
415  }
416 /*************************************************************/
417 /********** END PRIVATE MEMBER FUNCTION DECLARATION **********/
418 /*************************************************************/
419 
420 public:
421 
422  Objective_BurgersControl(Real alpha = 1.e-4, int nx = 128) : alpha_(alpha), nx_(nx) {
423  dx_ = 1.0/((Real)nx+1.0);
424  }
425 
427 
428  Real value( const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
429  ROL::Ptr<const std::vector<Real> > up =
430  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
431  ROL::Ptr<const std::vector<Real> > zp =
432  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
433  // COMPUTE RESIDUAL
434  Real res1 = 0.0, res2 = 0.0, res3 = 0.0;
435  Real valu = 0.0, valz = dot(*zp,*zp);
436  for (int i=0; i<nx_; i++) {
437  if ( i == 0 ) {
438  res1 = (*up)[i]-evaluate_target((Real)(i+1)*dx_);
439  res2 = (*up)[i+1]-evaluate_target((Real)(i+2)*dx_);
440  valu += dx_/6.0*(4.0*res1 + res2)*res1;
441  }
442  else if ( i == nx_-1 ) {
443  res1 = (*up)[i-1]-evaluate_target((Real)i*dx_);
444  res2 = (*up)[i]-evaluate_target((Real)(i+1)*dx_);
445  valu += dx_/6.0*(res1 + 4.0*res2)*res2;
446  }
447  else {
448  res1 = (*up)[i-1]-evaluate_target((Real)i*dx_);
449  res2 = (*up)[i]-evaluate_target((Real)(i+1)*dx_);
450  res3 = (*up)[i+1]-evaluate_target((Real)(i+2)*dx_);
451  valu += dx_/6.0*(res1 + 4.0*res2 + res3)*res2;
452  }
453  }
454  return 0.5*(valu + alpha_*valz);
455  }
456 
457  void gradient_1( ROL::Vector<Real> &g, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
458  // Unwrap g
459  ROL::Ptr<std::vector<Real> > gup =
460  dynamic_cast<ROL::StdVector<Real>&>(g).getVector();
461  // Unwrap x
462  ROL::Ptr<const std::vector<Real> > up =
463  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
464  ROL::Ptr<const std::vector<Real> > zp =
465  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
466  // COMPUTE GRADIENT WRT U
467  std::vector<Real> diff(nx_,0.0);
468  for (int i=0; i<nx_; i++) {
469  diff[i] = ((*up)[i]-evaluate_target((Real)(i+1)*dx_));
470  }
471  apply_mass(*gup,diff);
472  }
473 
474  void gradient_2( ROL::Vector<Real> &g, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
475  // Unwrap g
476  ROL::Ptr<std::vector<Real> > gzp =
477  dynamic_cast<ROL::StdVector<Real>&>(g).getVector();
478  // Unwrap x
479  ROL::Ptr<const std::vector<Real> > up =
480  dynamic_cast<const ROL::StdVector<Real>&>(u).getVector();
481  ROL::Ptr<const std::vector<Real> > zp =
482  dynamic_cast<const ROL::StdVector<Real>&>(z).getVector();
483  // COMPUTE GRADIENT WRT Z
484  for (int i=0; i<nx_+2; i++) {
485  if (i==0) {
486  (*gzp)[i] = alpha_*dx_/6.0*(2.0*(*zp)[i]+(*zp)[i+1]);
487  }
488  else if (i==nx_+1) {
489  (*gzp)[i] = alpha_*dx_/6.0*(2.0*(*zp)[i]+(*zp)[i-1]);
490  }
491  else {
492  (*gzp)[i] = alpha_*dx_/6.0*((*zp)[i-1]+4.0*(*zp)[i]+(*zp)[i+1]);
493  }
494  }
495  }
496 
498  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
499  ROL::Ptr<std::vector<Real> > hvup =
500  dynamic_cast<ROL::StdVector<Real>&>(hv).getVector();
501  // Unwrap v
502  ROL::Ptr<const std::vector<Real> > vup =
503  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
504  // COMPUTE GRADIENT WRT U
505  apply_mass(*hvup,*vup);
506  }
507 
509  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
510  hv.zero();
511  }
512 
514  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
515  hv.zero();
516  }
517 
519  const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol ) {
520  ROL::Ptr<std::vector<Real> > hvzp =
521  dynamic_cast<ROL::StdVector<Real>&>(hv).getVector();
522  // Unwrap v
523  ROL::Ptr<const std::vector<Real> > vzp =
524  dynamic_cast<const ROL::StdVector<Real>&>(v).getVector();
525  // COMPUTE GRADIENT WRT Z
526  for (int i=0; i<nx_+2; i++) {
527  if (i==0) {
528  (*hvzp)[i] = alpha_*dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i+1]);
529  }
530  else if (i==nx_+1) {
531  (*hvzp)[i] = alpha_*dx_/6.0*(2.0*(*vzp)[i]+(*vzp)[i-1]);
532  }
533  else {
534  (*hvzp)[i] = alpha_*dx_/6.0*((*vzp)[i-1]+4.0*(*vzp)[i]+(*vzp)[i+1]);
535  }
536  }
537  }
538 };
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...
Definition: example_05.hpp:244
Real evaluate_target(Real x)
Definition: example_05.hpp:372
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...
Definition: example_05.hpp:347
void solve(ROL::Vector< Real > &c, ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve for .
Definition: example_05.hpp:169
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 ...
Definition: example_05.hpp:323
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 ...
Definition: example_05.hpp:306
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
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)
Definition: example_05.hpp:518
Real value(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute value.
Definition: example_05.hpp:428
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.
Definition: example_05.hpp:457
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...
Definition: example_05.hpp:351
void compute_pde_jacobian(std::vector< Real > &dl, std::vector< Real > &d, std::vector< Real > &du, const std::vector< Real > &u)
Definition: example_05.hpp:109
Constraint_BurgersControl(int nx=128)
Definition: example_05.hpp:156
Real dot(const std::vector< Real > &x, const std::vector< Real > &y)
Definition: example_05.hpp:384
Objective_BurgersControl(Real alpha=1.e-4, int nx=128)
Definition: example_05.hpp:422
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 .
Definition: example_05.hpp:176
void hessVec_21(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Definition: example_05.hpp:513
void hessVec_12(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Definition: example_05.hpp:508
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.
Definition: example_05.hpp:474
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 .
Definition: example_05.hpp:225
void compute_residual(std::vector< Real > &r, const std::vector< Real > &u, const std::vector< Real > &z)
Definition: example_05.hpp:72
void scale(std::vector< Real > &u, const Real alpha=0.0)
Definition: example_05.hpp:66
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.
Definition: example_05.hpp:497
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 .
Definition: example_05.hpp:209
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)
Definition: example_05.hpp:401
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 ...
Definition: example_05.hpp:355
Real compute_norm(const std::vector< Real > &r)
Definition: example_05.hpp:37
void update(std::vector< Real > &u, const std::vector< Real > &s, const Real alpha=1.0)
Definition: example_05.hpp:60
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...
Definition: example_05.hpp:277
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 .
Definition: example_05.hpp:158
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)
Definition: example_05.hpp:136