Skip to content

Commit 25ebacb

Browse files
authored
Merge pull request #59 from polyfem/solver-info
add solver_info to PostStepData
2 parents fbfb31d + d65ca3a commit 25ebacb

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/polysolve/nonlinear/PostStepData.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace polysolve::nonlinear
44
{
55
PostStepData::PostStepData(const int iter_num,
6+
const json &solver_info,
67
const Eigen::VectorXd &x,
78
const Eigen::VectorXd &grad)
8-
: iter_num(iter_num), x(x), grad(grad)
9+
: iter_num(iter_num), solver_info(solver_info), x(x), grad(grad)
910
{
1011
}
1112
} // namespace polysolve::nonlinear

src/polysolve/nonlinear/PostStepData.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ namespace polysolve::nonlinear
99
{
1010
public:
1111
PostStepData(const int iter_num,
12+
const json &solver_info,
1213
const Eigen::VectorXd &x,
1314
const Eigen::VectorXd &grad);
1415

1516
const int iter_num;
17+
const json &solver_info;
1618
const Eigen::VectorXd &x;
1719
const Eigen::VectorXd &grad;
1820
};

src/polysolve/nonlinear/Solver.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ namespace polysolve::nonlinear
213213
objFunc.solution_changed(x);
214214
}
215215

216-
objFunc.post_step(PostStepData(this->m_current.iterations, x, grad));
217-
218216
const auto g_norm_tol = this->m_stop.gradNorm;
219217
this->m_stop.gradNorm = first_grad_norm_tol;
220218

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

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

233232
int f_delta_step_cnt = 0;
234233
double f_delta = 0;
@@ -386,15 +385,16 @@ namespace polysolve::nonlinear
386385
// -----------
387386
const double step = (rate * delta_x).norm();
388387

388+
update_solver_info(energy);
389+
objFunc.post_step(PostStepData(this->m_current.iterations, solver_info, x, grad));
390+
389391
if (objFunc.stop(x))
390392
{
391393
this->m_status = cppoptlib::Status::UserDefined;
392394
m_error_code = ErrorCode::SUCCESS;
393395
m_logger.debug("[{}][{}] Objective decided to stop", name(), m_line_search->name());
394396
}
395397

396-
objFunc.post_step(PostStepData(this->m_current.iterations, x, grad));
397-
398398
if (f_delta < this->m_stop.fDelta)
399399
f_delta_step_cnt++;
400400
else
@@ -411,8 +411,6 @@ namespace polysolve::nonlinear
411411
if (++this->m_current.iterations >= this->m_stop.iterations)
412412
this->m_status = cppoptlib::Status::IterationLimit;
413413

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

0 commit comments

Comments
 (0)