LCOV - code coverage report
Current view: top level - include/outputs - AdvancedOutput.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 29 29 100.0 %
Date: 2025-07-17 01:28:37 Functions: 2 2 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             :   /**
     204             :    * Handles logic for determining if a step should be output
     205             :    * @return True if a call if output should be performed
     206             :    */
     207             :   virtual bool shouldOutput();
     208             : 
     209             :   /**
     210             :    * A single call to this function should output all the necessary data for a single timestep. By
     211             :    * default this function performs calls each of the four virtual output methods:
     212             :    * outputScalarVariables(),
     213             :    * outputPostprocessors(), outputElementalVariables(), and outputNodalVariables(). But, only if
     214             :    * output exists
     215             :    * for each type.
     216             :    *
     217             :    * @see outputNodalVariables outputElementalVariables outputScalarVariables outputPostprocessors
     218             :    */
     219             :   virtual void output();
     220             : 
     221             :   /**
     222             :    * Performs output of nodal nonlinear variables
     223             :    * The child class must define this method to output the nonlinear variables as desired
     224             :    * @see Exodus::outputNodalVariables
     225             :    */
     226             :   virtual void outputNodalVariables();
     227             : 
     228             :   /**
     229             :    * Performs output of elemental nonlinear variables
     230             :    * The child class must define this method to output the nonlinear variables as desired
     231             :    * @see Exodus::outputElementalVariables
     232             :    */
     233             :   virtual void outputElementalVariables();
     234             : 
     235             :   /**
     236             :    * Performs output of scalar variables
     237             :    * The child class must define this method to output the scalar variables as desired
     238             :    * @see Exodus::outputScalarVariables
     239             :    */
     240             :   virtual void outputScalarVariables();
     241             : 
     242             :   /**
     243             :    * Performs output of postprocessors
     244             :    * The child class must define this method to output the postprocessors as desired
     245             :    * @see Exodus::outputPostprocessors
     246             :    */
     247             :   virtual void outputPostprocessors();
     248             : 
     249             :   /**
     250             :    * Performs output of VectorPostprocessors
     251             :    * The child class must define this method to output the VectorPostprocessors as desired
     252             :    */
     253             :   virtual void outputVectorPostprocessors();
     254             : 
     255             :   /**
     256             :    * Performs the output of the input file
     257             :    * By default this method does nothing and is not called, the individual Output objects are
     258             :    * responsible for calling it
     259             :    */
     260             :   virtual void outputInput();
     261             : 
     262             :   /**
     263             :    * \todo{Make this call automatic in similar fashion to outputInput}
     264             :    * Performs the output of system information
     265             :    * By default this method does nothing and is not called by output()
     266             :    */
     267             :   virtual void outputSystemInformation();
     268             : 
     269             :   /**
     270             :    * Output Reporter values.
     271             :    * The child class must define this method to output the Reporter values as desired
     272             :    * @see CSV::outputReporters
     273             :    */
     274             :   virtual void outputReporters();
     275             : 
     276             :   /**
     277             :    * Flags to control nodal output
     278             :    */
     279             :   bool _elemental_as_nodal, _scalar_as_nodal;
     280             : 
     281             :   /// Storage for Reporter values
     282             :   const ReporterData & _reporter_data;
     283             : 
     284             : private:
     285             :   /**
     286             :    * Initializes the available lists for each of the output types
     287             :    */
     288             :   void initAvailableLists();
     289             : 
     290             :   /**
     291             :    * Initialize the possible execution types
     292             :    * @param name The name of the supplied MultiMoose enum from the _execute_on std::map (e.g.,
     293             :    * scalars)
     294             :    * @param input The ExecFlagEnum for output type flags to initialize
     295             :    */
     296             :   void initExecutionTypes(const std::string & name, ExecFlagEnum & input);
     297             : 
     298             :   /**
     299             :    * Parses the user-supplied input for hiding and showing variables and postprocessors into
     300             :    * a list for each type of output
     301             :    * @param show The vector of names that are to be output
     302             :    * @param hide The vector of names that are to be suppressed from the output
     303             :    */
     304             :   void initShowHideLists(const std::vector<VariableName> & show,
     305             :                          const std::vector<VariableName> & hide);
     306             : 
     307             :   /**
     308             :    * Helper function for initAvailableLists, templated on warehouse type and postprocessor_type
     309             :    * @param execute_data_name Name of the OutputData struct to initialize
     310             :    * @param warehouse Reference to the postprocessor or vector postprocessor warehouse
     311             :    */
     312             :   template <typename postprocessor_type>
     313             :   void initPostprocessorOrVectorPostprocessorLists(const std::string & execute_data_name);
     314             : 
     315             :   /**
     316             :    * Initializes the list of items to be output using the available, show, and hide lists
     317             :    * @param data The OutputData to operate on
     318             :    */
     319             :   void initOutputList(OutputData & data);
     320             : 
     321             :   /**
     322             :    * Handles logic for determining if a step should be output
     323             :    * @return True if a call if output should be performed
     324             :    */
     325             :   bool wantOutput(const std::string & name, const ExecFlagType & type);
     326             : 
     327             :   /**
     328             :    * Method for defining the available parameters based on the types of outputs
     329             :    * @param params The InputParamters object to add parameters to
     330             :    * @param types The types of output this object should support (see Output::enableOutputTypes)
     331             :    *
     332             :    * Each output object may have a varying set of supported output types (e.g., elemental
     333             :    * variables may not be supported). This private, static method populates the InputParameters
     334             :    * object with the correct parameters based on the items contained in the ExecFlagEnum.
     335             :    *
     336             :    * This method is private, users should utilize the Output::enableOutputTypes method
     337             :    *
     338             :    * @see Output::enableOutputTypes
     339             :    */
     340             :   static void addValidParams(InputParameters & params, const MultiMooseEnum & types);
     341             : 
     342             :   /**
     343             :    * Helper method for checking if output types exists
     344             :    * @param name The name of the output type to test (e.g., postprocessors)
     345             :    */
     346             :   bool hasOutputHelper(const std::string & name);
     347             : 
     348             :   /**
     349             :    * Get the supported types of output (e.g., postprocessors, etc.)
     350             :    */
     351             :   static MultiMooseEnum getOutputTypes();
     352             : 
     353             :   /// Storage structures for the various output types
     354             :   OutputDataWarehouse _execute_data;
     355             : 
     356             :   /// Storage for the last output time for the various output types, this is used to avoid duplicate output when using OUTPUT_FINAL flag
     357             :   std::map<std::string, Real> _last_execute_time;
     358             : 
     359             :   /// Flags for outputting PP/VPP data as a reporter
     360             :   const bool _postprocessors_as_reporters, _vectorpostprocessors_as_reporters;
     361             : 
     362             :   // Allow complete access
     363             :   friend class OutputWarehouse;
     364             :   friend class Console;
     365             :   friend class TransientMultiApp;
     366             : };
     367             : 
     368             : // Helper function for initAvailableLists, templated on warehouse type and postprocessor_type
     369             : template <typename postprocessor_type>
     370             : void
     371      672972 : AdvancedOutput::initPostprocessorOrVectorPostprocessorLists(const std::string & execute_data_name)
     372             : {
     373             :   // Convenience reference to the OutputData being operated on (should used "postprocessors" or
     374             :   // "vector_postprocessors")
     375      672972 :   OutputData & execute_data = _execute_data[execute_data_name];
     376             : 
     377             :   // Build the input file parameter name (i.e. "output_postprocessors_on" or
     378             :   // "output_vector_postprocessors_on")
     379      672972 :   std::ostringstream oss;
     380      672972 :   oss << "execute_" << execute_data_name << "_on";
     381      672972 :   std::string execute_on_name = oss.str();
     382             : 
     383      672972 :   std::vector<UserObject *> objs;
     384      672972 :   _problem_ptr->theWarehouse()
     385             :       .query()
     386      672972 :       .condition<AttribSystem>("UserObject")
     387     1345944 :       .condition<AttribThread>(0)
     388      672972 :       .queryIntoUnsorted(objs);
     389             : 
     390     1487958 :   for (const auto & obj : objs)
     391             :   {
     392      814990 :     auto pps = dynamic_cast<postprocessor_type *>(obj);
     393      814990 :     if (!pps)
     394      470058 :       continue;
     395             : 
     396      344932 :     execute_data.available.insert(pps->PPName());
     397             : 
     398             :     // Extract the list of outputs
     399      344932 :     const auto & pps_outputs = pps->getOutputs();
     400             : 
     401             :     // Check that the outputs lists are valid
     402      344932 :     _app.getOutputWarehouse().checkOutputs(pps_outputs);
     403             : 
     404             :     // Check that the output object allows postprocessor output,
     405             :     // account for "all" keyword (if it is present assume "all" was desired)
     406     1016286 :     if (pps_outputs.find(name()) != pps_outputs.end() ||
     407      671358 :         pps_outputs.find("all") != pps_outputs.end())
     408             :     {
     409       37164 :       if (!_advanced_execute_on.contains(execute_data_name) ||
     410       18582 :           (_advanced_execute_on[execute_data_name].isValid() &&
     411       37164 :            _advanced_execute_on[execute_data_name].isValueSet("none")))
     412             :       {
     413           7 :         const bool is_pp_type = (execute_data_name == "postprocessors");
     414           7 :         const std::string pp_type_str = is_pp_type ? "post-processor" : "vector post-processor";
     415           7 :         mooseWarning("The ",
     416             :                      pp_type_str,
     417             :                      " '",
     418           7 :                      pps->PPName(),
     419             :                      "' has requested to be output by the '",
     420           7 :                      name(),
     421             :                      "' output, but ",
     422             :                      pp_type_str,
     423             :                      " output is disabled for that output object.");
     424           7 :       }
     425             :     }
     426             :   }
     427      672968 : }

Generated by: LCOV version 1.14