LCOV - code coverage report
Current view: top level - src/actions - SetupDebugAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 97 108 89.8 %
Date: 2026-05-29 20:35:17 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14