Skip to content

Commit

Permalink
updating nonlinear printing info
Browse files Browse the repository at this point in the history
  • Loading branch information
landinjm committed Jan 4, 2025
1 parent 64e7102 commit 13032eb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 57 deletions.
27 changes: 14 additions & 13 deletions applications/allenCahn_conserved/customPDE.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
// parabolic and auxilary equations should also be here
if (this->hasNonExplicitEquation)
{
bool nonlinear_it_converged = false;
unsigned int nonlinear_it_index = 0;
bool nonlinear_iteration_converged = false;
unsigned int nonlinear_iteration_index = 0;

while (!nonlinear_it_converged)
while (!nonlinear_iteration_converged)
{
nonlinear_it_converged = true; // Set to true here and will be set to false if
// any variable isn't converged
nonlinear_iteration_converged = true; // Set to true here and will be set to
// false if any variable isn't converged

// Update residualSet for the non-explicitly updated variables
// compute_nonexplicit_RHS()
Expand Down Expand Up @@ -214,16 +214,16 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
this->pcout << buffer;
}

nonlinear_it_converged =
this->updateImplicitSolution(fieldIndex, nonlinear_it_index);
nonlinear_iteration_converged =
this->updateImplicitSolution(fieldIndex, nonlinear_iteration_index);

// Apply Boundary conditions
this->applyBCs(fieldIndex);
}
else if (this->fields[fieldIndex].pdetype == AUXILIARY)
{
if (this->var_attributes.at(fieldIndex).is_nonlinear ||
nonlinear_it_index == 0)
nonlinear_iteration_index == 0)
{
// If the equation for this field is nonlinear, save the
// old solution
Expand Down Expand Up @@ -281,18 +281,19 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
{
this->pcout << "Relative difference between nonlinear "
"iterations: "
<< diff << " " << nonlinear_it_index << " "
<< this->currentIncrement << std::endl;
<< diff << " " << nonlinear_iteration_index
<< " " << this->currentIncrement
<< std::endl;
}

if (diff > MatrixFreePDE<dim, degree>::userInputs
.nonlinear_solver_parameters.getToleranceValue(
fieldIndex) &&
nonlinear_it_index <
nonlinear_iteration_index <
MatrixFreePDE<dim, degree>::userInputs
.nonlinear_solver_parameters.getMaxIterations())
{
nonlinear_it_converged = false;
nonlinear_iteration_converged = false;
}
}
else
Expand All @@ -318,7 +319,7 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
}
}

nonlinear_it_index++;
nonlinear_iteration_index++;
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/core/matrixFreePDE.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class MatrixFreePDE : public Subscriptor

/*Method to compute an implicit timestep*/
bool
updateImplicitSolution(unsigned int fieldIndex, unsigned int nonlinear_it_index);
updateImplicitSolution(unsigned int fieldIndex, unsigned int nonlinear_iteration_index);

/*Method to apply boundary conditions*/
void
Expand Down
14 changes: 0 additions & 14 deletions src/core/invM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ MatrixFreePDE<dim, degree>::computeInvM()
}
}

// Check if invM has been found. If not, print an "error" message
if (!invMscalarFound)
{
pcout << "matrixFreePDE.h: no PARABOLIC scalar field... hence setting "
"parabolicScalarFieldIndex to 0 and marching ahead withn invM "
"computation\n";
}
else if (!invMvectorFound)
{
pcout << "matrixFreePDE.h: no PARABOLIC vector field... hence setting "
"parabolicVectorFieldIndex to 0 and marching ahead withn invM "
"computation\n";
}

