www.mooseframework.org
OutputWarehouse.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
15 // Forward declarations
16 class FEProblemBase;
17 class InputParameters;
18 
23 {
24 public:
29 
30  /*
31  * Class destructor
32  * The OutputWarehouse deletes all output objects passed in via addOutput
33  */
34  virtual ~OutputWarehouse();
35 
42  void addOutput(std::shared_ptr<Output> & output);
43 
55  const std::set<OutputName> & getOutputNames();
56 
61  bool hasOutput(const std::string & name) const;
62 
66  void meshChanged();
67 
81  void buildInterfaceHideVariables(const std::string & output_name, std::set<std::string> & hide);
82 
86  void setFileNumbers(std::map<std::string, unsigned int> input, unsigned int offset = 0);
87 
92  std::map<std::string, unsigned int> getFileNumbers();
93 
100  void setCommonParameters(InputParameters * params_ptr);
101 
107 
111  std::set<Real> & getSyncTimes();
112 
119  void checkOutputs(const std::set<OutputName> & names);
120 
127  template <typename T>
128  T * getOutput(const OutputName & name);
129 
136  template <typename T>
137  std::vector<T *> getOutputs(const std::vector<OutputName> & names);
138 
144  template <typename T>
145  std::vector<T *> getOutputs() const;
146 
152  template <typename T>
153  std::vector<OutputName> getOutputNames();
154 
159  const std::set<std::string> & getReservedNames() const;
160 
166  bool isReservedName(const std::string & name);
167 
171  void mooseConsole();
172 
177  std::ostringstream & consoleBuffer() { return _console_buffer; }
178 
184  {
186  }
187 
190 
192  bool getLoggingRequested() const { return _logging_requested; }
193 
195  void reset();
196 
197 private:
205 
207 
212  void allowOutput(bool state);
213  template <typename T>
214  void allowOutput(bool state);
216 
222  void forceOutput();
223 
228  std::vector<std::shared_ptr<Output>> _all_ptrs;
229 
236  void addOutputFilename(const OutFileBase & filename);
237 
242  void initialSetup();
243 
248  void timestepSetup();
249 
254  void solveSetup();
255 
260  void jacobianSetup();
261 
266  void residualSetup();
267 
272  void subdomainSetup();
273 
282  void addInterfaceHideVariables(const std::string & output_name,
283  const std::set<std::string> & variable_names);
284 
291 
297  void flushConsoleBuffer();
298 
301 
303  std::vector<Output *> _all_objects;
304 
307 
309  std::map<OutputName, Output *> _object_map;
310 
312  std::set<OutputName> _object_names;
313 
315  std::set<OutFileBase> _file_base_set;
316 
319 
321  std::set<Real> _sync_times;
322 
324  std::string _input_file_name;
325 
327  std::map<OutputName, std::set<AuxVariableName>> _material_output_map;
328 
330  std::set<AuxVariableName> _all_material_output_variables;
331 
333  std::set<std::string> _reserved;
334 
336  std::ostringstream _console_buffer;
337 
339  std::map<std::string, std::set<std::string>> _interface_map;
340 
343 
346 
349 
350  // Allow complete access:
351  // FEProblemBase for calling initial, timestepSetup, outputStep, etc. methods
352  friend class FEProblemBase;
353 
354  // MaterialOutputAction for calling addInterfaceHideVariables
355  friend class MaterialOutputAction;
356 
357  // OutputInterface for calling addInterfaceHideVariables
358  friend class OutputInterface;
359 
360  // Console for calling flushConsoleBuffer()
361  friend class PetscOutput;
362 };
363 
364 template <typename T>
365 T *
366 OutputWarehouse::getOutput(const OutputName & name)
367 {
368  // Check that the object exists
369  if (!hasOutput(name))
370  mooseError("An output object with the name '", name, "' does not exist.");
371 
372  // Attempt to cast the object to the correct type
373  T * output = dynamic_cast<T *>(_object_map[name]);
374 
375  // Error if the cast fails
376  if (output == NULL)
377  mooseError("An output object with the name '", name, "' for the specified type does not exist");
378 
379  // Return the object
380  return output;
381 }
382 
383 template <typename T>
384 std::vector<T *>
385 OutputWarehouse::getOutputs(const std::vector<OutputName> & names)
386 {
387  // The vector to output
388  std::vector<T *> outputs;
389 
390  // Populate the vector
391  for (std::vector<OutputName>::const_iterator it = names.begin(); it != names.end(); ++it)
392  outputs.push_back(getOutput<T>(*it));
393 
394  // Return the objects
395  return outputs;
396 }
397 
398 template <typename T>
399 std::vector<T *>
401 {
402  // The vector to output
403  std::vector<T *> outputs;
404 
405  // Populate the vector
406  for (std::map<OutputName, Output *>::const_iterator it = _object_map.begin();
407  it != _object_map.end();
408  ++it)
409  {
410  T * output = dynamic_cast<T *>(it->second);
411  if (output != NULL)
412  outputs.push_back(output);
413  }
414 
415  // Return the objects
416  return outputs;
417 }
418 
419 template <typename T>
420 std::vector<OutputName>
422 {
423  // The output vector
424  std::vector<OutputName> names;
425 
426  // Loop through the objects and store the name if the type cast succeeds
427  for (std::map<OutputName, Output *>::const_iterator it = _object_map.begin();
428  it != _object_map.end();
429  ++it)
430  {
431  T * output = dynamic_cast<T *>(it->second);
432  if (output != NULL)
433  names.push_back(it->first);
434  }
435 
436  // Return the names
437  return names;
438 }
439 
440 template <typename T>
441 void
443 {
444  std::vector<T *> outputs = getOutputs<T>();
445  for (typename std::vector<T *>::iterator it = outputs.begin(); it != outputs.end(); ++it)
446  (*it)->allowOutput(state);
447 }
448 
T * getOutput(const OutputName &name)
Return an Output object by name.
bool getLoggingRequested() const
Returns a Boolean indicating whether performance logging is requested in this application.
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 mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
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.
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.
bool hasOutput(const std::string &name) const
Returns true if the output object exists.
Base class for MOOSE-based applications.
Definition: MooseApp.h:59
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.
std::vector< T * > getOutputs() const
Return a vector of objects of a given type.
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.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
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...
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
void mooseConsole()
Send current output buffer to Console output objects.
void reset()
Reset the output system.
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:24
const std::set< std::string > & getReservedNames() const
Return a set of reserved output names.
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.
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.