LCOV - code coverage report
Current view: top level - include/outputs - AdvancedOutput.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 33 33 100.0 %
Date: 2025-08-08 20:01:16 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             : #pragma once
      11             : 
      12             : // MOOSE includes
      13             : #include "AdvancedOutputUtils.h" // OutputDataWarehouse
      14             : #include "MooseTypes.h"
      15             : #include "UserObject.h"
      16             : #include "ExecuteMooseObjectWarehouse.h"
      17             : #include "FileOutput.h"
      18             : 
      19             : // Forward declarations
      20             : class OutputWarehouse;
      21             : class FileOutput;
      22             : class PetscOutput;
      23             : class Console;
      24             : class TransientMultiApp;
      25             : 
      26             : /**
      27             :  * Based class for output objects
      28             :  *
      29             :  * Each output class (e.g., Exodus) should inherit from this base class. At a minimum, the pure
      30             :  * virtual methods for the various types of output must be defined in the child class.
      31             :  *
      32             :  * @see Exodus Console CSV
      33             :  */
      34             : class AdvancedOutput : public FileOutput
      35             : {
      36             : public:
      37             :   static InputParameters validParams();
      38             : 
      39             :   /**
      40             :    * Class constructor
      41             :    *
      42             :    * The constructor performs all of the necessary initialization of the various
      43             :    * output lists required for the various output types.
      44             :    * @param parameters The InputParameters for the object
      45             :    */
      46             :   AdvancedOutput(const InputParameters & parameters);
      47             : 
      48             :   /**
      49             :    * Class destructor
      50             :    */
      51             :   virtual ~AdvancedOutput();
      52             : 
      53             :   /**
      54             :    * Returns true if any of the other has methods return true.
      55             :    */
      56             :   virtual bool hasOutput();
      57             : 
      58             :   /**
      59             :    * Tests that any output exist for the given output type
      60             :    *
      61             :    * @see Exodus
      62             :    */
      63             :   bool hasOutput(const ExecFlagType & type);
      64             : 
      65             :   /**
      66             :    * Returns true if there exists nodal nonlinear variables for output
      67             :    * @return True if nonlinear variable output exists
      68             :    * @see getNodalVariableOutput
      69             :    */
      70             :   bool hasNodalVariableOutput();
      71             : 
      72             :   /**
      73             :    * The list of nodal nonlinear variables names that are set for output
      74             :    * @return A vector of strings containing the names of the nodal nonlinear variables for output
      75             :    *
      76             :    * Note: The list returned by this will contain the names of both elemental and nodal variable
      77             :    * names if 'elemental_as_nodal = true' in the input file. The libMesh output system
      78             :    * (EquationSystems::build_solution_vector) performs the correct action within the solution vector
      79             :    * by setting the nodal values as the average of the values for each of the element that the node
      80             :    * shares.
      81             :    *
      82             :    * @see hasNodalVariableOutput
      83             :    */
      84             :   const std::set<std::string> & getNodalVariableOutput();
      85             : 
      86             :   /**
      87             :    * Returns true if there exists elemental nonlinear variables for output
      88             :    * @return True if nonlinear variable output exists
      89             :    * @see getElementalVariableOutput
      90             :    */
      91             :   bool hasElementalVariableOutput();
      92             : 
      93             :   /**
      94             :    * The list of elemental nonlinear variables names that are set for output
      95             :    * @return A vector of strings containing the names of the nonlinear variables for output
      96             :    * @see hasElementalVariableOutput
      97             :    */
      98             :   const std::set<std::string> & getElementalVariableOutput();
      99             : 
     100             :   /**
     101             :    * Returns true if there exists scalar variables for output
     102             :    * @return True if scalar variable output exists
     103             :    * @see getScalarVariableOutput
     104             :    */
     105             :   bool hasScalarOutput();
     106             : 
     107             :   /**
     108             :    * The list of scalar variables names that are set for output
     109             :    * @return A vector of strings containing the names of the scalar variables for output
     110             :    * @see hasScalarVariableOutput
     111             :    */
     112             :   const std::set<std::string> & getScalarOutput();
     113             : 
     114             :   /**
     115             :    * Returns true if there exists postprocessors for output
     116             :    * @return True if postprocessor output exists
     117             :    * @see getPostprocessorOutput
     118             :    */
     119             :   bool hasPostprocessorOutput();
     120             : 
     121             :   /**
     122             :    * The list of postprocessor names that are set for output
     123             :    * @return A vector of strings containing the names of the postprocessor variables for output
     124             :    * @see hasPostprocessorOutput
     125             :    */
     126             :   const std::set<std::string> & getPostprocessorOutput();
     127             : 
     128             :   /**
     129             :    * Returns true if there exists VectorPostprocessors for output
     130             :    * @return True if VectorPostprocessor output exists
     131             :    * @see getVectorPostprocessorOutput
     132             :    */
     133             :   bool hasVectorPostprocessorOutput();
     134             : 
     135             :   /**
     136             :    * The list of VectorPostprocessor names that are set for output
     137             :    * @return A vector of strings containing the names of the VectorPostprocessor variables for
     138             :    * output
     139             :    * @see hasVectorPostprocessorOutput
     140             :    */
     141             :   const std::set<std::string> & getVectorPostprocessorOutput();
     142             : 
     143             :   /**
     144             :    * Returns true if there exists Reporter for output
     145             :    * @return True if Reporter output exists
     146             :    * @see getReporterOutput
     147             :    */
     148             :   bool hasReporterOutput();
     149             : 
     150             :   /**
     151             :    * The list of Reporter names that are set for output
     152             :    * @return A vector  containing the names of the Reporter names for output
     153             :    * @see hasReporterOutput
     154             :    */
     155             :   const std::set<std::string> & getReporterOutput();
     156             : 
     157             :   /**
     158             :    * A method for enabling individual output type control
     159             :    * @param names (optional) Space separated of output type names that are supported by this Output
     160             :    * object,
     161             :    *              if this is omitted all outputs types will be supported. The list of available
     162             :    * output
     163             :    *              types is given below.
     164             :    *
     165             :    * Output objects vary widely in what type of outputs they support (e.g., elemental variables,
     166             :    * or postprocessor data). This method provides the user a means for controlling the types of
     167             :    * outputs that are supported for the object being created. This is a static method that MUST
     168             :    * be used to append parameters inside the objects validParams function.
     169             :    *
     170             :    * List of Output Types and Method Names
     171             :    * The output system is designed around overloading virtual method calls to output the
     172             :    * various output types, the following list gives the name of the output type and the associated
     173             :    * virtual method that should be overloaded to perform the output in the object being created.
     174             :    *
     175             :    * Type                 virtual Method Name
     176             :    * -------------------- ----------------------------
     177             :    * nodal                outputNodalVariables()
     178             :    * elemental            outputElementalVariables()
     179             :    * scalar               outputScalarVariables()
     180             :    * postprocessor        outputPostprocessors()
     181             :    * vector_postprocessor outputVectorPostprocessors()
     182             :    * input                outputInput()
     183             :    * system_information   outputSystemInformation()
     184             :    *
     185             :    * @see CSV Exodus
     186             :    */
     187             :   static InputParameters enableOutputTypes(const std::string & names = std::string());
     188             : 
     189             :   /**
     190             :    * Get the current advanced 'execute_on' selections for display
     191             :    */
     192             :   const OutputOnWarehouse & advancedExecuteOn() const;
     193             : 
     194             : protected:
     195             :   /// Call init() method on setup
     196             :   virtual void initialSetup();
     197             : 
     198             :   /**
     199             :    * Populates the various data structures needed to control the output
     200             :    */
     201             :   virtual void init();
     202             : 
     203             :   /// Add an additional variable to the hide list
     204          26 :   void hideAdditionalVariable(const std::string & category, const std::string & var_name)
     205             :   {
     206          26 :     _execute_data[category].hide.insert(var_name);
     207          26 :     _execute_data[category].output.erase(var_name);
     208          26 :   }
     209             : 
     210             :   /**
     211             :    * Handles logic for determining if a step should be output
     212             :    * @return True if a call if output should be performed
     213             :    */
     214             :   virtual bool shouldOutput();
     215             : 
     216             :   /**
     217             :    * A single call to this function should output all the necessary data for a single timestep. By
     218             :    * default this function performs calls each of the four virtual output methods:
     219             :    * outputScalarVariables(),
     220             :    * outputPostprocessors(), outputElementalVariables(), and outputNodalVariables(). But, only if
     221             :    * output exists
     222             :    * for each type.
     223             :    *
     224             :    * @see outputNodalVariables outputElementalVariables outputScalarVariables outputPostprocessors
     225             :    */
     226             :   virtual void output();
     227             : 
     228             :   /**
     229             :    * Performs output of nodal nonlinear variables
     230             :    * The child class must define this method to output the nonlinear variables as desired
     231             :    * @see Exodus::outputNodalVariables
     232             :    */
     233             :   virtual void outputNodalVariables();
     234             : 
     235             :   /**
     236             :    * Performs output of elemental nonlinear variables
     237             :    * The child class must define this method to output the nonlinear variables as desired
     238             :    * @see Exodus::outputElementalVariables
     239             :    */
     240             :   virtual void outputElementalVariables();
     241             : 
     242             :   /**
     243             :    * Performs output of scalar variables
     244             :    * The child class must define this method to output the scalar variables as desired
     245             :    * @see Exodus::outputScalarVariables
     246             :    */
     247             :   virtual void outputScalarVariables();
     248             : 
     249             :   /**
     250             :    * Performs output of postprocessors
     251             :    * The child class must define this method to output the postprocessors as desired
     252             :    * @see Exodus::outputPostprocessors
     253             :    */
     254             :   virtual void outputPostprocessors();
     255             : 
     256             :   /**
     257             :    * Performs output of VectorPostprocessors
     258             :    * The child class must define this method to output the VectorPostprocessors as desired
     259             :    */
     260             :   virtual void outputVectorPostprocessors();
     261             : 
     262             :   /**
     263             :    * Performs the output of the input file
     264             :    * By default this method does nothing and is not called, the individual Output objects are
     265             :    * responsible for calling it
     266             :    */
     267             :   virtual void outputInput();
     268             : 
     269             :   /**
     270             :    * \todo{Make this call automatic in similar fashion to outputInput}
     271             :    * Performs the output of system information
     272             :    * By default this method does nothing and is not called by output()
     273             :    */
     274             :   virtual void outputSystemInformation();
     275             : 
     276             :   /**
     277             :    * Output Reporter values.
     278             :    * The child class must define this method to output the Reporter values as desired
     279             :    * @see CSV::outputReporters
     280             :    */
     281             :   virtual void outputReporters();
     282             : 
     283             :   /**
     284             :    * Flags to control nodal output
     285             :    */
     286             :   bool _elemental_as_nodal, _scalar_as_nodal;
     287             : 
     288             :   /// Storage for Reporter values
     289             :   const ReporterData & _reporter_data;
     290             : 
     291             : private:
     292             :   /**
     293             :    * Initializes the available lists for each of the output types
     294             :    */
     295             :   void initAvailableLists();
     296             : 
     297             :   /**
     298             :    * Initialize the possible execution types
     299             :    * @param name The name of the supplied MultiMoose enum from the _execute_on std::map (e.g.,
     300             :    * scalars)
     301             :    * @param input The ExecFlagEnum for output type flags to initialize
     302             :    */
     303             :   void initExecutionTypes(const std::string & name, ExecFlagEnum & input);
     304             : 
     305             :   /**
     306             :    * Parses the user-supplied input for hiding and showing variables and postprocessors into
     307             :    * a list for each type of output
     308             :    * @param show The vector of names that are to be output
     309             :    * @param hide The vector of names that are to be suppressed from the output
     310             :    */
     311             :   void initShowHideLists(const std::vector<VariableName> & show,
     312             :                          const std::vector<VariableName> & hide);
     313             : 
     314             :   /**
     315             :    * Helper function for initAvailableLists, templated on warehouse type and postprocessor_type
     316             :    * @param execute_data_name Name of the OutputData struct to initialize
     317             :    * @param warehouse Reference to the postprocessor or vector postprocessor warehouse
     318             :    */
     319             :   template <typename postprocessor_type>
     320             :   void initPostprocessorOrVectorPostprocessorLists(const std::string & execute_data_name);
     321             : 
     322             :   /**
     323             :    * Initializes the list of items to be output using the available, show, and hide lists
     324             :    * @param data The OutputData to operate on
     325             :    */
     326             :   void initOutputList(OutputData & data);
     327             : 
     328             :   /**
     329             :    * Handles logic for determining if a step should be output
     330             :    * @return True if a call if output should be performed
     331             :    */
     332             :   bool wantOutput(const std::string & name, const ExecFlagType & type);
     333             : 
     334             :   /**
     335             :    * Method for defining the available parameters based on the types of outputs
     336             :    * @param params The InputParamters object to add parameters to
     337             :    * @param types The types of output this object should support (see Output::enableOutputTypes)
     338             :    *
     339             :    * Each output object may have a varying set of supported output types (e.g., elemental
     340             :    * variables may not be supported). This private, static method populates the InputParameters
     341             :    * object with the correct parameters based on the items contained in the ExecFlagEnum.
     342             :    *
     343             :    * This method is private, users should utilize the Output::enableOutputTypes method
     344             :    *
     345             :    * @see Output::enableOutputTypes
     346             :    */
     347             :   static void addValidParams(InputParameters & params, const MultiMooseEnum & types);
     348             : 
     349             :   /**
     350             :    * Helper method for checking if output types exists
     351             :    * @param name The name of the output type to test (e.g., postprocessors)
     352             :    */
     353             :   bool hasOutputHelper(const std::string & name);
     354             : 
     355             :   /**
     356             :    * Get the supported types of output (e.g., postprocessors, etc.)
     357             :    */
     358             :   static MultiMooseEnum getOutputTypes();
     359             : 
     360             :   /// Storage structures for the various output types
     361             :   OutputDataWarehouse _execute_data;
     362             : 
     363             :   /// Storage for the last output time for the various output types, this is used to avoid duplicate output when using OUTPUT_FINAL flag
     364             :   std::map<std::string, Real> & _last_execute_time;
     365             : 
     366             :   /// Flags for outputting PP/VPP data as a reporter
     367             :   const bool _postprocessors_as_reporters, _vectorpostprocessors_as_reporters;
     368             : 
     369             :   // Allow complete access
     370             :   friend class OutputWarehouse;
     371             :   friend class Console;
     372             :   friend class TransientMultiApp;
     373             : };
     374             : 
     375             : // Helper function for initAvailableLists, templated on warehouse type and postprocessor_type
     376             : template <typename postprocessor_type>
     377             : void
     378      731252 : AdvancedOutput::initPostprocessorOrVectorPostprocessorLists(const std::string & execute_data_name)
     379             : {
     380             :   // Convenience reference to the OutputData being operated on (should used "postprocessors" or
     381             :   // "vector_postprocessors")
     382      731252 :   OutputData & execute_data = _execute_data[execute_data_name];
     383             : 
     384             :   // Build the input file parameter name (i.e. "output_postprocessors_on" or
     385             :   // "output_vector_postprocessors_on")
     386      731252 :   std::ostringstream oss;
     387      731252 :   oss << "execute_" << execute_data_name << "_on";
     388      731252 :   std::string execute_on_name = oss.str();
     389             : 
     390      731252 :   std::vector<UserObject *> objs;
     391      731252 :   _problem_ptr->theWarehouse()
     392             :       .query()
     393      731252 :       .condition<AttribSystem>("UserObject")
     394     1462504 :       .condition<AttribThread>(0)
     395      731252 :       .queryIntoUnsorted(objs);
     396             : 
     397     1617524 :   for (const auto & obj : objs)
     398             :   {
     399      886276 :     auto pps = dynamic_cast<postprocessor_type *>(obj);
     400      886276 :     if (!pps)
     401      511721 :       continue;
     402             : 
     403      374555 :     execute_data.available.insert(pps->PPName());
     404             : 
     405             :     // Extract the list of outputs
     406      374555 :     const auto & pps_outputs = pps->getOutputs();
     407             : 
     408             :     // Check that the outputs lists are valid
     409      374555 :     _app.getOutputWarehouse().checkOutputs(pps_outputs);
     410             : 
     411             :     // Check that the output object allows postprocessor output,
     412             :     // account for "all" keyword (if it is present assume "all" was desired)
     413     1104923 :     if (pps_outputs.find(name()) != pps_outputs.end() ||
     414      730372 :         pps_outputs.find("all") != pps_outputs.end())
     415             :     {
     416       37642 :       if (!_advanced_execute_on.contains(execute_data_name) ||
     417       18821 :           (_advanced_execute_on[execute_data_name].isValid() &&
     418       37642 :            _advanced_execute_on[execute_data_name].isValueSet("none")))
     419             :       {
     420           7 :         const bool is_pp_type = (execute_data_name == "postprocessors");
     421           7 :         const std::string pp_type_str = is_pp_type ? "post-processor" : "vector post-processor";
     422           7 :         mooseWarning("The ",
     423             :                      pp_type_str,
     424             :                      " '",
     425           7 :                      pps->PPName(),
     426             :                      "' has requested to be output by the '",
     427           7 :                      name(),
     428             :                      "' output, but ",
     429             :                      pp_type_str,
     430             :                      " output is disabled for that output object.");
     431           7 :       }
     432             :     }
     433             :   }
     434      731248 : }

Generated by: LCOV version 1.14