https://mooseframework.inl.gov
DebugResidualAux.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 "DebugResidualAux.h"
11 #include "NonlinearSystem.h"
12 
13 #include "libmesh/string_to_enum.h"
14 
16 
19 {
21  params.addClassDescription(
22  "Populate an auxiliary variable with the residual contribution of a variable.");
23  params.addRequiredParam<NonlinearVariableName>("debug_variable",
24  "The variable that is being debugged.");
25  return params;
26 }
27 
29  : AuxKernel(parameters),
30  _debug_var(_nl_sys.getVariable(_tid, getParam<NonlinearVariableName>("debug_variable"))),
31  _residual_copy(_nl_sys.residualGhosted())
32 {
33  // Check that variable order/family match aux_variable order/family
34  auto var_order = Utility::string_to_enum<Order>(_var.getParam<MooseEnum>("order"));
35  auto debug_order = Utility::string_to_enum<Order>(_debug_var.getParam<MooseEnum>("order"));
36  auto var_family = Utility::string_to_enum<FEFamily>(_var.getParam<MooseEnum>("family"));
37  auto debug_family = Utility::string_to_enum<FEFamily>(_debug_var.getParam<MooseEnum>("family"));
38  if (var_order != debug_order || var_family != debug_family)
39  mooseError("A mismatch was found between family and order parameters for ",
40  _var.name(),
41  " and ",
42  _debug_var.name(),
43  " in ",
44  this->getParam<std::string>("_object_name"));
45  if (!_nodal && debug_order > 0)
46  mooseWarning("Residual output is approximate for variable order " +
47  Moose::stringify(debug_order));
48 }
49 
50 Real
52 {
53  if (_nodal)
54  {
55  dof_id_type dof = _current_node->dof_number(_nl_sys.number(), _debug_var.number(), 0);
56  return _residual_copy(dof);
57  }
58  else
59  {
60  dof_id_type dof = _current_elem->dof_number(_nl_sys.number(), _debug_var.number(), 0);
61  return _residual_copy(dof);
62  }
63 }
MooseVariableFEBase & _debug_var
bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition: AuxKernel.h:177
NumericVector< Number > & _residual_copy
unsigned int number() const
Get variable number coming from libMesh.
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:214
Auxiliary kernel for debugging convergence.
const std::string & name() const override
Get the variable name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", DebugResidualAux)
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
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...
static InputParameters validParams()
SystemBase & _nl_sys
Definition: AuxKernel.h:167
virtual Real computeValue() override
Compute and return the value of the aux variable.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1159
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
DebugResidualAux(const InputParameters &parameters)
MooseVariableField< Real > & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: AuxKernel.h:174
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:204
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...
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36
uint8_t dof_id_type