www.mooseframework.org
ControlOutput.C
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 // Moose includes
11 #include "ControlOutput.h"
12 #include "MooseApp.h"
15 #include "ConsoleUtils.h"
16 
18 
19 template <>
22 {
23  // Get the base class parameters
25  params.addClassDescription(
26  "Output for displaying objects and parameters associated with the Control system.");
27 
28  params.set<ExecFlagEnum>("execute_on", true) = {EXEC_INITIAL, EXEC_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  if (type == EXEC_INITIAL)
49  else
51 
54 }
55 
56 void
58 {
59  // Extract InputParameter objects from warehouse
61  const auto & params = wh.getInputParameters();
62 
63  // Populate a map based on unique InputParameter objects
64  std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects;
65  for (const auto & iter : params)
66  objects[iter.second].insert(iter.first);
67 
68  // The stream to build
69  std::stringstream oss;
70  oss << std::left;
71 
72  // Loop through unique objects
73  oss << "Active Objects:\n" << COLOR_DEFAULT;
74  for (const auto & iter : objects)
75  {
76  std::shared_ptr<InputParameters> ptr = iter.first;
77  if (ptr->get<bool>("enable"))
78  {
79  // We print slightly differently in the first iteration of the loop.
80  bool first_iteration = true;
81  for (const auto & obj_name : iter.second)
82  {
83  if (first_iteration)
84  {
85  oss << ConsoleUtils::indent(2) << COLOR_YELLOW << obj_name << COLOR_DEFAULT << '\n';
86  first_iteration = false;
87  }
88  else
89  oss << ConsoleUtils::indent(4) << obj_name << '\n';
90  }
91  }
92  }
93 
94  _console << oss.str() << std::endl;
95 }
96 
97 void
99 {
101  const auto & params = wh.getInputParameters();
102 
103  std::stringstream oss;
104  oss << std::left;
105 
106  // Populate a map based on unique InputParameter objects
107  std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects;
108  for (const auto & iter : params)
109  objects[iter.second].insert(iter.first);
110 
111  // Produce the control information
112  oss << "Controls:\n";
113  for (const auto & iter : objects)
114  {
115  std::shared_ptr<InputParameters> ptr = iter.first;
116 
117  const std::set<std::string> & names = ptr->getControllableParameters();
118 
119  if (!names.empty())
120  {
121  oss << ConsoleUtils::indent(2) << COLOR_YELLOW << ptr->get<std::string>("_object_name")
122  << COLOR_DEFAULT << '\n';
123 
124  // Full names(s)
125  oss << ConsoleUtils::indent(4) << "Name(s): ";
126  for (const auto & obj_name : iter.second)
127  oss << obj_name << " ";
128  oss << '\n';
129 
130  // Tag(s)
131  const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags");
132  if (!tags.empty())
133  {
134  oss << ConsoleUtils::indent(4) << "Tag(s): ";
135  for (const auto & tag_name : tags)
136  oss << tag_name << " ";
137  oss << '\n';
138  }
139 
140  oss << ConsoleUtils::indent(4) << "Parameter(s):\n";
141  for (const auto & param_name : names)
142  oss << ConsoleUtils::indent(6) << std::setw(ConsoleUtils::console_field_width) << param_name
143  << ptr->type(param_name) << '\n';
144  }
145  }
146 
147  _console << oss.str() << std::endl;
148 }
149 
150 void
152 {
154  std::string dump = wh.dumpChangedControls(_clear_after_output);
155  if (!dump.empty())
156  _console << "\nActive Controls:\n" << dump << std::endl;
157 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:30
virtual void output(const ExecFlagType &type) override
Perform the output of control information.
Definition: ControlOutput.C:45
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
Storage container for all InputParamter objects.
void outputControls()
Output list of controllable parameters.
Definition: ControlOutput.C:98
bool _show_active_objects
Flag for showing active objects.
Definition: ControlOutput.h:58
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:1341
registerMooseObject("MooseApp", ControlOutput)
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:57
std::string dumpChangedControls(bool reset_changed) const
static const unsigned int console_field_width
Width used for printing simulation information.
Definition: ConsoleUtils.h:29
const std::string & type() const
Get the type of this object.
Definition: MooseObject.h:53
Based class for output objects.
Definition: Output.h:41
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
const ExecFlagType EXEC_TIMESTEP_BEGIN
InputParameters validParams< ControlOutput >()
Definition: ControlOutput.C:21
void outputChangedControls()
Output list of parameters that have been controlled.
InputParameters validParams< Output >()
Definition: Output.C:29
bool _clear_after_output
Flag for clearing the controlled parameters after they are output.
Definition: ControlOutput.h:55
MatType type
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
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 option parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Class for output information regarding Controls to the screen.
Definition: ControlOutput.h:24
ControlOutput(const InputParameters &parameters)
Class constructor.
Definition: ControlOutput.C:37
const ExecFlagType EXEC_INITIAL