LCOV - code coverage report
Current view: top level - src/actions - CheckOutputAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 62 64 96.9 %
Date: 2026-05-29 20:35:17 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       65942 : CheckOutputAction::validParams()
      25             : {
      26       65942 :   InputParameters params = Action::validParams();
      27       65942 :   return params;
      28             : }
      29             : 
      30       65942 : CheckOutputAction::CheckOutputAction(const InputParameters & params) : Action(params) {}
      31             : 
      32             : void
      33       59841 : CheckOutputAction::act()
      34             : {
      35             :   // Perform the various output related checks
      36      119682 :   checkVariableOutput("add_variable");
      37       59841 :   checkVariableOutput("add_aux_variable");
      38       59841 :   checkMaterialOutput();
      39       59829 :   checkConsoleOutput();
      40       59829 :   checkPerfLogOutput();
      41       59829 : }
      42             : 
      43             : void
      44      119682 : CheckOutputAction::checkVariableOutput(const std::string & task)
      45             : {
      46      119682 :   if (_problem.get() == nullptr)
      47           0 :     return;
      48             : 
      49      119682 :   if (task == "add_variable")
      50             :   {
      51      118897 :     for (const auto i : make_range(_problem->numNonlinearSystems()))
      52             :     {
      53       59056 :       const auto & field_vars = _problem->getNonlinearSystemBase(i).getVariables(/*tid =*/0);
      54      114833 :       for (const auto & var : field_vars)
      55             :       {
      56       55777 :         std::set<OutputName> outputs = var->getOutputs();
      57       55777 :         _app.getOutputWarehouse().checkOutputs(outputs);
      58       55777 :       }
      59             : 
      60       59056 :       const auto & scalar_vars = _problem->getNonlinearSystemBase(i).getScalarVariables(/*tid =*/0);
      61       60281 :       for (const auto & var : scalar_vars)
      62             :       {
      63        1225 :         std::set<OutputName> outputs = var->getOutputs();
      64        1225 :         _app.getOutputWarehouse().checkOutputs(outputs);
      65        1225 :       }
      66             :     }
      67             :   }
      68             : 
      69       59841 :   else if (task == "add_aux_variable")
      70             :   {
      71       59841 :     const auto & field_vars = _problem->getAuxiliarySystem().getVariables(/*tid =*/0);
      72      151439 :     for (const auto & var : field_vars)
      73             :     {
      74       91598 :       std::set<OutputName> outputs = var->getOutputs();
      75       91598 :       _app.getOutputWarehouse().checkOutputs(outputs);
      76       91598 :     }
      77             : 
      78       59841 :     const auto & scalar_vars = _problem->getAuxiliarySystem().getScalarVariables(/*tid =*/0);
      79       61417 :     for (const auto & var : scalar_vars)
      80             :     {
      81        1576 :       std::set<OutputName> outputs = var->getOutputs();
      82        1576 :       _app.getOutputWarehouse().checkOutputs(outputs);
      83        1576 :     }
      84             :   }
      85             : }
      86             : 
      87             : void
      88       59841 : 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       59841 :   if (_problem.get() == NULL)
      93           0 :     return;
      94             : 
      95             :   // A complete list of all Material objects
      96       59841 :   const auto & materials = _problem->getMaterialWarehouse().getActiveObjects();
      97             : 
      98             :   // TODO include boundary materials
      99             : 
     100             :   // Loop through each material object
     101       73793 :   for (const auto & mat : materials)
     102             :   {
     103             :     // Extract the names of the output objects to which the material properties will be exported
     104       13964 :     std::set<OutputName> outputs = mat->getOutputs();
     105             : 
     106             :     // Check that the outputs exist, and that the output types support material output
     107       13964 :     _app.getOutputWarehouse().checkOutputs(outputs, /* supports_material_output = */ true);
     108       13952 :   }
     109             : }
     110             : 
     111             : void
     112       59829 : CheckOutputAction::checkConsoleOutput()
     113             : {
     114             :   // Warning if multiple Console objects are added with 'output_screen=true' in the input file
     115       59829 :   std::vector<Console *> console_ptrs = _app.getOutputWarehouse().getOutputs<Console>();
     116       59829 :   unsigned int num_screen_outputs = 0;
     117      119658 :   for (const auto & console : console_ptrs)
     118      179487 :     if (console->getParam<bool>("output_screen"))
     119       59829 :       num_screen_outputs++;
     120             : 
     121       59829 :   if (num_screen_outputs > 1)
     122           4 :     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       59829 : }
     128             : 
     129             : void
     130       59829 : CheckOutputAction::checkPerfLogOutput()
     131             : {
     132             : 
     133             :   // Search for the existence of a Console output object
     134       59829 :   bool has_console = false;
     135       59829 :   std::vector<Console *> ptrs = _app.getOutputWarehouse().getOutputs<Console>();
     136       59829 :   for (const auto & console : ptrs)
     137      179463 :     if (console->getParam<bool>("output_screen"))
     138             :     {
     139       59821 :       has_console = true;
     140       59821 :       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       59829 :   if (!has_console)
     146           8 :     libMesh::perflog.disable_logging();
     147       59829 : }

Generated by: LCOV version 1.14