Skip to content

Commit eed521e

Browse files
author
teseoch
authored
Merge pull request #61 from polyfem/better-logging
better logging
2 parents 374f787 + f347cf9 commit eed521e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/polysolve/nonlinear/Solver.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ namespace polysolve::nonlinear
282282
stop_watch.start();
283283

284284
m_logger.debug(
285-
"Starting {} with {} solve f₀={:g} ‖∇f₀‖={:g} "
285+
"Starting {} with {} solve f₀={:g} "
286286
"(stopping criteria: max_iters={:d} Δf={:g} ‖∇f‖={:g} ‖Δx‖={:g})",
287287
descent_strategy_name(), m_line_search->name(),
288-
objFunc.value(x), this->m_current.gradNorm, this->m_stop.iterations,
288+
objFunc.value(x), this->m_stop.iterations,
289289
this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);
290290

291291
update_solver_info(objFunc.value(x));
@@ -294,6 +294,9 @@ namespace polysolve::nonlinear
294294
int f_delta_step_cnt = 0;
295295
double f_delta = 0;
296296

297+
// Used for logging
298+
double xDelta = 0, gradNorm = 0;
299+
297300
do
298301
{
299302
m_line_search->set_is_final_strategy(m_descent_strategy == m_strategies.size() - 1);
@@ -340,7 +343,10 @@ namespace polysolve::nonlinear
340343
log_and_throw_error(m_logger, "[{}][{}] Gradient is nan; stopping", descent_strategy_name(), m_line_search->name());
341344
break;
342345
}
346+
343347
this->m_current.gradNorm = grad_norm;
348+
gradNorm = this->m_current.gradNorm;
349+
344350
this->m_status = checkConvergence(this->m_stop, this->m_current);
345351
if (this->m_status != cppoptlib::Status::Continue)
346352
break;
@@ -396,6 +402,7 @@ namespace polysolve::nonlinear
396402

397403
// Use the maximum absolute displacement value divided by the timestep,
398404
this->m_current.xDelta = delta_x_norm;
405+
xDelta = this->m_current.xDelta;
399406
this->m_status = checkConvergence(this->m_stop, this->m_current);
400407
if (this->m_status != cppoptlib::Status::Continue)
401408
break;
@@ -404,6 +411,11 @@ namespace polysolve::nonlinear
404411
// Variable update
405412
// ---------------
406413

414+
m_logger.trace(
415+
"[{}][{}] pre LS iter={:d} f={:g} ‖∇f‖={:g}",
416+
descent_strategy_name(), m_line_search->name(),
417+
this->m_current.iterations, energy, gradNorm);
418+
407419
// Perform a line_search to compute step scale
408420
double rate = m_line_search->line_search(x, delta_x, objFunc);
409421
if (std::isnan(rate))
@@ -473,7 +485,7 @@ namespace polysolve::nonlinear
473485
" (stopping criteria: max_iters={:d} Δf={:g} ‖∇f‖={:g} ‖Δx‖={:g})",
474486
descent_strategy_name(), m_line_search->name(),
475487
this->m_current.iterations, energy, f_delta,
476-
this->m_current.gradNorm, this->m_current.xDelta, delta_x.dot(grad), rate, step,
488+
gradNorm, xDelta, delta_x.dot(grad), rate, step,
477489
this->m_stop.iterations, this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);
478490

479491
if (++this->m_current.iterations >= this->m_stop.iterations)
@@ -502,7 +514,7 @@ namespace polysolve::nonlinear
502514
" (stopping criteria: max_iters={:d} Δf={:g} ‖∇f‖={:g} ‖Δx‖={:g})",
503515
descent_strategy_name(), m_line_search->name(),
504516
this->m_status, tot_time, this->m_current.iterations,
505-
old_energy, f_delta, this->m_current.gradNorm, this->m_current.xDelta,
517+
old_energy, f_delta, gradNorm, xDelta,
506518
this->m_stop.iterations, this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);
507519

508520
log_times();

0 commit comments

Comments
 (0)