solver control question

12 views
Skip to first unread message

Victor Eijkhout

unread,
Jul 14, 2026, 11:46:13 AM (22 hours ago) Jul 14
to deal.II User Group
I'm trying to write my own solver control, so I took the IterationNumberControl as template and:

class IterationPrintControl : public SolverControl
{
public:
  explicit IterationPrintControl(const unsigned int maxiter     = 100,
                                  const double       tolerance   = 1e-12,
                                  const bool         log_history = false,
                                  const bool         log_result  = false);

et cetera with implementation:

olverControl::State
IterationPrintControl::check(const unsigned int step, const double check_value)
{
  // check whether the given number of iterations was reached, and return
  // success in that case. Otherwise, go on to the check of the base class.
  std::println( "At iteration={}/{}, error={}",step,this->maxsteps,check_value );
  if (step >= this->maxsteps)
    {
      std::println( "stop iteration at {}",step );
      if (m_log_result)
        deallog << "Convergence step " << step << " value " << check_value
                << std::endl;
      lstep  = step;
      lvalue = check_value;

      lcheck = success;
      return success;
    }
  else {
    std::println( "base check in step {}",step );
    return SolverControl::check(step, check_value);
  }
}


Now strangely enough the very first println is not printed until maxits is reached. It's like this check is not executed before the base case, but after.

Can you shed any ligth on this?

V.

Wolfgang Bangerth

unread,
Jul 14, 2026, 1:34:39 PM (20 hours ago) Jul 14
to dea...@googlegroups.com
On 7/14/26 09:46, Victor Eijkhout wrote:
>
> olverControl::State
> IterationPrintControl::check(const unsigned int step, const double check_value)
> {
>   // check whether the given number of iterations was reached, and return
>   // success in that case. Otherwise, go on to the check of the base class.
>   std::println( "At iteration={}/{}, error={}",step,this->maxsteps,check_value );
>   if (step >= this->maxsteps)
>     {
>       std::println( "stop iteration at {}",step );
>       if (m_log_result)
>         deallog << "Convergence step " << step << " value " << check_value
>                 << std::endl;
>       lstep  = step;
>       lvalue = check_value;
>
>       lcheck = success;
>       return success;
>     }
>   else {
>     std::println( "base check in step {}",step );
>     return SolverControl::check(step, check_value);
>   }
> }
>
>
> Now strangely enough the very first println is not printed until maxits is
> reached. It's like this check is not executed before the base case, but after.

Victor,
you are asking us to speculate what happens in your program without either
giving us a complete program or at least showing us the output. None of us
here can know what is going on. We can all guess what the output *should* be,
but that's not helpful to either you or us. It's probably fair to point out
that that is a fairly common case with your questions.

You will either have to use a debugger, or better describe what it is you see
if you want us to help.

Best
W.
Reply all
Reply to author
Forward
0 new messages