diff --git a/src/polysolve/nonlinear/CMakeLists.txt b/src/polysolve/nonlinear/CMakeLists.txt index fc46887d..c842dbe3 100644 --- a/src/polysolve/nonlinear/CMakeLists.txt +++ b/src/polysolve/nonlinear/CMakeLists.txt @@ -5,6 +5,8 @@ set(SOURCES Solver.cpp Problem.hpp Problem.cpp + PostStepData.hpp + PostStepData.cpp ) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES}) diff --git a/src/polysolve/nonlinear/PostStepData.cpp b/src/polysolve/nonlinear/PostStepData.cpp new file mode 100644 index 00000000..a411dce4 --- /dev/null +++ b/src/polysolve/nonlinear/PostStepData.cpp @@ -0,0 +1,11 @@ +#include "PostStepData.hpp" + +namespace polysolve::nonlinear +{ + PostStepData::PostStepData(const int iter_num, + const Eigen::VectorXd &x, + const Eigen::VectorXd &grad) + : iter_num(iter_num), x(x), grad(grad) + { + } +} // namespace polysolve::nonlinear diff --git a/src/polysolve/nonlinear/PostStepData.hpp b/src/polysolve/nonlinear/PostStepData.hpp new file mode 100644 index 00000000..dc5ccdba --- /dev/null +++ b/src/polysolve/nonlinear/PostStepData.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace polysolve::nonlinear +{ + + class PostStepData + { + public: + PostStepData(const int iter_num, + const Eigen::VectorXd &x, + const Eigen::VectorXd &grad); + + const int iter_num; + const Eigen::VectorXd &x; + const Eigen::VectorXd &grad; + }; +} // namespace polysolve::nonlinear diff --git a/src/polysolve/nonlinear/Problem.hpp b/src/polysolve/nonlinear/Problem.hpp index 6cb15a3e..33e535c1 100644 --- a/src/polysolve/nonlinear/Problem.hpp +++ b/src/polysolve/nonlinear/Problem.hpp @@ -2,6 +2,8 @@ #include +#include "PostStepData.hpp" + #include #include @@ -33,7 +35,7 @@ namespace polysolve::nonlinear virtual void line_search_begin(const TVector &x0, const TVector &x1) {} virtual void line_search_end() {} - virtual void post_step(const int iter_num, const TVector &x) {} + virtual void post_step(const PostStepData &data) {} virtual void set_project_to_psd(bool val) {} diff --git a/src/polysolve/nonlinear/Solver.cpp b/src/polysolve/nonlinear/Solver.cpp index 5e995f99..38d34f87 100644 --- a/src/polysolve/nonlinear/Solver.cpp +++ b/src/polysolve/nonlinear/Solver.cpp @@ -1,6 +1,8 @@ #include "Solver.hpp" +#include "PostStepData.hpp" + #include "descent_strategies/BFGS.hpp" #include "descent_strategies/Newton.hpp" #include "descent_strategies/GradientDescent.hpp" @@ -191,7 +193,7 @@ namespace polysolve::nonlinear objFunc.solution_changed(x); } - objFunc.post_step(this->m_current.iterations, x); + objFunc.post_step(PostStepData(this->m_current.iterations, x, grad)); const auto g_norm_tol = this->m_stop.gradNorm; this->m_stop.gradNorm = first_grad_norm_tol; @@ -371,7 +373,7 @@ namespace polysolve::nonlinear m_logger.debug("[{}][{}] Objective decided to stop", name(), m_line_search->name()); } - objFunc.post_step(this->m_current.iterations, x); + objFunc.post_step(PostStepData(this->m_current.iterations, x, grad)); if (f_delta < this->m_stop.fDelta) f_delta_step_cnt++;