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 return params;
27}
28
30 : GeneralPostprocessor(parameters), _residual_type(getParam<MooseEnum>("residual_type"))
31{
32 if (_residual_type == "INITIAL_BEFORE_PRESET")
33 mooseDeprecated("INITIAL_BEFORE_PRESET is deprecated, use PRE_SMO instead.");
34 if (_residual_type == "INITIAL_AFTER_PRESET")
35 mooseDeprecated("INITIAL_AFTER_PRESET is deprecated, use INITIAL instead.");
36}
37
38Real
40{
41 Real residual = 0.0;
42 if (_residual_type == "FINAL")
44 else if (_residual_type == "CURRENT")
45 {
46 const auto & snes = _fe_problem.getNonlinearSystemBase(_sys.number()).getSNES();
47
48 PetscReal norm;
49 LibmeshPetscCall(SNESGetFunctionNorm(snes, &norm));
50
51 residual = norm;
52 }
53 else if (_residual_type == "COMPUTE")
55 else
56 {
57 FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem);
58 if (!fe_problem)
59 mooseError("Dynamic cast to FEProblemBase failed in Residual Postprocessor");
60
61 const auto & nl_sys = fe_problem->getNonlinearSystemBase(_sys.number());
62
63 if (_residual_type == "INITIAL_BEFORE_PRESET" || _residual_type == "PRE_SMO")
64 residual = nl_sys.preSMOResidual();
65 else if (_residual_type == "INITIAL_AFTER_PRESET" || _residual_type == "INITIAL")
66 residual = nl_sys.initialResidual();
67 else
68 mooseError("Invalid residual_type option in Residual Postprocessor: ", _residual_type);
69 }
70 return residual;
71}
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:29
static InputParameters validParams()
Definition Residual.C:19
virtual Real getValue() const override
This will return the final nonlinear residual.
Definition Residual.C:39
MooseEnum _residual_type
Definition Residual.h:30
virtual Real finalNonlinearResidual(const unsigned int nl_sys_num) const
Definition SubProblem.C:755
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.