23 #include <petscsnes.h> 34 "Check the convergence of a problem with respect to a user-supplied reference solution." 35 " Replaces ReferenceResidualProblem, currently still used in conjunction with it.");
43 _reference_vector(nullptr),
44 _converge_on(getParam<
std::vector<NonlinearVariableName>>(
"converge_on")),
53 mooseDeprecated(
"The `solution_variables` parameter is deprecated, has no effect when " 54 "the tagging system is used, and will be removed on January 1, 2020. " 55 "Please simply delete this parameter from your input file.");
62 "You may specify either the `reference_residual_variables` " 63 "or `reference_vector` parameter, not both. `reference_residual_variables` is deprecated " 64 "so we recommend using `reference_vector`");
69 "The save-in method for composing reference residual quantities is deprecated " 70 "and will be removed on January 1, 2020. Please use the tagging system instead; " 71 "specifically, please assign a TagName to the `reference_vector` parameter");
74 parameters.
get<std::vector<AuxVariableName>>(
"reference_residual_variables");
79 ") != size of reference_residual_variables (",
88 "reference residual problem does not currently support multiple nonlinear systems");
93 mooseInfo(
"Neither the `reference_residual_variables` nor `reference_vector` parameter is " 94 "specified, which means that no reference " 95 "quantites are set. Because of this, the standard technique of comparing the " 96 "norm of the full residual vector with its initial value will be used.");
101 const auto norm_type_enum =
125 mooseAssert(
false,
"This point should not be reached.");
129 paramError(
"reference_vector",
"If local norm is used, a reference_vector must be provided.");
139 System & s = nonlinear_sys.
system();
140 auto & as = aux_sys.
sys();
149 for (
unsigned int var_num = 0; var_num < s.n_vars(); var_num++)
158 ") != number of variables in system (",
168 for (std::size_t i = 0; i < n_soln_vars; ++i)
179 unsigned int group_variable_num = 0;
186 mooseError(
" In the 'group_variables' parameter, variable ",
188 " is not grouped with other variables.");
191 unsigned int size = n_soln_vars - group_variable_num +
_group_variables.size();
208 std::set<std::string> check_duplicate;
215 if (check_duplicate.size() != group_variable_num)
217 "A variable cannot be included in multiple groups in the 'group_variables' parameter.");
221 for (
unsigned int i = 0; i < n_soln_vars; ++i)
223 bool found_match =
false;
224 for (
unsigned int var_num = 0; var_num < s.n_vars(); var_num++)
233 mooseError(
"Could not find solution variable '",
245 bool foundMatch =
false;
246 for (
unsigned int var_num = 0; var_num < as.n_vars(); var_num++)
259 unsigned int ungroup_index = 0;
265 bool find_group =
false;
275 "You added variable '",
277 "' to a group but excluded it from the convergence check. This is not " 300 unsigned int num_scalar_vars = 0;
301 unsigned int num_field_vars = 0;
305 for (
unsigned int var_num = 0; var_num < s.n_vars(); var_num++)
315 if (num_scalar_vars > 0 && num_field_vars > 0)
316 mooseWarning(
"In the 'group_variables' parameter, standard variables and scalar variables " 317 "are grouped together in group ",
323 for (
unsigned int i = 0; i < n_soln_vars; ++i)
342 const unsigned int size_soln_vars =
_soln_vars.size();
344 for (
unsigned int i = 0; i < size_soln_vars; ++i)
358 System & s = _current_nl_sys.
system();
359 auto & as = aux_sys.
sys();
374 mooseAssert(_current_nl_sys.
RHS().
size() == (*_reference_vector).size(),
375 "Sizes of nonlinear RHS and reference vector should be the same.");
376 mooseAssert((*_reference_vector).size(),
"Reference vector must be provided.");
380 auto div = _current_nl_sys.
RHS().
clone();
402 const auto ref_resid =
425 std::ostringstream
out;
429 out << std::setprecision(2) << std::scientific
430 <<
" Solution, reference convergence variable norms:\n";
431 unsigned int maxwsv = 0;
432 unsigned int maxwrv = 0;
446 out <<
" " << std::setw(maxwsv + (
_local_norm ? 5 : 2)) << std::left
456 const auto ref_var_name =
458 out <<
" " << std::setw(maxwrv + 2) << ref_var_name +
":" << std::setw(8)
474 const Real initial_residual_before_preset_bcs)
486 bool convergedRelative =
true;
498 else if (fnorm > initial_residual_before_preset_bcs * rtol)
499 convergedRelative =
false;
501 return convergedRelative;
507 const Real the_residual,
510 std::ostringstream & oss)
514 oss <<
"Converged due to function norm " << fnorm <<
" < relative tolerance (" << rtol
515 <<
") or absolute tolerance (" << abstol <<
") for all solution variables\n";
522 oss <<
"Converged due to function norm " << fnorm <<
" < acceptable relative tolerance (" 524 <<
") for all solution variables\n";
525 _console <<
"Converged due to ACCEPTABLE tolerances" << std::endl;
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
bool globCompare(const std::string &candidate, const std::string &pattern, std::size_t c=0, std::size_t p=0)
virtual void nonlinearConvergenceSetup() override
Performs setup necessary for each call to checkConvergence.
void mooseDeprecated(Args &&... args) const
Interface class shared between ReferenceResidualProblem and ReferenceResidualConvergence.
bool checkConvergenceIndividVars(const Real fnorm, const Real abstol, const Real rtol, const Real initial_residual_before_preset_bcs)
Check the convergence by comparing the norm of each variable's residual separately against its refere...
virtual std::size_t numNonlinearSystems() const override
std::vector< Real > _group_output_resid
std::vector< NonlinearVariableName > _soln_var_names
void mooseInfo(Args &&... args) const
std::vector< std::vector< NonlinearVariableName > > _group_variables
Name of variables that are grouped together to check convergence.
virtual numeric_index_type size() const =0
ReferenceResidualConvergence(const InputParameters ¶meters)
std::vector< bool > _converge_on_var
Flag for each solution variable being in 'converge_on'.
virtual bool checkRelativeConvergence(const unsigned int it, const Real fnorm, const Real the_residual, const Real rtol, const Real abstol, std::ostringstream &oss) override
Check the relative convergence of the nonlinear solution.
std::vector< NonlinearVariableName > _group_soln_var_names
virtual std::unique_ptr< NumericVector< Number > > clone() const =0
const NumericVector< Number > * _reference_vector
The vector storing the reference residual values.
std::vector< unsigned int > _variable_group_num_index
Group number index for each variable.
std::vector< Real > _group_resid
void updateReferenceResidual()
Computes the reference residuals for each group.
static InputParameters validParams()
static InputParameters validParams()
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
std::vector< AuxVariableName > _ref_resid_var_names
Nonlinear system to be solved.
registerMooseObject("MooseApp", ReferenceResidualConvergence)
bool _use_group_variables
True if any variables are grouped.
std::vector< unsigned int > _soln_vars
TagID _reference_vector_tag_id
The reference vector tag id.
NonlinearSystemBase & currentNonlinearSystem()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
bool _local_norm
Flag to optionally perform normalization of residual by reference residual before or after L2 norm is...
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
std::vector< AuxVariableName > _group_ref_resid_var_names
std::vector< Real > _group_ref_resid
AuxiliarySystem & getAuxiliarySystem()
unsigned int _accept_iters
std::vector< unsigned int > _ref_resid_vars
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
Uses a reference residual to define relative convergence criteria.
virtual libMesh::System & sys()
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a scalar variable with specified number.
virtual NumericVector< Number > & RHS()=0
libMesh::FEMNormType _norm_type
Container for normalization type.
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
enum ReferenceResidualConvergence::ZeroReferenceType _zero_ref_type
const TagID INVALID_TAG_ID
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
virtual bool isScalarVariable(unsigned int var_name) const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
std::vector< Real > _scaling_factors
Local storage for the scaling factors applied to each of the variables to apply to _ref_resid_vars...
std::vector< NonlinearVariableName > _converge_on
Variables to use for individual variable convergence checks.
auto min(const L &left, const R &right)
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
FEProblemBase & _fe_problem
Default convergence criteria for FEProblem.
A system that holds auxiliary variables.
auto index_range(const T &sizable)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template pow< 2 >(tan(_arg))+1.0) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(sqrt
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
ZeroReferenceType
Container for convergence treatment when the reference residual is zero.
virtual libMesh::System & system() override
Get the reference to the libMesh system.