www.mooseframework.org
ControlOutput.C
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 // Moose includes
16 #include "ControlOutput.h"
17 #include "MooseApp.h"
20 #include "ConsoleUtils.h"
21 
22 template <>
25 {
26  // Get the base class parameters
28  params.set<MultiMooseEnum>("execute_on") = "initial timestep_begin";
29  params.addParam<bool>(
30  "clear_after_output", true, "Clear the active control display after each output.");
31  params.addParam<bool>("show_active_objects", true, "List active MooseObjects.");
32 
33  // Return the InputParameters
34  return params;
35 }
36 
38  : Output(parameters),
39  _clear_after_output(getParam<bool>("clear_after_output")),
40  _show_active_objects(getParam<bool>("show_active_objects"))
41 {
42 }
43 
44 void
46 {
47  switch (type)
48  {
49  case EXEC_INITIAL:
51  break;
52  default:
54  }
55 
58 }
59 
60 void
62 {
63  // Extract InputParameter objects from warehouse
65  const auto & params = wh.getInputParameters();
66 
67  // Populate a map based on unique InputParameter objects
68  std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects;
69  for (const auto & iter : params)
70  objects[iter.second].insert(iter.first);
71 
72  // The stream to build
73  std::stringstream oss;
74  oss << std::left;
75 
76  // Loop through unique objects
77  oss << "Active Objects:\n" << COLOR_DEFAULT;
78  for (const auto & iter : objects)
79  {
80  std::shared_ptr<InputParameters> ptr = iter.first;
81  if (ptr->get<bool>("enable"))
82  {
83  // We print slightly differently in the first iteration of the loop.
84  bool first_iteration = true;
85  for (const auto & obj_name : iter.second)
86  {
87  if (first_iteration)
88  {
89  oss << ConsoleUtils::indent(2) << COLOR_YELLOW << obj_name << COLOR_DEFAULT << '\n';
90  first_iteration = false;
91  }
92  else
93  oss << ConsoleUtils::indent(4) << obj_name << '\n';
94  }
95  }
96  }
97 
98  _console << oss.str() << std::endl;
99 }
100 
101 void
103 {
104 
105  // Extract InputParameter objects from warehouse
107  const auto & params = wh.getInputParameters();
108 
109  // The stream to build
110  std::stringstream oss;
111  oss << std::left;
112 
113  // Populate a map based on unique InputParameter objects
114  std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects;
115  for (const auto & iter : params)
116  objects[iter.second].insert(iter.first);
117 
118  // Produce the control information
119  oss << "Controls:\n";
120  for (const auto & iter : objects)
121  {
122  std::shared_ptr<InputParameters> ptr = iter.first;
123 
124  const std::set<std::string> & names = ptr->getControllableParameters();
125 
126  if (!names.empty())
127  {
128  oss << ConsoleUtils::indent(2) << COLOR_YELLOW << ptr->get<std::string>("_object_name")
129  << COLOR_DEFAULT << '\n';
130 
131  // Full names(s)
132  oss << ConsoleUtils::indent(4) << "Name(s): ";
133  for (const auto & obj_name : iter.second)
134  oss << obj_name << " ";
135  oss << '\n';
136 
137  // Tag(s)
138  const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags");
139  if (!tags.empty())
140  {
141  oss << ConsoleUtils::indent(4) << "Tag(s): ";
142  for (const auto & tag_name : tags)
143  oss << tag_name << " ";
144  oss << '\n';
145  }
146 
147  oss << ConsoleUtils::indent(4) << "Parameter(s):\n";
148  for (const auto & param_name : names)
149  oss << ConsoleUtils::indent(6) << std::setw(ConsoleUtils::console_field_width) << param_name
150  << ptr->type(param_name) << '\n';
151  }
152  }
153 
154  _console << oss.str() << std::endl;
155 }
156 
157 void
159 {
160  // Extract InputParameter objects from warehouse
162  const auto & controls = wh.getControlledParameters();
163 
164  // The stream to build
165  std::stringstream oss;
166  oss << std::left;
167 
168  // Print header
169  if (!controls.empty())
170  oss << "Active Controls:\n";
171 
172  // Loop over the controlled parameters
173  for (const auto & iter : controls)
174  {
175  const auto ptr = iter.first;
176  oss << " " << COLOR_YELLOW << ptr->get<std::string>("_object_name") << COLOR_DEFAULT << '\n';
177 
178  // Tag(s)
179  const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags");
180  if (!tags.empty())
181  {
182  oss << ConsoleUtils::indent(4) << "Tag(s): ";
183  for (const auto & tag_name : tags)
184  oss << tag_name << " ";
185  oss << '\n';
186  }
187 
188  oss << ConsoleUtils::indent(4) << "Parameter(s):\n";
189  for (const auto & param_name : iter.second)
191  << param_name.parameter() << ptr->type(param_name.parameter()) << '\n';
192  }
193 
194  _console << oss.str() << std::endl;
195 
198 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:34
virtual void output(const ExecFlagType &type) override
Perform the output of control information.
Definition: ControlOutput.C:45
Storage container for all InputParamter objects.
void outputControls()
Output list of controllable parameters.
Object is evaluated only once at the beginning of the simulation.
Definition: MooseTypes.h:94
bool _show_active_objects
Flag for showing active objects.
Definition: ControlOutput.h:64
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:1121
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void outputActiveObjects()
Output a list of active MooseObjects.
Definition: ControlOutput.C:61
static const unsigned int console_field_width
Width used for printing simulation information.
Definition: ConsoleUtils.h:35
Based class for output objects.
Definition: Output.h:45
InputParameters validParams< ControlOutput >()
Definition: ControlOutput.C:24
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
void outputChangedControls()
Output list of parameters that have been controlled.
const std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > & getControlledParameters()
Return the list of controlled parameters (used for output)
InputParameters validParams< Output >()
Definition: Output.C:34
bool _clear_after_output
Flag for clearing the controlled parameters after they are output.
Definition: ControlOutput.h:61
MatType type
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
ControlOutput(const InputParameters &parameters)
Class constructor.
Definition: ControlOutput.C:37