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 
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 }
OutputWarehouse::mooseConsole
void mooseConsole()
Send current output buffer to Console output objects.
Definition: OutputWarehouse.C:176
OutputWarehouse::_all_material_output_variables
std::set< AuxVariableName > _all_material_output_variables
List of all variable created by auto material output.
Definition: OutputWarehouse.h:330
OutputWarehouse::isReservedName
bool isReservedName(const std::string &name)
Test if the given name is reserved.
Definition: OutputWarehouse.C:305
OutputWarehouse::addInterfaceHideVariables
void addInterfaceHideVariables(const std::string &output_name, const std::set< std::string > &variable_names)
Insert variable names for hiding via the OutoutInterface.
Definition: OutputWarehouse.C:274
type
MatType type
Definition: PetscDMMoose.C:1477
OutputWarehouse::setFileNumbers
void setFileNumbers(std::map< std::string, unsigned int > input, unsigned int offset=0)
Calls the setFileNumber method for every FileOutput output object.
Definition: OutputWarehouse.C:221
OutputWarehouse::setCommonParameters
void setCommonParameters(InputParameters *params_ptr)
Stores the common InputParameters object.
Definition: OutputWarehouse.C:256
OutputWarehouse::hasOutput
bool hasOutput(const std::string &name) const
Returns true if the output object exists.
Definition: OutputWarehouse.C:117
OutputWarehouse::subdomainSetup
void subdomainSetup()
Calls the subdomainSetup function for each of the output objects.
Definition: OutputWarehouse.C:81
OutputWarehouse::getOutputNames
const std::set< OutputName > & getOutputNames()
Get a complete set of all output object names.
Definition: OutputWarehouse.C:123
OutputWarehouse::_buffer_action_console_outputs
bool _buffer_action_console_outputs
True to buffer console outputs in actions.
Definition: OutputWarehouse.h:306
OutputWarehouse::_object_names
std::set< OutputName > _object_names
A set of output names.
Definition: OutputWarehouse.h:312
OutputWarehouse::getSyncTimes
std::set< Real > & getSyncTimes()
Return the sync times for all objects.
Definition: OutputWarehouse.C:268
OutputWarehouse::_logging_requested
bool _logging_requested
Indicates that performance logging has been requested by the console or some object (PerformanceData)
Definition: OutputWarehouse.h:348
OutputWarehouse::flushConsoleBuffer
void flushConsoleBuffer()
If content exists in the buffer, write it.
Definition: OutputWarehouse.C:214
OutputWarehouse::_force_output
bool _force_output
Flag indicating that next call to outputStep is forced.
Definition: OutputWarehouse.h:345
OutputWarehouse::_console_buffer
std::ostringstream _console_buffer
The stream for holding messages passed to _console prior to Output object construction.
Definition: OutputWarehouse.h:336
OutputWarehouse::addOutput
void addOutput(std::shared_ptr< Output > &output)
Adds an existing output object to the warehouse.
Definition: OutputWarehouse.C:88
OutputWarehouse::addOutputFilename
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 ...
Definition: OutputWarehouse.C:135
OutputWarehouse::_all_ptrs
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.
Definition: OutputWarehouse.h:228
OutputWarehouse::getReservedNames
const std::set< std::string > & getReservedNames() const
Return a set of reserved output names.
Definition: OutputWarehouse.C:299
OutputWarehouse::buildInterfaceHideVariables
void buildInterfaceHideVariables(const std::string &output_name, std::set< std::string > &hide)
Return the list of hidden variables for the given output name.
Definition: OutputWarehouse.C:281
OutputWarehouse::_file_base_set
std::set< OutFileBase > _file_base_set
List of object names.
Definition: OutputWarehouse.h:315
OutputWarehouse::_material_output_map
std::map< OutputName, std::set< AuxVariableName > > _material_output_map
Map of output name and AuxVariable names to be output (used by auto Material output)
Definition: OutputWarehouse.h:327
OutputWarehouse::_object_map
std::map< OutputName, Output * > _object_map
A map of the output pointers.
Definition: OutputWarehouse.h:309
OutputWarehouse::forceOutput
void forceOutput()
Indicates that the next call to outputStep should be forced This is private, users should utilize FEP...
Definition: OutputWarehouse.C:324
OutputWarehouse::consoleBuffer
std::ostringstream & consoleBuffer()
The buffered messages stream for Console objects.
Definition: OutputWarehouse.h:177
OutputWarehouse::_common_params_ptr
InputParameters * _common_params_ptr
Pointer to the common InputParameters (.
Definition: OutputWarehouse.h:318
OutputInterface
A class to provide an common interface to objects requiring "outputs" option.
Definition: OutputInterface.h:37
OutputWarehouse::_interface_map
std::map< std::string, std::set< std::string > > _interface_map
Storage for variables to hide as prescribed by the object via the OutputInterface.
Definition: OutputWarehouse.h:339
OutputWarehouse::OutputWarehouse
OutputWarehouse(MooseApp &app)
Class constructor.
Definition: OutputWarehouse.C:25
OutputWarehouse::outputStep
void outputStep(ExecFlagType type)
Calls the outputStep method for each output object.
Definition: OutputWarehouse.C:143
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
OutputWarehouse::_output_exec_flag
ExecFlagType _output_exec_flag
The current output execution flag.
Definition: OutputWarehouse.h:342
OutputWarehouse
Class for storing and utilizing output objects.
Definition: OutputWarehouse.h:22
OutputWarehouse::solveSetup
void solveSetup()
Calls the timestepSetup function for each of the output objects.
Definition: OutputWarehouse.C:60
OutputWarehouse::~OutputWarehouse
virtual ~OutputWarehouse()
Definition: OutputWarehouse.C:38
OutputWarehouse::allowOutput
void allowOutput(bool state)
Ability to enable/disable output calls This is private, users should utilize FEProblemBase::allowOutp...
Definition: OutputWarehouse.C:317
OutputWarehouse::initialSetup
void initialSetup()
Calls the initialSetup function for each of the output objects.
Definition: OutputWarehouse.C:46
PetscOutput
Adds the ability to output on every nonlinear and/or linear residual.
Definition: PetscOutput.h:24
OutputWarehouse::getOutputs
std::vector< T * > getOutputs() const
Return a vector of objects of a given type.
Definition: OutputWarehouse.h:403
MooseEnumItem
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
Output.h
OutputWarehouse::_sync_times
std::set< Real > _sync_times
Sync times for all objects.
Definition: OutputWarehouse.h:321
OutputWarehouse::timestepSetup
void timestepSetup()
Calls the timestepSetup function for each of the output objects.
Definition: OutputWarehouse.C:53
Output::output
virtual void output(const ExecFlagType &type)=0
Overload this function with the desired output activities.
OutputWarehouse::_all_objects
std::vector< Output * > _all_objects
All instances of objects (raw pointers)
Definition: OutputWarehouse.h:303
OutputWarehouse::checkOutputs
void checkOutputs(const std::set< OutputName > &names)
Test that the output names exist.
Definition: OutputWarehouse.C:291
OutputWarehouse::jacobianSetup
void jacobianSetup()
Calls the jacobianSetup function for each of the output objects.
Definition: OutputWarehouse.C:67
OutputWarehouse::meshChanged
void meshChanged()
Calls the meshChanged method for every output object.
Definition: OutputWarehouse.C:169
OutputWarehouse::getOutput
T * getOutput(const OutputName &name)
Return an Output object by name.
Definition: OutputWarehouse.h:369
OutputWarehouse::bufferConsoleOutputsBeforeConstruction
void bufferConsoleOutputsBeforeConstruction(bool buffer)
Set if the outputs to Console before its construction are to be buffered or to screen directly.
Definition: OutputWarehouse.h:183
OutputWarehouse::setOutputExecutionType
void setOutputExecutionType(ExecFlagType type)
Sets the execution flag type.
Definition: OutputWarehouse.C:311
OutputWarehouse::_reserved
std::set< std::string > _reserved
List of reserved names.
Definition: OutputWarehouse.h:333
MooseApp
Base class for MOOSE-based applications.
Definition: MooseApp.h:61
OutputWarehouse::reset
void reset()
Reset the output system.
Definition: OutputWarehouse.C:330
OutputWarehouse::getLoggingRequested
bool getLoggingRequested() const
Returns a Boolean indicating whether performance logging is requested in this application.
Definition: OutputWarehouse.h:192
OutputWarehouse::residualSetup
void residualSetup()
Calls the residualSetup function for each of the output objects.
Definition: OutputWarehouse.C:74
OutputWarehouse::getCommonParameters
InputParameters * getCommonParameters()
Get a reference to the common output parameters.
Definition: OutputWarehouse.C:262
OutputWarehouse::_last_message_ended_in_newline
bool _last_message_ended_in_newline
Whether or not the last thing output by mooseConsole had a newline as the last character.
Definition: OutputWarehouse.h:351
OutputWarehouse::_input_file_name
std::string _input_file_name
Input file name for this output object.
Definition: OutputWarehouse.h:324
OutputWarehouse::_app
MooseApp & _app
MooseApp.
Definition: OutputWarehouse.h:300
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
MaterialOutputAction
Creates AuxVariables and AuxKernels for automatic output of material properties.
Definition: MaterialOutputAction.h:27
OutputWarehouse::getFileNumbers
std::map< std::string, unsigned int > getFileNumbers()
Extracts the file numbers from the output objects.
Definition: OutputWarehouse.C:242
MooseObject::name
virtual const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:70
OutputWarehouse::setLoggingRequested
void setLoggingRequested()
Sets a Boolean indicating that at least one object is requesting performance logging in this applicat...
Definition: OutputWarehouse.h:189