https://mooseframework.inl.gov
OutputInterface.C
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 // MOOSE includes
11 #include "OutputInterface.h"
12 #include "OutputWarehouse.h"
13 #include "MooseApp.h"
14 #include "ActionWarehouse.h"
15 
16 // Define input parameters
19 {
21  params.addClassDescription("Interface to handle the restriction of outputs from objects");
22  params.addParam<std::vector<OutputName>>("outputs",
23  "Vector of output names where you would like "
24  "to restrict the output of variables(s) "
25  "associated with this object");
26 
27  params.addParamNamesToGroup("outputs", "Advanced");
28  std::set<std::string> reserved = {"all", "none"};
29  params.setReservedValues("outputs", reserved);
30 
31  return params;
32 }
33 
34 OutputInterface::OutputInterface(const InputParameters & parameters, bool build_list)
35  : _oi_moose_app(*parameters.getCheckedPointerParam<MooseApp *>(MooseBase::app_param)),
36  _oi_output_warehouse(_oi_moose_app.getOutputWarehouse()),
37  _oi_outputs(parameters.get<std::vector<OutputName>>("outputs").begin(),
38  parameters.get<std::vector<OutputName>>("outputs").end())
39 {
40  // By default it is assumed that the variable name associated with 'outputs' is the name
41  // of the block, this is the case for Markers, Indicators, VectorPostprocessors, and
42  // Postprocessors.
43  // However, for Materials this is not the case, so the call to buildOutputHideVariableList must
44  // be disabled, the build_list allows for this behavior. The hide lists are handled by
45  // MaterialOutputAction in this case.
46  //
47  // Variables/AuxVariables also call the buildOutputHideVariableList method later, because when
48  // their actions are called the Output objects do not exist. This case is handled by the
49  // CheckOutputAction::checkVariableOutput.
50  if (build_list)
51  {
52  std::set<std::string> names_set;
53  names_set.insert(parameters.getObjectName());
54  buildOutputHideVariableList(names_set);
55  }
56 }
57 
58 #ifdef MOOSE_KOKKOS_ENABLED
60  : _oi_moose_app(object._oi_moose_app),
61  _oi_output_warehouse(object._oi_output_warehouse),
62  _oi_outputs(object._oi_outputs)
63 {
64 }
65 #endif
66 
67 void
68 OutputInterface::buildOutputHideVariableList(std::set<std::string> variable_names)
69 {
70  // Set of available names
71  const std::set<OutputName> & avail = _oi_output_warehouse.getOutputNames();
72 
73  // Check for 'none'; hide variables on all outputs
74  if (_oi_outputs.find("none") != _oi_outputs.end())
75  for (const auto & name : avail)
77 
78  // Check for empty and 'all' in 'outputs' parameter; do not perform any variable restrictions in
79  // these cases
80  else if (_oi_outputs.empty() || _oi_outputs.find("all") != _oi_outputs.end())
81  return;
82 
83  // Limit the variable output to Output objects listed
84  else
85  {
86  // Create a list of outputs where the variable should be hidden
87  std::set<OutputName> hide;
88  std::set_difference(avail.begin(),
89  avail.end(),
90  _oi_outputs.begin(),
91  _oi_outputs.end(),
92  std::inserter(hide, hide.begin()));
93 
94  // If 'outputs' is specified add the object name to the list of items to hide
95  for (const auto & name : hide)
97  }
98 }
99 
100 const std::set<OutputName> &
102 {
103  return _oi_outputs;
104 }
std::string name(const ElemQuality q)
OutputWarehouse & _oi_output_warehouse
Reference to the OutputWarehouse for populating the Output object hide lists.
Base class for everything in MOOSE with a name and a type.
Definition: MooseBase.h:49
static InputParameters validParams()
const std::string & getObjectName() const
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1133
A class to provide an common interface to objects requiring "outputs" option.
Base class for MOOSE-based applications.
Definition: MooseApp.h:103
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
OutputInterface(const InputParameters &parameters, bool build_list=true)
Handles &#39;outputs&#39; parameter for objects that desire control of variable outputs.
InputParameters emptyInputParameters()
std::set< OutputName > _oi_outputs
The set of Output object names listed in the &#39;outputs&#39; parameter.
void buildOutputHideVariableList(std::set< std::string > variable_names)
Builds hide lists for output objects NOT listed in the &#39;outputs&#39; parameter.
void setReservedValues(const std::string &name, const std::set< std::string > &reserved)
Provide a set of reserved values for a parameter.
const std::set< OutputName > & getOutputNames()
Get a complete set of all output object names.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
void addInterfaceHideVariables(const std::string &output_name, const std::set< std::string > &variable_names)
Insert variable names for hiding via the OutoutInterface.
const std::set< OutputName > & getOutputs()
Get the list of output objects that this class is restricted.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...