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, global_i = _sampler.getLocalRowBegin();
63 ++i, ++global_i)
64 for (const auto j : make_range(_sampler.getNumberOfCols()))
65 (*_sample_vectors[j])[i] = _sampler.getSample(global_i, j);
66}
67
70 const ReporterData & from_data,
71 const ReporterName & from_reporter,
72 std::string prefix)
73{
74 if (sampler.name() != _sampler.name())
75 paramError("sampler",
76 "Attempting to create a stochastic vector with a different sampler (",
77 sampler.name(),
78 ") than the one specified at input (",
79 _sampler.name(),
80 ").");
81
83 sampler, from_data, from_reporter, prefix);
84}
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
Real getSample(dof_id_type row_index, dof_id_type col_index) const
dof_id_type getNumberOfLocalRows() const
dof_id_type getLocalRowBegin() 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="")