Line data Source code
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 "ControlOutput.h" 12 : #include "MooseApp.h" 13 : #include "MooseObjectParameterName.h" 14 : #include "InputParameterWarehouse.h" 15 : #include "ConsoleUtils.h" 16 : 17 : registerMooseObject("MooseApp", ControlOutput); 18 : 19 : InputParameters 20 14385 : ControlOutput::validParams() 21 : { 22 : // Get the base class parameters 23 14385 : InputParameters params = Output::validParams(); 24 14385 : params.addClassDescription( 25 : "Output for displaying objects and parameters associated with the Control system."); 26 : 27 43155 : params.set<ExecFlagEnum>("execute_on", true) = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN}; 28 43155 : params.addParam<bool>( 29 28770 : "clear_after_output", true, "Clear the active control display after each output."); 30 14385 : params.addParam<bool>("show_active_objects", true, "List active MooseObjects."); 31 : 32 : // Return the InputParameters 33 14385 : return params; 34 14385 : } 35 : 36 60 : ControlOutput::ControlOutput(const InputParameters & parameters) 37 : : Output(parameters), 38 60 : _clear_after_output(getParam<bool>("clear_after_output")), 39 120 : _show_active_objects(getParam<bool>("show_active_objects")) 40 : { 41 60 : } 42 : 43 : void 44 240 : ControlOutput::output() 45 : { 46 240 : if (_current_execute_flag == EXEC_INITIAL) 47 60 : outputControls(); 48 : else 49 180 : outputChangedControls(); 50 : 51 240 : if (_show_active_objects) 52 240 : outputActiveObjects(); 53 240 : } 54 : 55 : void 56 240 : ControlOutput::outputActiveObjects() 57 : { 58 : // Extract InputParameter objects from warehouse 59 240 : InputParameterWarehouse & wh = _app.getInputParameterWarehouse(); 60 240 : const auto & params = wh.getInputParameters(); 61 : 62 : // Populate a map based on unique InputParameter objects 63 240 : std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects; 64 22008 : for (const auto & iter : params) 65 21768 : objects[iter.second].insert(iter.first); 66 : 67 : // The stream to build 68 240 : std::stringstream oss; 69 240 : oss << std::left; 70 : 71 : // Loop through unique objects 72 240 : oss << "Active Objects:\n" << COLOR_DEFAULT; 73 18488 : for (const auto & iter : objects) 74 : { 75 18248 : std::shared_ptr<InputParameters> ptr = iter.first; 76 : // actions do not have 'enable' parameter 77 18248 : if (!ptr->have_parameter<bool>("enable") || ptr->get<bool>("enable")) 78 : { 79 : // We print slightly differently in the first iteration of the loop. 80 18248 : bool first_iteration = true; 81 40016 : for (const auto & obj_name : iter.second) 82 : { 83 21768 : if (first_iteration) 84 : { 85 18248 : oss << ConsoleUtils::indent(2) << COLOR_YELLOW << obj_name << COLOR_DEFAULT << '\n'; 86 18248 : first_iteration = false; 87 : } 88 : else 89 3520 : oss << ConsoleUtils::indent(4) << obj_name << '\n'; 90 : } 91 : } 92 18248 : } 93 : 94 240 : _console << oss.str() << std::endl; 95 240 : } 96 : 97 : void 98 60 : ControlOutput::outputControls() 99 : { 100 60 : InputParameterWarehouse & wh = _app.getInputParameterWarehouse(); 101 60 : const auto & params = wh.getInputParameters(); 102 : 103 60 : std::stringstream oss; 104 60 : oss << std::left; 105 : 106 : // Populate a map based on unique InputParameter objects 107 60 : std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectName>> objects; 108 5502 : for (const auto & iter : params) 109 5442 : objects[iter.second].insert(iter.first); 110 : 111 : // Produce the control information 112 60 : oss << "Controls:\n"; 113 4622 : for (const auto & iter : objects) 114 : { 115 4562 : std::shared_ptr<InputParameters> ptr = iter.first; 116 : 117 4562 : const std::set<std::string> & names = ptr->getControllableParameters(); 118 : 119 4562 : if (!names.empty()) 120 : { 121 1144 : oss << ConsoleUtils::indent(2) << COLOR_YELLOW << ptr->get<std::string>("_object_name") 122 1144 : << COLOR_DEFAULT << '\n'; 123 : 124 : // Full names(s) 125 1040 : oss << ConsoleUtils::indent(4) << "Name(s): "; 126 2720 : for (const auto & obj_name : iter.second) 127 1680 : oss << obj_name << " "; 128 1040 : oss << '\n'; 129 : 130 : // Tag(s) 131 1040 : const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags"); 132 1040 : if (!tags.empty()) 133 : { 134 920 : oss << ConsoleUtils::indent(4) << "Tag(s): "; 135 1840 : for (const auto & tag_name : tags) 136 920 : oss << tag_name << " "; 137 920 : oss << '\n'; 138 : } 139 : 140 1040 : oss << ConsoleUtils::indent(4) << "Parameter(s):\n"; 141 2620 : for (const auto & param_name : names) 142 3160 : oss << ConsoleUtils::indent(6) << std::setw(ConsoleUtils::console_field_width) << param_name 143 1580 : << ptr->type(param_name) << '\n'; 144 : } 145 4562 : } 146 : 147 60 : _console << oss.str() << std::endl; 148 60 : } 149 : 150 : void 151 180 : ControlOutput::outputChangedControls() 152 : { 153 180 : InputParameterWarehouse & wh = _app.getInputParameterWarehouse(); 154 180 : std::string dump = wh.dumpChangedControls(_clear_after_output); 155 180 : if (!dump.empty()) 156 90 : _console << "\nActive Controls:\n" << dump << std::endl; 157 180 : }