https://mooseframework.inl.gov
DefaultMultiAppFixedPointConvergence.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "FEProblemBase.h"
12 #include "FixedPointSolve.h"
13 #include "Console.h"
14 #include "SteffensenSolve.h"
16 
18 
21 {
24  params.addClassDescription("Default fixed point convergence criteria.");
25  return params;
26 }
27 
29  const InputParameters & parameters)
30  : DefaultConvergenceBase(parameters),
31  _min_fixed_point_its(getSharedExecutionerParam<unsigned int>("fixed_point_min_its")),
32  _max_fixed_point_its(getSharedExecutionerParam<unsigned int>("fixed_point_max_its")),
33  _has_fixed_point_norm(
34  !getSharedExecutionerParam<bool>("disable_fixed_point_residual_norm_check")),
35  _fixed_point_force_norms(getSharedExecutionerParam<bool>("fixed_point_force_norms")),
36  _accept_max_it(getSharedExecutionerParam<bool>("accept_on_max_fixed_point_iteration")),
37  _fixed_point_rel_tol(getSharedExecutionerParam<Real>("fixed_point_rel_tol")),
38  _fixed_point_abs_tol(getSharedExecutionerParam<Real>("fixed_point_abs_tol")),
39  _custom_pp_rel_tol(getSharedExecutionerParam<Real>("custom_rel_tol")),
40  _custom_pp_abs_tol(getSharedExecutionerParam<Real>("custom_abs_tol")),
41  _fixed_point_custom_pp(isParamValid("custom_pp") ? &getPostprocessorValue("custom_pp")
42  : nullptr),
43  _fixed_point_custom_pp_old(isParamValid("custom_pp") ? &getPostprocessorValueOld("custom_pp")
44  : nullptr),
45  _pp_previous(0.0),
46  _pp_current(std::numeric_limits<Real>::max()),
47  _pp_scaling(1.0),
48  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
49  _fp_solve(getMooseApp().getExecutioner()->fixedPointSolve())
50 {
52  paramError("fixed_point_min_its",
53  "The minimum number of fixed point iterations may not exceed the maximum.");
54  if (!_has_fixed_point_norm && parameters.isParamSetByUser("fixed_point_rel_tol"))
56  "disable_fixed_point_residual_norm_check",
57  "fixed_point_rel_tol will be ignored because the fixed point residual check is disabled.");
58  if (!_has_fixed_point_norm && parameters.isParamSetByUser("fixed_point_abs_tol"))
60  "disable_fixed_point_residual_norm_check",
61  "fixed_point_abs_tol will be ignored because the fixed point residual check is disabled.");
62  if (!_has_fixed_point_norm && parameters.isParamSetByUser("fixed_point_force_norms"))
63  paramWarning("disable_fixed_point_residual_norm_check",
64  "fixed_point_force_norms will be ignored because the fixed point residual check "
65  "is disabled.");
66 
67  if (dynamic_cast<SteffensenSolve *>(&_fp_solve) && _fe_problem.hasMultiApps())
68  {
69  // Steffensen method uses half-steps
70  if (!parameters.isParamSetByAddParam("fixed_point_min_its"))
73  }
74 }
75 
76 void
78 {
80 
82  mooseError(
83  "DefaultMultiAppFixedPointConvergence can only be used with MultiApp fixed point solves.");
84 }
85 
86 void
88 {
90 
95 
96  _pp_history.str("");
97 
98  // compute residual norm before iteration loop
100  {
102  _console << COLOR_MAGENTA << "Initial fixed point residual norm: " << COLOR_DEFAULT;
104  _console << " MAX ";
105  else
106  _console << std::scientific << _fixed_point_initial_norm;
107  _console << COLOR_DEFAULT << "\n" << std::endl;
108  }
109 }
110 
111 void
113 {
115 
116  // compute TIMESTEP_BEGIN residual norm; this should be executed after TIMESTEP_BEGIN
117  // but before the solve
118  if (_has_fixed_point_norm &&
120  {
121  const auto iter = _fp_solve.numFixedPointIts() - 1;
123 
124  Real begin_norm_old =
126 
127  outputResidualNorm("TIMESTEP_BEGIN", begin_norm_old, _fixed_point_timestep_begin_norm[iter]);
128  }
129 }
130 
133 {
134  TIME_SECTION(_perfid_check_convergence);
135 
138 
139  // compute TIMESTEP_END residual norm; this should be executed between TIMESTEP_END
140  // and TIMESTEP_BEGIN
143  {
145 
146  Real end_norm_old =
148 
149  outputResidualNorm("TIMESTEP_END", end_norm_old, _fixed_point_timestep_end_norm[iter]);
150  }
151 
152  // print residual norm history
157 
158  if (iter + 2 > _min_fixed_point_its)
159  {
160  Real max_norm =
162 
163  Real max_relative_drop = max_norm / _fixed_point_initial_norm;
164 
166  {
170  }
171  if (_has_fixed_point_norm && max_relative_drop < _fixed_point_rel_tol)
172  {
176  }
177 
179  {
183  }
185  {
189  }
190  }
191 
192  if (iter + 1 == _max_fixed_point_its)
193  {
194  if (_accept_max_it)
195  {
199  }
200  else
201  {
205  }
206  }
207 
209 }
210 
211 void
213  Real old_norm,
214  Real new_norm) const
215 {
216  _console << COLOR_MAGENTA << "Fixed point residual norm after " << execute_on_str
217  << " MultiApps: " << Console::outputNorm(old_norm, new_norm) << std::endl;
218 }
219 
220 void
222 {
223  if (!getParam<bool>("direct_pp_value"))
225 
226  if ((iter == 0 && getParam<bool>("direct_pp_value")) || !getParam<bool>("direct_pp_value"))
229 
230  const auto pp_name = getParam<PostprocessorName>("custom_pp");
231  _pp_history << std::setw(2) << iter + 1 << " fixed point " << pp_name << " = "
233  _console << _pp_history.str() << std::flush;
234 }
const bool _fixed_point_force_norms
Whether or not we force evaluation of residual norms even without multiapps.
static InputParameters fixedPointDefaultConvergenceParams()
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
virtual void preExecute() override
Method that gets called in each iteration before the solve.
Real _pp_current
Value of the custom convergence check postprocessor from current iteration.
virtual void initialize()
Method that gets called before each iteration loop.
Definition: Convergence.h:53
const bool _has_fixed_point_norm
Whether or not to use residual norm to check the fixed point convergence.
Base class for default convergence criteria.
void setFixedPointStatus(MooseFixedPointConvergenceReason status)
Set fixed point status.
registerMooseObject("MooseApp", DefaultMultiAppFixedPointConvergence)
virtual void initialize() override
Method that gets called before each iteration loop.
Real _pp_scaling
Scaling of custom convergence check postprocessor (its initial value)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Real _pp_previous
Value of the custom convergence check postprocessor from previous iteration.
const Real _fixed_point_abs_tol
Absolute tolerance on residual norm.
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
const PostprocessorValue *const _fixed_point_custom_pp_old
Postprocessor value for user-defined fixed point convergence check from previous timestep.
unsigned int numFixedPointIts() const
Get the number of fixed point iterations performed Because this returns the number of fixed point ite...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
auto max(const L &left, const R &right)
FP converged according to Convergence object.
std::vector< Real > _fixed_point_timestep_end_norm
Full history of residual norm after evaluation of timestep_end.
const PostprocessorValue *const _fixed_point_custom_pp
Postprocessor value for user-defined fixed point convergence check.
bool isParamSetByAddParam(const std::string &name) const
Returns whether or not the parameter was set due to addParam.
virtual MooseConvergenceStatus checkConvergence(unsigned int iter) override
Returns convergence status.
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:35
std::ostringstream _pp_history
Convergence history of the custom convergence check postprocessor.
unsigned int _min_fixed_point_its
Minimum fixed point iterations.
void computeCustomConvergencePostprocessor(unsigned int iter)
Computes and prints the user-specified postprocessor assessing convergence.
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
Definition: Convergence.h:48
virtual void checkIterationType(IterationType it_type) const override
Perform checks related to the iteration type.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
FP converged by relative residual tolerance.
MooseConvergenceStatus
Status returned by calls to checkConvergence.
Definition: Convergence.h:33
const bool _accept_max_it
Whether or not to treat reaching maximum number of fixed point iteration as converged.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
PerfID _perfid_check_convergence
Performance ID for checkConvergence.
Definition: Convergence.h:77
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real _custom_pp_rel_tol
Relative tolerance on postprocessor value.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
static std::string outputNorm(const Real &old_norm, const Real &norm, const unsigned int precision=6)
A helper function for outputting norms in color.
Definition: Console.C:623
const Real _custom_pp_abs_tol
Absolute tolerance on postprocessor value.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
unsigned int _max_fixed_point_its
Maximum fixed point iterations.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const InputParameters & parameters() const
Get the parameters of the object.
std::vector< Real > _fixed_point_timestep_begin_norm
Full history of residual norm after evaluation of timestep_begin.
DefaultMultiAppFixedPointConvergence(const InputParameters &parameters)
Main app nonlinear solve converged, FP unassessed.
void outputResidualNorm(const std::string &execute_on_str, Real old_norm, Real new_norm) const
Outputs residual norm to console.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
void paramWarning(const std::string &param, Args... args) const
Emits a warning prefixed with the file and line number of the given param (from the input file) along...
bool hasMultiApps() const
Returns whether or not the current simulation has any multiapps.
const Real _fixed_point_rel_tol
Relative tolerance on residual norm.
virtual void preExecute()
Method that gets called in each iteration before the solve.
Definition: Convergence.h:58
void ErrorVector unsigned int
static InputParameters validParams()
FP converged by absolute or relative PP tolerance.
virtual void printFixedPointConvergenceHistory(Real initial_norm, const std::vector< Real > &timestep_begin_norms, const std::vector< Real > &timestep_end_norms) const =0
Print the convergence history of the coupling, at every fixed point iteration.
Default fixed point convergence criteria.
Real computeResidualL2Norm(NonlinearSystemBase &sys)
Computes the residual of a nonlinear system using whatever is sitting in the current solution vector ...