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 
21 {
22  // Get the base class parameters
24  params.addClassDescription(
25  "Output for displaying objects and parameters associated with the Control system.");
26 
27  params.set<ExecFlagEnum>("execute_on", true) = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
28  params.addParam<bool>(
29  "clear_after_output", true, "Clear the active control display after each output.");
30  params.addParam<bool>("show_active_objects", true, "List active MooseObjects.");
31 
32  // Return the InputParameters
33  return params;
34 }
35 
37  : Output(parameters),
38  _clear_after_output(getParam<bool>("clear_after_output")),
39  _show_active_objects(getParam<bool>("show_active_objects"))
40 {
41 }
42 
43 void
45 {
48  else
50 
53 }
54 
55 void
57 {
58  // Extract InputParameter objects from warehouse
60  const auto & params = wh.getInputParameters();
61 
62  // Populate a map based on unique InputParameter objects
63  std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects;
64  for (const auto & iter : params)
65  objects[iter.second].insert(iter.first);
66 
67  // The stream to build
68  std::stringstream oss;
69  oss << std::left;
70 
71  // Loop through unique objects
72  oss << "Active Objects:\n" << COLOR_DEFAULT;
73  for (const auto & iter : objects)
74  {
75  std::shared_ptr<InputParameters> ptr = iter.first;
76  // actions do not have 'enable' parameter
77  if (!ptr->have_parameter<bool>("enable") || 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:31
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
Storage container for all InputParamter objects.
void outputControls()
Output list of controllable parameters.
Definition: ControlOutput.C:98
static InputParameters validParams()
Definition: ControlOutput.C:20
bool _show_active_objects
Flag for showing active objects.
Definition: ControlOutput.h:54
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:2224
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:56
std::string dumpChangedControls(bool reset_changed) const
static const unsigned int console_field_width
Width used for printing simulation information.
Definition: ConsoleUtils.h:30
Based class for output objects.
Definition: Output.h:43
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
Definition: Moose.C:33
ExecFlagType _current_execute_flag
Current execute on flag.
Definition: Output.h:205
void outputChangedControls()
Output list of parameters that have been controlled.
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:69
bool _clear_after_output
Flag for clearing the controlled parameters after they are output.
Definition: ControlOutput.h:51
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:18
virtual void output() override
Perform the output of control information.
Definition: ControlOutput.C:44
ControlOutput(const InputParameters &parameters)
Class constructor.
Definition: ControlOutput.C:36
static InputParameters validParams()
Definition: Output.C:32
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28