Line data Source code
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"
20 : #include "BlockRestrictionDebugOutput.h"
21 :
22 : using namespace libMesh;
23 :
24 : registerMooseAction("MooseApp", SetupDebugAction, "add_output");
25 :
26 : InputParameters
27 1813 : SetupDebugAction::validParams()
28 : {
29 1813 : InputParameters params = Action::validParams();
30 5439 : params.addParam<unsigned int>(
31 3626 : "show_top_residuals", 0, "The number of top residuals to print out (0 = no output)");
32 5439 : params.addParam<bool>(
33 : "show_var_residual_norms",
34 3626 : false,
35 : "Print the residual norms of the individual solution variables at each nonlinear iteration");
36 7252 : params.addParam<bool>("show_action_dependencies", false, "Print out the action dependencies");
37 7252 : params.addParam<bool>("show_actions", false, "Print out the actions being executed");
38 5439 : params.addParam<bool>(
39 3626 : "show_parser", false, "Shows parser block extraction and debugging information");
40 5439 : params.addParam<bool>(
41 : "show_material_props",
42 3626 : false,
43 : "Print out the material properties supplied for each block, face, neighbor, and/or sideset");
44 5439 : params.addParam<bool>("show_chain_control_data",
45 3626 : false,
46 : "Print out the chain control data on every time step setup");
47 5439 : params.addParam<bool>("show_controllable",
48 3626 : false,
49 : "Print out the controllable parameters from all input parameters");
50 7252 : params.addParam<bool>("show_mesh_meta_data", false, "Print out the available mesh meta data");
51 5439 : params.addParam<bool>(
52 3626 : "show_reporters", false, "Print out information about the declared and requested Reporters");
53 3626 : params.addParam<bool>(
54 3626 : "show_mesh_generators", false, "Print out the mesh generators being executed");
55 :
56 1813 : ExecFlagEnum print_on = MooseUtils::getDefaultExecFlagEnum();
57 1813 : print_on.addAvailableFlags(EXEC_TRANSFER);
58 1813 : print_on.addAvailableFlags(EXEC_FAILED);
59 1813 : print_on.addAvailableFlags(EXEC_ALWAYS);
60 7252 : params.addParam<ExecFlagEnum>(
61 : "show_execution_order",
62 : print_on,
63 : "Print more information about the order of execution during calculations");
64 10878 : params.addDeprecatedParam<bool>(
65 : "pid_aux",
66 : "Add a AuxVariable named \"pid\" that shows the processors and partitioning",
67 : "pid_aux is deprecated, use output_process_domains");
68 5439 : params.addParam<bool>(
69 : "output_process_domains",
70 3626 : false,
71 : "Add a AuxVariable named \"pid\" that shows the partitioning for each process");
72 5439 : params.addParam<bool>(
73 3626 : "show_functors", false, "Whether to print information about the functors in the problem");
74 5439 : params.addParam<MultiMooseEnum>(
75 : "show_block_restriction",
76 5439 : BlockRestrictionDebugOutput::getScopes("none"),
77 : "Print out active objects like variables supplied for each block.");
78 5439 : params.addParam<bool>("show_block_restriction_groups",
79 3626 : false,
80 : "Print groups of objects with identical block restrictions.");
81 5439 : params.addParam<bool>("show_boundary_restriction_groups",
82 3626 : false,
83 : "Print groups of objects with identical boundary restrictions.");
84 5439 : params.addParam<bool>(
85 : "error_on_residual_nan",
86 3626 : false,
87 : "This option applies only to dbg and devel modes. If enabled, residual contributions are "
88 : "checked for NaN or Inf values; if found, an error is reported.");
89 :
90 1813 : params.addClassDescription("Adds various debugging type output to the simulation system.");
91 :
92 3626 : return params;
93 1813 : }
94 :
95 1769 : SetupDebugAction::SetupDebugAction(const InputParameters & parameters) : Action(parameters)
96 : {
97 3538 : _awh.showActionDependencies(getParam<bool>("show_action_dependencies"));
98 3538 : _awh.showActions(getParam<bool>("show_actions"));
99 3538 : _awh.showParser(getParam<bool>("show_parser"));
100 3538 : _awh.mooseApp().getMeshGeneratorSystem().setVerbose(getParam<bool>("show_mesh_generators"));
101 1769 : }
102 :
103 : void
104 1756 : SetupDebugAction::act()
105 : {
106 : // Material properties
107 1756 : if (_pars.get<bool>("show_material_props"))
108 : {
109 259 : const std::string type = "MaterialPropertyDebugOutput";
110 259 : auto params = _factory.getValidParams(type);
111 518 : _problem->addOutput(type, "_moose_material_property_debug_output", params);
112 259 : }
113 :
114 : // Variable residual norms
115 1756 : if (_pars.get<bool>("show_var_residual_norms"))
116 : {
117 1072 : const std::string type = "VariableResidualNormsDebugOutput";
118 1072 : auto params = _factory.getValidParams(type);
119 : // Add one for every nonlinear system
120 2144 : for (const auto & sys_name : _problem->getNonlinearSystemNames())
121 : {
122 1072 : params.set<NonlinearSystemName>("nl_sys") = sys_name;
123 1072 : _problem->addOutput(type, "_moose_variable_residual_norms_debug_output_" + sys_name, params);
124 : }
125 1072 : }
126 :
127 : // Top residuals
128 1756 : if (_pars.get<unsigned int>("show_top_residuals") > 0)
129 : {
130 22 : const std::string type = "TopResidualDebugOutput";
131 22 : auto params = _factory.getValidParams(type);
132 44 : params.set<unsigned int>("num_residuals") = _pars.get<unsigned int>("show_top_residuals");
133 44 : _problem->addOutput(type, "_moose_top_residual_debug_output", params);
134 22 : }
135 :
136 : // Print full names of mesh meta data
137 5268 : if (getParam<bool>("show_mesh_meta_data"))
138 : {
139 32 : _console << "Mesh meta data:\n";
140 64 : for (auto it = _app.getRestartableDataMapBegin(); it != _app.getRestartableDataMapEnd(); ++it)
141 32 : if (it->first == MooseApp::MESH_META_DATA)
142 327 : for (auto & data : it->second.first)
143 295 : _console << " " << data.name() << std::endl;
144 : }
145 :
146 : // Print Reporter information
147 5268 : if (getParam<bool>("show_reporters"))
148 : {
149 9 : const std::string type = "ReporterDebugOutput";
150 9 : auto params = _factory.getValidParams(type);
151 18 : _problem->addOutput(type, "_moose_reporter_debug_output", params);
152 9 : }
153 :
154 : // Print execution information in all loops
155 5268 : if (parameters().isParamSetByUser("show_execution_order"))
156 672 : _problem->setExecutionPrinting(getParam<ExecFlagEnum>("show_execution_order"));
157 :
158 : // Add pid aux
159 8780 : if (getParam<bool>("output_process_domains") ||
160 7024 : (isParamValid("pid_aux") && getParam<bool>("pid_aux")))
161 : {
162 0 : if (_problem->hasVariable("pid"))
163 0 : paramError("output_process_domains", "Variable with the name \"pid\" already exists");
164 :
165 0 : auto fe_type = FEType(CONSTANT, MONOMIAL);
166 0 : auto type = AddAuxVariableAction::variableType(fe_type);
167 0 : auto var_params = _factory.getValidParams(type);
168 0 : _problem->addAuxVariable(type, "pid", var_params);
169 :
170 0 : InputParameters params = _factory.getValidParams("ProcessorIDAux");
171 0 : params.set<AuxVariableName>("variable") = "pid";
172 0 : params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
173 0 : _problem->addAuxKernel("ProcessorIDAux", "pid_aux", params);
174 0 : }
175 :
176 : // Add functor output
177 5268 : if (getParam<bool>("show_functors"))
178 99 : _problem->setFunctorOutput(getParam<bool>("show_functors"));
179 :
180 : // Add chain control data output
181 5268 : if (getParam<bool>("show_chain_control_data"))
182 12 : _problem->setChainControlDataOutput(true);
183 :
184 : // Block-restriction
185 : const MultiMooseEnum & block_restriction_scope =
186 1756 : _pars.get<MultiMooseEnum>("show_block_restriction");
187 : const bool show_block_restriction_map =
188 3512 : block_restriction_scope.isValid() && !block_restriction_scope.contains("none");
189 3512 : const bool show_block_restriction_groups = getParam<bool>("show_block_restriction_groups");
190 3512 : const bool show_boundary_restriction_groups = getParam<bool>("show_boundary_restriction_groups");
191 1756 : if (show_block_restriction_map || show_block_restriction_groups ||
192 : show_boundary_restriction_groups)
193 : {
194 18 : const std::string type = "BlockRestrictionDebugOutput";
195 18 : auto params = _factory.getValidParams(type);
196 18 : params.set<MultiMooseEnum>("scope") = block_restriction_scope;
197 36 : params.set<bool>("show_block_restriction_map") = show_block_restriction_map;
198 36 : params.set<bool>("show_block_restriction_groups") = show_block_restriction_groups;
199 36 : params.set<bool>("show_boundary_restriction_groups") = show_boundary_restriction_groups;
200 36 : _problem->addOutput(type, "_moose_block_restriction_debug_output", params);
201 18 : }
202 :
203 : // Controllable output
204 5268 : if (getParam<bool>("show_controllable"))
205 : {
206 9 : const std::string type = "ControlOutput";
207 9 : auto params = _factory.getValidParams(type);
208 18 : _problem->addOutput(type, "_moose_controllable_debug_output", params);
209 9 : }
210 :
211 : // Enable residual NaN/Inf-checking
212 5268 : if (getParam<bool>("error_on_residual_nan"))
213 : {
214 : #ifdef NDEBUG
215 3 : mooseError("The parameter 'error_on_residual_nan' may only be set to 'true' for 'dbg' and "
216 : "'devel' modes.");
217 : #else
218 : _problem->setCheckResidualForNans(true);
219 : #endif
220 : }
221 1753 : }
|