www.mooseframework.org
VariableResidual.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 "VariableResidual.h"
11 
12 // MOOSE includes
13 #include "MooseVariable.h"
14 #include "NonlinearSystemBase.h"
15 
16 // libMesh includes
17 #include "libmesh/enum_norm_type.h"
18 
20 
23 {
25  params.addRequiredParam<VariableName>("variable",
26  "The name of the variable to compute the residual for");
27 
28  params.addClassDescription(
29  "Computes the L2 norm of the residual of a single variable in the solution vector.");
30  return params;
31 }
32 
34  : GeneralPostprocessor(parameters),
35  _var(_fe_problem.getVariable(_tid,
36  getParam<VariableName>("variable"),
39 {
40 }
41 
42 void
44 {
45  _var_residual = 0;
46 }
47 
48 void
50 {
52  _var_residual = nl.system().calculate_norm(nl.RHS(), _var.number(), DISCRETE_L2);
53 }
54 
57 {
58  return _var_residual;
59 }
VarFieldType
Definition: MooseTypes.h:634
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
unsigned int number() const
Get variable number coming from libMesh.
DISCRETE_L2
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...
MooseVariableFEBase & _var
MOOSE variable we compute the residual for.
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...
Nonlinear system to be solved.
static InputParameters validParams()
static InputParameters validParams()
VariableResidual(const InputParameters &parameters)
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
Real PostprocessorValue
various MOOSE typedefs
Definition: MooseTypes.h:191
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
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
virtual NumericVector< Number > & RHS()=0
virtual void execute() override
Execute method.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:210
virtual System & system() override
Get the reference to the libMesh system.
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...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
Real _var_residual
The residual of the variable.
registerMooseObject("MooseApp", VariableResidual)