www.mooseframework.org
OutputWarehouse.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef OUTPUTWAREHOUSE_H
16 #define OUTPUTWAREHOUSE_H
17 
18 // MOOSE includes
19 #include "Output.h"
20 
21 // Forward declarations
22 class FEProblemBase;
23 class InputParameters;
24 
29 {
30 public:
35 
36  /*
37  * Class destructor
38  * The OutputWarehouse deletes all output objects passed in via addOutput
39  */
40  virtual ~OutputWarehouse();
41 
48  void addOutput(std::shared_ptr<Output> & output);
49 
61  const std::set<OutputName> & getOutputNames();
62 
67  bool hasOutput(const std::string & name) const;
68 
72  void meshChanged();
73 
87  void buildInterfaceHideVariables(const std::string & output_name, std::set<std::string> & hide);
88 
92  void setFileNumbers(std::map<std::string, unsigned int> input, unsigned int offset = 0);
93 
98  std::map<std::string, unsigned int> getFileNumbers();
99 
106  void setCommonParameters(InputParameters * params_ptr);
107 
113 
117  std::set<Real> & getSyncTimes();
118 
125  void checkOutputs(const std::set<OutputName> & names);
126 
133  template <typename T>
134  T * getOutput(const OutputName & name);
135 
142  template <typename T>
143  std::vector<T *> getOutputs(const std::vector<OutputName> & names);
144 
150  template <typename T>
151  std::vector<T *> getOutputs() const;
152 
158  template <typename T>
159  std::vector<OutputName> getOutputNames();
160 
165  const std::set<std::string> & getReservedNames() const;
166 
172  bool isReservedName(const std::string & name);
173 
177  void mooseConsole();
178 
183  std::ostringstream & consoleBuffer() { return _console_buffer; }
184 
190  {
192  }
193 
196 
198  bool getLoggingRequested() const { return _logging_requested; }
199 
200 private:
208 
210 
215  void allowOutput(bool state);
216  template <typename T>
217  void allowOutput(bool state);
219 
225  void forceOutput();
226 
231  std::vector<std::shared_ptr<Output>> _all_ptrs;
232 
239  void addOutputFilename(const OutFileBase & filename);
240 
245  void initialSetup();
246 
251  void timestepSetup();
252 
257  void solveSetup();
258 
263  void jacobianSetup();
264 
269  void residualSetup();
270 
275  void subdomainSetup();
276 
285  void addInterfaceHideVariables(const std::string & output_name,
286  const std::set<std::string> & variable_names);
287 
294 
300  void flushConsoleBuffer();
301 
304 
306  std::vector<Output *> _all_objects;
307 
310 
312  std::map<OutputName, Output *> _object_map;
313 
315  std::set<OutputName> _object_names;
316 
318  std::set<OutFileBase> _file_base_set;
319 
322 
324  std::set<Real> _sync_times;
325 
327  std::string _input_file_name;
328 
330  std::map<OutputName, std::set<AuxVariableName>> _material_output_map;
331 
333  std::set<AuxVariableName> _all_material_output_variables;
334 
336  std::set<std::string> _reserved;
337 
339  std::ostringstream _console_buffer;
340 
342  std::map<std::string, std::set<std::string>> _interface_map;
343 
346 
349 
352 
353  // Allow complete access:
354  // FEProblemBase for calling initial, timestepSetup, outputStep, etc. methods
355  friend class FEProblemBase;
356 
357  // MaterialOutputAction for calling addInterfaceHideVariables
358  friend class MaterialOutputAction;
359 
360  // OutputInterface for calling addInterfaceHideVariables
361  friend class OutputInterface;
362 
363  // Console for calling flushConsoleBuffer()
364  friend class PetscOutput;
365 };
366 
367 template <typename T>
368 T *
369 OutputWarehouse::getOutput(const OutputName & name)
370 {
371  // Check that the object exists
372  if (!hasOutput(name))
373  mooseError("An output object with the name '", name, "' does not exist.");
374 
375  // Attempt to cast the object to the correct type
376  T * output = dynamic_cast<T *>(_object_map[name]);
377 
378  // Error if the cast fails
379  if (output == NULL)
380  mooseError("An output object with the name '", name, "' for the specified type does not exist");
381 
382  // Return the object
383  return output;
384 }
385 
386 template <typename T>
387 std::vector<T *>
388 OutputWarehouse::getOutputs(const std::vector<OutputName> & names)
389 {
390  // The vector to output
391  std::vector<T *> outputs;
392 
393  // Populate the vector
394  for (std::vector<OutputName>::const_iterator it = names.begin(); it != names.end(); ++it)
395  outputs.push_back(getOutput<T>(*it));
396 
397  // Return the objects
398  return outputs;
399 }
400 
401 template <typename T>
402 std::vector<T *>
404 {
405  // The vector to output
406  std::vector<T *> outputs;
407 
408  // Populate the vector
409  for (std::map<OutputName, Output *>::const_iterator it = _object_map.begin();
410  it != _object_map.end();
411  ++it)
412  {
413  T * output = dynamic_cast<T *>(it->second);
414  if (output != NULL)
415  outputs.push_back(output);
416  }
417 
418  // Return the objects
419  return outputs;
420 }
421 
422 template <typename T>
423 std::vector<OutputName>
425 {
426  // The output vector
427  std::vector<OutputName> names;
428 
429  // Loop through the objects and store the name if the type cast succeeds
430  for (std::map<OutputName, Output *>::const_iterator it = _object_map.begin();
431  it != _object_map.end();
432  ++it)
433  {
434  T * output = dynamic_cast<T *>(it->second);
435  if (output != NULL)
436  names.push_back(it->first);
437  }
438 
439  // Return the names
440  return names;
441 }
442 
443 template <typename T>
444 void
446 {
447  std::vector<T *> outputs = getOutputs<T>();
448  for (typename std::vector<T *>::iterator it = outputs.begin(); it != outputs.end(); ++it)
449  (*it)->allowOutput(state);
450 }
451 
452 #endif // OUTPUTWAREHOUSE_H
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
T * getOutput(const OutputName &name)
Return an Output object by name.
void outputStep(ExecFlagType type)
Calls the outputStep method for each output object.
bool _buffer_action_console_outputs
True to buffer console outputs in actions.
void initialSetup()
Calls the initialSetup function for each of the output objects.
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.
virtual void output(const ExecFlagType &type)=0
Overload this function with the desired output activities.
void setCommonParameters(InputParameters *params_ptr)
Stores the common InputParameters object.
bool getLoggingRequested() const
Returns a Boolean indicating whether performance logging is requested in this application.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void setLoggingRequested()
Sets a Boolean indicating that at least one object is requesting performance logging in this applicat...
std::set< OutputName > _object_names
A set of output names.
bool isReservedName(const std::string &name)
Test if the given name is reserved.
A class to provide an common interface to objects requiring "outputs" option.
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void setOutputExecutionType(ExecFlagType type)
Sets the execution flag type.
std::vector< Output * > _all_objects
All instances of objects (raw pointers)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void forceOutput()
Indicates that the next call to outputStep should be forced This is private, users should utilize FEP...
std::set< std::string > _reserved
List of reserved names.
Creates AuxVariables and AuxKernels for automatic output of material properties.
void jacobianSetup()
Calls the jacobianSetup function for each of the output objects.
std::map< std::string, std::set< std::string > > _interface_map
Storage for variables to hide as prescribed by the object via the OutputInterface.
InputParameters * _common_params_ptr
Pointer to the common InputParameters (.
ExecFlagType _output_exec_flag
The current output execution flag.
MooseApp & _app
MooseApp.
OutputWarehouse(MooseApp &app)
Class constructor.
void addOutputFilename(const OutFileBase &filename)
Adds the file name to the list of filenames being output The main function of this object is to test ...
std::set< AuxVariableName > _all_material_output_variables
List of all variable created by auto material output.
std::map< std::string, unsigned int > getFileNumbers()
Extracts the file numbers from the output objects.
void meshChanged()
Calls the meshChanged method for every output object.
bool _force_output
Flag indicating that next call to outputStep is forced.
virtual ~OutputWarehouse()
std::ostringstream & consoleBuffer()
The buffered messages stream for Console objects.
void checkOutputs(const std::set< OutputName > &names)
Test that the output names exist.
Class for storing and utilizing output objects.
std::ostringstream _console_buffer
The stream for holding messages passed to _console prior to Output object construction.
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.
void residualSetup()
Calls the residualSetup function for each of the output objects.
void solveSetup()
Calls the timestepSetup function for each of the output objects.
const std::set< OutputName > & getOutputNames()
Get a complete set of all output object names.
std::string _input_file_name
Input file name for this output object.
MatType type
InputParameters * getCommonParameters()
Get a reference to the common output parameters.
void subdomainSetup()
Calls the subdomainSetup function for each of the output objects.
std::set< OutFileBase > _file_base_set
List of object names.
void allowOutput(bool state)
Ability to enable/disable output calls This is private, users should utilize FEProblemBase::allowOutp...
std::vector< T * > getOutputs() const
Return a vector of objects of a given type.
bool hasOutput(const std::string &name) const
Returns true if the output object exists.
void mooseConsole()
Send current output buffer to Console output objects.
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
void addInterfaceHideVariables(const std::string &output_name, const std::set< std::string > &variable_names)
Insert variable names for hiding via the OutoutInterface.
void bufferConsoleOutputsBeforeConstruction(bool buffer)
Set if the outputs to Console before its construction are to be buffered or to screen directly...
void buildInterfaceHideVariables(const std::string &output_name, std::set< std::string > &hide)
Return the list of hidden variables for the given output name.
Adds the ability to output on every nonlinear and/or linear residual.
Definition: PetscOutput.h:30
void setFileNumbers(std::map< std::string, unsigned int > input, unsigned int offset=0)
Calls the setFileNumber method for every FileOutput output object.
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::set< Real > & getSyncTimes()
Return the sync times for all objects.
void timestepSetup()
Calls the timestepSetup function for each of the output objects.
const std::set< std::string > & getReservedNames() const
Return a set of reserved output names.
bool _logging_requested
Indicates that performance logging has been requested by the console or some object (PerformanceData)...
void flushConsoleBuffer()
If content exists in the buffer, write it.
std::set< Real > _sync_times
Sync times for all objects.