OptiPack  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
OptiPack_NonlinearCG_decl.hpp
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // OptiPack: Collection of simple Thyra-based Optimization ANAs
6 // Copyright (2009) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 #ifndef OPTIPACK_NONLINEAR_CG_DECL_HPP
45 #define OPTIPACK_NONLINEAR_CG_DECL_HPP
46 
47 
48 #include "OptiPack_Types.hpp"
49 #include "Thyra_ModelEvaluator.hpp"
50 #include "GlobiPack_LineSearchBase.hpp"
51 #include "Teuchos_Describable.hpp"
52 #include "Teuchos_VerboseObject.hpp"
53 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
54 #include "Teuchos_ParameterEntryValidator.hpp"
55 
56 
57 namespace OptiPack {
58 
59 
60 namespace NonlinearCGUtils {
61 
62 
64 enum ESolveReturn {
65  SOLVE_SOLUTION_FOUND,
66  SOLVE_LINSEARCH_FAILURE,
67  SOLVE_MAX_ITERS_EXCEEDED
68 };
69 
70 
72 enum ESolverTypes {
73  NONLINEAR_CG_FR,
74  NONLINEAR_CG_PR_PLUS,
75  NONLINEAR_CG_FR_PR,
76  NONLINEAR_CG_HS
77 };
78 
79 
80 } // namespace NonlinearCGUtils
81 
82 
87 template<typename Scalar>
89  : public Teuchos::Describable,
90  public Teuchos::VerboseObject<NonlinearCG<Scalar> >,
92 {
93 public:
94 
97 
100 
102  NonlinearCG();
103 
105  void initialize(
106  const RCP<const Thyra::ModelEvaluator<Scalar> > &model,
107  const int paramIndex,
108  const int responseIndex,
109  const RCP<GlobiPack::LineSearchBase<Scalar> > &linesearch
110  );
111 
113  NonlinearCGUtils::ESolverTypes get_solverType() const;
115  ScalarMag get_alpha_init() const;
117  bool get_alpha_reinit() const;
119  bool get_and_conv_tests() const;
121  int get_minIters() const;
123  int get_maxIters() const;
125  ScalarMag get_g_reduct_tol() const;
127  ScalarMag get_g_grad_tol() const;
129  ScalarMag get_g_mag() const;
130 
132 
135 
137  void setParameterList(RCP<ParameterList> const& paramList);
140 
142 
145 
172  NonlinearCGUtils::ESolveReturn
173  doSolve(
174  const Ptr<Thyra::VectorBase<Scalar> > &p,
175  const Ptr<ScalarMag> &g_opt,
176  const Ptr<const ScalarMag> &g_reduct_tol = Teuchos::null,
177  const Ptr<const ScalarMag> &g_grad_tol = Teuchos::null,
178  const Ptr<const ScalarMag> &alpha_init = Teuchos::null,
179  const Ptr<int> &numIters = Teuchos::null
180  );
181 
183 
184 private:
185 
186  // //////////////////////
187  // Private data members
188 
190  int paramIndex_;
191  int responseIndex_;
193 
194  NonlinearCGUtils::ESolverTypes solverType_;
195  ScalarMag alpha_init_;
196  bool alpha_reinit_;
197  bool and_conv_tests_;
198  int minIters_;
199  int maxIters_;
200  ScalarMag g_reduct_tol_;
201  ScalarMag g_grad_tol_;
202  ScalarMag g_mag_;
203 
204  mutable int numIters_;
205 
207  solverType_validator_;
208 
209 };
210 
211 
216 template<typename Scalar>
219 {
220  return Teuchos::rcp(new NonlinearCG<Scalar>);
221 }
222 
223 
228 template<typename Scalar>
231  const RCP<const Thyra::ModelEvaluator<Scalar> > &model,
232  const int paramIndex,
233  const int responseIndex,
234  const RCP<GlobiPack::LineSearchBase<Scalar> > &linesearch
235  )
236 {
237  const RCP<NonlinearCG<Scalar> > solver =
239  solver->initialize(model, paramIndex, responseIndex, linesearch);
240  return solver;
241 }
242 
243 
244 // Default values are exposed here for unit testing purposes
245 
246 
247 namespace NonlinearCGUtils {
248 
249 const std::string solverType_name = "Solver Type";
250 const std::string solverType_default = "FR";
251 const ESolverTypes solverType_default_integral_val = NONLINEAR_CG_FR;
252 
253 const std::string alpha_init_name = "Initial Linesearch Step Length";
254 const double alpha_init_default = 1.0;
255 
256 const std::string alpha_reinit_name = "Reinitlaize Linesearch Step Length";
257 const bool alpha_reinit_default = false;
258 
259 const std::string and_conv_tests_name = "AND Convergence Tests";
260 const bool and_conv_tests_default = false;
261 
262 const std::string minIters_name = "Min Num Iterations";
263 const int minIters_default = 0;
264 
265 const std::string maxIters_name = "Max Num Iterations";
266 const int maxIters_default = 20;
267 
268 const std::string g_reduct_tol_name = "Objective Reduction Tol";
269 const double g_reduct_tol_default = 1e-5;
270 
271 const std::string g_grad_tol_name = "Objective Gradient Tol";
272 const double g_grad_tol_default = 1e-5;
273 
274 const std::string g_mag_name = "Objective Magnitude";
275 const double g_mag_default = 1.0;
276 
277 
278 } // namespace NonlinearCGUtils
279 
280 
281 
282 } // namespace OptiPack
283 
284 
285 /* Todos:
286 
287 6) Implement FR-PR method
288 
289 7) Implement tabular output option
290 
291 */
292 
293 
294 #endif // OPTIPACK_NONLINEAR_CG_DECL_HPP
const RCP< NonlinearCG< Scalar > > nonlinearCG()
Nonmember constructor.
RCP< const ParameterList > getValidParameters() const
Concrete class implementing several nonlinear CG algorithms.
NonlinearCGUtils::ESolverTypes get_solverType() const
void setParameterList(RCP< ParameterList > const &paramList)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
NonlinearCG()
Construct with default parameters.
void initialize(const RCP< const Thyra::ModelEvaluator< Scalar > > &model, const int paramIndex, const int responseIndex, const RCP< GlobiPack::LineSearchBase< Scalar > > &linesearch)
Initialize.
const RCP< NonlinearCG< Scalar > > nonlinearCG(const RCP< const Thyra::ModelEvaluator< Scalar > > &model, const int paramIndex, const int responseIndex, const RCP< GlobiPack::LineSearchBase< Scalar > > &linesearch)
Nonmember constructor.
NonlinearCGUtils::ESolveReturn doSolve(const Ptr< Thyra::VectorBase< Scalar > > &p, const Ptr< ScalarMag > &g_opt, const Ptr< const ScalarMag > &g_reduct_tol=Teuchos::null, const Ptr< const ScalarMag > &g_grad_tol=Teuchos::null, const Ptr< const ScalarMag > &alpha_init=Teuchos::null, const Ptr< int > &numIters=Teuchos::null)
Perform a solve.
ScalarTraits< Scalar >::magnitudeType ScalarMag