Line data Source code
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 : 15 : registerMooseObject("MooseApp", DebugResidualAux); 16 : 17 : InputParameters 18 3143 : DebugResidualAux::validParams() 19 : { 20 3143 : InputParameters params = AuxKernel::validParams(); 21 6286 : params.addClassDescription( 22 : "Populate an auxiliary variable with the residual contribution of a variable's equation."); 23 9429 : params.addRequiredParam<NonlinearVariableName>( 24 : "debug_variable", "The variable whose equation residual is being output."); 25 3143 : return params; 26 0 : } 27 : 28 46 : DebugResidualAux::DebugResidualAux(const InputParameters & parameters) 29 : : AuxKernel(parameters), 30 46 : _debug_var(_nl_sys.getVariable(_tid, getParam<NonlinearVariableName>("debug_variable"))), 31 92 : _residual_copy(_nl_sys.residualGhosted()) 32 : { 33 : // Note we don't use Coupleable API checks to avoid computing the variable values 34 109 : for (const auto block_id : blockIDs()) 35 66 : if (!_debug_var.hasBlocks(block_id)) 36 : { 37 3 : const auto block_name = _mesh.getSubdomainName(block_id); 38 : const auto block_description = 39 3 : block_name.empty() ? Moose::stringify(block_id) 40 3 : : "'" + block_name + "' (" + Moose::stringify(block_id) + ")"; 41 : 42 9 : paramError("debug_variable", 43 : "The variable '", 44 3 : _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 3 : name(), 49 : "' is active."); 50 0 : } 51 : 52 : // Check that variable order/family match aux_variable order/family 53 86 : auto var_order = Utility::string_to_enum<Order>(_var.getParam<MooseEnum>("order")); 54 86 : auto debug_order = Utility::string_to_enum<Order>(_debug_var.getParam<MooseEnum>("order")); 55 86 : auto var_family = Utility::string_to_enum<FEFamily>(_var.getParam<MooseEnum>("family")); 56 86 : auto debug_family = Utility::string_to_enum<FEFamily>(_debug_var.getParam<MooseEnum>("family")); 57 43 : if (var_order != debug_order || var_family != debug_family) 58 9 : paramError("variable", 59 : "A mismatch was found between family and order parameters for ", 60 3 : _var.name(), 61 : " and ", 62 3 : _debug_var.name()); 63 40 : if (!_nodal && debug_order > 0) 64 0 : mooseWarning("Residual output is approximate for variable order " + 65 0 : Moose::stringify(debug_order)); 66 40 : } 67 : 68 : Real 69 551943 : DebugResidualAux::computeValue() 70 : { 71 551943 : if (_nodal) 72 : { 73 494343 : dof_id_type dof = _current_node->dof_number(_nl_sys.number(), _debug_var.number(), 0); 74 494343 : return _residual_copy(dof); 75 : } 76 : else 77 : { 78 57600 : dof_id_type dof = _current_elem->dof_number(_nl_sys.number(), _debug_var.number(), 0); 79 57600 : return _residual_copy(dof); 80 : } 81 : }