https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ReferenceResidualConvergence.h
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
10#pragma once
11
14
15#include <optional>
16
17// PETSc includes
18#include <petsc.h>
19#include <petscmat.h>
20
21#include "libmesh/enum_norm_type.h"
22
28{
29public:
31
33
36
37 virtual void initialSetup() override;
38
45
48
49protected:
50 virtual NonlinearSystemBase & nonlinearSystem() override;
51
52 virtual void nonlinearConvergenceSetup() override;
53
54 virtual bool checkResidualConvergence(const unsigned int n_iter,
55 const Real fnorm,
56 const Real ref_norm,
57 const Real rel_tol,
58 const Real abs_tol,
59 std::ostringstream & oss) override;
60
75 bool checkConvergenceIndividVars(const Real fnorm,
76 const Real default_abs_tol,
77 const Real default_rel_tol,
78 const Real initial_residual_before_preset_bcs,
79 const Real multiplier = 1);
80
83 Real groupAbsTol(const std::size_t group, const Real abs_tol) const;
84
87
91 std::vector<NonlinearVariableName> _soln_var_names;
92 std::vector<AuxVariableName> _ref_resid_var_names;
94
97 std::vector<NonlinearVariableName> _group_names;
99
102 std::vector<unsigned int> _soln_vars;
103 std::vector<unsigned int> _ref_resid_vars;
105
110 const Real _accept_mult;
111 const unsigned int _accept_iters;
113
115 const unsigned int _nl_sys_num;
116
119 std::vector<Real> _group_ref_resid;
120 std::vector<Real> _group_resid;
122
124 std::vector<bool> _is_var_grouped;
125
127 std::vector<unsigned int> _group_index;
128
131 std::vector<std::optional<Real>> _group_abs_tol;
132
134 std::vector<Real> _scaling_factors;
135
137 const NumericVector<Number> * _residual_vector;
138
140 const NumericVector<Number> * _reference_vector;
141
143 std::vector<bool> _converge_on_var;
144 std::vector<bool> _converge_on_group;
145
148
151
154
157
160};
unsigned int TagID
Definition MooseTypes.h:238
Default nonlinear convergence criteria for FEProblem.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Nonlinear system to be solved.
Uses a reference residual to define relative convergence criteria.
virtual void nonlinearConvergenceSetup() override
Performs setup necessary for each call to checkConvergence.
ZeroReferenceType
Container for convergence treatment when the reference residual is zero.
virtual bool checkResidualConvergence(const unsigned int n_iter, const Real fnorm, const Real ref_norm, const Real rel_tol, const Real abs_tol, std::ostringstream &oss) override
Check the absolute and relative convergence of the nonlinear solution.
std::vector< AuxVariableName > _ref_resid_var_names
enum ReferenceResidualConvergence::ZeroReferenceType _zero_ref_type
std::vector< bool > _is_var_grouped
Vector of bools to signify if variable is in a group.
const NumericVector< Number > * _reference_vector
The vector storing the reference residual values.
bool checkConvergenceIndividVars(const Real fnorm, const Real default_abs_tol, const Real default_rel_tol, const Real initial_residual_before_preset_bcs, const Real multiplier=1)
Check the convergence by comparing the norm of each variable's residual separately against its refere...
const bool _unscale_the_residual
Bool to unscale the residual before convergence checks and screen output.
const MooseEnum _norm_type_enum
Enum holding the normalization type.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
void updateReferenceResidual()
Computes the reference residuals for each group.
const unsigned int _nl_sys_num
Nonlinear system to which this convergence object applies.
virtual NonlinearSystemBase & nonlinearSystem() override
Nonlinear system whose convergence state should be checked.
TagID referenceVectorTagID(ReferenceVectorTagIDKey) const
Returns the tag ID associated with the reference vector tag ID key.
libMesh::FEMNormType _norm_type
Container for normalization type.
std::vector< NonlinearVariableName > _group_names
std::vector< unsigned int > _group_index
Group number index for each variable.
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< unsigned int > _ref_resid_vars
std::vector< bool > _converge_on_var
Flag for each solution variable or group being in 'converge_on'.
const NumericVector< Number > * _residual_vector
The optional vector storing the reference residual values.
TagID _reference_vector_tag_id
The reference vector tag id.
std::vector< std::optional< Real > > _group_abs_tol
Absolute tolerance of each group from variable_nl_abs_tol, unset for groups that use the default abso...
bool _local_norm
Flag to optionally perform normalization of residual by reference residual before or after L2 norm is...
Real groupAbsTol(const std::size_t group, const Real abs_tol) const
The absolute tolerance of group group, where abs_tol applies to groups without a variable_nl_abs_tol ...
std::vector< NonlinearVariableName > _soln_var_names
Interface class shared between ReferenceResidualProblem and ReferenceResidualConvergence.