Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Rovinelli committed Dec 17, 2020
1 parent 43d08e5 commit b7404bd
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 4 deletions.
15 changes: 15 additions & 0 deletions framework/include/problems/FEProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,15 @@ class FEProblemBase : public SubProblem, public Restartable
_n_max_nl_pingpong = n_max_nl_pingpong;
}

/// method setting the minimum number of nonlinear iterations before performing divergence checks
void setNLForcedIterations(const unsigned int nl_forced_its) { _nl_forced_its = nl_forced_its; }

/// method setting the absolute divergence tolerance
void setNLAbsoluteDivergenceTolerance(const Real abs_nl_divtol)
{
_abs_nl_divtol = abs_nl_divtol;
}

protected:
/// Create extra tagged vectors and matrices
void createTagVectors();
Expand All @@ -1941,6 +1950,12 @@ class FEProblemBase : public SubProblem, public Restartable
unsigned int _n_nl_pingpong = 0;
unsigned int _n_max_nl_pingpong = std::numeric_limits<unsigned int>::max();

/// the number of forced nonlinear iterations
int _nl_forced_its = 0;

/// the absolute non linear divergnce tolerance
Real _abs_nl_divtol = -1;

std::shared_ptr<NonlinearSystemBase> _nl;
std::shared_ptr<AuxiliarySystem> _aux;

Expand Down
15 changes: 14 additions & 1 deletion framework/src/executioners/FEProblemSolve.C
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@ FEProblemSolve::validParams()
params.addParam<Real>("l_abs_tol", 1.0e-50, "Linear Absolute Tolerance");
params.addParam<unsigned int>("l_max_its", 10000, "Max Linear Iterations");
params.addParam<unsigned int>("nl_max_its", 50, "Max Nonlinear Iterations");
params.addParam<unsigned int>(
"nl_forced_its", 0, "The number of nonlinear iteration before performing divergence checks");
params.addParam<unsigned int>("nl_max_funcs", 10000, "Max Nonlinear solver function evaluations");
params.addParam<Real>("nl_abs_tol", 1.0e-50, "Nonlinear Absolute Tolerance");
params.addParam<Real>("nl_rel_tol", 1.0e-8, "Nonlinear Relative Tolerance");
params.addParam<Real>("nl_div_tol", 1.0e10, "Nonlinear Divergence Tolerance");
params.addParam<Real>(
"nl_div_tol",
1.0e10,
"Nonlinear Relative Divergence Tolerance. A negative value disables this check.");
params.addParam<Real>(
"nl_abs_div_tol",
1.0e50,
"Nonlinear Absolute Divergence Tolerance. A negative value disables this check.");
params.addParam<Real>("nl_abs_step_tol", 0., "Nonlinear Absolute step Tolerance");
params.addParam<Real>("nl_rel_step_tol", 0., "Nonlinear Relative step Tolerance");
params.addParam<unsigned int>(
Expand Down Expand Up @@ -176,6 +185,10 @@ FEProblemSolve::FEProblemSolve(Executioner * ex)

_problem.setMaxNLPingPong(getParam<unsigned int>("n_max_nonlinear_pingpong"));

_problem.setNLForcedIterations(getParam<unsigned int>("nl_forced_its"));

_problem.setNLAbsoluteDivergenceTolerance(getParam<Real>("nl_abs_div_tol"));

_nl.setDecomposition(_splitting);
}

