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  paramError("variable",
40  "A mismatch was found between family and order parameters for ",
41  _var.name(),
42  " and ",
43  _debug_var.name());
44  if (!_nodal && debug_order > 0)
45  mooseWarning("Residual output is approximate for variable order " +
46  Moose::stringify(debug_order));
47 }
48 
49 Real
51 {
52  if (_nodal)
53  {
54  dof_id_type dof = _current_node->dof_number(_nl_sys.number(), _debug_var.number(), 0);
55  return _residual_copy(dof);
56  }
57  else
58  {
59  dof_id_type dof = _current_elem->dof_number(_nl_sys.number(), _debug_var.number(), 0);
60  return _residual_copy(dof);
61  }
62 }
MooseVariableFEBase & _debug_var
bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition: AuxKernel.h:177
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:384
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.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", DebugResidualAux)
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()
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
SystemBase & _nl_sys
Definition: AuxKernel.h:167
virtual Real computeValue() override
Compute and return the value of the aux variable.
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:1157
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 mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
Definition: MooseBase.h:295
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