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's equation.");
23  params.addRequiredParam<NonlinearVariableName>(
24  "debug_variable", "The variable whose equation residual is being output.");
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  // Note we don't use Coupleable API checks to avoid computing the variable values
34  for (const auto block_id : blockIDs())
35  if (!_debug_var.hasBlocks(block_id))
36  {
37  const auto block_name = _mesh.getSubdomainName(block_id);
38  const auto block_description =
39  block_name.empty() ? Moose::stringify(block_id)
40  : "'" + block_name + "' (" + Moose::stringify(block_id) + ")";
41 
42  paramError("debug_variable",
43  "The variable '",
44  _debug_var.name(),
45  "', whose equation we want to output the residual of, is not defined on block ",
46  block_description,
47  ", where DebugResidualAux '",
48  name(),
49  "' is active.");
50  }
51 
52  // Check that variable order/family match aux_variable order/family
53  auto var_order = Utility::string_to_enum<Order>(_var.getParam<MooseEnum>("order"));
54  auto debug_order = Utility::string_to_enum<Order>(_debug_var.getParam<MooseEnum>("order"));
55  auto var_family = Utility::string_to_enum<FEFamily>(_var.getParam<MooseEnum>("family"));
56  auto debug_family = Utility::string_to_enum<FEFamily>(_debug_var.getParam<MooseEnum>("family"));
57  if (var_order != debug_order || var_family != debug_family)
58  paramError("variable",
59  "A mismatch was found between family and order parameters for ",
60  _var.name(),
61  " and ",
62  _debug_var.name());
63  if (!_nodal && debug_order > 0)
64  mooseWarning("Residual output is approximate for variable order " +
65  Moose::stringify(debug_order));
66 }
67 
68 Real
70 {
71  if (_nodal)
72  {
73  dof_id_type dof = _current_node->dof_number(_nl_sys.number(), _debug_var.number(), 0);
74  return _residual_copy(dof);
75  }
76  else
77  {
78  dof_id_type dof = _current_elem->dof_number(_nl_sys.number(), _debug_var.number(), 0);
79  return _residual_copy(dof);
80  }
81 }
MooseVariableFEBase & _debug_var
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:467
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:416
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:143
Auxiliary kernel for debugging convergence.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
registerMooseObject("MooseApp", DebugResidualAux)
MooseMesh & _mesh
Mesh this kernel is active on.
const std::string & getSubdomainName(SubdomainID subdomain_id) const
Return the name of a block given an id.
Definition: MooseMesh.C:1758
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...
void mooseWarning(Args &&... args) const
static InputParameters validParams()
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
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:54
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1158
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, hides base _var.
Definition: AuxKernel.h:113
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition: AuxKernel.h:116
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:133
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:17
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
SystemBase & _nl_sys
uint8_t dof_id_type