https://mooseframework.inl.gov
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 
12 registerMooseObject("StochasticToolsApp", StochasticMatrix);
13 
16 {
18  params.addClassDescription(
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 
58 void
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 }
static InputParameters validParams()
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
Sampler & _sampler
The sampler to extract data.
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="")
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="") override
std::vector< Real > getNextLocalRow()
dof_id_type getNumberOfLocalRows() const
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
registerMooseObject("StochasticToolsApp", StochasticMatrix)
bool isParamValid(const std::string &name) const
void paramError(const std::string &param, Args... args) const
int numDigits(const T &num)
StochasticMatrix(const InputParameters &parameters)
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< std::vector< Real > * > _sample_vectors
Storage for declared vectors, one for each column.
dof_id_type getNumberOfCols() const
virtual void execute() override
uint8_t dof_id_type