1+ /*
2+ //@HEADER
3+ // ************************************************************************
4+ //
5+ // lspg_pick_solver_and_run.hpp
6+ // Pressio
7+ // Copyright 2019
8+ // National Technology & Engineering Solutions of Sandia, LLC (NTESS)
9+ //
10+ // Under the terms of Contract DE-NA0003525 with NTESS, the
11+ // U.S. Government retains certain rights in this software.
12+ //
13+ // Pressio is licensed under BSD-3-Clause terms of use:
14+ //
15+ // Redistribution and use in source and binary forms, with or without
16+ // modification, are permitted provided that the following conditions
17+ // are met:
18+ //
19+ // 1. Redistributions of source code must retain the above copyright
20+ // notice, this list of conditions and the following disclaimer.
21+ //
22+ // 2. Redistributions in binary form must reproduce the above copyright
23+ // notice, this list of conditions and the following disclaimer in the
24+ // documentation and/or other materials provided with the distribution.
25+ //
26+ // 3. Neither the name of the copyright holder nor the names of its
27+ // contributors may be used to endorse or promote products derived
28+ // from this software without specific prior written permission.
29+ //
30+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33+ // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34+ // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35+ // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36+ // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38+ // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39+ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40+ // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41+ // POSSIBILITY OF SUCH DAMAGE.
42+ //
43+ // Questions? Contact Francesco Rizzi ([email protected] ) 44+ //
45+ // ************************************************************************
46+ //@HEADER
47+ */
148
249#ifndef RUN_LSPG_PICK_SOLVER_AND_RUN_HPP_
350#define RUN_LSPG_PICK_SOLVER_AND_RUN_HPP_
451
5- /* NOTE:
6- 1. the formatting here matters because the rst docs
7- use literalincludes so if you change somehting below
8- it is likely you impact the documentation
9-
10- 2. the comments below are used by the rst documentaion
11- in non contiguous literalinclude statetements so that
12- we can make the documentation more clear
13-
14- 3. do NOT erase these comments, and do NOT move them
15- or you impact the rst docs
16-
17- // branch taken in this demo
18- // branch not used in this demo
19- */
20-
2152template <class LspgStepperType , class ParserType , class RomStateType >
2253void lspg_pick_solver_and_run (const ParserType & parser,
2354 LspgStepperType & lspgStepper,
@@ -33,49 +64,49 @@ void lspg_pick_solver_and_run(const ParserType & parser,
3364
3465 if (parser.nonlinearSolver () == " GaussNewton" )
3566 {
36- using hessian_t = Eigen::Matrix<scalar_type, -1 , -1 >;
37- using solver_tag = pressio::linearsolvers::direct::HouseholderQR;
38- using linear_solver_t = pressio::linearsolvers::Solver<solver_tag, hessian_t >;
39- linear_solver_t linearSolver;
67+ using hessian_t = Eigen::Matrix<scalar_type, -1 , -1 >;
68+ using solver_tag = pressio::linearsolvers::direct::HouseholderQR;
69+ using linear_solver_t = pressio::linearsolvers::Solver<solver_tag, hessian_t >;
70+ linear_solver_t linearSolver;
4071
41- auto solver = pnlins::create_gauss_newton (lspgStepper, linearSolver);
42- solver.setStoppingCriterion (pnlins::Stop::WhenGradientAbsoluteNormBelowTolerance);
43- solver.setTolerance (parser.nonlinearSolverTolerance ());
72+ auto solver = pnlins::create_gauss_newton (lspgStepper, linearSolver);
73+ solver.setStoppingCriterion (pnlins::Stop::WhenGradientAbsoluteNormBelowTolerance);
74+ solver.setTolerance (parser.nonlinearSolverTolerance ());
4475
45- pode::advance_n_steps (lspgStepper, reducedState, startTime,
46- parser.timeStepSize (), numSteps,
47- observer, solver);
76+ pode::advance_n_steps (lspgStepper, reducedState, startTime,
77+ parser.timeStepSize (), numSteps,
78+ observer, solver);
4879 }
4980
5081 else if (parser.nonlinearSolver () == " GaussNewtonQR" )
5182 {
52- using mat_t = typename LspgStepperType::jacobian_type;
53- using qr_solver_t = pressio::qr::QRSolver<mat_t , pressio::qr::Householder>;
54- qr_solver_t qrSolver;
55- auto solver = pnlins::create_gauss_newtonQR (lspgStepper, qrSolver);
56- solver.setStoppingCriterion (pnlins::Stop::WhenGradientAbsoluteNormBelowTolerance);
57- solver.setTolerance (parser.nonlinearSolverTolerance ());
83+ using mat_t = typename LspgStepperType::jacobian_type;
84+ using qr_solver_t = pressio::qr::QRSolver<mat_t , pressio::qr::Householder>;
85+ qr_solver_t qrSolver;
86+ auto solver = pnlins::create_gauss_newtonQR (lspgStepper, qrSolver);
87+ solver.setStoppingCriterion (pnlins::Stop::WhenGradientAbsoluteNormBelowTolerance);
88+ solver.setTolerance (parser.nonlinearSolverTolerance ());
5889
59- pode::advance_n_steps (lspgStepper, reducedState, startTime,
60- parser.timeStepSize (), numSteps,
61- observer, solver);
90+ pode::advance_n_steps (lspgStepper, reducedState, startTime,
91+ parser.timeStepSize (), numSteps,
92+ observer, solver);
6293 }
6394
6495 else if (parser.nonlinearSolver () == " LevenbergMarquardt" )
6596 {
66- using hessian_t = Eigen::Matrix<scalar_type, -1 , -1 >;
67- using solver_tag = pressio::linearsolvers::direct::HouseholderQR;
68- using linear_solver_t = pressio::linearsolvers::Solver<solver_tag, hessian_t >;
69- linear_solver_t linearSolver;
97+ using hessian_t = Eigen::Matrix<scalar_type, -1 , -1 >;
98+ using solver_tag = pressio::linearsolvers::direct::HouseholderQR;
99+ using linear_solver_t = pressio::linearsolvers::Solver<solver_tag, hessian_t >;
100+ linear_solver_t linearSolver;
70101
71- auto solver = pnlins::create_levenberg_marquardt (lspgStepper, linearSolver);
72- solver.setUpdatingCriterion (pnlins::Update::LMSchedule2);
73- solver.setStoppingCriterion (pnlins::Stop::WhenGradientAbsoluteNormBelowTolerance);
74- solver.setTolerance (parser.nonlinearSolverTolerance ());
102+ auto solver = pnlins::create_levenberg_marquardt (lspgStepper, linearSolver);
103+ solver.setUpdatingCriterion (pnlins::Update::LMSchedule2);
104+ solver.setStoppingCriterion (pnlins::Stop::WhenGradientAbsoluteNormBelowTolerance);
105+ solver.setTolerance (parser.nonlinearSolverTolerance ());
75106
76- pode::advance_n_steps (lspgStepper, reducedState, startTime,
77- parser.timeStepSize (), numSteps,
78- observer, solver);
107+ pode::advance_n_steps (lspgStepper, reducedState, startTime,
108+ parser.timeStepSize (), numSteps,
109+ observer, solver);
79110 }
80111}
81112#endif
0 commit comments