https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
76void
78{
80
83 "DefaultMultiAppFixedPointConvergence can only be used with MultiApp fixed point solves.");
84}
85
86void
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;
103 if (_fixed_point_initial_norm == std::numeric_limits<Real>::max())
104 _console << " MAX ";
105 else
106 _console << std::scientific << _fixed_point_initial_norm;
107 _console << COLOR_DEFAULT << "\n" << std::endl;
108 }
109}
110
111void
113{
115
116 // compute TIMESTEP_BEGIN residual norm; this should be executed after TIMESTEP_BEGIN
117 // but before the solve
120 {
121 const auto iter = _fp_solve.numFixedPointIts() - 1;
123
124 Real begin_norm_old =
125 (iter > 0 ? _fixed_point_timestep_begin_norm[iter - 1] : std::numeric_limits<Real>::max());
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
136 // index of the iteration, starting at 0; n_iter is number of iterations performed.
137 const auto iter = n_iter - 1;
138
141
142 // compute TIMESTEP_END residual norm; this should be executed between TIMESTEP_END
143 // and TIMESTEP_BEGIN
146 {
147 auto & end_norm = _fixed_point_timestep_end_norm[iter];
149
150 Real end_norm_old =
151 (iter > 0 ? _fixed_point_timestep_end_norm[iter - 1] : std::numeric_limits<Real>::max());
152
153 outputResidualNorm("TIMESTEP_END", end_norm_old, end_norm);
154 }
155
156 // print residual norm history
161
162 if (n_iter >= _min_fixed_point_its)
163 {
164 Real max_norm =
166
167 Real max_relative_drop = max_norm / _fixed_point_initial_norm;
168
170 {
174 }
175 if (_has_fixed_point_norm && max_relative_drop < _fixed_point_rel_tol)
176 {
180 }
181
183 {
187 }
189 {
193 }
194 }
195
196 if (n_iter == _max_fixed_point_its)
197 {
198 if (_accept_max_it)
199 {
203 }
204 else
205 {
209 }
210 }
211
213}
214
215void
217 Real old_norm,
218 Real new_norm) const
219{
220 _console << COLOR_MAGENTA << "Fixed point residual norm after " << execute_on_str
221 << " MultiApps: " << Console::outputNorm(old_norm, new_norm) << std::endl;
222}
223
224void
226{
227 if (!getParam<bool>("direct_pp_value"))
229
230 if ((iter == 0 && getParam<bool>("direct_pp_value")) || !getParam<bool>("direct_pp_value"))
233
234 const auto pp_name = getParam<PostprocessorName>("custom_pp");
235 _pp_history << std::setw(2) << iter + 1 << " fixed point " << pp_name << " = "
236 << Console::outputNorm(std::numeric_limits<Real>::max(), _pp_current, 8) << std::endl;
237 _console << _pp_history.str() << std::flush;
238}
registerMooseObject("MooseApp", DefaultMultiAppFixedPointConvergence)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:37
void ErrorVector unsigned int
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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:619
PerfID _perfid_check_convergence
Performance ID for checkConvergence.
Definition Convergence.h:80
virtual void initialize()
Method that gets called before each iteration loop.
Definition Convergence.h:53
MooseConvergenceStatus
Status returned by calls to checkConvergence.
Definition Convergence.h:34
virtual void preExecute()
Method that gets called in each iteration before the solve.
Definition Convergence.h:58
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
Definition Convergence.h:48
Base class for default convergence criteria.
static InputParameters validParams()
Default fixed point convergence criteria.
std::vector< Real > _fixed_point_timestep_begin_norm
Full history of residual norm after evaluation of timestep_begin, indexed by iteration index.
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.
Real _pp_previous
Value of the custom convergence check postprocessor from previous iteration.
DefaultMultiAppFixedPointConvergence(const InputParameters &parameters)
void outputResidualNorm(const std::string &execute_on_str, Real old_norm, Real new_norm) const
Outputs residual norm to console.
const PostprocessorValue *const _fixed_point_custom_pp_old
Postprocessor value for user-defined fixed point convergence check from previous timestep.
const Real _fixed_point_abs_tol
Absolute tolerance on residual norm.
virtual void preExecute() override
Method that gets called in each iteration before the solve.
std::vector< Real > _fixed_point_timestep_end_norm
Full history of residual norm after evaluation of timestep_end, indexed by iteration index.
unsigned int _max_fixed_point_its
Maximum fixed point iterations.
const bool _accept_max_it
Whether or not to treat reaching maximum number of fixed point iteration as converged.
const Real _custom_pp_rel_tol
Relative tolerance on postprocessor value.
Real _pp_scaling
Scaling of custom convergence check postprocessor (its initial value)
const bool _fixed_point_force_norms
Whether or not we force evaluation of residual norms even without multiapps.
virtual void initialize() override
Method that gets called before each iteration loop.
const Real _custom_pp_abs_tol
Absolute tolerance on postprocessor value.
virtual void checkIterationType(IterationType it_type) const override
Perform checks related to the iteration type.
Real _pp_current
Value of the custom convergence check postprocessor from current iteration.
const bool _has_fixed_point_norm
Whether or not to use residual norm to check the fixed point convergence.
const Real _fixed_point_rel_tol
Relative tolerance on residual norm.
virtual MooseConvergenceStatus checkConvergence(unsigned int n_iter) override
Returns convergence status.
const PostprocessorValue *const _fixed_point_custom_pp
Postprocessor value for user-defined fixed point convergence check.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Real computeResidualL2Norm(NonlinearSystemBase &sys)
Computes the residual of a nonlinear system using whatever is sitting in the current solution vector ...
bool hasMultiApps() const
Returns whether or not the current simulation has any multiapps.
void setFixedPointStatus(MooseFixedPointConvergenceReason status)
Set fixed point status.
@ DIVERGED_MAX_ITS
FP converged according to Convergence object.
@ CONVERGED_ABS
Main app nonlinear solve converged, FP unassessed.
@ REACH_MAX_ITS
FP converged by absolute or relative PP tolerance.
@ CONVERGED_PP
FP converged by relative residual tolerance.
@ CONVERGED_RELATIVE
FP converged by absolute residual tolerance.
unsigned int numFixedPointIts() const
Get the number of fixed point iterations performed Because this returns the number of fixed point ite...
static InputParameters fixedPointDefaultConvergenceParams()
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.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
bool isParamSetByAddParam(const std::string &name) const
Returns whether or not the parameter was set due to addParam.
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.
Definition MooseBase.h:131
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 ...
Definition MooseBase.h:457
Class for containing MooseEnum item information.
void paramWarning(const std::string &param, Args... args) const