https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VariableResidualNormsDebugOutput.C
Go to the documentation of this file.
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// 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
46void
48{
49 // Only output if the problem is solving for the relevant nonlinear system
51 return;
52
53 // Stream for outputting
54 std::ostringstream oss;
55
56 // Determine the maximum variable name size
57 unsigned int max_name_size = 0;
58 for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
59 {
60 unsigned int var_name_size = _sys.variable_name(var_num).size();
61 if (var_name_size > max_name_size)
62 max_name_size = var_name_size;
63 }
64
65 // Perform the output of the variable residuals
66 oss << " |residual|_2 of individual variables:\n";
67 for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
68 {
69 Real var_res_id = _sys.calculate_norm(_nl.RHS(), var_num, libMesh::DISCRETE_L2);
70 oss << std::setw(27 - max_name_size) << " "
71 << std::setw(max_name_size + 2) // match position of overall NL residual
72 << std::left << _sys.variable_name(var_num) + ":" << var_res_id << "\n";
73 }
74
75 _console << oss.str() << std::flush;
76}
const ExecFlagType EXEC_NONLINEAR
Definition Moose.C:33
registerMooseObject("MooseApp", VariableResidualNormsDebugOutput)
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
A MultiMooseEnum object to hold "execute_on" flags.
NonlinearSystemBase & currentNonlinearSystem()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
virtual NumericVector< Number > & RHS()=0
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition Output.h:185
Adds the ability to output on every nonlinear and/or linear residual.
Definition PetscOutput.h:42
static InputParameters validParams()
unsigned int number() const
Gets the number of this system.
A class for producing various debug related outputs.
VariableResidualNormsDebugOutput(const InputParameters &parameters)
Class constructor.
NonlinearSystemBase & _nl
Reference to MOOSE's nonlinear system.
virtual void output() override
Perform the debugging output.
libMesh::System & _sys
Reference to libMesh system.
const std::string & variable_name(const unsigned int i) const
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
unsigned int n_vars() const