https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
19#include "MooseUtils.h"
21
22registerMooseAction("MooseApp", SetupDebugAction, "add_output");
23
26{
28 params.addParam<unsigned int>(
29 "show_top_residuals", 0, "The number of top residuals to print out (0 = no output)");
30 params.addParam<bool>(
31 "show_var_residual_norms",
32 false,
33 "Print the residual norms of the individual solution variables at each nonlinear iteration");
34 params.addParam<bool>("show_action_dependencies", false, "Print out the action dependencies");
35 params.addParam<bool>("show_actions", false, "Print out the actions being executed");
36 params.addParam<bool>(
37 "show_parser", false, "Shows parser block extraction and debugging information");
38 params.addParam<bool>(
39 "show_material_props",
40 false,
41 "Print out the material properties supplied for each block, face, neighbor, and/or sideset");
42 params.addParam<bool>("show_chain_control_data",
43 false,
44 "Print out the chain control data on every time step setup");
45 params.addParam<bool>("show_controllable",
46 false,
47 "Print out the controllable parameters from all input parameters");
48 params.addParam<bool>("show_mesh_meta_data", false, "Print out the available mesh meta data");
49 params.addParam<bool>(
50 "show_reporters", false, "Print out information about the declared and requested Reporters");
51 params.addParam<bool>(
52 "show_mesh_generators", false, "Print out the mesh generators being executed");
53
55 print_on.addAvailableFlags(EXEC_TRANSFER);
56 print_on.addAvailableFlags(EXEC_FAILED);
57 print_on.addAvailableFlags(EXEC_ALWAYS);
58 params.addParam<ExecFlagEnum>(
59 "show_execution_order",
60 print_on,
61 "Print more information about the order of execution during calculations");
62 params.addDeprecatedParam<bool>(
63 "pid_aux",
64 "Add a AuxVariable named \"pid\" that shows the processors and partitioning",
65 "pid_aux is deprecated, use output_process_domains");
66 params.addParam<bool>(
67 "output_process_domains",
68 false,
69 "Add a AuxVariable named \"pid\" that shows the partitioning for each process");
70 params.addParam<bool>(
71 "show_functors", false, "Whether to print information about the functors in the problem");
73 "show_block_restriction",
75 "Print out active objects like variables supplied for each block.");
76 params.addParam<bool>("show_block_restriction_groups",
77 false,
78 "Print groups of objects with identical block restrictions.");
79 params.addParam<bool>("show_boundary_restriction_groups",
80 false,
81 "Print groups of objects with identical boundary restrictions.");
82 params.addParam<bool>(
83 "error_on_residual_nan",
84 false,
85 "This option applies only to dbg and devel modes. If enabled, residual contributions are "
86 "checked for NaN or Inf values; if found, an error is reported.");
87
88 params.addClassDescription("Adds various debugging type output to the simulation system.");
89
90 return params;
91}
92
94{
95 _awh.showActionDependencies(getParam<bool>("show_action_dependencies"));
96 _awh.showActions(getParam<bool>("show_actions"));
97 _awh.showParser(getParam<bool>("show_parser"));
98 _awh.mooseApp().getMeshGeneratorSystem().setVerbose(getParam<bool>("show_mesh_generators"));
99}
100
101void
103{
104 // Material properties
105 if (_pars.get<bool>("show_material_props"))
106 {
107 const std::string type = "MaterialPropertyDebugOutput";
108 auto params = _factory.getValidParams(type);
109 _problem->addOutput(type, "_moose_material_property_debug_output", params);
110 }
111
112 // Variable residual norms
113 if (_pars.get<bool>("show_var_residual_norms"))
114 {
115 const std::string type = "VariableResidualNormsDebugOutput";
116 auto params = _factory.getValidParams(type);
117 // Add one for every nonlinear system
118 for (const auto & sys_name : _problem->getNonlinearSystemNames())
119 {
120 params.set<NonlinearSystemName>("nl_sys") = sys_name;
121 _problem->addOutput(type, "_moose_variable_residual_norms_debug_output_" + sys_name, params);
122 }
123 }
124
125 // Top residuals
126 if (_pars.get<unsigned int>("show_top_residuals") > 0)
127 {
128 const std::string type = "TopResidualDebugOutput";
129 auto params = _factory.getValidParams(type);
130 params.set<unsigned int>("num_residuals") = _pars.get<unsigned int>("show_top_residuals");
131 _problem->addOutput(type, "_moose_top_residual_debug_output", params);
132 }
133
134 // Print full names of mesh meta data
135 if (getParam<bool>("show_mesh_meta_data"))
136 {
137 _console << "Mesh meta data:\n";
138 for (auto it = _app.getRestartableDataMapBegin(); it != _app.getRestartableDataMapEnd(); ++it)
139 if (it->first == MooseApp::MESH_META_DATA)
140 for (auto & data : it->second.first)
141 _console << " " << data.name() << std::endl;
142 }
143
144 // Print Reporter information
145 if (getParam<bool>("show_reporters"))
146 {
147 const std::string type = "ReporterDebugOutput";
148 auto params = _factory.getValidParams(type);
149 _problem->addOutput(type, "_moose_reporter_debug_output", params);
150 }
151
152 // Print execution information in all loops
153 if (parameters().isParamSetByUser("show_execution_order"))
154 _problem->setExecutionPrinting(getParam<ExecFlagEnum>("show_execution_order"));
155
156 // Add pid aux
157 if (getParam<bool>("output_process_domains") ||
158 (isParamValid("pid_aux") && getParam<bool>("pid_aux")))
159 {
160 if (_problem->hasVariable("pid"))
161 paramError("output_process_domains", "Variable with the name \"pid\" already exists");
162
163 auto fe_type = FEType(CONSTANT, MONOMIAL);
165 auto var_params = _factory.getValidParams(type);
166 _problem->addAuxVariable(type, "pid", var_params);
167
168 InputParameters params = _factory.getValidParams("ProcessorIDAux");
169 params.set<AuxVariableName>("variable") = "pid";
170 params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
171 _problem->addAuxKernel("ProcessorIDAux", "pid_aux", params);
172 }
173
174 // Add functor output
175 if (getParam<bool>("show_functors"))
176 _problem->setFunctorOutput(getParam<bool>("show_functors"));
177
178 // Add chain control data output
179 if (getParam<bool>("show_chain_control_data"))
180 _problem->setChainControlDataOutput(true);
181
182 // Block-restriction
183 const MultiMooseEnum & block_restriction_scope =
184 _pars.get<MultiMooseEnum>("show_block_restriction");
185 const bool show_block_restriction_map =
186 block_restriction_scope.isValid() && !block_restriction_scope.contains("none");
187 const bool show_block_restriction_groups = getParam<bool>("show_block_restriction_groups");
188 const bool show_boundary_restriction_groups = getParam<bool>("show_boundary_restriction_groups");
189 if (show_block_restriction_map || show_block_restriction_groups ||
190 show_boundary_restriction_groups)
191 {
192 const std::string type = "BlockRestrictionDebugOutput";
193 auto params = _factory.getValidParams(type);
194 params.set<MultiMooseEnum>("scope") = block_restriction_scope;
195 params.set<bool>("show_block_restriction_map") = show_block_restriction_map;
196 params.set<bool>("show_block_restriction_groups") = show_block_restriction_groups;
197 params.set<bool>("show_boundary_restriction_groups") = show_boundary_restriction_groups;
198 _problem->addOutput(type, "_moose_block_restriction_debug_output", params);
199 }
200
201 // Controllable output
202 if (getParam<bool>("show_controllable"))
203 {
204 const std::string type = "ControlOutput";
205 auto params = _factory.getValidParams(type);
206 _problem->addOutput(type, "_moose_controllable_debug_output", params);
207 }
208
209 // Enable residual NaN/Inf-checking
210 if (getParam<bool>("error_on_residual_nan"))
211 {
212#ifdef NDEBUG
213 mooseError("The parameter 'error_on_residual_nan' may only be set to 'true' for 'dbg' and "
214 "'devel' modes.");
215#else
216 _problem->setCheckResidualForNans(true);
217#endif
218 }
219}
const ExecFlagType EXEC_TRANSFER
Definition Moose.C:58
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:38
const ExecFlagType EXEC_ALWAYS
Definition Moose.C:54
const ExecFlagType EXEC_INITIAL
Definition Moose.C:31
const ExecFlagType EXEC_FAILED
Definition Moose.C:51
registerMooseAction("MooseApp", SetupDebugAction, "add_output")
void showActionDependencies(bool state=true)
This method sets a Boolean which is used to print information about action dependencies before variou...
MooseApp & mooseApp()
void showParser(bool state=true)
This method sets a Boolean which is used to show debugging information when actions are inserted in t...
void showActions(bool state=true)
This method sets a Boolean which is used to show information about action execution of various wareho...
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition Action.h:169
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
Determines a variable type.
static MultiMooseEnum getScopes(std::string default_scopes="")
Get the supported scopes of output (e.g., variables, etc.)
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
A MultiMooseEnum object to hold "execute_on" flags.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
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 addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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.
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.
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:1079
auto getRestartableDataMapEnd()
Definition MooseApp.h:1081
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition MooseApp.h:886
static const RestartableDataMapName MESH_META_DATA
Definition MooseApp.h:136
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
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 ...
Definition MooseBase.h:457
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
const InputParameters & _pars
The object's parameters.
Definition MooseBase.h:384
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
bool contains(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
virtual bool isValid() const override
IsValid.
Factory & _factory
The Factory associated with the MooseApp.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
static InputParameters validParams()
SetupDebugAction(const InputParameters &parameters)
ExecFlagEnum getDefaultExecFlagEnum()
Definition MooseUtils.C:972