https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Residual.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
10#include "Residual.h"
11
12#include "FEProblem.h"
13#include "SubProblem.h"
14#include "NonlinearSystem.h"
15
17
20{
22 params.addClassDescription("Report the non-linear residual.");
23 MooseEnum residual_types(
24 "FINAL INITIAL_BEFORE_PRESET INITIAL_AFTER_PRESET PRE_SMO INITIAL CURRENT COMPUTE", "FINAL");
25 params.addParam<MooseEnum>("residual_type", residual_types, "Type of residual to be reported.");
26 params.addParam<SolverSystemName>("solver_sys", "Name of the nonlinear system");
27
28 return params;
29}
30
32 : GeneralPostprocessor(parameters), _residual_type(getParam<MooseEnum>("residual_type"))
33{
34 if (_residual_type == "INITIAL_BEFORE_PRESET")
35 mooseDeprecated("INITIAL_BEFORE_PRESET is deprecated, use PRE_SMO instead.");
36 if (_residual_type == "INITIAL_AFTER_PRESET")
37 mooseDeprecated("INITIAL_AFTER_PRESET is deprecated, use INITIAL instead.");
38}
39
40Real
42{
43 Real residual = 0.0;
44 if (_residual_type == "FINAL")
46 else if (_residual_type == "CURRENT")
47 {
48 const auto & snes = _fe_problem.getNonlinearSystemBase(_sys.number()).getSNES();
49
50 PetscReal norm;
51 LibmeshPetscCall(SNESGetFunctionNorm(snes, &norm));
52
53 residual = norm;
54 }
55 else if (_residual_type == "COMPUTE")
57 else
58 {
59 FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem);
60 if (!fe_problem)
61 mooseError("Dynamic cast to FEProblemBase failed in Residual Postprocessor");
62
63 const auto & nl_sys = fe_problem->getNonlinearSystemBase(_sys.number());
64
65 if (_residual_type == "INITIAL_BEFORE_PRESET" || _residual_type == "PRE_SMO")
66 residual = nl_sys.preSMOResidual();
67 else if (_residual_type == "INITIAL_AFTER_PRESET" || _residual_type == "INITIAL")
68 residual = nl_sys.initialResidual();
69 else
70 mooseError("Invalid residual_type option in Residual Postprocessor: ", _residual_type);
71 }
72 return residual;
73}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:363
registerMooseObject("MooseApp", Residual)
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 ...
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
virtual SNES getSNES()=0
Real preSMOResidual() const
The pre-SMO residual.
Residual(const InputParameters &parameters)
Definition Residual.C:31
static InputParameters validParams()
Definition Residual.C:19
virtual Real getValue() const override
This will return the final nonlinear residual.
Definition Residual.C:41
MooseEnum _residual_type
Definition Residual.h:30
virtual Real finalNonlinearResidual(const unsigned int nl_sys_num) const
Definition SubProblem.C:746
unsigned int number() const
Gets the number of this system.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
SystemBase & _sys
Reference to the system object for this user object.