ROL
ROL_Types.hpp
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 #ifndef ROL_TYPES_HPP
50 #define ROL_TYPES_HPP
51 
52 #ifdef HAVE_ROL_DEBUG
53 #define ROL_VALIDATE( A ) A
54 #else
55 #define ROL_VALIDATE( A ) /* empty */
56 #endif
57 
58 #include <algorithm>
59 #include <complex>
60 #include <exception>
61 #include <string>
62 #include <sstream>
63 #include <limits>
64 #include <type_traits>
65 #include <ROL_stacktrace.hpp>
66 #include "ROL_ScalarTraits.hpp"
67 #include <ROL_Ptr.hpp>
68 #include <ROL_Vector.hpp>
69 #include <ROL_config.h>
70 
74 #define ROL_NUM_CHECKDERIV_STEPS 13
75 
76 
77 
78 namespace ROL {
79 
80  template<class T>
81  std::string NumberToString( T Number )
82  {
83  std::ostringstream ss;
84  ss << Number;
85  return ss.str();
86  }
87 
90  template<class Real>
91  inline Real ROL_EPSILON(void) { return std::abs(ROL::ScalarTraits<Real>::eps()); }
92  //static const Real ROL_EPSILON<Real>() = std::abs(ROL::ScalarTraits<Real>::eps());
93 
96  template<class Real>
97  inline Real ROL_THRESHOLD(void) { return 10.0 * ROL_EPSILON<Real>(); }
98 
101  template<class Real>
102  inline Real ROL_OVERFLOW(void) { return std::abs(ROL::ScalarTraits<Real>::rmax()); }
103 
104  template<class Real>
105  inline Real ROL_INF(void) { return 0.1*ROL_OVERFLOW<Real>(); }
106 
107  template<class Real>
108  inline Real ROL_NINF(void) { return -ROL_INF<Real>(); }
109 
112  template<class Real>
113  inline Real ROL_UNDERFLOW(void) { return std::abs(ROL::ScalarTraits<Real>::rmin()); }
114 
117  enum EExitStatus {
124  };
125 
126  inline std::string EExitStatusToString(EExitStatus tr) {
127  std::string retString;
128  switch(tr) {
129  case EXITSTATUS_CONVERGED: retString = "Converged"; break;
130  case EXITSTATUS_MAXITER: retString = "Iteration Limit Exceeded"; break;
131  case EXITSTATUS_STEPTOL: retString = "Step Tolerance Met"; break;
132  case EXITSTATUS_NAN: retString = "Step and/or Gradient Returned NaN"; break;
133  case EXITSTATUS_USERDEFINED: retString = "User Defined"; break;
134  case EXITSTATUS_LAST: retString = "Last Type (Dummy)"; break;
135  default: retString = "INVALID EExitStatus";
136  }
137  return retString;
138  }
139 
142  template<class Real>
143  struct AlgorithmState {
144  int iter;
145  int minIter;
146  int nfval;
147  int ncval;
148  int ngrad;
149  Real value;
150  Real minValue;
151  Real gnorm;
152  Real cnorm;
153  Real snorm;
156  bool flag;
157  ROL::Ptr<Vector<Real> > iterateVec;
158  ROL::Ptr<Vector<Real> > lagmultVec;
159  ROL::Ptr<Vector<Real> > minIterVec;
161 
162  AlgorithmState(void) : iter(0), minIter(0), nfval(0), ngrad(0), value(0), minValue(0),
163  gnorm(std::numeric_limits<Real>::max()),
164  cnorm(std::numeric_limits<Real>::max()),
165  snorm(std::numeric_limits<Real>::max()),
166  aggregateGradientNorm(std::numeric_limits<Real>::max()),
167  aggregateModelError(std::numeric_limits<Real>::max()),
168  flag(false),
169  iterateVec(ROL::nullPtr), lagmultVec(ROL::nullPtr), minIterVec(ROL::nullPtr),
171 
172  void reset(void) {
173  iter = 0;
174  minIter = 0;
175  nfval = 0;
176  ncval = 0;
177  ngrad = 0;
178  value = ROL_INF<Real>();
179  minValue = ROL_INF<Real>();
180  gnorm = ROL_INF<Real>();
181  cnorm = ROL_INF<Real>();
182  snorm = ROL_INF<Real>();
183  aggregateGradientNorm = ROL_INF<Real>();
184  aggregateModelError = ROL_INF<Real>();
185  flag = false;
186  if (iterateVec != ROL::nullPtr) {
187  iterateVec->zero();
188  }
189  if (lagmultVec != ROL::nullPtr) {
190  lagmultVec->zero();
191  }
192  if (minIterVec != ROL::nullPtr) {
193  minIterVec->zero();
194  }
195  }
196  };
197 
200  template<class Real>
201  struct StepState {
202  ROL::Ptr<Vector<Real> > gradientVec;
203  ROL::Ptr<Vector<Real> > descentVec;
204  ROL::Ptr<Vector<Real> > constraintVec;
205  int nfval;
206  int ngrad;
207  Real searchSize; // line search parameter (alpha) or trust-region radius (delta)
208  int flag; // Was step successful?
209  int SPiter; // Subproblem iteration count
210  int SPflag; // Subproblem termination flag
211 
212  StepState(void) : gradientVec(ROL::nullPtr),
213  descentVec(ROL::nullPtr),
214  constraintVec(ROL::nullPtr),
215  nfval(0),
216  ngrad(0),
217  searchSize(0),
218  flag(0),
219  SPiter(0),
220  SPflag(0) {}
221 
222  void reset(const Real searchSizeInput = 1.0) {
223  if (gradientVec != ROL::nullPtr) {
224  gradientVec->zero();
225  }
226  if (descentVec != ROL::nullPtr) {
227  descentVec->zero();
228  }
229  if (constraintVec != ROL::nullPtr) {
230  constraintVec->zero();
231  }
232  nfval = 0;
233  ngrad = 0;
234  searchSize = searchSizeInput;
235  flag = 0;
236  SPiter = 0;
237  SPflag = 0;
238  }
239  };
240 
242  bool operator()(char c) {
243  return (c ==' ' || c =='-' || c == '(' || c == ')' || c=='\'' || c=='\r' || c=='\n' || c=='\t');
244  }
245  };
246 
247  inline std::string removeStringFormat( std::string s ) {
248  std::string output = s;
249  output.erase( std::remove_if( output.begin(), output.end(), removeSpecialCharacters()), output.end() );
250  std::transform( output.begin(), output.end(), output.begin(), ::tolower );
251  return output;
252  }
253 
254  // Types of optimization problem
255  enum EProblem {
256  TYPE_U = 0,
261  };
262 
274  enum EStep{
285  };
286 
287  inline std::string EStepToString(EStep tr) {
288  std::string retString;
289  switch(tr) {
290  case STEP_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
291  case STEP_BUNDLE: retString = "Bundle"; break;
292  case STEP_COMPOSITESTEP: retString = "Composite Step"; break;
293  case STEP_LINESEARCH: retString = "Line Search"; break;
294  case STEP_MOREAUYOSIDAPENALTY: retString = "Moreau-Yosida Penalty"; break;
295  case STEP_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
296  case STEP_TRUSTREGION: retString = "Trust Region"; break;
297  case STEP_INTERIORPOINT: retString = "Interior Point"; break;
298  case STEP_FLETCHER: retString = "Fletcher"; break;
299  case STEP_LAST: retString = "Last Type (Dummy)"; break;
300  default: retString = "INVALID EStep";
301  }
302  return retString;
303  }
304 
305  inline bool isCompatibleStep( EProblem p, EStep s ) {
306  bool comp = false;
307  switch(p) {
308 
309  case TYPE_U: comp = ( (s == STEP_LINESEARCH) ||
310  (s == STEP_TRUSTREGION) ||
311  (s == STEP_BUNDLE) );
312  break;
313 
314  case TYPE_B: comp = ( (s == STEP_LINESEARCH) ||
315  (s == STEP_TRUSTREGION) ||
316  (s == STEP_MOREAUYOSIDAPENALTY) ||
317  (s == STEP_PRIMALDUALACTIVESET) ||
318  (s == STEP_INTERIORPOINT) );
319  break;
320 
321  case TYPE_E: comp = ( (s == STEP_COMPOSITESTEP) ||
322  (s == STEP_AUGMENTEDLAGRANGIAN) ||
323  (s == STEP_FLETCHER) );
324  break;
325 
326  case TYPE_EB: comp = ( (s == STEP_AUGMENTEDLAGRANGIAN) ||
327  (s == STEP_MOREAUYOSIDAPENALTY) ||
328  (s == STEP_INTERIORPOINT) ||
329  (s == STEP_FLETCHER) );
330  break;
331 
332  case TYPE_LAST: comp = false; break;
333  default: comp = false;
334  }
335  return comp;
336  }
337 
338  inline std::string EProblemToString( EProblem p ) {
339  std::string retString;
340  switch(p) {
341  case TYPE_U: retString = "Type-U"; break;
342  case TYPE_E: retString = "Type-E"; break;
343  case TYPE_B: retString = "Type-B"; break;
344  case TYPE_EB: retString = "Type-EB"; break;
345  case TYPE_LAST: retString = "Type-Last (Dummy)"; break;
346  default: retString = "Invalid EProblem";
347  }
348  return retString;
349  }
350 
351 
357  inline int isValidStep(EStep ls) {
358  return( (ls == STEP_AUGMENTEDLAGRANGIAN) ||
359  (ls == STEP_BUNDLE) ||
360  (ls == STEP_COMPOSITESTEP) ||
361  (ls == STEP_LINESEARCH) ||
362  (ls == STEP_MOREAUYOSIDAPENALTY) ||
363  (ls == STEP_PRIMALDUALACTIVESET) ||
364  (ls == STEP_TRUSTREGION) ||
365  (ls == STEP_INTERIORPOINT) ||
366  (ls == STEP_FLETCHER) ) ;
367  }
368 
369  inline EStep & operator++(EStep &type) {
370  return type = static_cast<EStep>(type+1);
371  }
372 
373  inline EStep operator++(EStep &type, int) {
374  EStep oldval = type;
375  ++type;
376  return oldval;
377  }
378 
379  inline EStep & operator--(EStep &type) {
380  return type = static_cast<EStep>(type-1);
381  }
382 
383  inline EStep operator--(EStep &type, int) {
384  EStep oldval = type;
385  --type;
386  return oldval;
387  }
388 
389  inline EStep StringToEStep(std::string s) {
390  s = removeStringFormat(s);
391  for ( EStep st = STEP_AUGMENTEDLAGRANGIAN; st < STEP_LAST; ++st ) {
392  if ( !s.compare(removeStringFormat(EStepToString(st))) ) {
393  return st;
394  }
395  }
396  return STEP_LAST;
397  }
398 
409  enum EDescent{
416  };
417 
418  inline std::string EDescentToString(EDescent tr) {
419  std::string retString;
420  switch(tr) {
421  case DESCENT_STEEPEST: retString = "Steepest Descent"; break;
422  case DESCENT_NONLINEARCG: retString = "Nonlinear CG"; break;
423  case DESCENT_SECANT: retString = "Quasi-Newton Method"; break;
424  case DESCENT_NEWTON: retString = "Newton's Method"; break;
425  case DESCENT_NEWTONKRYLOV: retString = "Newton-Krylov"; break;
426  case DESCENT_LAST: retString = "Last Type (Dummy)"; break;
427  default: retString = "INVALID ESecant";
428  }
429  return retString;
430  }
431 
437  inline int isValidDescent(EDescent d){
438  return( (d == DESCENT_STEEPEST) ||
439  (d == DESCENT_NONLINEARCG) ||
440  (d == DESCENT_SECANT) ||
441  (d == DESCENT_NEWTON) ||
442  (d == DESCENT_NEWTONKRYLOV)
443  );
444  }
445 
446  inline EDescent & operator++(EDescent &type) {
447  return type = static_cast<EDescent>(type+1);
448  }
449 
450  inline EDescent operator++(EDescent &type, int) {
451  EDescent oldval = type;
452  ++type;
453  return oldval;
454  }
455 
456  inline EDescent & operator--(EDescent &type) {
457  return type = static_cast<EDescent>(type-1);
458  }
459 
460  inline EDescent operator--(EDescent &type, int) {
461  EDescent oldval = type;
462  --type;
463  return oldval;
464  }
465 
466  inline EDescent StringToEDescent(std::string s) {
467  s = removeStringFormat(s);
468  for ( EDescent des = DESCENT_STEEPEST; des < DESCENT_LAST; des++ ) {
469  if ( !s.compare(removeStringFormat(EDescentToString(des))) ) {
470  return des;
471  }
472  }
473  return DESCENT_SECANT;
474  }
475 
484  enum ESecant{
491  };
492 
493  inline std::string ESecantToString(ESecant tr) {
494  std::string retString;
495  switch(tr) {
496  case SECANT_LBFGS: retString = "Limited-Memory BFGS"; break;
497  case SECANT_LDFP: retString = "Limited-Memory DFP"; break;
498  case SECANT_LSR1: retString = "Limited-Memory SR1"; break;
499  case SECANT_BARZILAIBORWEIN: retString = "Barzilai-Borwein"; break;
500  case SECANT_USERDEFINED: retString = "User-Defined"; break;
501  case SECANT_LAST: retString = "Last Type (Dummy)"; break;
502  default: retString = "INVALID ESecant";
503  }
504  return retString;
505  }
506 
512  inline int isValidSecant(ESecant s) {
513  return( (s == SECANT_LBFGS) ||
514  (s == SECANT_LDFP) ||
515  (s == SECANT_LSR1) ||
516  (s == SECANT_BARZILAIBORWEIN) ||
517  (s == SECANT_USERDEFINED)
518  );
519  }
520 
521  inline ESecant & operator++(ESecant &type) {
522  return type = static_cast<ESecant>(type+1);
523  }
524 
525  inline ESecant operator++(ESecant &type, int) {
526  ESecant oldval = type;
527  ++type;
528  return oldval;
529  }
530 
531  inline ESecant & operator--(ESecant &type) {
532  return type = static_cast<ESecant>(type-1);
533  }
534 
535  inline ESecant operator--(ESecant &type, int) {
536  ESecant oldval = type;
537  --type;
538  return oldval;
539  }
540 
541  inline ESecant StringToESecant(std::string s) {
542  s = removeStringFormat(s);
543  for ( ESecant sec = SECANT_LBFGS; sec < SECANT_LAST; sec++ ) {
544  if ( !s.compare(removeStringFormat(ESecantToString(sec))) ) {
545  return sec;
546  }
547  }
548  return SECANT_LBFGS;
549  }
550 
576  };
577 
578  inline std::string ENonlinearCGToString(ENonlinearCG tr) {
579  std::string retString;
580  switch(tr) {
581  case NONLINEARCG_HESTENES_STIEFEL: retString = "Hestenes-Stiefel"; break;
582  case NONLINEARCG_FLETCHER_REEVES: retString = "Fletcher-Reeves"; break;
583  case NONLINEARCG_DANIEL: retString = "Daniel (uses Hessian)"; break;
584  case NONLINEARCG_POLAK_RIBIERE: retString = "Polak-Ribiere"; break;
585  case NONLINEARCG_FLETCHER_CONJDESC: retString = "Fletcher Conjugate Descent"; break;
586  case NONLINEARCG_LIU_STOREY: retString = "Liu-Storey"; break;
587  case NONLINEARCG_DAI_YUAN: retString = "Dai-Yuan"; break;
588  case NONLINEARCG_HAGER_ZHANG: retString = "Hager-Zhang"; break;
589  case NONLINEARCG_OREN_LUENBERGER: retString = "Oren-Luenberger"; break;
590  case NONLINEARCG_USERDEFINED: retString = "User Defined"; break;
591  case NONLINEARCG_LAST: retString = "Last Type (Dummy)"; break;
592  default: retString = "INVALID ENonlinearCG";
593  }
594  return retString;
595  }
596 
603  return( (s == NONLINEARCG_HESTENES_STIEFEL) ||
605  (s == NONLINEARCG_DANIEL) ||
606  (s == NONLINEARCG_POLAK_RIBIERE) ||
608  (s == NONLINEARCG_LIU_STOREY) ||
609  (s == NONLINEARCG_DAI_YUAN) ||
610  (s == NONLINEARCG_HAGER_ZHANG) ||
613  );
614  }
615 
617  return type = static_cast<ENonlinearCG>(type+1);
618  }
619 
620  inline ENonlinearCG operator++(ENonlinearCG &type, int) {
621  ENonlinearCG oldval = type;
622  ++type;
623  return oldval;
624  }
625 
627  return type = static_cast<ENonlinearCG>(type-1);
628  }
629 
630  inline ENonlinearCG operator--(ENonlinearCG &type, int) {
631  ENonlinearCG oldval = type;
632  --type;
633  return oldval;
634  }
635 
636  inline ENonlinearCG StringToENonlinearCG(std::string s) {
637  s = removeStringFormat(s);
638  for ( ENonlinearCG nlcg = NONLINEARCG_HESTENES_STIEFEL; nlcg < NONLINEARCG_LAST; nlcg++ ) {
639  if ( !s.compare(removeStringFormat(ENonlinearCGToString(nlcg))) ) {
640  return nlcg;
641  }
642  }
644  }
645 
666  };
667 
668  inline std::string ELineSearchToString(ELineSearch ls) {
669  std::string retString;
670  switch(ls) {
671  case LINESEARCH_ITERATIONSCALING: retString = "Iteration Scaling"; break;
672  case LINESEARCH_PATHBASEDTARGETLEVEL: retString = "Path-Based Target Level"; break;
673  case LINESEARCH_BACKTRACKING: retString = "Backtracking"; break;
674  case LINESEARCH_BISECTION: retString = "Bisection"; break;
675  case LINESEARCH_GOLDENSECTION: retString = "Golden Section"; break;
676  case LINESEARCH_CUBICINTERP: retString = "Cubic Interpolation"; break;
677  case LINESEARCH_BRENTS: retString = "Brent's"; break;
678  case LINESEARCH_USERDEFINED: retString = "User Defined"; break;
679  case LINESEARCH_LAST: retString = "Last Type (Dummy)"; break;
680  default: retString = "INVALID ELineSearch";
681  }
682  return retString;
683  }
684 
691  return( (ls == LINESEARCH_BACKTRACKING) ||
692  (ls == LINESEARCH_ITERATIONSCALING) ||
694  (ls == LINESEARCH_BISECTION) ||
695  (ls == LINESEARCH_GOLDENSECTION) ||
696  (ls == LINESEARCH_CUBICINTERP) ||
697  (ls == LINESEARCH_BRENTS) ||
698  (ls == LINESEARCH_USERDEFINED)
699  );
700  }
701 
703  return type = static_cast<ELineSearch>(type+1);
704  }
705 
706  inline ELineSearch operator++(ELineSearch &type, int) {
707  ELineSearch oldval = type;
708  ++type;
709  return oldval;
710  }
711 
713  return type = static_cast<ELineSearch>(type-1);
714  }
715 
716  inline ELineSearch operator--(ELineSearch &type, int) {
717  ELineSearch oldval = type;
718  --type;
719  return oldval;
720  }
721 
722  inline ELineSearch StringToELineSearch(std::string s) {
723  s = removeStringFormat(s);
724  for ( ELineSearch ls = LINESEARCH_ITERATIONSCALING; ls < LINESEARCH_LAST; ls++ ) {
725  if ( !s.compare(removeStringFormat(ELineSearchToString(ls))) ) {
726  return ls;
727  }
728  }
730  }
731 
747  };
748 
750  std::string retString;
751  switch(ls) {
752  case CURVATURECONDITION_WOLFE: retString = "Wolfe Conditions"; break;
753  case CURVATURECONDITION_STRONGWOLFE: retString = "Strong Wolfe Conditions"; break;
754  case CURVATURECONDITION_GENERALIZEDWOLFE: retString = "Generalized Wolfe Conditions"; break;
755  case CURVATURECONDITION_APPROXIMATEWOLFE: retString = "Approximate Wolfe Conditions"; break;
756  case CURVATURECONDITION_GOLDSTEIN: retString = "Goldstein Conditions"; break;
757  case CURVATURECONDITION_NULL: retString = "Null Curvature Condition"; break;
758  case CURVATURECONDITION_LAST: retString = "Last Type (Dummy)"; break;
759  default: retString = "INVALID ECurvatureCondition";
760  }
761  return retString;
762  }
763 
770  return( (ls == CURVATURECONDITION_WOLFE) ||
776  );
777  }
778 
780  return type = static_cast<ECurvatureCondition>(type+1);
781  }
782 
784  ECurvatureCondition oldval = type;
785  ++type;
786  return oldval;
787  }
788 
790  return type = static_cast<ECurvatureCondition>(type-1);
791  }
792 
794  ECurvatureCondition oldval = type;
795  --type;
796  return oldval;
797  }
798 
800  s = removeStringFormat(s);
802  if ( !s.compare(removeStringFormat(ECurvatureConditionToString(cc))) ) {
803  return cc;
804  }
805  }
807  }
808 
819  enum ECGFlag {
826  };
827 
828 
829  inline std::string ECGFlagToString(ECGFlag cgf) {
830  std::string retString;
831  switch(cgf) {
832  case CG_FLAG_SUCCESS:
833  retString = "Residual tolerance met";
834  break;
835  case CG_FLAG_ITEREXCEED:
836  retString = "Iteration limit exceeded";
837  break;
838  case CG_FLAG_NEGCURVE:
839  retString = "Negative curvature detected";
840  break;
841  case CG_FLAG_TRRADEX:
842  retString = "Trust-Region radius exceeded";
843  break;
844  case CG_FLAG_ZERORHS:
845  retString = "Initial right hand side is zero";
846  break;
847  default:
848  retString = "INVALID ECGFlag";
849  }
850  return retString;
851  }
852 
853 
854 
855  // For use in gradient and Hessian checks
856  namespace Finite_Difference_Arrays {
857 
858  // Finite difference steps in axpy form
859  const int shifts[4][4] = { { 1, 0, 0, 0 }, // First order
860  { -1, 2, 0, 0 }, // Second order
861  { -1, 2, 1, 0 }, // Third order
862  { -1, -1, 3, 1 } // Fourth order
863  };
864 
865  // Finite difference weights
866  const double weights[4][5] = { { -1.0, 1.0, 0.0, 0.0, 0.0 }, // First order
867  { 0.0, -1.0/2.0, 1.0/2.0, 0.0, 0.0 }, // Second order
868  { -1.0/2.0, -1.0/3.0, 1.0, -1.0/6.0, 0.0 }, // Third order
869  { 0.0, -2.0/3.0, 1.0/12.0, 2.0/3.0, -1.0/12.0 } // Fourth order
870  };
871 
872  }
873 
874 
875 // Generic conversion from Element type to Real type
876 template<class Real, class Element>
877 struct TypeCaster {
878  static Real ElementToReal( const Element &val ) {
879  return Real(0);
880  }
881 };
882 
883 // Partially specialize for complex<Real>
884 template<class Real>
885 struct TypeCaster<Real, std::complex<Real> > {
886  static Real ElementToReal( const std::complex<Real> &val ) {
887  return val.real();
888  }
889 };
890 
891 // Fully specialize for double,float
892 template<>
893 struct TypeCaster<double,float> {
894  static double ElementToReal( const float &val ) {
895  return static_cast<double>(val);
896  }
897 };
898 
899 // Cast from Element type to Real type
900 template<class Element, class Real>
901 Real rol_cast(const Element &val) {
903 }
904 
905 
906 
907 
908 
909 
910 namespace Exception {
911 
912 class NotImplemented : public std::logic_error {
913 public:
914  NotImplemented( const std::string& what_arg ) :
915  std::logic_error(what_arg) {}
916 
917 
918 }; // class NotImplemented
919 
920 
921 #if __cplusplus >= 201402L // using C++14
922 
923 using std::enable_if_t;
924 
925 #else // No C++14
926 
927 template<bool B, class T=void>
928 using enable_if_t = typename std::enable_if<B,T>::type;
929 
930 #endif
931 
932 
933 
934 
935 
936 } // namespace Exception
937 
938 
939 } // namespace ROL
940 
941 
1160 #endif
std::string ECGFlagToString(ECGFlag cgf)
Definition: ROL_Types.hpp:829
EStep StringToEStep(std::string s)
Definition: ROL_Types.hpp:389
static Real ElementToReal(const Element &val)
Definition: ROL_Types.hpp:878
int isValidSecant(ESecant s)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:512
Real ROL_THRESHOLD(void)
Tolerance for various equality tests.
Definition: ROL_Types.hpp:97
const double weights[4][5]
Definition: ROL_Types.hpp:866
EExitStatus statusFlag
Definition: ROL_Types.hpp:160
ELineSearch StringToELineSearch(std::string s)
Definition: ROL_Types.hpp:722
Real ROL_INF(void)
Definition: ROL_Types.hpp:105
EKrylov & operator++(EKrylov &type)
NotImplemented(const std::string &what_arg)
Definition: ROL_Types.hpp:914
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:247
ELineSearch
Enumeration of line-search types.
Definition: ROL_Types.hpp:656
ESecant StringToESecant(std::string s)
Definition: ROL_Types.hpp:541
std::string EDescentToString(EDescent tr)
Definition: ROL_Types.hpp:418
static Real ElementToReal(const std::complex< Real > &val)
Definition: ROL_Types.hpp:886
ECGFlag
Enumation of flags used by conjugate gradient methods.
Definition: ROL_Types.hpp:819
ROL::Ptr< Vector< Real > > gradientVec
Definition: ROL_Types.hpp:202
EDescent StringToEDescent(std::string s)
Definition: ROL_Types.hpp:466
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:143
std::string NumberToString(T Number)
Definition: ROL_Types.hpp:81
ENonlinearCG
Enumeration of nonlinear CG algorithms.
Definition: ROL_Types.hpp:564
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Definition: ROL_Types.hpp:749
Real rol_cast(const Element &val)
Definition: ROL_Types.hpp:901
std::string EExitStatusToString(EExitStatus tr)
Definition: ROL_Types.hpp:126
typename std::enable_if< B, T >::type enable_if_t
Definition: ROL_Types.hpp:928
EExitStatus
Enum for algorithm termination.
Definition: ROL_Types.hpp:117
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:484
ROL::Ptr< Vector< Real > > constraintVec
Definition: ROL_Types.hpp:204
ROL::Ptr< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:157
std::string ENonlinearCGToString(ENonlinearCG tr)
Definition: ROL_Types.hpp:578
ENonlinearCG StringToENonlinearCG(std::string s)
Definition: ROL_Types.hpp:636
int isValidDescent(EDescent d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:437
std::string ELineSearchToString(ELineSearch ls)
Definition: ROL_Types.hpp:668
Real ROL_OVERFLOW(void)
Platform-dependent maximum double.
Definition: ROL_Types.hpp:102
int isValidLineSearch(ELineSearch ls)
Verifies validity of a LineSearch enum.
Definition: ROL_Types.hpp:690
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:201
std::string EProblemToString(EProblem p)
Definition: ROL_Types.hpp:338
int isValidStep(EStep ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:357
ROL::Ptr< Vector< Real > > descentVec
Definition: ROL_Types.hpp:203
static double ElementToReal(const float &val)
Definition: ROL_Types.hpp:894
int isValidCurvatureCondition(ECurvatureCondition ls)
Verifies validity of a CurvatureCondition enum.
Definition: ROL_Types.hpp:769
ECurvatureCondition
Enumeration of line-search curvature conditions.
Definition: ROL_Types.hpp:739
void reset(const Real searchSizeInput=1.0)
Definition: ROL_Types.hpp:222
ROL::Ptr< Vector< Real > > lagmultVec
Definition: ROL_Types.hpp:158
ECurvatureCondition StringToECurvatureCondition(std::string s)
Definition: ROL_Types.hpp:799
EKrylov & operator--(EKrylov &type)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:91
ROL::Ptr< Vector< Real > > minIterVec
Definition: ROL_Types.hpp:159
std::string ESecantToString(ESecant tr)
Definition: ROL_Types.hpp:493
std::string EStepToString(EStep tr)
Definition: ROL_Types.hpp:287
EStep
Enumeration of step types.
Definition: ROL_Types.hpp:274
Real ROL_UNDERFLOW(void)
Platform-dependent minimum double.
Definition: ROL_Types.hpp:113
EProblem
Definition: ROL_Types.hpp:255
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.
Definition: ROL_Types.hpp:602
EDescent
Enumeration of descent direction types.
Definition: ROL_Types.hpp:409
Real ROL_NINF(void)
Definition: ROL_Types.hpp:108
bool isCompatibleStep(EProblem p, EStep s)
Definition: ROL_Types.hpp:305