// Initialize invM and clear its values
matrixFreeObject.initialize_dof_vector(invMscalar, parabolicScalarFieldIndex);
invMscalar = 0.0;
Expand Down
74 changes: 45 additions & 29 deletions src/core/solvers/solveIncrement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,14 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
// parabolic and auxilary equations should also be here
if (hasNonExplicitEquation)
{
bool nonlinear_it_converged = false;
unsigned int nonlinear_it_index = 0;
bool nonlinear_iteration_converged = false;
unsigned int nonlinear_iteration_index = 0;

while (!nonlinear_it_converged)
while (!nonlinear_iteration_converged)
{
nonlinear_it_converged = true; // Set to true here and will be set to false if
// any variable isn't converged
nonlinear_iteration_converged = true;

// Update residualSet for the non-explicitly updated variables
// compute_nonexplicit_RHS()
// Ideally, I'd just do this for the non-explicit variables, but for
// now I'll do all of them this is a little redundant, but hopefully
// not too terrible
computeNonexplicitRHS();

for (const auto &[fieldIndex, variable] : var_attributes)
Expand All @@ -102,15 +97,15 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
pcout << buffer;
}

nonlinear_it_converged =
updateImplicitSolution(fieldIndex, nonlinear_it_index);
nonlinear_iteration_converged =
updateImplicitSolution(fieldIndex, nonlinear_iteration_index);

// Apply Boundary conditions
applyBCs(fieldIndex);
}
else if (fields[fieldIndex].pdetype == AUXILIARY)
{
if (variable.is_nonlinear || nonlinear_it_index == 0)
if (variable.is_nonlinear || nonlinear_iteration_index == 0)
{
// If the equation for this field is nonlinear, save the old
// solution
Expand Down Expand Up @@ -164,19 +159,26 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
}
if (currentIncrement % userInputs.skip_print_steps == 0)
{
pcout << "Relative difference between nonlinear "
"iterations: "
<< diff << " " << nonlinear_it_index << " "
<< currentIncrement << "\n";
snprintf(buffer,
sizeof(buffer),
" field '%2s' [nonlinear solve] current "
"increment: %u, nonlinear "
"iteration: "
"%u, dU: %12.6e\n",
fields[fieldIndex].name.c_str(),
currentIncrement,
nonlinear_iteration_index,
diff);
pcout << buffer;
}

if (diff > userInputs.nonlinear_solver_parameters
.getToleranceValue(fieldIndex) &&
nonlinear_it_index <
nonlinear_iteration_index <
userInputs.nonlinear_solver_parameters
.getMaxIterations())
{
nonlinear_it_converged = false;
nonlinear_iteration_converged = false;
}
}
else
Expand All @@ -201,7 +203,7 @@ MatrixFreePDE<dim, degree>::solveIncrement(bool skip_time_dependent)
}
}

nonlinear_it_index++;
nonlinear_iteration_index++;
}
}

Expand Down Expand Up @@ -286,12 +288,12 @@ MatrixFreePDE<dim, degree>::updateExplicitSolution(unsigned int fieldIndex)
template <int dim, int degree>
bool
MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
unsigned int nonlinear_it_index)
unsigned int nonlinear_iteration_index)
{
char buffer[200];

// Assume convergence criterion is met, unless otherwise proven later on.
bool nonlinear_it_converged = true;
bool nonlinear_iteration_converged = true;

// Apply Dirichlet BC's. This clears the residual where we want to apply Dirichlet BCs,
// otherwise the solver sees a positive residual
Expand Down Expand Up @@ -469,18 +471,32 @@ MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
}
if (currentIncrement % userInputs.skip_print_steps == 0)
{
pcout << "Relative difference between nonlinear "
"iterations: "
<< diff << " " << nonlinear_it_index << " " << currentIncrement
<< "\n";
snprintf(buffer,
sizeof(buffer),
" field '%2s' [nonlinear solve] current increment: %u, nonlinear "
"iteration: "
"%u, dU: %12.6e\n",
fields[fieldIndex].name.c_str(),
currentIncrement,
nonlinear_iteration_index,
diff);
pcout << buffer;
}

if (diff >
userInputs.nonlinear_solver_parameters.getToleranceValue(fieldIndex) &&
nonlinear_it_index <
nonlinear_iteration_index <
userInputs.nonlinear_solver_parameters.getMaxIterations())
{
nonlinear_it_converged = false;
nonlinear_iteration_converged = false;
}
else if (diff >
userInputs.nonlinear_solver_parameters.getToleranceValue(fieldIndex))
{
pcout << "\nWarning: nonlinear solver did not converge as "
"per set tolerances. consider increasing the "
"maximum number of iterations or decreasing the "
"solver tolerance.\n";
}
}
else
Expand All @@ -492,7 +508,7 @@ MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
}
else
{
if (nonlinear_it_index == 0)
if (nonlinear_iteration_index == 0)
{
if (fields[fieldIndex].type == SCALAR)
{
Expand Down Expand Up @@ -532,5 +548,5 @@ MatrixFreePDE<dim, degree>::updateImplicitSolution(unsigned int fieldIndex,
}
}

return nonlinear_it_converged;
return nonlinear_iteration_converged;
}

0 comments on commit 13032eb

Please sign in to comment.