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 : #pragma once 11 : 12 : #include "Action.h" 13 : #include "hit/hit.h" 14 : 15 : // Forward declarations 16 : class ReporterName; 17 : 18 : class ParameterStudyAction : public Action 19 : { 20 : public: 21 : static InputParameters validParams(); 22 : 23 : ParameterStudyAction(const InputParameters & params); 24 : 25 : virtual void act() override; 26 : 27 : /// Return an enum of available sampling types for the study 28 : static MooseEnum samplingTypes(); 29 : /// Return an enum of available distributions for the study 30 : static MultiMooseEnum distributionTypes(); 31 : 32 : protected: 33 : /** 34 : * The perscribed name of the distribution. Need this to give the right name to the sampler 35 : * 36 : * @param count The index of the distribution 37 : * @return Name of the distribution 38 : */ 39 : DistributionName distributionName(unsigned int count) const; 40 : std::vector<DistributionName> distributionNames(unsigned int full_count) const; 41 : 42 : /** 43 : * The perscribed name of the sampler created in this action. 44 : * 45 : * @return SamplerName The name of sampler. 46 : */ 47 : SamplerName samplerName() const { return "study_sampler"; } 48 : 49 : /** 50 : * The perscribed name of the multiapp created in this action. 51 : * 52 : * @return MultiAppName The name of multiapp. 53 : */ 54 : MultiAppName multiappName() const { return "study_app"; } 55 : 56 : /** 57 : * The perscribed name of the control given to the sub-app for parameter transfer. 58 : * 59 : * @return std::string The name of the SamplerReceiver control. 60 : */ 61 320 : std::string samplerReceiverName() const { return "study_receiver"; } 62 : 63 : /** 64 : * The perscribed name of the command-line control created in this action. 65 : * 66 : * @return std::string The name of the SamplerReceiver control. 67 : */ 68 144 : std::string multiappControlName() const { return "study_multiapp_control"; } 69 : 70 : /** 71 : * The perscribed name of the parameter transfer created in this action. 72 : * 73 : * @return std::string The name of the SamplerParameterTransfer transfer. 74 : */ 75 512 : std::string parameterTransferName() const { return "study_parameter_transfer"; } 76 : 77 : /** 78 : * The perscribed name of the reporter transfer created in this action. 79 : * 80 : * @return std::string The name of the SamplerReporterTransfer transfer. 81 : */ 82 656 : std::string reporterTransferName() const { return "study_qoi_transfer"; } 83 : 84 : /** 85 : * The perscribed name of the QoI storage object created in this action. 86 : * 87 : * @return std::string The name of the StochasticReporter. 88 : */ 89 1616 : std::string stochasticReporterName() const { return "study_results"; } 90 : 91 : /** 92 : * The perscribed name of the output objects created in this action. 93 : * 94 : * @param type The type of output object created 95 : * @return std::string The name of the StochasticReporter. 96 : */ 97 1840 : OutputName outputName(std::string type) const { return type; } 98 : 99 : /** 100 : * The name of the reporter values in the StochasticReporter representing the QoIs. 101 : * 102 : * @param qoi The name of the reporter on the sub-app 103 : * @return ReporterName The name of the QoI in StochasticReporter. 104 : */ 105 : ReporterName quantityOfInterestName(const ReporterName & qoi) const; 106 : 107 : /** 108 : * The perscribed name of the statistics object created in this action. 109 : * 110 : * @return std::string The name of the StatisticsReporter. 111 : */ 112 560 : std::string statisticsName() const { return "study_statistics"; } 113 : 114 : /** 115 : * Helper function for getting the param value for the distribution index 116 : * 117 : * @tparam T The type of parameter, it will be trying to get std::vector<T> 118 : * @param param The name of the parameter 119 : * @param count The index of the specific distribution 120 : * @return T The inputted value of the parameter at the given index 121 : */ 122 : template <typename T> 123 : T getDistributionParam(std::string param, unsigned int count) const; 124 : 125 : /** 126 : * Helper function to show the object being built. Will display: 127 : * - Object base type 128 : * - Object type 129 : * - Object name 130 : * - Parameters set by the action 131 : * 132 : * @param type The type of objecte, i.e. "SamplerFullSolveMultiApp" 133 : * @param name The name of the object 134 : * @param params The parameters used to create the object 135 : */ 136 : void showObject(std::string type, std::string name, const InputParameters & params) const; 137 : 138 : private: 139 : /** 140 : * This is a vector associating the sampling type with a list of associated parameters 141 : * The list includes the parameter name and whether or not it is required. 142 : */ 143 : static std::vector<std::map<std::string, bool>> samplerParameters(); 144 : 145 : /** 146 : * This is a vector associating the distribution type and a list of parameters that are needed 147 : */ 148 : static std::vector<std::vector<std::string>> distributionParameters(); 149 : 150 : /** 151 : * List of parameters that are only associated with computing statistics 152 : */ 153 : static std::set<std::string> statisticsParameters(); 154 : 155 : /** 156 : * This function will infer the best way to run the multiapps 157 : * 158 : * @return unsigned int The multiapp execution mode, see the 'multiapp_mode' input param for 159 : * details 160 : */ 161 : unsigned int inferMultiAppMode(); 162 : 163 : /// The inputted parameter vector 164 : const std::vector<std::string> & _parameters; 165 : /// The sampling type 166 : const unsigned int _sampling_type; 167 : /// The distributions 168 : const MultiMooseEnum _distributions; 169 : /// The multiapp mode. This is used for determining type of execution for the multiapp and the 170 : /// way to send the perturbed parameters 171 : const unsigned int _multiapp_mode; 172 : /// Whether or not we are computing statistics 173 : const bool _compute_stats; 174 : /// Switch to show the objects being built on console 175 : const bool _show_objects; 176 : }; 177 : 178 : template <typename T> 179 : T 180 1776 : ParameterStudyAction::getDistributionParam(std::string param, unsigned int count) const 181 : { 182 : const auto & val = getParam<std::vector<T>>(param); 183 1776 : return val[count]; 184 : } 185 : 186 : /** 187 : * This class is a hit walker used to see if a list of parameters are all controllable 188 : */ 189 : class AreParametersControllableWalker : public hit::Walker 190 : { 191 : public: 192 : AreParametersControllableWalker(const std::vector<std::string> & parameters, MooseApp & app); 193 : 194 : void walk(const std::string & fullpath, const std::string & nodename, hit::Node * n) override; 195 : bool areControllable() const; 196 : 197 : private: 198 : MooseApp & _app; 199 : std::vector<bool> _is_controllable; 200 : std::vector<std::pair<std::string, std::string>> _pars; 201 : }; 202 : 203 : /** 204 : * This class is a hit walker used to see what type of execution the input is doing 205 : */ 206 324 : class ExecutionTypeWalker : public hit::Walker 207 : { 208 : public: 209 324 : ExecutionTypeWalker() : _exec_type(0), _found_exec(false) {} 210 : 211 : void walk(const std::string & fullpath, const std::string & nodename, hit::Node * n) override; 212 324 : unsigned int getExecutionType() const { return _exec_type; } 213 : 214 : private: 215 : unsigned int _exec_type; 216 : bool _found_exec; 217 : };