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 24 : void hideAdditionalVariable(const std::string & category, const std::string & var_name) 205 : { 206 24 : _execute_data[category].hide.insert(var_name); 207 24 : _execute_data[category].output.erase(var_name); 208 24 : } 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 : * Clears bookkeeping used to suppress duplicate EXEC_FINAL output at the same time. 285 : */ 286 : void clearLastExecuteTime(); 287 : 288 : /** 289 : * Flags to control nodal output 290 : */ 291 : bool _elemental_as_nodal, _scalar_as_nodal; 292 : 293 : /// Storage for Reporter values 294 : const ReporterData & _reporter_data; 295 : 296 : private: 297 : /** 298 : * Initializes the available lists for each of the output types 299 : */ 300 : void initAvailableLists(); 301 : 302 : /** 303 : * Initialize the possible execution types 304 : * @param name The name of the supplied MultiMoose enum from the _execute_on std::map (e.g., 305 : * scalars) 306 : * @param input The ExecFlagEnum for output type flags to initialize 307 : */ 308 : void initExecutionTypes(const std::string & name, ExecFlagEnum & input); 309 : 310 : /** 311 : * Parses the user-supplied input for hiding and showing variables and postprocessors into 312 : * a list for each type of output 313 : * @param show The vector of names that are to be output 314 : * @param hide The vector of names that are to be suppressed from the output 315 : */ 316 : void initShowHideLists(const std::vector<VariableName> & show, 317 : const std::vector<VariableName> & hide); 318 : 319 : /** 320 : * Helper function for initAvailableLists, templated on warehouse type and postprocessor_type 321 : * @param execute_data_name Name of the OutputData struct to initialize 322 : * @param warehouse Reference to the postprocessor or vector postprocessor warehouse 323 : */ 324 : template <typename postprocessor_type> 325 : void initPostprocessorOrVectorPostprocessorLists(const std::string & execute_data_name); 326 : 327 : /** 328 : * Initializes the list of items to be output using the available, show, and hide lists 329 : * @param data The OutputData to operate on 330 : */ 331 : void initOutputList(OutputData & data); 332 : 333 : /** 334 : * Handles logic for determining if a step should be output 335 : * @return True if a call if output should be performed 336 : */ 337 : bool wantOutput(const std::string & name, const ExecFlagType & type); 338 : 339 : /** 340 : * Method for defining the available parameters based on the types of outputs 341 : * @param params The InputParamters object to add parameters to 342 : * @param types The types of output this object should support (see Output::enableOutputTypes) 343 : * 344 : * Each output object may have a varying set of supported output types (e.g., elemental 345 : * variables may not be supported). This private, static method populates the InputParameters 346 : * object with the correct parameters based on the items contained in the ExecFlagEnum. 347 : * 348 : * This method is private, users should utilize the Output::enableOutputTypes method 349 : * 350 : * @see Output::enableOutputTypes 351 : */ 352 : static void addValidParams(InputParameters & params, const MultiMooseEnum & types); 353 : 354 : /** 355 : * Helper method for checking if output types exists 356 : * @param name The name of the output type to test (e.g., postprocessors) 357 : */ 358 : bool hasOutputHelper(const std::string & name); 359 : 360 : /** 361 : * Get the supported types of output (e.g., postprocessors, etc.) 362 : */ 363 : static MultiMooseEnum getOutputTypes(); 364 : 365 : /// Storage structures for the various output types 366 : OutputDataWarehouse _execute_data; 367 : 368 : /// Storage for the last output time for the various output types, this is used to avoid duplicate output when using OUTPUT_FINAL flag 369 : std::map<std::string, Real> & _last_execute_time; 370 : 371 : /// Flags for outputting PP/VPP data as a reporter 372 : const bool _postprocessors_as_reporters, _vectorpostprocessors_as_reporters; 373 : 374 : // Allow complete access 375 : friend class OutputWarehouse; 376 : friend class Console; 377 : friend class TransientMultiApp; 378 : }; 379 : 380 : // Helper function for initAvailableLists, templated on warehouse type and postprocessor_type 381 : template <typename postprocessor_type> 382 : void 383 712473 : AdvancedOutput::initPostprocessorOrVectorPostprocessorLists(const std::string & execute_data_name) 384 : { 385 : // Convenience reference to the OutputData being operated on (should used "postprocessors" or 386 : // "vector_postprocessors") 387 712473 : OutputData & execute_data = _execute_data[execute_data_name]; 388 : 389 : // Build the input file parameter name (i.e. "output_postprocessors_on" or 390 : // "output_vector_postprocessors_on") 391 712473 : std::ostringstream oss; 392 712473 : oss << "execute_" << execute_data_name << "_on"; 393 712473 : std::string execute_on_name = oss.str(); 394 : 395 712473 : std::vector<postprocessor_type *> objs; 396 : if constexpr (std::is_same_v<postprocessor_type, Postprocessor>) 397 356363 : _problem_ptr->theWarehouse() 398 : .query() 399 356363 : .condition<AttribInterfaces>(Interfaces::Postprocessor) 400 712726 : .condition<AttribThread>(0) 401 356363 : .queryIntoUnsorted(objs); 402 : else if constexpr (std::is_same_v<postprocessor_type, VectorPostprocessor>) 403 356110 : _problem_ptr->theWarehouse() 404 : .query() 405 356110 : .condition<AttribInterfaces>(Interfaces::VectorPostprocessor) 406 712220 : .condition<AttribThread>(0) 407 356110 : .queryIntoUnsorted(objs); 408 : 409 1075555 : for (const auto & obj : objs) 410 : { 411 363085 : execute_data.available.insert(obj->PPName()); 412 : 413 : // Extract the list of outputs 414 363085 : const auto & pps_outputs = obj->getOutputs(); 415 : 416 : // Check that the outputs lists are valid 417 363085 : _app.getOutputWarehouse().checkOutputs(pps_outputs); 418 : 419 : // Check that the output object allows postprocessor output, 420 : // account for "all" keyword (if it is present assume "all" was desired) 421 1078231 : if (pps_outputs.find(name()) != pps_outputs.end() || 422 715149 : pps_outputs.find("all") != pps_outputs.end()) 423 : { 424 22196 : if (!_advanced_execute_on.contains(execute_data_name) || 425 11098 : (_advanced_execute_on[execute_data_name].isValid() && 426 44392 : _advanced_execute_on[execute_data_name].isValueSet("none"))) 427 : { 428 4 : const bool is_pp_type = (execute_data_name == "postprocessors"); 429 4 : const std::string pp_type_str = is_pp_type ? "post-processor" : "vector post-processor"; 430 4 : mooseWarning("The ", 431 : pp_type_str, 432 : " '", 433 4 : obj->PPName(), 434 : "' has requested to be output by the '", 435 4 : name(), 436 : "' output, but ", 437 : pp_type_str, 438 : " output is disabled for that output object."); 439 4 : } 440 : } 441 : } 442 712470 : }