LCOV - code coverage report
Current view: top level - src/actions - CheckOutputAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 62 64 96.9 %
Date: 2025-08-08 20:01:16 Functions: 7 7 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             : // MOOSE includes
      11             : #include "CheckOutputAction.h"
      12             : #include "Material.h"
      13             : #include "MooseApp.h"
      14             : #include "Console.h"
      15             : #include "CommonOutputAction.h"
      16             : #include "MooseVariableFEBase.h"
      17             : #include "MooseVariableScalar.h"
      18             : #include "AuxiliarySystem.h"
      19             : #include "NonlinearSystemBase.h"
      20             : 
      21             : registerMooseAction("MooseApp", CheckOutputAction, "check_output");
      22             : 
      23             : InputParameters
      24       66787 : CheckOutputAction::validParams()
      25             : {
      26       66787 :   InputParameters params = Action::validParams();
      27       66787 :   return params;
      28             : }
      29             : 
      30       66787 : CheckOutputAction::CheckOutputAction(const InputParameters & params) : Action(params) {}
      31             : 
      32             : void
      33       60571 : CheckOutputAction::act()
      34             : {
      35             :   // Perform the various output related checks
      36       60571 :   checkVariableOutput("add_variable");
      37       60571 :   checkVariableOutput("add_aux_variable");
      38       60571 :   checkMaterialOutput();
      39       60555 :   checkConsoleOutput();
      40       60555 :   checkPerfLogOutput();
      41       60555 : }
      42             : 
      43             : void
      44      121142 : CheckOutputAction::checkVariableOutput(const std::string & task)
      45             : {
      46      121142 :   if (_problem.get() == nullptr)
      47           0 :     return;
      48             : 
      49      121142 :   if (task == "add_variable")
      50             :   {
      51      120077 :     for (const auto i : make_range(_problem->numNonlinearSystems()))
      52             :     {
      53       59506 :       const auto & field_vars = _problem->getNonlinearSystemBase(i).getVariables(/*tid =*/0);
      54      118336 :       for (const auto & var : field_vars)
      55             :       {
      56       58830 :         std::set<OutputName> outputs = var->getOutputs();
      57       58830 :         _app.getOutputWarehouse().checkOutputs(outputs);
      58       58830 :       }
      59             : 
      60       59506 :       const auto & scalar_vars = _problem->getNonlinearSystemBase(i).getScalarVariables(/*tid =*/0);
      61       60895 :       for (const auto & var : scalar_vars)
      62             :       {
      63        1389 :         std::set<OutputName> outputs = var->getOutputs();
      64        1389 :         _app.getOutputWarehouse().checkOutputs(outputs);
      65        1389 :       }
      66             :     }
      67             :   }
      68             : 
      69       60571 :   else if (task == "add_aux_variable")
      70             :   {
      71       60571 :     const auto & field_vars = _problem->getAuxiliarySystem().getVariables(/*tid =*/0);
      72      152910 :     for (const auto & var : field_vars)
      73             :     {
      74       92339 :       std::set<OutputName> outputs = var->getOutputs();
      75       92339 :       _app.getOutputWarehouse().checkOutputs(outputs);
      76       92339 :     }
      77             : 
      78       60571 :     const auto & scalar_vars = _problem->getAuxiliarySystem().getScalarVariables(/*tid =*/0);
      79       62364 :     for (const auto & var : scalar_vars)
      80             :     {
      81        1793 :       std::set<OutputName> outputs = var->getOutputs();
      82        1793 :       _app.getOutputWarehouse().checkOutputs(outputs);
      83        1793 :     }
      84             :   }
      85             : }
      86             : 
      87             : void
      88       60571 : CheckOutputAction::checkMaterialOutput()
      89             : {
      90             :   // Do nothing if _problem is NULL (this is the case for coupled problems)
      91             :   // Do not produce warning, you will get a warning from OutputAction
      92       60571 :   if (_problem.get() == NULL)
      93           0 :     return;
      94             : 
      95             :   // A complete list of all Material objects
      96       60571 :   const auto & materials = _problem->getMaterialWarehouse().getActiveObjects();
      97             : 
      98             :   // TODO include boundary materials
      99             : 
     100             :   // Loop through each material object
     101       74261 :   for (const auto & mat : materials)
     102             :   {
     103             :     // Extract the names of the output objects to which the material properties will be exported
     104       13706 :     std::set<OutputName> outputs = mat->getOutputs();
     105             : 
     106             :     // Check that the outputs exist, and that the output types support material output
     107       13706 :     _app.getOutputWarehouse().checkOutputs(outputs, /* supports_material_output = */ true);
     108       13690 :   }
     109             : }
     110             : 
     111             : void
     112       60555 : CheckOutputAction::checkConsoleOutput()
     113             : {
     114             :   // Warning if multiple Console objects are added with 'output_screen=true' in the input file
     115       60555 :   std::vector<Console *> console_ptrs = _app.getOutputWarehouse().getOutputs<Console>();
     116       60555 :   unsigned int num_screen_outputs = 0;
     117      121123 :   for (const auto & console : console_ptrs)
     118       60568 :     if (console->getParam<bool>("output_screen"))
     119       60568 :       num_screen_outputs++;
     120             : 
     121       60555 :   if (num_screen_outputs > 1)
     122           7 :     mooseWarning("Multiple (",
     123             :                  num_screen_outputs,
     124             :                  ") Console output objects are writing to the "
     125             :                  "screen, this will likely cause duplicate "
     126             :                  "messages printed.");
     127       60555 : }
     128             : 
     129             : void
     130       60555 : CheckOutputAction::checkPerfLogOutput()
     131             : {
     132             : 
     133             :   // Search for the existence of a Console output object
     134       60555 :   bool has_console = false;
     135       60555 :   std::vector<Console *> ptrs = _app.getOutputWarehouse().getOutputs<Console>();
     136       60555 :   for (const auto & console : ptrs)
     137       60554 :     if (console->getParam<bool>("output_screen"))
     138             :     {
     139       60554 :       has_console = true;
     140       60554 :       break;
     141             :     }
     142             : 
     143             :   // If a Console outputter is found then all the correct handling of performance logs are
     144             :   // handled within the object(s), so do nothing
     145       60555 :   if (!has_console)
     146           1 :     libMesh::perflog.disable_logging();
     147       60555 : }

Generated by: LCOV version 1.14