www.mooseframework.org
VariableResidualNormsDebugOutput.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // MOOSE includes
12 #include "FEProblem.h"
13 #include "MooseApp.h"
14 #include "Material.h"
15 #include "NonlinearSystemBase.h"
16 
17 // libMesh includes
18 #include "libmesh/transient_system.h"
19 #include "libmesh/enum_norm_type.h"
20 
22 
25 {
27  params.addClassDescription("Reports the residual norm for each variable.");
28 
29  // By default this outputs on every nonlinear iteration
30  params.set<ExecFlagEnum>("execute_on") = EXEC_NONLINEAR;
31  params.suppressParameter<ExecFlagEnum>("execute_on");
32  params.addParam<NonlinearSystemName>(
33  "nl_sys", "nl0", "The nonlinear system that we should output information for.");
34  return params;
35 }
36 
38  const InputParameters & parameters)
39  : PetscOutput(parameters),
40  _nl(_problem_ptr->getNonlinearSystemBase(
41  _problem_ptr->nlSysNum(getParam<NonlinearSystemName>("nl_sys")))),
42  _sys(_nl.system())
43 {
44 }
45 
46 void
48 {
49  // Stream for outputting
50  std::ostringstream oss;
51 
52  // Determine the maximum variable name size
53  unsigned int max_name_size = 0;
54  for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
55  {
56  unsigned int var_name_size = _sys.variable_name(var_num).size();
57  if (var_name_size > max_name_size)
58  max_name_size = var_name_size;
59  }
60 
61  // Perform the output of the variable residuals
62  oss << " |residual|_2 of individual variables:\n";
63  for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
64  {
65  Real var_res_id = _sys.calculate_norm(_nl.RHS(), var_num, DISCRETE_L2);
66  oss << std::setw(27 - max_name_size) << " "
67  << std::setw(max_name_size + 2) // match position of overall NL residual
68  << std::left << _sys.variable_name(var_num) + ":" << var_res_id << "\n";
69  }
70 
71  _console << oss.str() << std::flush;
72 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
NonlinearSystemBase & _nl
Reference to MOOSE&#39;s nonlinear system.
DISCRETE_L2
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
System & _sys
Reference to libMesh system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
A class for producing various debug related outputs.
static InputParameters validParams()
Definition: PetscOutput.C:124
virtual void output() override
Perform the debugging output.
const ExecFlagType EXEC_NONLINEAR
Definition: Moose.C:30
virtual NumericVector< Number > & RHS()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Adds the ability to output on every nonlinear and/or linear residual.
Definition: PetscOutput.h:41
registerMooseObject("MooseApp", VariableResidualNormsDebugOutput)
VariableResidualNormsDebugOutput(const InputParameters &parameters)
Class constructor.