https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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 '",
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 ",
63 if (!_nodal && debug_order > 0)
64 mooseWarning("Residual output is approximate for variable order " +
65 Moose::stringify(debug_order));
66}
67
68Real
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}
registerMooseObject("MooseApp", DebugResidualAux)
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
SystemBase & _nl_sys
MooseMesh & _mesh
Mesh this kernel is active on.
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition AuxKernel.h:133
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition AuxKernel.h:143
const bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition AuxKernel.h:116
MooseVariableField< Real > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition AuxKernel.h:113
static InputParameters validParams()
Definition AuxKernel.C:27
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
Auxiliary kernel for debugging convergence.
virtual Real computeValue() override
Compute and return the value of the aux variable.
MooseVariableFEBase & _debug_var
static InputParameters validParams()
NumericVector< Number > & _residual_copy
DebugResidualAux(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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:457
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
const std::string & getSubdomainName(SubdomainID subdomain_id) const
Return the name of a block given an id.
Definition MooseMesh.C:1751
unsigned int number() const
Get variable number coming from libMesh.
unsigned int number() const
Gets the number of this system.
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64