Expand Down
10 changes: 8 additions & 2 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -6700,13 +6700,19 @@ FEProblemBase::checkNonlinearConvergence(std::string & msg,
<< '\n';
reason = MooseNonlinearConvergenceReason::CONVERGED_SNORM_RELATIVE;
}
else if (divtol > 0 && fnorm > the_residual * divtol)
else if (divtol > 0 && it >= _nl_forced_its && fnorm > the_residual * divtol)
{
oss << "Diverged due to initial residual " << the_residual << " > divergence tolerance "
<< divtol << " * initial residual " << the_residual << '\n';
reason = MooseNonlinearConvergenceReason::DIVERGED_DTOL;
}
else if (_n_nl_pingpong > _n_max_nl_pingpong)
else if (_abs_nl_divtol > 0 && it >= _nl_forced_its && fnorm > _abs_nl_divtol)
{
oss << "Diverged due to residual " << fnorm << " > absolute divergence tolerance "
<< _abs_nl_divtol << '\n';
reason = MooseNonlinearConvergenceReason::DIVERGED_DTOL;
}
else if (it >= _nl_forced_its && _n_nl_pingpong > _n_max_nl_pingpong)
{
oss << "Diverged due to maximum non linear residual pingpong achieved" << '\n';
reason = MooseNonlinearConvergenceReason::DIVERGED_NL_RESIDUAL_PINGPONG;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 15
ny = 15
[]

[Variables]
[./u]
scaling = 1e-5
[../]
[]

[Kernels]
[./diff]
type = CoefDiffusion
variable = u
coef = 0.1
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
preset = false
boundary = left
value = -1000
[../]
[./right]
type = DirichletBC
variable = u
preset = false
boundary = right
value = 100000
[../]
[]

[Executioner]
type = Transient
scheme = 'implicit-euler'
line_search = 'none'
solve_type = PJFNK

l_max_its = 20
nl_max_its = 20
nl_abs_div_tol = 1e+7
nl_div_tol = 1e+50
dt = 1
num_steps = 2

petsc_options = '-snes_converged_reason -ksp_converged_reason '
petsc_options_iname = '-pc_type -pc_hypre_type '
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]
10 changes: 9 additions & 1 deletion test/tests/executioners/nl_divergence_tolerance/tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Tests]
[Tests]
design = 'syntax/Executioner/index.md'
[./test]
type = 'Exodiff'
Expand All @@ -11,4 +11,12 @@
requirement = "The Executioner system shall support the PETSc non-linear divergence tolerance."
issues = '#13991'
[../]
[./test_abs_divtol]
type = RunApp
input = 'nl_abs_divergence_tolerance.i'
expect_out = "Nonlinear solve did not converge due to DIVERGED_DTOL iterations 1"
requirement = 'The system shall consider a nonlinear solve diverged if the nonlinear residaul exceeds the absolute divergence tolerance while iterating'
issues = '#16474'
design = 'FEProblemSolve.md'
[../]
[]
64 changes: 64 additions & 0 deletions test/tests/executioners/nl_forced_its/nl_forced_its.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 15
ny = 15
[]

[Variables]
[./u]
scaling = 1e-5
[../]
[]

[Kernels]
[./diff]
type = CoefDiffusion
variable = u
coef = 0.1
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
preset = false
boundary = left
value = -1000
[../]
[./right]
type = DirichletBC
variable = u
preset = false
boundary = right
value = 100000
[../]
[]

[Executioner]
type = Transient
scheme = 'implicit-euler'
line_search = 'none'
solve_type = PJFNK

l_max_its = 20
nl_max_its = 20
nl_forced_its = 4
nl_abs_div_tol = 1e+5

dt = 1
num_steps = 2

petsc_options = '-snes_converged_reason -ksp_converged_reason '
petsc_options_iname = '-pc_type -pc_hypre_type '
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]
11 changes: 11 additions & 0 deletions test/tests/executioners/nl_forced_its/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Tests]
design = 'syntax/Executioner/index.md'
[./test_nl_forced_iterations]
type = RunApp
input = 'nl_forced_its.i'
expect_out = "Nonlinear solve did not converge due to DIVERGED_DTOL iterations 4"
requirement = 'The system shall perform n non linear iterations before checking for non linear divergence'
issues = '#16474'
design = 'FEProblemSolve.md'
[../]
[]

0 comments on commit b7404bd

Please sign in to comment.