20 #include "libmesh/transient_system.h" 21 #include "libmesh/fe_type.h" 29 params.
addClassDescription(
"Debug output object for displaying the top contributing residuals.");
33 "num_residuals", 0,
"The number of top residuals to print out (0 = no output)");
37 params.
addParam<NonlinearSystemName>(
38 "nl_sys",
"nl0",
"The nonlinear system that we should output information for.");
44 _num_residuals(getParam<unsigned
int>(
"num_residuals")),
45 _nl(_problem_ptr->getNonlinearSystemBase(
46 _problem_ptr->nlSysNum(getParam<NonlinearSystemName>(
"nl_sys")))),
64 std::vector<TopResidualDebugOutputTopResidualData> vec;
70 for (
const auto & node :
as_range(
mesh.localNodesBegin(),
mesh.localNodesEnd()))
74 for (
unsigned int var = 0; var < node->n_vars(
_sys.
number()); ++var)
78 const auto & subdomain_ids =
mesh.getNodeBlockIds(*node);
81 var, subdomain_ids, nd, *node, residual(dof_idx),
false,
true);
87 for (
const auto & elem :
as_range(
mesh.activeLocalElementsBegin(),
mesh.activeLocalElementsEnd()))
90 const SubdomainID subdomain_id = elem->subdomain_id();
92 for (
unsigned int var = 0; var < elem->n_vars(
_sys.
number()); ++var)
98 var, {subdomain_id}, elem_id, elem->vertex_average(), residual(dof_idx),
false,
false);
104 std::vector<unsigned int> var_nums;
107 for (
const auto & var_num : var_nums)
110 std::vector<dof_id_type> dof_indices;
113 for (
const auto & dof : dof_indices)
114 if (dof >= dof_map.first_dof() && dof < dof_map.end_dof())
126 Moose::err <<
"[DBG][" <<
processor_id() <<
"] Max " << n <<
" residuals";
130 Moose::err <<
" (Only " << n <<
" available)";
132 Moose::err << std::endl;
134 for (
unsigned int i = 0; i < n; ++i)
136 Moose::err <<
"[DBG][" <<
processor_id() <<
"] " << std::setprecision(15) << vec[i]._residual
138 if (vec[i]._is_scalar)
139 Moose::err <<
"(SCALAR)\n";
143 const unsigned int n_subdomains = vec[i]._subdomain_ids.size();
144 std::vector<SubdomainName> subdomain_names(n_subdomains);
145 unsigned int i_block = 0;
146 for (
const auto & subdomain_id : vec[i]._subdomain_ids)
148 subdomain_names[i_block] =
mesh.getSubdomainName(subdomain_id);
151 const std::string subdomains_string =
Moose::stringify(subdomain_names,
", ",
"'",
true);
153 const std::string elem_or_node_string = vec[i]._is_nodal ?
"node" :
"element";
155 Moose::err <<
"in subdomain(s) " << subdomains_string <<
" at " << elem_or_node_string <<
" " 156 << vec[i]._id <<
": " << vec[i]._point <<
'\n';
160 Moose::err << std::flush;
static bool sortTopResidualData(TopResidualDebugOutputTopResidualData i, TopResidualDebugOutputTopResidualData j)
Method for sorting the residuals data from TopResidualDebugOutputTopResidualData structs.
A MultiMooseEnum object to hold "execute_on" flags.
static InputParameters validParams()
void printTopResiduals(const NumericVector< Number > &residual, unsigned int n)
Prints the n top residuals for the variables in the system.
registerMooseObject("MooseApp", TopResidualDebugOutput)
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
A class for producing various debug related outputs.
const ExecFlagType EXEC_TIMESTEP_END
void SCALAR_dof_indices(std::vector< dof_id_type > &di, const unsigned int vn, const bool old_dofs=false) const
virtual void output() override
Perform the debugging output.
unsigned int number() const
static InputParameters validParams()
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
const std::string & variable_name(const unsigned int i) const
A structure for storing data related to top residuals.
const ExecFlagType EXEC_LINEAR
std::string stringify(const T &t)
conversion to string
const ExecFlagType EXEC_NONLINEAR
virtual NumericVector< Number > & RHS()=0
TopResidualDebugOutput(const InputParameters ¶meters)
Class constructor.
const FEType & variable_type(const unsigned int i) const
virtual numeric_index_type local_size() const =0
libMesh::System & _sys
Reference to libMesh system.
virtual MooseMesh & mesh() override
Adds the ability to output on every nonlinear and/or linear residual.
processor_id_type processor_id() const
const DofMap & get_dof_map() const
void ErrorVector unsigned int
unsigned int _num_residuals
Number of residuals to display.
NonlinearSystemBase & _nl
Reference to MOOSE's nonlinear system.