https://mooseframework.inl.gov
StochasticReporter.C
Go to the documentation of this file.
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 // Stocastic Tools Includes
11 #include "StochasticReporter.h"
12 #include "Sampler.h"
13 
14 registerMooseObject("StochasticToolsApp", StochasticReporter);
15 
18 {
20  params.addClassDescription(
21  "Storage container for stochastic simulation results coming from Reporters.");
22  MooseEnum parallel_type("DISTRIBUTED=0 ROOT=1", "DISTRIBUTED");
23  params.addParam<MooseEnum>(
24  "parallel_type",
25  parallel_type,
26  "This parameter will determine how the stochastic data is gathered. It is common for "
27  "outputting purposes that this parameter be set to ROOT, otherwise, many files will be "
28  "produced showing the values on each processor. However, if there are lot of samples, "
29  "gathering on root may be memory restrictive.");
30  return params;
31 }
32 
34  : GeneralReporter(parameters), _parallel_type(getParam<MooseEnum>("parallel_type"))
35 {
36 }
37 
40  const ReporterData & from_data,
41  const ReporterName & from_reporter,
42  std::string prefix)
43 {
44  std::string value_name = (prefix.empty() ? "" : prefix + ":") + from_reporter.getObjectName() +
45  ":" + from_reporter.getValueName();
46 
47  if (!from_data.hasReporterValue(from_reporter))
48  mooseError("Reporter value ", from_reporter, " has not been declared.");
49 
50  // Single quantities
51  if (from_data.hasReporterValue<bool>(from_reporter))
52  declareStochasticReporter<bool>(value_name, sampler);
53  else if (from_data.hasReporterValue<int>(from_reporter))
54  declareStochasticReporter<int>(value_name, sampler);
55  else if (from_data.hasReporterValue<Real>(from_reporter))
56  declareStochasticReporter<Real>(value_name, sampler);
57  else if (from_data.hasReporterValue<std::string>(from_reporter))
58  declareStochasticReporter<std::string>(value_name, sampler);
59  // Vector quantities
60  else if (from_data.hasReporterValue<std::vector<bool>>(from_reporter))
61  declareStochasticReporter<std::vector<bool>>(value_name, sampler);
62  else if (from_data.hasReporterValue<std::vector<int>>(from_reporter))
63  declareStochasticReporter<std::vector<int>>(value_name, sampler);
64  else if (from_data.hasReporterValue<std::vector<Real>>(from_reporter))
65  declareStochasticReporter<std::vector<Real>>(value_name, sampler);
66  else if (from_data.hasReporterValue<std::vector<std::string>>(from_reporter))
67  declareStochasticReporter<std::vector<std::string>>(value_name, sampler);
68  // Vector of vector quantities
69  else if (from_data.hasReporterValue<std::vector<std::vector<bool>>>(from_reporter))
70  declareStochasticReporter<std::vector<std::vector<bool>>>(value_name, sampler);
71  else if (from_data.hasReporterValue<std::vector<std::vector<int>>>(from_reporter))
72  declareStochasticReporter<std::vector<std::vector<int>>>(value_name, sampler);
73  else if (from_data.hasReporterValue<std::vector<std::vector<Real>>>(from_reporter))
74  declareStochasticReporter<std::vector<std::vector<Real>>>(value_name, sampler);
75  else if (from_data.hasReporterValue<std::vector<std::vector<std::string>>>(from_reporter))
76  declareStochasticReporter<std::vector<std::vector<std::string>>>(value_name, sampler);
77  else
78  return {}; // Empty ReporterName to show that reporter value is unsupported type
79 
80  return {name(), value_name};
81 }
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="")
static InputParameters validParams()
virtual const std::string & name() const
StochasticReporter(const InputParameters &parameters)
registerMooseObject("StochasticToolsApp", StochasticReporter)
const std::string & getObjectName() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
bool hasReporterValue(const ReporterName &reporter_name) const
std::vector< T > & declareStochasticReporter(std::string value_name, const Sampler &sampler)
const std::string & getValueName() const