@@ -66,19 +66,14 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
6666 // parabolic and auxilary equations should also be here
6767 if (hasNonExplicitEquation)
6868 {
69- bool nonlinear_it_converged = false ;
70- unsigned int nonlinear_it_index = 0 ;
69+ bool nonlinear_iteration_converged = false ;
70+ unsigned int nonlinear_iteration_index = 0 ;
7171
72- while (!nonlinear_it_converged )
72+ while (!nonlinear_iteration_converged )
7373 {
74- nonlinear_it_converged = true ; // Set to true here and will be set to false if
75- // any variable isn't converged
74+ nonlinear_iteration_converged = true ;
7675
7776 // Update residualSet for the non-explicitly updated variables
78- // compute_nonexplicit_RHS()
79- // Ideally, I'd just do this for the non-explicit variables, but for
80- // now I'll do all of them this is a little redundant, but hopefully
81- // not too terrible
8277 computeNonexplicitRHS ();
8378
8479 for (const auto &[fieldIndex, variable] : var_attributes)
@@ -102,15 +97,15 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
10297 pcout << buffer;
10398 }
10499
105- nonlinear_it_converged =
106- updateImplicitSolution (fieldIndex, nonlinear_it_index );
100+ nonlinear_iteration_converged =
101+ updateImplicitSolution (fieldIndex, nonlinear_iteration_index );
107102
108103 // Apply Boundary conditions
109104 applyBCs (fieldIndex);
110105 }
111106 else if (fields[fieldIndex].pdetype == AUXILIARY)
112107 {
113- if (variable.is_nonlinear || nonlinear_it_index == 0 )
108+ if (variable.is_nonlinear || nonlinear_iteration_index == 0 )
114109 {
115110 // If the equation for this field is nonlinear, save the old
116111 // solution
@@ -164,19 +159,26 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
164159 }
165160 if (currentIncrement % userInputs.skip_print_steps == 0 )
166161 {
167- pcout << " Relative difference between nonlinear "
168- " iterations: "
169- << diff << " " << nonlinear_it_index << " "
170- << currentIncrement << " \n " ;
162+ snprintf (buffer,
163+ sizeof (buffer),
164+ " field '%2s' [nonlinear solve] current "
165+ " increment: %u, nonlinear "
166+ " iteration: "
167+ " %u, dU: %12.6e\n " ,
168+ fields[fieldIndex].name .c_str (),
169+ currentIncrement,
170+ nonlinear_iteration_index,
171+ diff);
172+ pcout << buffer;
171173 }
172174
173175 if (diff > userInputs.nonlinear_solver_parameters
174176 .getToleranceValue (fieldIndex) &&
175- nonlinear_it_index <
177+ nonlinear_iteration_index <
176178 userInputs.nonlinear_solver_parameters
177179 .getMaxIterations ())
178180 {
179- nonlinear_it_converged = false ;
181+ nonlinear_iteration_converged = false ;
180182 }
181183 }
182184 else
@@ -201,7 +203,7 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
201203 }
202204 }
203205
204- nonlinear_it_index ++;
206+ nonlinear_iteration_index ++;
205207 }
206208 }
207209
@@ -286,12 +288,12 @@ MatrixFreePDE<dim, degree>::updateExplicitSolution(unsigned int fieldIndex)
286288template <int dim, int degree>
287289bool
288290MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
289- unsigned int nonlinear_it_index )
291+ unsigned int nonlinear_iteration_index )
290292{
291293 char buffer[200 ];
292294
293295 // Assume convergence criterion is met, unless otherwise proven later on.
294- bool nonlinear_it_converged = true ;
296+ bool nonlinear_iteration_converged = true ;
295297
296298 // Apply Dirichlet BC's. This clears the residual where we want to apply Dirichlet BCs,
297299 // otherwise the solver sees a positive residual
@@ -469,18 +471,32 @@ MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
469471 }
470472 if (currentIncrement % userInputs.skip_print_steps == 0 )
471473 {
472- pcout << " Relative difference between nonlinear "
473- " iterations: "
474- << diff << " " << nonlinear_it_index << " " << currentIncrement
475- << " \n " ;
474+ snprintf (buffer,
475+ sizeof (buffer),
476+ " field '%2s' [nonlinear solve] current increment: %u, nonlinear "
477+ " iteration: "
478+ " %u, dU: %12.6e\n " ,
479+ fields[fieldIndex].name .c_str (),
480+ currentIncrement,
481+ nonlinear_iteration_index,
482+ diff);
483+ pcout << buffer;
476484 }
477485
478486 if (diff >
479487 userInputs.nonlinear_solver_parameters .getToleranceValue (fieldIndex) &&
480- nonlinear_it_index <
488+ nonlinear_iteration_index <
481489 userInputs.nonlinear_solver_parameters .getMaxIterations ())
482490 {
483- nonlinear_it_converged = false ;
491+ nonlinear_iteration_converged = false ;
492+ }
493+ else if (diff >
494+ userInputs.nonlinear_solver_parameters .getToleranceValue (fieldIndex))
495+ {
496+ pcout << " \n Warning: nonlinear solver did not converge as "
497+ " per set tolerances. consider increasing the "
498+ " maximum number of iterations or decreasing the "
499+ " solver tolerance.\n " ;
484500 }
485501 }
486502 else
@@ -492,7 +508,7 @@ MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
492508 }
493509 else
494510 {
495- if (nonlinear_it_index == 0 )
511+ if (nonlinear_iteration_index == 0 )
496512 {
497513 if (fields[fieldIndex].type == SCALAR)
498514 {
@@ -532,5 +548,5 @@ MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
532548 }
533549 }
534550
535- return nonlinear_it_converged ;
551+ return nonlinear_iteration_converged ;
536552}
0 commit comments