34 "input",
"The input file containing the physics for the parameter study.");
36 "parameters",
"List of parameters being perturbed for the study.");
37 params.
addParam<std::vector<ReporterName>>(
38 "quantities_of_interest",
39 "List of the reporter names (object_name/value_name) " 40 "that represent the quantities of interest for the study.");
46 "Whether or not to compute statistics on the 'quantities_of_interest'. " 47 "The default is to compute mean and standard deviation with 0.01, 0.05, 0.1, 0.9, " 48 "0.95, and 0.99 confidence intervals.");
50 stats =
"mean stddev";
52 "statistics", stats,
"The statistic(s) to compute for the study.");
53 params.
addParam<std::vector<Real>>(
"ci_levels",
54 std::vector<Real>({0.01, 0.05, 0.1, 0.9, 0.95, 0.99}),
55 "A vector of confidence levels to consider for statistics " 56 "confidence intervals, values must be in (0, 1).");
60 "The number of replicates to use when computing confidence level intervals for statistics.");
64 "sampling_type",
samplingTypes(),
"The type of sampling to use for the parameter study.");
65 params.
addParam<
unsigned int>(
"seed", 0,
"Random number generator initial seed");
69 "normal=0 batch-reset=1 batch-restore=2 batch-keep-solution=3 batch-no-restore=4");
73 "The operation mode, 'normal' creates one sub-application for each sample." 74 "'batch' creates one sub-app for each processor and re-executes for each local sample. " 75 "'reset' re-initializes the sub-app for every sample in the batch. " 76 "'restore' does not re-initialize and instead restores to first sample's initialization. " 77 "'keep-solution' re-uses the solution obtained from the first sample in the batch. " 78 "'no-restore' does not restore the sub-app." 79 "The default will be inferred based on the study.");
81 "min_procs_per_sample",
83 "Minimum number of processors to give to each sample. Useful for larger, distributed mesh " 84 "solves where there are memory constraints.");
85 params.
addParam<
bool>(
"ignore_solve_not_converge",
87 "True to continue main app even if a sub app's solve does not converge.");
92 "num_samples",
"The number of samples to generate for 'monte-carlo' and 'lhs' sampling.");
96 "The types of distribution to use for 'monte-carlo' and " 97 "'lhs' sampling. The number of entries defines the number of columns in the matrix.");
100 "linear_space_items",
101 "Parameter for defining the 'cartesian-prodcut' sampling scheme. A list of triplets, each " 102 "item should include the min, step size, and number of steps.");
106 "Name of the CSV file that contains the sample matrix for 'csv' sampling.");
107 params.
addParam<std::vector<dof_id_type>>(
108 "csv_column_indices",
109 "Column indices in the CSV file to be sampled from for 'csv' sampling. Number of indices " 111 "will be the same as the number of columns per matrix.");
112 params.
addParam<std::vector<std::string>>(
114 "Column names in the CSV file to be sampled from for 'csv' sampling. Number of columns names " 115 "here will be the same as the number of columns per matrix.");
121 params.
addParam<std::vector<Real>>(
"normal_mean",
122 "Means (or expectations) of the 'normal' distributions.");
123 params.
addParam<std::vector<Real>>(
"normal_standard_deviation",
124 "Standard deviations of the 'normal' distributions.");
126 params.
addParam<std::vector<Real>>(
"uniform_lower_bound",
127 "Lower bounds for 'uniform' distributions.");
128 params.
addParam<std::vector<Real>>(
"uniform_upper_bound",
129 "Upper bounds 'uniform' distributions.");
131 params.
addParam<std::vector<Real>>(
"weibull_location",
132 "Location parameter (a or low) for 'weibull' distributions.");
133 params.
addParam<std::vector<Real>>(
"weibull_scale",
134 "Scale parameter (b or lambda) for 'weibull' distributions.");
135 params.
addParam<std::vector<Real>>(
"weibull_shape",
136 "Shape parameter (c or k) for 'weibull' distributions.");
139 "lognormal_location",
"The 'lognormal' distributions' location parameter (m or mu).");
141 "lognormal_scale",
"The 'lognormal' distributions' scale parameter (s or sigma).");
143 params.
addParam<std::vector<Real>>(
"tnormal_mean",
144 "Means (or expectations) of the 'tnormal' distributions.");
145 params.
addParam<std::vector<Real>>(
"tnormal_standard_deviation",
146 "Standard deviations of the 'tnormal' distributions.");
147 params.
addParam<std::vector<Real>>(
"tnormal_lower_bound",
"'tnormal' distributions' lower bound");
148 params.
addParam<std::vector<Real>>(
"tnormal_upper_bound",
"'tnormal' distributions' upper bound");
155 "Method in which to output sampler matrix and quantities of interest. Warning: " 156 "'csv' output will not include vector-type quantities.");
157 params.
addParam<std::vector<ReporterValueName>>(
158 "sampler_column_names",
159 "Names of the sampler columns for outputting the sampling matrix. If 'parameters' are not " 160 "bracketed, the default is based on these values. Otherwise, the default is based on the " 164 params.
addParam<
bool>(
"show_study_objects",
166 "Set to true to show all the objects being built by this action.");
172 _parameters(getParam<
std::vector<
std::string>>(
"parameters")),
173 _sampling_type(getParam<
MooseEnum>(
"sampling_type")),
174 _distributions(isParamValid(
"distributions") ? getParam<
MultiMooseEnum>(
"distributions")
176 _multiapp_mode(inferMultiAppMode()),
177 _compute_stats(isParamValid(
"quantities_of_interest") && getParam<bool>(
"compute_statistics")),
178 _show_objects(getParam<bool>(
"show_study_objects"))
184 for (
const auto & param : this_sampler_params)
189 " parameter is required to build the requested sampling type.");
191 std::string msg =
"";
192 for (
unsigned int i = 0; i < sampler_params.size(); ++i)
193 for (
const auto & param : sampler_params[i])
194 if (this_sampler_params.find(param.first) == this_sampler_params.end() &&
196 msg += (msg.empty() ?
"" :
", ") + param.first;
199 "The following parameters are unused for the selected sampling type: ",
204 std::vector<unsigned int> dist_count(distribution_params.size(), 0);
206 dist_count[(
unsigned int)dist]++;
208 for (
unsigned int i = 0; i < distribution_params.size(); ++i)
209 for (
const auto & param : distribution_params[i])
216 " parameter is required to build the listed distributions.");
218 else if (dist_count[i] > 0 &&
getParam<std::vector<Real>>(param).size() != dist_count[i])
220 "The number of entries in ",
222 " does not match the number of required entries (",
224 ") to build the listed distributions.");
227 msg += (msg.empty() ?
"" :
", ") + param;
231 "distributions",
"The following parameters are unused for the listed distributions: ", msg);
239 msg += (msg.empty() ?
"" :
", ") + param;
242 "The following parameters are unused since statistics are not being computed: ",
250 return MooseEnum(
"monte-carlo=0 lhs=1 cartesian-product=2 csv=3 input-matrix=4");
256 return MultiMooseEnum(
"normal=0 uniform=1 weibull=2 lognormal=3 tnormal=4");
265 if (stm_actions.empty())
268 params.
set<
bool>(
"_built_by_moose") =
true;
269 params.set<std::string>(
"registered_identifier") =
"(AutoBuilt)";
272 "StochasticToolsAction",
_name +
"_stochastic_tools_action", params);
276 showObject(
"StochasticToolsAction",
_name +
"_stochastic_tools_action", params);
283 std::unordered_map<std::string, unsigned int> dist_count;
289 std::string distribution_type;
293 unsigned int full_count = 0;
297 unsigned int & count = dist_count[dist.name()];
300 if (dist ==
"normal")
302 distribution_type =
"Normal";
304 params.
set<
Real>(
"mean") = getDistributionParam<Real>(
"normal_mean", count);
305 params.
set<
Real>(
"standard_deviation") =
306 getDistributionParam<Real>(
"normal_standard_deviation", count);
308 else if (dist ==
"uniform")
310 distribution_type =
"Uniform";
312 params.
set<
Real>(
"lower_bound") = getDistributionParam<Real>(
"uniform_lower_bound", count);
313 params.
set<
Real>(
"upper_bound") = getDistributionParam<Real>(
"uniform_upper_bound", count);
315 else if (dist ==
"weibull")
317 distribution_type =
"Weibull";
319 params.
set<
Real>(
"location") = getDistributionParam<Real>(
"weibull_location", count);
320 params.
set<
Real>(
"scale") = getDistributionParam<Real>(
"weibull_scale", count);
321 params.
set<
Real>(
"shape") = getDistributionParam<Real>(
"weibull_shape", count);
323 else if (dist ==
"lognormal")
325 distribution_type =
"Lognormal";
327 params.
set<
Real>(
"location") = getDistributionParam<Real>(
"lognormal_location", count);
328 params.
set<
Real>(
"scale") = getDistributionParam<Real>(
"lognormal_scale", count);
330 else if (dist ==
"tnormal")
332 distribution_type =
"TruncatedNormal";
334 params.
set<
Real>(
"mean") = getDistributionParam<Real>(
"tnormal_mean", count);
335 params.
set<
Real>(
"standard_deviation") =
336 getDistributionParam<Real>(
"tnormal_standard_deviation", count);
337 params.
set<
Real>(
"lower_bound") = getDistributionParam<Real>(
"tnormal_lower_bound", count);
338 params.
set<
Real>(
"upper_bound") = getDistributionParam<Real>(
"tnormal_upper_bound", count);
341 paramError(
"distributions",
"Unknown distribution type.");
357 std::string sampler_type;
364 sampler_type =
_sampling_type == 0 ?
"MonteCarlo" :
"LatinHypercube";
366 params.
set<
dof_id_type>(
"num_rows") = getParam<dof_id_type>(
"num_samples");
367 params.
set<std::vector<DistributionName>>(
"distributions") =
373 sampler_type =
"CartesianProduct";
375 params.
set<std::vector<Real>>(
"linear_space_items") =
376 getParam<std::vector<Real>>(
"linear_space_items");
381 sampler_type =
"CSVSampler";
383 params.
set<FileName>(
"samples_file") = getParam<FileName>(
"csv_samples_file");
386 "'csv_column_indices' and 'csv_column_names' cannot both be set.");
388 params.
set<std::vector<dof_id_type>>(
"column_indices") =
389 getParam<std::vector<dof_id_type>>(
"csv_column_indices");
391 params.
set<std::vector<std::string>>(
"column_names") =
392 getParam<std::vector<std::string>>(
"csv_column_names");
397 sampler_type =
"InputMatrix";
402 paramError(
"sampling_type",
"Unknown sampling type.");
411 params.
set<
unsigned int>(
"min_procs_per_row") = getParam<unsigned int>(
"min_procs_per_sample");
423 params.
set<
bool>(
"ignore_solve_not_converge") = getParam<bool>(
"ignore_solve_not_converge");
426 params.set<std::vector<FileName>>(
"input_files") = {getParam<FileName>(
"input")};
429 params.set<SamplerName>(
"sampler") =
samplerName();
434 params.set<
MooseEnum>(
"mode") =
"normal";
437 params.set<
MooseEnum>(
"mode") =
"batch-reset";
442 params.set<
MooseEnum>(
"mode") =
"batch-restore";
447 params.set<std::vector<CLIArgString>>(
"cli_args").push_back(clia);
451 params.set<
bool>(
"keep_solution_during_restore") =
true;
454 params.set<
bool>(
"no_restore") =
true;
458 params.set<
unsigned int>(
"min_procs_per_app") = getParam<unsigned int>(
"min_procs_per_sample");
475 params.set<SamplerName>(
"sampler") =
samplerName();
476 params.set<std::vector<std::string>>(
"parameters") =
_parameters;
487 params.set<SamplerName>(
"sampler") =
samplerName();
489 params.set<std::vector<ReporterName>>(
"from_reporter") =
490 getParam<std::vector<ReporterName>>(
"quantities_of_interest");
491 params.set<std::string>(
"prefix") =
"";
499 const auto & output = getParam<MultiMooseEnum>(
"output_type");
502 if (output.isValueSet(
"csv"))
532 params.set<SamplerName>(
"sampler") =
samplerName();
535 auto & names = params.set<std::vector<ReporterValueName>>(
"sampler_column_names");
537 names =
getParam<std::vector<ReporterValueName>>(
"sampler_column_names");
541 bool has_bracket =
false;
543 if (param.find(
"[") != std::string::npos)
551 std::replace(param.begin(), param.end(),
'/',
'_');
552 names.push_back(param);
557 const auto & output_type = getParam<MultiMooseEnum>(
"output_type");
558 auto & outputs = params.set<std::vector<OutputName>>(
"outputs");
559 if (output_type.isValueSet(
"csv"))
561 if (output_type.isValueSet(
"json"))
563 if (output_type.isValueSet(
"none"))
575 auto & reps = params.
set<std::vector<ReporterName>>(
"reporters");
576 for (
const auto & qoi :
getParam<std::vector<ReporterName>>(
"quantities_of_interest"))
578 params.set<
MultiMooseEnum>(
"compute") = getParam<MultiMooseEnum>(
"statistics");
579 params.set<
MooseEnum>(
"ci_method") =
"percentile";
580 params.set<std::vector<Real>>(
"ci_levels") =
getParam<std::vector<Real>>(
"ci_levels");
581 params.set<
unsigned int>(
"ci_replicates") = getParam<unsigned int>(
"ci_replicates");
583 params.set<std::vector<OutputName>>(
"outputs") = {
outputName(
"json")};
596 params.set<SamplerName>(
"sampler") =
samplerName();
597 params.set<std::vector<std::string>>(
"param_names") =
_parameters;
600 _problem->getControlWarehouse().addObject(control);
610 return "study_distribution_" + std::to_string(count);
613 std::vector<DistributionName>
616 std::vector<DistributionName> dist_names;
634 std::string base_type = params.
have_parameter<std::string>(
"_moose_base")
635 ? params.
get<std::string>(
"_moose_base")
638 <<
"Base Type: " << COLOR_YELLOW << base_type << COLOR_DEFAULT <<
"\n" 639 <<
" Type: " << COLOR_YELLOW <<
type << COLOR_DEFAULT <<
"\n" 640 <<
" Name: " << COLOR_YELLOW <<
name << COLOR_DEFAULT;
647 std::map<std::string, std::string> param_map;
648 for (
const auto & it : params)
649 if (!params.isPrivate(it.first) && it.first[0] !=
'_' && params.isParamSetByUser(it.first) &&
652 std::stringstream ss;
653 it.second->print(ss);
654 param_map[it.first] = ss.str();
658 if (!param_map.empty())
661 for (
const auto & it : param_map)
664 _console <<
"\n" << std::string(29,
' ');
665 _console << COLOR_YELLOW << std::setw(24) << it.first << COLOR_DEFAULT <<
" : " << COLOR_MAGENTA
666 << it.second << COLOR_DEFAULT;
673 std::vector<std::map<std::string, bool>>
677 return {{{
"num_samples",
true}, {
"distributions",
true}},
678 {{
"num_samples",
true}, {
"distributions",
true}},
679 {{
"linear_space_items",
true}},
680 {{
"csv_samples_file",
true}, {
"csv_column_indices",
false}, {
"csv_column_names",
false}},
681 {{
"input_matrix",
true}}};
684 std::vector<std::vector<std::string>>
689 {
"normal_mean",
"normal_standard_deviation"},
690 {
"uniform_lower_bound",
"uniform_upper_bound"},
691 {
"weibull_location",
"weibull_scale",
"weibull_shape"},
692 {
"lognormal_location",
"lognormal_scale"},
693 {
"tnormal_mean",
"tnormal_standard_deviation",
"tnormal_lower_bound",
"tnormal_upper_bound"}};
696 std::set<std::string>
699 return {
"statistics",
"ci_levels",
"ci_replicates"};
706 return getParam<MooseEnum>(
"multiapp_mode");
708 const unsigned int default_mode = 1;
712 if (param.find(
"/") == std::string::npos)
716 if (param.find(
"GlobalParams") != std::string::npos)
722 std::ifstream
f(input_filename);
723 std::string input((std::istreambuf_iterator<char>(
f)), std::istreambuf_iterator<char>());
724 std::unique_ptr<hit::Node>
root(hit::parse(input_filename, input));
725 hit::explode(
root.get());
729 root->walk(&control_walker, hit::NodeType::Section);
730 if (!control_walker.areControllable())
735 root->walk(&exec_walker, hit::NodeType::Section);
748 const std::vector<std::string> & parameters,
MooseApp & app)
749 : _app(app), _is_controllable(parameters.size(), false)
752 for (
const auto & param : parameters)
754 const auto pos = param.rfind(
"/");
755 _pars.emplace_back(param.substr(0, pos), param.substr(pos + 1));
761 const std::string & ,
766 const std::string obj =
_pars[i].first;
767 const std::string par =
_pars[i].second;
770 const auto typeit = n->find(
"type");
771 if (typeit && typeit != n && typeit->type() == hit::NodeType::Field)
773 const std::string obj_type = n->param<std::string>(
"type");
792 const std::string & ,
795 if (fullpath ==
"Executioner")
804 std::string executioner_type =
"Unknown";
805 const auto typeit = n->find(
"type");
806 if (typeit && typeit != n && typeit->type() == hit::NodeType::Field)
807 executioner_type = n->param<std::string>(
"type");
810 if (executioner_type ==
"Steady" || executioner_type ==
"Eigenvalue")
813 else if (executioner_type ==
"Transient")
816 const auto it = n->find(
"steady_state_detection");
817 if (it && it != n && it->type() == hit::NodeType::Field &&
818 n->param<
bool>(
"steady_state_detection"))
SamplerName samplerName() const
The perscribed name of the sampler created in this action.
unsigned int getExecutionType() const
DistributionName distributionName(unsigned int count) const
The perscribed name of the distribution.
std::string statisticsName() const
The perscribed name of the statistics object created in this action.
InputParameters getValidParams(const std::string &name)
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
InputParameters getValidParams(const std::string &name) const
unsigned int size() const
This class is a hit walker used to see what type of execution the input is doing. ...
const unsigned int _sampling_type
The sampling type.
void addActionBlock(std::shared_ptr< Action > blk)
const ExecFlagType EXEC_TIMESTEP_END
const unsigned int _multiapp_mode
The multiapp mode.
std::string realpath(const std::string &path)
const bool _show_objects
Switch to show the objects being built on console.
virtual const std::string & name() const
std::string samplerReceiverName() const
The perscribed name of the control given to the sub-app for parameter transfer.
registerMooseAction("StochasticToolsApp", ParameterStudyAction, "meta_action")
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters ¶meters)
virtual void act() override
std::string multiappControlName() const
The perscribed name of the command-line control created in this action.
bool isParamValid(const std::string &name) const
const MultiMooseEnum _distributions
The distributions.
std::vector< DistributionName > distributionNames(unsigned int full_count) const
static InputParameters validParams()
bool areControllable() const
std::string stochasticReporterName() const
The perscribed name of the QoI storage object created in this action.
static MooseEnum samplingTypes()
Return an enum of available sampling types for the study.
std::vector< bool > _is_controllable
void walk(const std::string &fullpath, const std::string &nodename, hit::Node *n) override
ParameterStudyAction(const InputParameters ¶ms)
Real f(Real x)
Test function for Brents method.
const ExecFlagType EXEC_TIMESTEP_BEGIN
std::string reporterTransferName() const
The perscribed name of the reporter transfer created in this action.
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Real root(std::function< Real(Real)> const &f, Real x1, Real x2, Real tol=1.0e-12)
Finds the root of a function using Brent's method.
void walk(const std::string &fullpath, const std::string &nodename, hit::Node *n) override
void showObject(std::string type, std::string name, const InputParameters ¶ms) const
Helper function to show the object being built.
const std::string & type() const
const T & getParam(const std::string &name) const
const std::string & _current_task
OutputName outputName(std::string type) const
The perscribed name of the output objects created in this action.
AreParametersControllableWalker(const std::vector< std::string > ¶meters, MooseApp &app)
void paramError(const std::string ¶m, Args... args) const
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
const std::string & getObjectName() const
ReporterName quantityOfInterestName(const ReporterName &qoi) const
The name of the reporter values in the StochasticReporter representing the QoIs.
ActionFactory & _action_factory
static std::set< std::string > statisticsParameters()
List of parameters that are only associated with computing statistics.
std::vector< std::pair< std::string, std::string > > _pars
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::vector< std::string > & _parameters
The inputted parameter vector.
static std::vector< std::map< std::string, bool > > samplerParameters()
This is a vector associating the sampling type with a list of associated parameters The list includes...
static std::vector< std::vector< std::string > > distributionParameters()
This is a vector associating the distribution type and a list of parameters that are needed...
std::string parameterTransferName() const
The perscribed name of the parameter transfer created in this action.
MultiAppName multiappName() const
The perscribed name of the multiapp created in this action.
IntRange< T > make_range(T beg, T end)
unsigned int inferMultiAppMode()
This function will infer the best way to run the multiapps.
const bool _compute_stats
Whether or not we are computing statistics.
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const
const ConsoleStream _console
const std::string & getValueName() const
std::vector< const T *> getActions()
static InputParameters validParams()
static MultiMooseEnum distributionTypes()
Return an enum of available distributions for the study.
void ErrorVector unsigned int
auto index_range(const T &sizable)
This class is a hit walker used to see if a list of parameters are all controllable.
const ExecFlagType EXEC_INITIAL