www.mooseframework.org
Residual.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
16 registerMooseObject("MooseApp", Residual);
17 
20 {
22  params.addClassDescription("Report the non-linear residual.");
23  MooseEnum residual_types("FINAL INITIAL_BEFORE_PRESET INITIAL_AFTER_PRESET", "FINAL");
24  params.addParam<MooseEnum>("residual_type", residual_types, "Type of residual to be reported.");
25  return params;
26 }
27 
29  : GeneralPostprocessor(parameters), _residual_type(getParam<MooseEnum>("residual_type"))
30 {
31 }
32 
33 Real
35 {
36  Real residual = 0.0;
37  if (_residual_type == "FINAL")
39  else
40  {
41  FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem);
42  if (!fe_problem)
43  mooseError("Dynamic cast to FEProblemBase failed in Residual Postprocessor");
44  if (_residual_type == "INITIAL_BEFORE_PRESET")
45  residual =
46  fe_problem->getNonlinearSystemBase(_sys.number())._initial_residual_before_preset_bcs;
47  else if (_residual_type == "INITIAL_AFTER_PRESET")
48  residual =
49  fe_problem->getNonlinearSystemBase(_sys.number())._initial_residual_after_preset_bcs;
50  else
51  mooseError("Invalid residual_type option in Residual Postprocessor: ", _residual_type);
52  }
53  return residual;
54 }
static InputParameters validParams()
Definition: Residual.C:19
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
registerMooseObject("MooseApp", Residual)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:207
virtual Real finalNonlinearResidual(const unsigned int nl_sys_num) const
Definition: SubProblem.C:712
virtual Real getValue() const override
This will return the final nonlinear residual.
Definition: Residual.C:34
static InputParameters validParams()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
SystemBase & _sys
Reference to the system object for this user object.
Definition: UserObject.h:214
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1125
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Residual(const InputParameters &parameters)
Definition: Residual.C:28
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
MooseEnum _residual_type
Definition: Residual.h:30