https://mooseframework.inl.gov
Loading...
Searching...
No Matches
OutputWarehouse.h
Go to the documentation of this file.
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 "Output.h"
14#include "PerfGraphInterface.h"
15
16// System includes
17#include <atomic>
18
19// Forward declarations
20class FEProblemBase;
21class InputParameters;
22
27{
28public:
33
34 /*
35 * Class destructor
36 * The OutputWarehouse deletes all output objects passed in via addOutput
37 */
38 virtual ~OutputWarehouse();
39
46 void addOutput(std::shared_ptr<Output> output);
47
59 const std::set<OutputName> & getOutputNames();
60
65 bool hasOutput(const std::string & name) const;
66
71 bool hasMaterialPropertyOutput(const std::string & name) const;
72
76 void meshChanged();
77
91 void buildInterfaceHideVariables(const std::string & output_name, std::set<std::string> & hide);
92
96 void setFileNumbers(std::map<std::string, unsigned int> input, unsigned int offset = 0);
97
102 std::map<std::string, unsigned int> getFileNumbers();
103
110 void setCommonParameters(const InputParameters * params_ptr);
111
116 const InputParameters * getCommonParameters() const;
117
121 bool commonFileBaseSet() const;
122
126 std::set<Real> & getSyncTimes();
127
137 void checkOutputs(const std::set<OutputName> & names,
138 const bool supports_material_output = false);
139
144 std::set<OutputName> getAllMaterialPropertyOutputNames() const;
145
152 template <typename T>
153 T * getOutput(const OutputName & name);
154
161 template <typename T>
162 std::vector<T *> getOutputs(const std::vector<OutputName> & names);
163
169 template <typename T>
170 std::vector<T *> getOutputs() const;
171
177 template <typename T>
178 std::vector<OutputName> getOutputNames();
179
184 const std::set<std::string> & getReservedNames() const;
185
191 bool isReservedName(const std::string & name);
192
196 void mooseConsole();
197
201 void mooseConsole(std::ostringstream & buffer);
202
207 std::ostringstream & consoleBuffer() { return _console_buffer; }
208
217
219 void reset();
220
230 void solveSetup();
231
233 unsigned long long int numPrinted() const { return _num_printed; }
234
235private:
242 void outputStep(ExecFlagType type);
243
245
250 void allowOutput(bool state);
251 template <typename T>
252 void allowOutput(bool state);
254
260 void forceOutput();
261
266 std::vector<std::shared_ptr<Output>> _all_ptrs;
267
276 void addOutputFilename(const OutputName & obj_name, const OutFileBase & filename);
277
282 void initialSetup();
283
288 void timestepSetup();
289
294 void customSetup(const ExecFlagType & exec_type);
295
300 void jacobianSetup();
301
306 void residualSetup();
307
312 void subdomainSetup();
313
322 void addInterfaceHideVariables(const std::string & output_name,
323 const std::set<std::string> & variable_names);
324
331
337 void flushConsoleBuffer();
338
342 void resetFileBase();
343
346
348 std::vector<Output *> _all_objects;
349
352
354 std::map<OutputName, Output *> _object_map;
355
357 std::set<OutputName> _object_names;
358
360 std::map<OutputName, std::set<OutFileBase>> _file_base_map;
361
364
366 std::set<Real> _sync_times;
367
369 std::string _input_file_name;
370
372 std::map<OutputName, std::set<AuxVariableName>> _material_output_map;
373
375 std::set<AuxVariableName> _all_material_output_variables;
376
378 std::set<std::string> _reserved;
379
381 std::ostringstream _console_buffer;
382
384 std::map<std::string, std::set<std::string>> _interface_map;
385
388
391
394
396 const std::ostringstream * _last_buffer;
397
399 std::atomic<unsigned long long int> _num_printed;
400
401 // Allow complete access:
402 // FEProblemBase for calling initial, timestepSetup, outputStep, etc. methods
403 friend class FEProblemBase;
404
405 // MaterialOutputAction for calling addInterfaceHideVariables
407
408 // OutputInterface for calling addInterfaceHideVariables
409 friend class OutputInterface;
410
411 // Console for calling flushConsoleBuffer()
413
414 // MooseApp for resetFileBase()
415 friend class MooseApp;
416};
417
418template <typename T>
419T *
421{
422 // Check that the object exists
423 if (!hasOutput(name))
424 mooseError("An output object with the name '", name, "' does not exist.");
425
426 // Attempt to cast the object to the correct type
427 T * output = dynamic_cast<T *>(_object_map[name]);
428
429 // Error if the cast fails
430 if (output == NULL)
431 mooseError("An output object with the name '", name, "' for the specified type does not exist");
432
433 // Return the object
434 return output;
435}
436
437template <typename T>
438std::vector<T *>
439OutputWarehouse::getOutputs(const std::vector<OutputName> & names)
440{
441 // The vector to output
442 std::vector<T *> outputs;
443
444 // Populate the vector
445 for (std::vector<OutputName>::const_iterator it = names.begin(); it != names.end(); ++it)
446 outputs.push_back(getOutput<T>(*it));
447
448 // Return the objects
449 return outputs;
450}
451
452template <typename T>
453std::vector<T *>
455{
456 // The vector to output
457 std::vector<T *> outputs;
458
459 // Populate the vector
460 for (std::map<OutputName, Output *>::const_iterator it = _object_map.begin();
461 it != _object_map.end();
462 ++it)
463 {
464 T * output = dynamic_cast<T *>(it->second);
465 if (output != NULL)
466 outputs.push_back(output);
467 }
468
469 // Return the objects
470 return outputs;
471}
472
473template <typename T>
474std::vector<OutputName>
476{
477 // The output vector
478 std::vector<OutputName> names;
479
480 // Loop through the objects and store the name if the type cast succeeds
481 for (std::map<OutputName, Output *>::const_iterator it = _object_map.begin();
482 it != _object_map.end();
483 ++it)
484 {
485 T * output = dynamic_cast<T *>(it->second);
486 if (output != NULL)
487 names.push_back(it->first);
488 }
489
490 // Return the names
491 return names;
492}
493
494template <typename T>
495void
497{
498 std::vector<T *> outputs = getOutputs<T>();
499 for (typename std::vector<T *>::iterator it = outputs.begin(); it != outputs.end(); ++it)
500 (*it)->allowOutput(state);
501}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Creates AuxVariables and AuxKernels for automatic output of material properties.
Base class for MOOSE-based applications.
Definition MooseApp.h:110
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Class for containing MooseEnum item information.
A class to provide an common interface to objects requiring "outputs" option.
Class for storing and utilizing output objects.
const InputParameters * getCommonParameters() const
Get a reference to the common output parameters.
void flushConsoleBuffer()
If content exists in the buffer, write it.
void reset()
Reset the output system.
void addOutputFilename(const OutputName &obj_name, const OutFileBase &filename)
Adds the file name to the map of filenames being output with an associated object The main function o...
std::vector< Output * > _all_objects
All instances of objects (raw pointers)
bool isReservedName(const std::string &name)
Test if the given name is reserved.
void solveSetup()
Calls the timestepSetup function for each of the output objects.
void jacobianSetup()
Calls the jacobianSetup function for each of the output objects.
void setFileNumbers(std::map< std::string, unsigned int > input, unsigned int offset=0)
Calls the setFileNumber method for every FileOutput output object.
void bufferConsoleOutputsBeforeConstruction(bool buffer)
Set if the outputs to Console before its construction are to be buffered or to screen directly.
std::set< OutputName > getAllMaterialPropertyOutputNames() const
Returns all output names that support material output.
std::atomic< unsigned long long int > _num_printed
Number of times the stream has been printed to.
void forceOutput()
Indicates that the next call to outputStep should be forced This is private, users should utilize FEP...
void timestepSetup()
Calls the timestepSetup function for each of the output objects.
const InputParameters * _common_params_ptr
Pointer to the common InputParameters (.
std::set< Real > & getSyncTimes()
Return the sync times for all objects.
const std::set< std::string > & getReservedNames() const
Return a set of reserved output names.
const std::ostringstream * _last_buffer
What the last buffer was that was printed.
MooseApp & _app
MooseApp.
bool _last_message_ended_in_newline
Whether or not the last thing output by mooseConsole had a newline as the last character.
unsigned long long int numPrinted() const
The number of times something has been printed.
std::vector< std::shared_ptr< Output > > _all_ptrs
We are using std::shared_ptr to handle the cleanup of the pointers at the end of execution.
std::set< Real > _sync_times
Sync times for all objects.
const std::set< OutputName > & getOutputNames()
Get a complete set of all output object names.
std::ostringstream & consoleBuffer()
The buffered messages stream for Console objects.
void initialSetup()
Calls the initialSetup function for each of the output objects.
std::set< AuxVariableName > _all_material_output_variables
List of all variable created by auto material output.
ExecFlagType _output_exec_flag
The current output execution flag.
bool _buffer_action_console_outputs
True to buffer console outputs in actions.
void meshChanged()
Calls the meshChanged method for every output object.
void customSetup(const ExecFlagType &exec_type)
Calls the setup function for each of the output objects.
std::map< OutputName, std::set< AuxVariableName > > _material_output_map
Map of output name and AuxVariable names to be output (used by auto Material output)
std::string _input_file_name
Input file name for this output object.
std::map< std::string, unsigned int > getFileNumbers()
Extracts the file numbers from the output objects.
bool hasOutput(const std::string &name) const
Returns true if the output object exists.
void addInterfaceHideVariables(const std::string &output_name, const std::set< std::string > &variable_names)
Insert variable names for hiding via the OutoutInterface.
std::set< OutputName > _object_names
A set of output names.
T * getOutput(const OutputName &name)
Return an Output object by name.
std::map< std::string, std::set< std::string > > _interface_map
Storage for variables to hide as prescribed by the object via the OutputInterface.
virtual ~OutputWarehouse()
bool _force_output
Flag indicating that next call to outputStep is forced.
void subdomainSetup()
Calls the subdomainSetup function for each of the output objects.
void checkOutputs(const std::set< OutputName > &names, const bool supports_material_output=false)
Test that the output names exist.
void setCommonParameters(const InputParameters *params_ptr)
Stores the common InputParameters object.
bool commonFileBaseSet() const
Whether the common [Outputs] block set file_base from input parsing.
void mooseConsole()
Send current output buffer to Console output objects.
void setOutputExecutionType(ExecFlagType type)
Sets the execution flag type.
void residualSetup()
Calls the residualSetup function for each of the output objects.
void outputStep(ExecFlagType type)
Calls the outputStep method for each output object.
void resetFileBase()
Resets the file base for all FileOutput objects.
void buildInterfaceHideVariables(const std::string &output_name, std::set< std::string > &hide)
Return the list of hidden variables for the given output name.
void allowOutput(bool state)
Ability to enable/disable output calls This is private, users should utilize FEProblemBase::allowOutp...
std::map< OutputName, std::set< OutFileBase > > _file_base_map
List of object names.
std::vector< T * > getOutputs() const
Return a vector of objects of a given type.
bool hasMaterialPropertyOutput(const std::string &name) const
Returns true if the output object exists, and it supports material property output.
std::map< OutputName, Output * > _object_map
A map of the output pointers.
void addOutput(std::shared_ptr< Output > output)
Adds an existing output object to the warehouse.
std::ostringstream _console_buffer
The stream for holding messages passed to _console prior to Output object construction.
std::set< std::string > _reserved
List of reserved names.
Interface for objects interacting with the PerfGraph.