https://mooseframework.inl.gov
SetupDebugAction.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 #include "SetupDebugAction.h"
11 #include "FEProblem.h"
12 #include "ActionWarehouse.h"
13 #include "Factory.h"
14 #include "Output.h"
15 #include "MooseApp.h"
16 #include "MooseObjectAction.h"
17 #include "ActionFactory.h"
18 #include "AddAuxVariableAction.h"
19 #include "MooseUtils.h"
21 
22 using namespace libMesh;
23 
24 registerMooseAction("MooseApp", SetupDebugAction, "add_output");
25 
28 {
30  params.addParam<unsigned int>(
31  "show_top_residuals", 0, "The number of top residuals to print out (0 = no output)");
32  params.addParam<bool>(
33  "show_var_residual_norms",
34  false,
35  "Print the residual norms of the individual solution variables at each nonlinear iteration");
36  params.addParam<bool>("show_action_dependencies", false, "Print out the action dependencies");
37  params.addParam<bool>("show_actions", false, "Print out the actions being executed");
38  params.addParam<bool>(
39  "show_parser", false, "Shows parser block extraction and debugging information");
40  params.addParam<bool>(
41  "show_material_props",
42  false,
43  "Print out the material properties supplied for each block, face, neighbor, and/or sideset");
44  params.addParam<bool>("show_controllable",
45  false,
46  "Print out the controllable parameters from all input parameters");
47  params.addParam<bool>("show_mesh_meta_data", false, "Print out the available mesh meta data");
48  params.addParam<bool>(
49  "show_reporters", false, "Print out information about the declared and requested Reporters");
50  params.addParam<bool>(
51  "show_mesh_generators", false, "Print out the mesh generators being executed");
52 
54  print_on.addAvailableFlags(EXEC_TRANSFER);
55  print_on.addAvailableFlags(EXEC_FAILED);
56  print_on.addAvailableFlags(EXEC_ALWAYS);
57  params.addParam<ExecFlagEnum>(
58  "show_execution_order",
59  print_on,
60  "Print more information about the order of execution during calculations");
61  params.addDeprecatedParam<bool>(
62  "pid_aux",
63  "Add a AuxVariable named \"pid\" that shows the processors and partitioning",
64  "pid_aux is deprecated, use output_process_domains");
65  params.addParam<bool>(
66  "output_process_domains",
67  false,
68  "Add a AuxVariable named \"pid\" that shows the partitioning for each process");
69  params.addParam<bool>(
70  "show_functors", false, "Whether to print information about the functors in the problem");
71  params.addParam<MultiMooseEnum>(
72  "show_block_restriction",
74  "Print out active objects like variables supplied for each block.");
75 
76  params.addClassDescription("Adds various debugging type output to the simulation system.");
77 
78  return params;
79 }
80 
82 {
83  _awh.showActionDependencies(getParam<bool>("show_action_dependencies"));
84  _awh.showActions(getParam<bool>("show_actions"));
85  _awh.showParser(getParam<bool>("show_parser"));
86  _awh.mooseApp().getMeshGeneratorSystem().setVerbose(getParam<bool>("show_mesh_generators"));
87 }
88 
89 void
91 {
92  // Material properties
93  if (_pars.get<bool>("show_material_props"))
94  {
95  const std::string type = "MaterialPropertyDebugOutput";
96  auto params = _factory.getValidParams(type);
97  _problem->addOutput(type, "_moose_material_property_debug_output", params);
98  }
99 
100  // Variable residual norms
101  if (_pars.get<bool>("show_var_residual_norms"))
102  {
103  const std::string type = "VariableResidualNormsDebugOutput";
104  auto params = _factory.getValidParams(type);
105  // Add one for every nonlinear system
106  for (const auto & sys_name : _problem->getNonlinearSystemNames())
107  {
108  params.set<NonlinearSystemName>("nl_sys") = sys_name;
109  _problem->addOutput(type, "_moose_variable_residual_norms_debug_output_" + sys_name, params);
110  }
111  }
112 
113  // Top residuals
114  if (_pars.get<unsigned int>("show_top_residuals") > 0)
115  {
116  const std::string type = "TopResidualDebugOutput";
117  auto params = _factory.getValidParams(type);
118  params.set<unsigned int>("num_residuals") = _pars.get<unsigned int>("show_top_residuals");
119  _problem->addOutput(type, "_moose_top_residual_debug_output", params);
120  }
121 
122  // Print full names of mesh meta data
123  if (getParam<bool>("show_mesh_meta_data"))
124  {
125  _console << "Mesh meta data:\n";
126  for (auto it = _app.getRestartableDataMapBegin(); it != _app.getRestartableDataMapEnd(); ++it)
127  if (it->first == MooseApp::MESH_META_DATA)
128  for (auto & data : it->second.first)
129  _console << " " << data.name() << std::endl;
130  }
131 
132  // Print Reporter information
133  if (getParam<bool>("show_reporters"))
134  {
135  const std::string type = "ReporterDebugOutput";
136  auto params = _factory.getValidParams(type);
137  _problem->addOutput(type, "_moose_reporter_debug_output", params);
138  }
139 
140  // Print execution information in all loops
141  if (parameters().isParamSetByUser("show_execution_order"))
142  _problem->setExecutionPrinting(getParam<ExecFlagEnum>("show_execution_order"));
143 
144  // Add pid aux
145  if (getParam<bool>("output_process_domains") ||
146  (isParamValid("pid_aux") && getParam<bool>("pid_aux")))
147  {
148  if (_problem->hasVariable("pid"))
149  paramError("output_process_domains", "Variable with the name \"pid\" already exists");
150 
151  auto fe_type = FEType(CONSTANT, MONOMIAL);
153  auto var_params = _factory.getValidParams(type);
154  _problem->addAuxVariable(type, "pid", var_params);
155 
156  InputParameters params = _factory.getValidParams("ProcessorIDAux");
157  params.set<AuxVariableName>("variable") = "pid";
158  params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
159  _problem->addAuxKernel("ProcessorIDAux", "pid_aux", params);
160  }
161 
162  // Add functor output
163  if (getParam<bool>("show_functors"))
164  _problem->setFunctorOutput(getParam<bool>("show_functors"));
165 
166  // Block-restriction
167  const MultiMooseEnum & block_restriction_scope =
168  _pars.get<MultiMooseEnum>("show_block_restriction");
169  if (block_restriction_scope.isValid() && !block_restriction_scope.contains("none"))
170  {
171  const std::string type = "BlockRestrictionDebugOutput";
172  auto params = _factory.getValidParams(type);
173  params.set<MultiMooseEnum>("scope") = block_restriction_scope;
174  _problem->addOutput(type, "_moose_block_restriction_debug_output", params);
175  }
176 
177  // Controllable output
178  if (getParam<bool>("show_controllable"))
179  {
180  const std::string type = "ControlOutput";
181  auto params = _factory.getValidParams(type);
182  _problem->addOutput(type, "_moose_controllable_debug_output", params);
183  }
184 }
const ExecFlagType EXEC_TRANSFER
Definition: Moose.C:51
const ExecFlagType EXEC_FAILED
Definition: Moose.C:44
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
void setVerbose(const bool verbose)
Set the verbose flag.
auto getRestartableDataMapBegin()
Iterator based access to the extra RestartableDataMap objects; see Checkpoint.C for use case...
Definition: MooseApp.h:1084
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
MooseApp & mooseApp()
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:159
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
static const RestartableDataMapName MESH_META_DATA
Definition: MooseApp.h:112
virtual bool isValid() const override
IsValid.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void showActions(bool state=true)
This method sets a Boolean which is used to show information about action execution of various wareho...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void showActionDependencies(bool state=true)
This method sets a Boolean which is used to print information about action dependencies before variou...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:47
registerMooseAction("MooseApp", SetupDebugAction, "add_output")
Base class for actions.
Definition: Action.h:33
SetupDebugAction(const InputParameters &parameters)
ExecFlagEnum getDefaultExecFlagEnum()
Return the default ExecFlagEnum for MOOSE.
Definition: MooseUtils.C:1067
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Factory & _factory
The Factory associated with the MooseApp.
bool contains(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
CONSTANT
void showParser(bool state=true)
This method sets a Boolean which is used to show debugging information when actions are inserted in t...
static InputParameters validParams()
Definition: Action.C:24
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:35
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
Determines a variable type.
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
MONOMIAL
bool isParamSetByUser(const std::string &nm) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
auto getRestartableDataMapEnd()
Definition: MooseApp.h:1086
static MultiMooseEnum getScopes(std::string default_scopes="")
Get the supported scopes of output (e.g., variables, etc.)
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
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...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:168
const InputParameters & parameters() const
Get the parameters of the object.
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...
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...
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition: MooseApp.h:867
static InputParameters validParams()
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28