LCOV - code coverage report
Current view: top level - src/actions - SetupDebugAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 89 100 89.0 %
Date: 2025-07-17 01:28:37 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        1827 : SetupDebugAction::validParams()
      28             : {
      29        1827 :   InputParameters params = Action::validParams();
      30        5481 :   params.addParam<unsigned int>(
      31        3654 :       "show_top_residuals", 0, "The number of top residuals to print out (0 = no output)");
      32        5481 :   params.addParam<bool>(
      33             :       "show_var_residual_norms",
      34        3654 :       false,
      35             :       "Print the residual norms of the individual solution variables at each nonlinear iteration");
      36        1827 :   params.addParam<bool>("show_action_dependencies", false, "Print out the action dependencies");
      37        1827 :   params.addParam<bool>("show_actions", false, "Print out the actions being executed");
      38        5481 :   params.addParam<bool>(
      39        3654 :       "show_parser", false, "Shows parser block extraction and debugging information");
      40        5481 :   params.addParam<bool>(
      41             :       "show_material_props",
      42        3654 :       false,
      43             :       "Print out the material properties supplied for each block, face, neighbor, and/or sideset");
      44        5481 :   params.addParam<bool>("show_controllable",
      45        3654 :                         false,
      46             :                         "Print out the controllable parameters from all input parameters");
      47        1827 :   params.addParam<bool>("show_mesh_meta_data", false, "Print out the available mesh meta data");
      48        5481 :   params.addParam<bool>(
      49        3654 :       "show_reporters", false, "Print out information about the declared and requested Reporters");
      50        5481 :   params.addParam<bool>(
      51        3654 :       "show_mesh_generators", false, "Print out the mesh generators being executed");
      52             : 
      53        1827 :   ExecFlagEnum print_on = MooseUtils::getDefaultExecFlagEnum();
      54        1827 :   print_on.addAvailableFlags(EXEC_TRANSFER);
      55        1827 :   print_on.addAvailableFlags(EXEC_FAILED);
      56        1827 :   print_on.addAvailableFlags(EXEC_ALWAYS);
      57        1827 :   params.addParam<ExecFlagEnum>(
      58             :       "show_execution_order",
      59             :       print_on,
      60             :       "Print more information about the order of execution during calculations");
      61        1827 :   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        5481 :   params.addParam<bool>(
      66             :       "output_process_domains",
      67        3654 :       false,
      68             :       "Add a AuxVariable named \"pid\" that shows the partitioning for each process");
      69        5481 :   params.addParam<bool>(
      70        3654 :       "show_functors", false, "Whether to print information about the functors in the problem");
      71        5481 :   params.addParam<MultiMooseEnum>(
      72             :       "show_block_restriction",
      73        3654 :       BlockRestrictionDebugOutput::getScopes("none"),
      74             :       "Print out active objects like variables supplied for each block.");
      75             : 
      76        1827 :   params.addClassDescription("Adds various debugging type output to the simulation system.");
      77             : 
      78        3654 :   return params;
      79        1827 : }
      80             : 
      81        1623 : SetupDebugAction::SetupDebugAction(const InputParameters & parameters) : Action(parameters)
      82             : {
      83        1623 :   _awh.showActionDependencies(getParam<bool>("show_action_dependencies"));
      84        1623 :   _awh.showActions(getParam<bool>("show_actions"));
      85        1623 :   _awh.showParser(getParam<bool>("show_parser"));
      86        1623 :   _awh.mooseApp().getMeshGeneratorSystem().setVerbose(getParam<bool>("show_mesh_generators"));
      87        1623 : }
      88             : 
      89             : void
      90        1607 : SetupDebugAction::act()
      91             : {
      92             :   // Material properties
      93        1607 :   if (_pars.get<bool>("show_material_props"))
      94             :   {
      95         206 :     const std::string type = "MaterialPropertyDebugOutput";
      96         206 :     auto params = _factory.getValidParams(type);
      97         206 :     _problem->addOutput(type, "_moose_material_property_debug_output", params);
      98         206 :   }
      99             : 
     100             :   // Variable residual norms
     101        1607 :   if (_pars.get<bool>("show_var_residual_norms"))
     102             :   {
     103         938 :     const std::string type = "VariableResidualNormsDebugOutput";
     104         938 :     auto params = _factory.getValidParams(type);
     105             :     // Add one for every nonlinear system
     106        1876 :     for (const auto & sys_name : _problem->getNonlinearSystemNames())
     107             :     {
     108         938 :       params.set<NonlinearSystemName>("nl_sys") = sys_name;
     109         938 :       _problem->addOutput(type, "_moose_variable_residual_norms_debug_output_" + sys_name, params);
     110             :     }
     111         938 :   }
     112             : 
     113             :   // Top residuals
     114        1607 :   if (_pars.get<unsigned int>("show_top_residuals") > 0)
     115             :   {
     116          27 :     const std::string type = "TopResidualDebugOutput";
     117          27 :     auto params = _factory.getValidParams(type);
     118          27 :     params.set<unsigned int>("num_residuals") = _pars.get<unsigned int>("show_top_residuals");
     119          27 :     _problem->addOutput(type, "_moose_top_residual_debug_output", params);
     120          27 :   }
     121             : 
     122             :   // Print full names of mesh meta data
     123        1607 :   if (getParam<bool>("show_mesh_meta_data"))
     124             :   {
     125          36 :     _console << "Mesh meta data:\n";
     126          72 :     for (auto it = _app.getRestartableDataMapBegin(); it != _app.getRestartableDataMapEnd(); ++it)
     127          36 :       if (it->first == MooseApp::MESH_META_DATA)
     128         368 :         for (auto & data : it->second.first)
     129         332 :           _console << " " << data.name() << std::endl;
     130             :   }
     131             : 
     132             :   // Print Reporter information
     133        1607 :   if (getParam<bool>("show_reporters"))
     134             :   {
     135          10 :     const std::string type = "ReporterDebugOutput";
     136          10 :     auto params = _factory.getValidParams(type);
     137          10 :     _problem->addOutput(type, "_moose_reporter_debug_output", params);
     138          10 :   }
     139             : 
     140             :   // Print execution information in all loops
     141        1607 :   if (parameters().isParamSetByUser("show_execution_order"))
     142         270 :     _problem->setExecutionPrinting(getParam<ExecFlagEnum>("show_execution_order"));
     143             : 
     144             :   // Add pid aux
     145        4821 :   if (getParam<bool>("output_process_domains") ||
     146        3214 :       (isParamValid("pid_aux") && getParam<bool>("pid_aux")))
     147             :   {
     148           0 :     if (_problem->hasVariable("pid"))
     149           0 :       paramError("output_process_domains", "Variable with the name \"pid\" already exists");
     150             : 
     151           0 :     auto fe_type = FEType(CONSTANT, MONOMIAL);
     152           0 :     auto type = AddAuxVariableAction::variableType(fe_type);
     153           0 :     auto var_params = _factory.getValidParams(type);
     154           0 :     _problem->addAuxVariable(type, "pid", var_params);
     155             : 
     156           0 :     InputParameters params = _factory.getValidParams("ProcessorIDAux");
     157           0 :     params.set<AuxVariableName>("variable") = "pid";
     158           0 :     params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
     159           0 :     _problem->addAuxKernel("ProcessorIDAux", "pid_aux", params);
     160           0 :   }
     161             : 
     162             :   // Add functor output
     163        1607 :   if (getParam<bool>("show_functors"))
     164          34 :     _problem->setFunctorOutput(getParam<bool>("show_functors"));
     165             : 
     166             :   // Block-restriction
     167             :   const MultiMooseEnum & block_restriction_scope =
     168        1607 :       _pars.get<MultiMooseEnum>("show_block_restriction");
     169        1607 :   if (block_restriction_scope.isValid() && !block_restriction_scope.contains("none"))
     170             :   {
     171          10 :     const std::string type = "BlockRestrictionDebugOutput";
     172          10 :     auto params = _factory.getValidParams(type);
     173          10 :     params.set<MultiMooseEnum>("scope") = block_restriction_scope;
     174          10 :     _problem->addOutput(type, "_moose_block_restriction_debug_output", params);
     175          10 :   }
     176             : 
     177             :   // Controllable output
     178        1607 :   if (getParam<bool>("show_controllable"))
     179             :   {
     180          10 :     const std::string type = "ControlOutput";
     181          10 :     auto params = _factory.getValidParams(type);
     182          10 :     _problem->addOutput(type, "_moose_controllable_debug_output", params);
     183          10 :   }
     184        1607 : }

Generated by: LCOV version 1.14