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 
23 template <>
26 {
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  return params;
33 }
34 
36  const InputParameters & parameters)
37  : PetscOutput(parameters), _sys(_problem_ptr->getNonlinearSystemBase().system())
38 {
39 }
40 
41 void
43 {
44  // Stream for outputting
45  std::ostringstream oss;
46 
47  // Determine the maximum variable name size
48  unsigned int max_name_size = 0;
49  for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
50  {
51  unsigned int var_name_size = _sys.variable_name(var_num).size();
52  if (var_name_size > max_name_size)
53  max_name_size = var_name_size;
54  }
55 
56  // Perform the output of the variable residuals
57  oss << " |residual|_2 of individual variables:\n";
58  for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
59  {
60  Real var_res_id =
61  _sys.calculate_norm(_problem_ptr->getNonlinearSystemBase().RHS(), var_num, DISCRETE_L2);
62  oss << std::setw(27 - max_name_size) << " "
63  << std::setw(max_name_size + 2) // match position of overall NL residual
64  << std::left << _sys.variable_name(var_num) + ":" << var_res_id << "\n";
65  }
66 
67  _console << oss.str() << std::flush;
68 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
NonlinearSystemBase & getNonlinearSystemBase()
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...
InputParameters validParams< VariableResidualNormsDebugOutput >()
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.
nl system()
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:167
const ExecFlagType EXEC_NONLINEAR
virtual NumericVector< Number > & RHS()=0
InputParameters validParams< PetscOutput >()
Definition: PetscOutput.C:20
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
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:24
virtual void output(const ExecFlagType &type) override
Perform the debugging output.
registerMooseObject("MooseApp", VariableResidualNormsDebugOutput)
VariableResidualNormsDebugOutput(const InputParameters &parameters)
Class constructor.