https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15
18{
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 params.set<ExecFlagEnum>("execute_on", true).addAvailableFlags(EXEC_TRANSFER);
31 return params;
32}
33
35 : GeneralReporter(parameters), _parallel_type(getParam<MooseEnum>("parallel_type"))
36{
37}
38
39void
41{
42 for (auto & vector : _vectors)
43 vector->initialize();
44}
45
48 const ReporterData & from_data,
49 const ReporterName & from_reporter,
50 std::string prefix)
51{
52 std::string value_name = (prefix.empty() ? "" : prefix + ":") + from_reporter.getObjectName() +
53 ":" + from_reporter.getValueName();
54
55 if (!from_data.hasReporterValue(from_reporter))
56 mooseError("Reporter value ", from_reporter, " has not been declared.");
57
58 // Single quantities
59 if (from_data.hasReporterValue<bool>(from_reporter))
60 declareStochasticReporter<bool>(value_name, sampler);
61 else if (from_data.hasReporterValue<int>(from_reporter))
62 declareStochasticReporter<int>(value_name, sampler);
63 else if (from_data.hasReporterValue<Real>(from_reporter))
64 declareStochasticReporter<Real>(value_name, sampler);
65 else if (from_data.hasReporterValue<std::string>(from_reporter))
66 declareStochasticReporter<std::string>(value_name, sampler);
67 // Vector quantities
68 else if (from_data.hasReporterValue<std::vector<bool>>(from_reporter))
69 declareStochasticReporter<std::vector<bool>>(value_name, sampler);
70 else if (from_data.hasReporterValue<std::vector<int>>(from_reporter))
71 declareStochasticReporter<std::vector<int>>(value_name, sampler);
72 else if (from_data.hasReporterValue<std::vector<Real>>(from_reporter))
73 declareStochasticReporter<std::vector<Real>>(value_name, sampler);
74 else if (from_data.hasReporterValue<std::vector<std::string>>(from_reporter))
75 declareStochasticReporter<std::vector<std::string>>(value_name, sampler);
76 // Vector of vector quantities
77 else if (from_data.hasReporterValue<std::vector<std::vector<bool>>>(from_reporter))
78 declareStochasticReporter<std::vector<std::vector<bool>>>(value_name, sampler);
79 else if (from_data.hasReporterValue<std::vector<std::vector<int>>>(from_reporter))
80 declareStochasticReporter<std::vector<std::vector<int>>>(value_name, sampler);
81 else if (from_data.hasReporterValue<std::vector<std::vector<Real>>>(from_reporter))
82 declareStochasticReporter<std::vector<std::vector<Real>>>(value_name, sampler);
83 else if (from_data.hasReporterValue<std::vector<std::vector<std::string>>>(from_reporter))
84 declareStochasticReporter<std::vector<std::vector<std::string>>>(value_name, sampler);
85 else
86 return {}; // Empty ReporterName to show that reporter value is unsupported type
87
88 return {name(), value_name};
89}
const ExecFlagType EXEC_TRANSFER
registerMooseObject("StochasticToolsApp", StochasticReporter)
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
const std::string & name() const
void mooseError(Args &&... args) const
bool hasReporterValue(const ReporterName &reporter_name) const
const std::string & getObjectName() const
const std::string & getValueName() const
StochasticReporter(const InputParameters &parameters)
static InputParameters validParams()
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="")
std::deque< std::unique_ptr< StochasticReporterValueBase > > _vectors
Container for declared values that we may need to resize at initialize.
std::vector< T > & declareStochasticReporter(std::string value_name, const Sampler &sampler)
virtual void initialize() override final
virtual void initialize()=0