www.mooseframework.org
VariableResidual.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "VariableResidual.h"
16 
17 // MOOSE includes
18 #include "MooseVariable.h"
19 #include "NonlinearSystemBase.h"
20 
21 template <>
24 {
26  params.addRequiredParam<VariableName>("variable",
27  "The name of the variable to compute the residual for");
28  return params;
29 }
30 
32  : GeneralPostprocessor(parameters),
33  _var(_fe_problem.getVariable(_tid, getParam<VariableName>("variable")))
34 {
36  mooseError(name(), ": Residual can be computed only for nonlinear variables.");
37 }
38 
39 void
41 {
42  _var_residual = 0;
43 }
44 
45 void
47 {
49  _var_residual = nl.system().calculate_norm(nl.RHS(), _var.number(), DISCRETE_L2);
50 }
51 
54 {
55  return _var_residual;
56 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
InputParameters validParams< VariableResidual >()
NonlinearSystemBase & getNonlinearSystemBase()
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralPostprocessor >()
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
NonlinearSystemBase * nl
Nonlinear system to be solved.
VariableResidual(const InputParameters &parameters)
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:73
MooseVariable & _var
MOOSE variable we compute the residual for.
virtual NumericVector< Number > & RHS()=0
unsigned int number() const
Get variable number coming from libMesh.
virtual PostprocessorValue getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
virtual void execute() override
Execute method.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:149
virtual System & system() override
Get the reference to the libMesh system.
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
Real _var_residual
The residual of the variable.