www.mooseframework.org
VariableResidualNormsDebugOutput.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
17 #include "FEProblem.h"
18 #include "MooseApp.h"
19 #include "Material.h"
20 #include "NonlinearSystemBase.h"
21 
22 #include "libmesh/transient_system.h"
23 
24 template <>
27 {
29 
30  // By default this outputs on every nonlinear iteration
31  params.set<MultiMooseEnum>("execute_on") = "nonlinear";
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 }
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.
nl system()
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:171
virtual NumericVector< Number > & RHS()=0
InputParameters validParams< PetscOutput >()
Definition: PetscOutput.C:25
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Adds the ability to output on every nonlinear and/or linear residual.
Definition: PetscOutput.h:30
virtual void output(const ExecFlagType &type) override
Perform the debugging output.
VariableResidualNormsDebugOutput(const InputParameters &parameters)
Class constructor.