Skip to content

Commit

Permalink
add solver_info to PostStepData
Browse files Browse the repository at this point in the history
  • Loading branch information
Huangzizhou committed Dec 8, 2023
1 parent fbfb31d commit d65ca3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/polysolve/nonlinear/PostStepData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace polysolve::nonlinear
{
PostStepData::PostStepData(const int iter_num,
const json &solver_info,
const Eigen::VectorXd &x,
const Eigen::VectorXd &grad)
: iter_num(iter_num), x(x), grad(grad)
: iter_num(iter_num), solver_info(solver_info), x(x), grad(grad)
{
}
} // namespace polysolve::nonlinear
2 changes: 2 additions & 0 deletions src/polysolve/nonlinear/PostStepData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace polysolve::nonlinear
{
public:
PostStepData(const int iter_num,
const json &solver_info,
const Eigen::VectorXd &x,
const Eigen::VectorXd &grad);

const int iter_num;
const json &solver_info;
const Eigen::VectorXd &x;
const Eigen::VectorXd &grad;
};
Expand Down
10 changes: 4 additions & 6 deletions src/polysolve/nonlinear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ namespace polysolve::nonlinear
objFunc.solution_changed(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;

Expand All @@ -229,6 +227,7 @@ namespace polysolve::nonlinear
this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);

update_solver_info(objFunc.value(x));
objFunc.post_step(PostStepData(this->m_current.iterations, solver_info, x, grad));

int f_delta_step_cnt = 0;
double f_delta = 0;
Expand Down Expand Up @@ -386,15 +385,16 @@ namespace polysolve::nonlinear
// -----------
const double step = (rate * delta_x).norm();

update_solver_info(energy);
objFunc.post_step(PostStepData(this->m_current.iterations, solver_info, x, grad));

if (objFunc.stop(x))
{
this->m_status = cppoptlib::Status::UserDefined;
m_error_code = ErrorCode::SUCCESS;
m_logger.debug("[{}][{}] Objective decided to stop", name(), m_line_search->name());
}

objFunc.post_step(PostStepData(this->m_current.iterations, x, grad));

if (f_delta < this->m_stop.fDelta)
f_delta_step_cnt++;
else
Expand All @@ -411,8 +411,6 @@ namespace polysolve::nonlinear
if (++this->m_current.iterations >= this->m_stop.iterations)
this->m_status = cppoptlib::Status::IterationLimit;

update_solver_info(energy);

// reset the tolerance, since in the first iter it might be smaller
this->m_stop.gradNorm = g_norm_tol;
} while (objFunc.callback(this->m_current, x) && (this->m_status == cppoptlib::Status::Continue));
Expand Down

0 comments on commit d65ca3a

Please sign in to comment.