https://mooseframework.inl.gov
Loading...
Searching...
No Matches
StochasticMatrix.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#include "StochasticMatrix.h"
11
13
16{
19 "Tool for extracting Sampler object data and storing data from stochastic simulations.");
20 params.addRequiredParam<SamplerName>("sampler",
21 "The sample from which to extract distribution data.");
22 params.addParam<std::vector<ReporterValueName>>(
23 "sampler_column_names",
24 "Prescribed names of sampler columns, used to assign names of outputted vectors.");
25 return params;
26}
27
29 : StochasticReporter(parameters), _sampler(getSampler("sampler"))
30{
31 std::vector<ReporterValueName> names;
32 if (isParamValid("sampler_column_names"))
33 names = getParam<std::vector<ReporterValueName>>("sampler_column_names");
34 else
35 {
36 names.resize(_sampler.getNumberOfCols());
37 const int padding = MooseUtils::numDigits(_sampler.getNumberOfCols());
38 for (dof_id_type j = 0; j < _sampler.getNumberOfCols(); ++j)
39 {
40 std::stringstream nm;
41 nm << getParam<SamplerName>("sampler") << "_" << std::setw(padding) << std::setfill('0') << j;
42 names[j] = nm.str();
43 }
44 }
45
46 if (names.size() != _sampler.getNumberOfCols())
47 paramError("sampler_column_names",
48 "The number of column names specified (",
49 names.size(),
50 ") does not match the number of sampler columns (",
52 ").");
53
54 for (const auto & nm : names)
55 _sample_vectors.push_back(&declareStochasticReporter<Real>(nm, _sampler));
56}
57
58void
60{
61 for (dof_id_type i = 0; i < _sampler.getNumberOfLocalRows(); ++i)
62 {
63 std::vector<Real> data = _sampler.getNextLocalRow();
64 for (std::size_t j = 0; j < data.size(); ++j)
65 (*_sample_vectors[j])[i] = data[j];
66 }
67}
68
71 const ReporterData & from_data,
72 const ReporterName & from_reporter,
73 std::string prefix)
74{
75 if (sampler.name() != _sampler.name())
76 paramError("sampler",
77 "Attempting to create a stochastic vector with a different sampler (",
78 sampler.name(),
79 ") than the one specified at input (",
80 _sampler.name(),
81 ").");
82
84 sampler, from_data, from_reporter, prefix);
85}
registerMooseObject("StochasticToolsApp", StochasticMatrix)
void addRequiredParam(const std::string &name, const std::string &doc_string)
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)
const std::string & name() const
void paramError(const std::string &param, Args... args) const
bool isParamValid(const std::string &name) const
std::vector< Real > getNextLocalRow()
dof_id_type getNumberOfLocalRows() const
dof_id_type getNumberOfCols() const
std::vector< std::vector< Real > * > _sample_vectors
Storage for declared vectors, one for each column.
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="") override
virtual void execute() override
Sampler & _sampler
The sampler to extract data.
static InputParameters validParams()
StochasticMatrix(const InputParameters &parameters)
static InputParameters validParams()
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="")