ROL
poisson-inversion/example_02.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #include "ROL_StdVector.hpp"
50 #include "ROL_Objective.hpp"
51 #include "ROL_Bounds.hpp"
52 #include "ROL_Algorithm.hpp"
54 #include "ROL_TrustRegionStep.hpp"
55 #include "ROL_StatusTest.hpp"
56 #include "ROL_Types.hpp"
57 #include "ROL_HelperFunctions.hpp"
58 #include "ROL_Stream.hpp"
59 
60 
61 #include "Teuchos_GlobalMPISession.hpp"
62 
63 #include <iostream>
64 #include <algorithm>
65 
66 template<class Real>
68 
69  typedef std::vector<Real> vector;
72 
73  typedef typename vector::size_type uint;
74 
75 
76 private:
79 
80  Real hu_;
81  Real hz_;
82 
83  Real u0_;
84  Real u1_;
85 
86  Real alpha_;
87 
89  Teuchos::SerialDenseMatrix<int, Real> H_;
90 
91  ROL::Ptr<const vector> getVector( const V& x ) {
92 
93  return dynamic_cast<const SV&>(x).getVector();
94  }
95 
96  ROL::Ptr<vector> getVector( V& x ) {
97 
98  return dynamic_cast<SV&>(x).getVector();
99  }
100 
101 public:
102 
103  /* CONSTRUCTOR */
104  Objective_PoissonInversion(int nz = 32, Real alpha = 1.e-4)
105  : nz_(nz), u0_(1.0), u1_(0.0), alpha_(alpha), useCorrection_(false) {
106  nu_ = nz_-1;
107  hu_ = 1.0/((Real)nu_+1.0);
108  hz_ = hu_;
109  }
110 
111  void apply_mass(std::vector<Real> &Mz, const std::vector<Real> &z ) {
112  Mz.resize(nu_,0.0);
113  for (uint i=0; i<nu_; i++) {
114  if ( i == 0 ) {
115  Mz[i] = hu_/6.0*(2.0*z[i] + z[i+1]);
116  }
117  else if ( i == nu_-1 ) {
118  Mz[i] = hu_/6.0*(z[i-1] + 2.0*z[i]);
119  }
120  else {
121  Mz[i] = hu_/6.0*(z[i-1] + 4.0*z[i] + z[i+1]);
122  }
123  }
124  }
125 
126  Real evaluate_target(Real x) {
127  return (x <= 0.5) ? 1.0 : 0.0;
128  }
129 
130  void apply_linearized_control_operator( std::vector<Real> &Bd, const std::vector<Real> &z,
131  const std::vector<Real> &d, const std::vector<Real> &u,
132  bool addBC = true ) {
133  Bd.clear();
134  Bd.resize(nu_,0.0);
135  for (uint i = 0; i < nu_; i++) {
136  if ( i == 0 ) {
137  Bd[i] = 1.0/hu_*( u[i]*d[i] + (u[i]-u[i+1])*d[i+1] );
138  }
139  else if ( i == nu_-1 ) {
140  Bd[i] = 1.0/hu_*( (u[i]-u[i-1])*d[i] + u[i]*d[i+1] );
141  }
142  else {
143  Bd[i] = 1.0/hu_*( (u[i]-u[i-1])*d[i] + (u[i]-u[i+1])*d[i+1] );
144  }
145  }
146  if ( addBC ) {
147  Bd[ 0] -= u0_*d[ 0]/hu_;
148  Bd[nu_-1] -= u1_*d[nz_-1]/hu_;
149  }
150  }
151 
152  void apply_transposed_linearized_control_operator( std::vector<Real> &Bd, const std::vector<Real> &z,
153  const std::vector<Real> &d, const std::vector<Real> &u,
154  bool addBC = true ) {
155  Bd.clear();
156  Bd.resize(nz_,0.0);
157  for (uint i = 0; i < nz_; i++) {
158  if ( i == 0 ) {
159  Bd[i] = 1.0/hu_*u[i]*d[i];
160  }
161  else if ( i == nz_-1 ) {
162  Bd[i] = 1.0/hu_*u[i-1]*d[i-1];
163  }
164  else {
165  Bd[i] = 1.0/hu_*( (u[i]-u[i-1])*(d[i]-d[i-1]) );
166  }
167  }
168  if ( addBC ) {
169  Bd[ 0] -= u0_*d[ 0]/hu_;
170  Bd[nz_-1] -= u1_*d[nu_-1]/hu_;
171  }
172  }
173 
174  /* STATE AND ADJOINT EQUATION DEFINTIONS */
175  void solve_state_equation(std::vector<Real> &u, const std::vector<Real> &z) {
176  // Get Diagonal and Off-Diagonal Entries of PDE Jacobian
177  std::vector<Real> d(nu_,1.0);
178  std::vector<Real> o(nu_-1,1.0);
179  for ( uint i = 0; i < nu_; i++ ) {
180  d[i] = (z[i] + z[i+1])/hu_;
181  if ( i < nu_-1 ) {
182  o[i] *= -z[i+1]/hu_;
183  }
184  }
185  // Set right hand side
186  u.clear();
187  u.resize(nu_,0.0);
188  u[ 0] = z[ 0]/hu_ * u0_;
189  u[nu_-1] = z[nz_-1]/hu_ * u1_;
190  // Solve Tridiagonal System Using LAPACK's SPD Tridiagonal Solver
191  Teuchos::LAPACK<int,Real> lp;
192  int info;
193  int ldb = nu_;
194  int nhrs = 1;
195  lp.PTTRF(nu_,&d[0],&o[0],&info);
196  lp.PTTRS(nu_,nhrs,&d[0],&o[0],&u[0],ldb,&info);
197  }
198 
199  void solve_adjoint_equation(std::vector<Real> &p, const std::vector<Real> &u, const std::vector<Real> &z) {
200  // Get Diagonal and Off-Diagonal Entries of PDE Jacobian
201  vector d(nu_,1.0);
202  vector o(nu_-1,1.0);
203  for ( uint i = 0; i < nu_; i++ ) {
204  d[i] = (z[i] + z[i+1])/hu_;
205  if ( i < nu_-1 ) {
206  o[i] *= -z[i+1]/hu_;
207  }
208  }
209  // Set right hand side
210  vector r(nu_,0.0);
211  for (uint i = 0; i < nu_; i++) {
212  r[i] = -(u[i]-evaluate_target((Real)(i+1)*hu_));
213  }
214  p.clear();
215  p.resize(nu_,0.0);
216  apply_mass(p,r);
217  // Solve Tridiagonal System Using LAPACK's SPD Tridiagonal Solver
218  Teuchos::LAPACK<int,Real> lp;
219  int info;
220  int ldb = nu_;
221  int nhrs = 1;
222  lp.PTTRF(nu_,&d[0],&o[0],&info);
223  lp.PTTRS(nu_,nhrs,&d[0],&o[0],&p[0],ldb,&info);
224  }
225 
226  void solve_state_sensitivity_equation(std::vector<Real> &w, const std::vector<Real> &v,
227  const std::vector<Real> &u, const std::vector<Real> &z) {
228  // Get Diagonal and Off-Diagonal Entries of PDE Jacobian
229  vector d(nu_,1.0);
230  vector o(nu_-1,1.0);
231  for ( uint i = 0; i < nu_; i++ ) {
232  d[i] = (z[i] + z[i+1])/hu_;
233  if ( i < nu_-1 ) {
234  o[i] *= -z[i+1]/hu_;
235  }
236  }
237  // Set right hand side
238  w.clear();
239  w.resize(nu_,0.0);
241  // Solve Tridiagonal System Using LAPACK's SPD Tridiagonal Solver
242  Teuchos::LAPACK<int,Real> lp;
243  int info;
244  int ldb = nu_;
245  int nhrs = 1;
246  lp.PTTRF(nu_,&d[0],&o[0],&info);
247  lp.PTTRS(nu_,nhrs,&d[0],&o[0],&w[0],ldb,&info);
248  }
249 
250  void solve_adjoint_sensitivity_equation(std::vector<Real> &q, const std::vector<Real> &w,
251  const std::vector<Real> &v, const std::vector<Real> &p,
252  const std::vector<Real> &u, const std::vector<Real> &z) {
253  // Get Diagonal and Off-Diagonal Entries of PDE Jacobian
254  vector d(nu_,1.0);
255  vector o(nu_-1,1.0);
256  for ( uint i = 0; i < nu_; i++ ) {
257  d[i] = (z[i] + z[i+1])/hu_;
258  if ( i < nu_-1 ) {
259  o[i] *= -z[i+1]/hu_;
260  }
261  }
262  // Set right hand side
263  q.clear();
264  q.resize(nu_,0.0);
265  apply_mass(q,w);
266  std::vector<Real> res(nu_,0.0);
267  apply_linearized_control_operator(res,z,v,p,false);
268  for (uint i = 0; i < nu_; i++) {
269  q[i] -= res[i];
270  }
271  // Solve Tridiagonal System Using LAPACK's SPD Tridiagonal Solver
272  Teuchos::LAPACK<int,Real> lp;
273  int info;
274  int ldb = nu_;
275  int nhrs = 1;
276  lp.PTTRF(nu_,&d[0],&o[0],&info);
277  lp.PTTRS(nu_,nhrs,&d[0],&o[0],&q[0],ldb,&info);
278  }
279 
280  void update(const ROL::Vector<Real> &z, bool flag, int iter) {
281 
282 
283 
284  if ( flag && useCorrection_ ) {
285  Real tol = std::sqrt(ROL::ROL_EPSILON<Real>());
286  H_.shape(nz_,nz_);
287  ROL::Ptr<V> e = z.clone();
288  ROL::Ptr<V> h = z.clone();
289  for ( uint i = 0; i < nz_; i++ ) {
290  e = z.basis(i);
291  hessVec_true(*h,*e,z,tol);
292  for ( uint j = 0; j < nz_; j++ ) {
293  e = z.basis(j);
294  (H_)(j,i) = e->dot(*h);
295  }
296  }
297  std::vector<vector> eigenvals = ROL::computeEigenvalues<Real>(H_);
298  std::sort((eigenvals[0]).begin(), (eigenvals[0]).end());
299  Real inertia = (eigenvals[0])[0];
300  Real correction = 0.0;
301  if ( inertia <= 0.0 ) {
302  correction = (1.0+std::sqrt(ROL::ROL_EPSILON<Real>()))*std::abs(inertia);
303  if ( inertia == 0.0 ) {
304  uint cnt = 0;
305  while ( eigenvals[0][cnt] == 0.0 ) {
306  cnt++;
307  }
308  correction = std::sqrt(ROL::ROL_EPSILON<Real>())*eigenvals[0][cnt];
309  if ( cnt == nz_-1 ) {
310  correction = 1.0;
311  }
312  }
313  for ( uint i = 0; i < nz_; i++ ) {
314  (H_)(i,i) += correction;
315  }
316  }
317  }
318  }
319 
320  /* OBJECTIVE FUNCTION DEFINITIONS */
321  Real value( const ROL::Vector<Real> &z, Real &tol ) {
322 
323 
324  ROL::Ptr<const vector> zp = getVector(z);
325 
326  // SOLVE STATE EQUATION
327  vector u(nu_,0.0);
328  solve_state_equation(u,*zp);
329 
330  // EVALUATE OBJECTIVE
331  Real val = 0.0;
332  for (uint i=0; i<nz_;i++) {
333  val += hz_*alpha_*0.5*(*zp)[i]*(*zp)[i];
334  }
335  Real res = 0.0;
336  Real res1 = 0.0;
337  Real res2 = 0.0;
338  Real res3 = 0.0;
339  for (uint i=0; i<nu_; i++) {
340  if ( i == 0 ) {
341  res1 = u[i]-evaluate_target((Real)(i+1)*hu_);
342  res2 = u[i+1]-evaluate_target((Real)(i+2)*hu_);
343  res = hu_/6.0*(2.0*res1 + res2)*res1;
344  }
345  else if ( i == nu_-1 ) {
346  res1 = u[i-1]-evaluate_target((Real)i*hu_);
347  res2 = u[i]-evaluate_target((Real)(i+1)*hu_);
348  res = hu_/6.0*(res1 + 2.0*res2)*res2;
349  }
350  else {
351  res1 = u[i-1]-evaluate_target((Real)i*hu_);
352  res2 = u[i]-evaluate_target((Real)(i+1)*hu_);
353  res3 = u[i+1]-evaluate_target((Real)(i+2)*hu_);
354  res = hu_/6.0*(res1 + 4.0*res2 + res3)*res2;
355  }
356  val += 0.5*res;
357  }
358  return val;
359  }
360 
361  void gradient( ROL::Vector<Real> &g, const ROL::Vector<Real> &z, Real &tol ) {
362 
363 
364 
365  ROL::Ptr<const vector> zp = getVector(z);
366  ROL::Ptr<vector> gp = getVector(g);
367 
368  // SOLVE STATE EQUATION
369  vector u(nu_,0.0);
370  solve_state_equation(u,*zp);
371 
372  // SOLVE ADJOINT EQUATION
373  vector p(nu_,0.0);
374  solve_adjoint_equation(p,u,*zp);
375 
376  // Apply Transpose of Linearized Control Operator
378  // Build Gradient
379  for ( uint i = 0; i < nz_; i++ ) {
380  (*gp)[i] += hz_*alpha_*(*zp)[i];
381  }
382  }
383 
384  void hessVec( ROL::Vector<Real> &hv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &z, Real &tol ) {
385  if ( useCorrection_ ) {
386  hessVec_inertia(hv,v,z,tol);
387  }
388  else {
389  hessVec_true(hv,v,z,tol);
390  }
391  }
392 
393  void activateInertia(void) {
394  useCorrection_ = true;
395  }
396 
397  void deactivateInertia(void) {
398  useCorrection_ = false;
399  }
400 
401  void hessVec_true( ROL::Vector<Real> &hv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &z, Real &tol ) {
402 
403 
404 
405  ROL::Ptr<const vector> vp = getVector(v);
406  ROL::Ptr<const vector> zp = getVector(z);
407  ROL::Ptr<vector> hvp = getVector(hv);
408 
409  // SOLVE STATE EQUATION
410  vector u(nu_,0.0);
411  solve_state_equation(u,*zp);
412 
413  // SOLVE ADJOINT EQUATION
414  vector p(nu_,0.0);
415  solve_adjoint_equation(p,u,*zp);
416 
417  // SOLVE STATE SENSITIVITY EQUATION
418  vector w(nu_,0.0);
420  // SOLVE ADJOINT SENSITIVITY EQUATION
421  vector q(nu_,0.0);
422  solve_adjoint_sensitivity_equation(q,w,*vp,p,u,*zp);
423 
424  // Apply Transpose of Linearized Control Operator
426 
427  // Apply Transpose of Linearized Control Operator
428  std::vector<Real> tmp(nz_,0.0);
430  for (uint i=0; i < nz_; i++) {
431  (*hvp)[i] -= tmp[i];
432  }
433  // Regularization hessVec
434  for (uint i=0; i < nz_; i++) {
435  (*hvp)[i] += hz_*alpha_*(*vp)[i];
436  }
437  }
438 
439  void hessVec_inertia( ROL::Vector<Real> &hv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &z, Real &tol ) {
440 
441 
442  using ROL::constPtrCast;
443 
444  ROL::Ptr<vector> hvp = getVector(hv);
445 
446 
447  ROL::Ptr<vector> vp = ROL::constPtrCast<vector>(getVector(v));
448 
449  Teuchos::SerialDenseVector<int, Real> hv_teuchos(Teuchos::View, &((*hvp)[0]), static_cast<int>(nz_));
450  Teuchos::SerialDenseVector<int, Real> v_teuchos(Teuchos::View, &(( *vp)[0]), static_cast<int>(nz_));
451  hv_teuchos.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, H_, v_teuchos, 0.0);
452  }
453 
454 };
455 
456 
457 
458 typedef double RealT;
459 
460 int main(int argc, char *argv[]) {
461 
462  typedef std::vector<RealT> vector;
463  typedef ROL::Vector<RealT> V;
464  typedef ROL::StdVector<RealT> SV;
465 
466  typedef typename vector::size_type uint;
467 
468 
469 
470  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
471 
472  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
473  int iprint = argc - 1;
474  ROL::Ptr<std::ostream> outStream;
475  ROL::nullstream bhs; // outputs nothing
476  if (iprint > 0)
477  outStream = ROL::makePtrFromRef(std::cout);
478  else
479  outStream = ROL::makePtrFromRef(bhs);
480 
481  int errorFlag = 0;
482 
483  // *** Example body.
484 
485  try {
486 
487  uint dim = 128; // Set problem dimension.
488  RealT alpha = 1.e-6;
489  Objective_PoissonInversion<RealT> obj(dim, alpha);
490 
491  // Iteration vector.
492  ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(dim, 0.0);
493  ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(dim, 0.0);
494 
495  // Set initial guess.
496  for (uint i=0; i<dim; i++) {
497  (*x_ptr)[i] = (RealT)rand()/(RealT)RAND_MAX + 1.e2;
498  (*y_ptr)[i] = (RealT)rand()/(RealT)RAND_MAX + 1.e2;
499  }
500 
501  SV x(x_ptr);
502  SV y(y_ptr);
503 
504  obj.checkGradient(x,y,true);
505  obj.checkHessVec(x,y,true);
506 
507  ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(dim,1.0);
508  ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(dim,10.0);
509 
510  ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
511  ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
512 
513  ROL::Bounds<RealT> icon(lo,up);
514 
515  ROL::ParameterList parlist;
516 
517  // Krylov parameters.
518  parlist.sublist("General").sublist("Krylov").set("Absolute Tolerance",1.e-8);
519  parlist.sublist("General").sublist("Krylov").set("Relative Tolerance",1.e-4);
520  parlist.sublist("General").sublist("Krylov").set("Iteration Limit",static_cast<int>(dim));
521  // PDAS parameters.
522  parlist.sublist("Step").sublist("Primal Dual Active Set").set("Relative Step Tolerance",1.e-8);
523  parlist.sublist("Step").sublist("Primal Dual Active Set").set("Relative Gradient Tolerance",1.e-6);
524  parlist.sublist("Step").sublist("Primal Dual Active Set").set("Iteration Limit", 10);
525  parlist.sublist("Step").sublist("Primal Dual Active Set").set("Dual Scaling",(alpha>0.0)?alpha:1.e-4);
526  parlist.sublist("General").sublist("Secant").set("Use as Hessian",true);
527  // Status test parameters.
528  parlist.sublist("Status Test").set("Gradient Tolerance",1.e-12);
529  parlist.sublist("Status Test").set("Step Tolerance",1.e-14);
530  parlist.sublist("Status Test").set("Iteration Limit",100);
531 
532  // Define algorithm.
533  ROL::Algorithm<RealT> algo("Primal Dual Active Set",parlist,false);
534 
535  x.zero();
536  obj.deactivateInertia();
537  algo.run(x,obj,icon,true,*outStream);
538 
539  // Output control to file.
540  std::ofstream file;
541  file.open("control_PDAS.txt");
542  for ( uint i = 0; i < dim; i++ ) {
543  file << (*x_ptr)[i] << "\n";
544  }
545  file.close();
546 
547  // Projected Newtion.
548  // Define step.
549  parlist.sublist("General").sublist("Secant").set("Use as Hessian",false);
550  parlist.sublist("Step").sublist("Trust Region").set("Subproblem Solver", "Truncated CG");
551  parlist.sublist("Step").sublist("Trust Region").set("Initial Radius", 1e3);
552  parlist.sublist("Step").sublist("Trust Region").set("Maximum Radius", 1e8);
553  ROL::Algorithm<RealT> algo_tr("Trust Region",parlist);
554  // Run Algorithm
555  y.zero();
556  obj.deactivateInertia();
557  algo_tr.run(y,obj,icon,true,*outStream);
558 
559  std::ofstream file_tr;
560  file_tr.open("control_TR.txt");
561  for ( uint i = 0; i < dim; i++ ) {
562  file_tr << (*y_ptr)[i] << "\n";
563  }
564  file_tr.close();
565 
566  std::vector<RealT> u;
567  obj.solve_state_equation(u,*y_ptr);
568  std::ofstream file_u;
569  file_u.open("state.txt");
570  for ( uint i = 0; i < (dim-1); i++ ) {
571  file_u << u[i] << "\n";
572  }
573  file_u.close();
574 
575  ROL::Ptr<V> diff = x.clone();
576  diff->set(x);
577  diff->axpy(-1.0,y);
578  RealT error = diff->norm()/std::sqrt((RealT)dim-1.0);
579  std::cout << "\nError between PDAS solution and TR solution is " << error << "\n";
580  errorFlag = ((error > 1.e2*std::sqrt(ROL::ROL_EPSILON<RealT>())) ? 1 : 0);
581 
582  }
583  catch (std::logic_error err) {
584  *outStream << err.what() << "\n";
585  errorFlag = -1000;
586  }; // end try
587 
588  if (errorFlag != 0)
589  std::cout << "End Result: TEST FAILED\n";
590  else
591  std::cout << "End Result: TEST PASSED\n";
592 
593  return 0;
594 
595 }
596 
Provides the interface to evaluate objective functions.
typename PV< Real >::size_type size_type
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual ROL::Ptr< Vector > basis(const int i) const
Return i-th basis vector.
Definition: ROL_Vector.hpp:182
void solve_state_equation(std::vector< Real > &u, const std::vector< Real > &z)
void apply_transposed_linearized_control_operator(std::vector< Real > &Bd, const std::vector< Real > &z, const std::vector< Real > &d, const std::vector< Real > &u, bool addBC=true)
Contains definitions of custom data types in ROL.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
Contains definitions for helper functions in ROL.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
void solve_adjoint_sensitivity_equation(std::vector< Real > &q, const std::vector< Real > &w, const std::vector< Real > &v, const std::vector< Real > &p, const std::vector< Real > &u, const std::vector< Real > &z)
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Vector< Real > V
void apply_mass(std::vector< Real > &Mz, const std::vector< Real > &z)
Real value(const ROL::Vector< Real > &z, Real &tol)
Compute value.
void update(const ROL::Vector< Real > &z, bool flag, int iter)
Update objective function.
Provides an interface to run optimization algorithms.
Provides the elementwise interface to apply upper and lower bound constraints.
Definition: ROL_Bounds.hpp:59
void hessVec_true(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &z, Real &tol)
void solve_adjoint_equation(std::vector< Real > &p, const std::vector< Real > &u, const std::vector< Real > &z)
void solve_state_sensitivity_equation(std::vector< Real > &w, const std::vector< Real > &v, const std::vector< Real > &u, const std::vector< Real > &z)
basic_nullstream< char, char_traits< char >> nullstream
Definition: ROL_Stream.hpp:72
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &z, Real &tol)
Apply Hessian approximation to vector.
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
void apply_linearized_control_operator(std::vector< Real > &Bd, const std::vector< Real > &z, const std::vector< Real > &d, const std::vector< Real > &u, bool addBC=true)
void hessVec_inertia(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &z, Real &tol)
Objective_PoissonInversion(int nz=32, Real alpha=1.e-4)
void gradient(ROL::Vector< Real > &g, const ROL::Vector< Real > &z, Real &tol)
Compute gradient.
ROL::Ptr< const vector > getVector(const V &x)
Teuchos::SerialDenseMatrix< int, Real > H_