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