www.mooseframework.org
SamplerData.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 // Stocastic Tools Includes
9 #include "SamplerData.h"
10 
11 // MOOSE includes
12 #include "Sampler.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<GeneralVectorPostprocessor>();
19  params.addClassDescription(
20  "Tool for extracting Sampler object data and storing in VectorPostprocessor vectors.");
21  params += validParams<SamplerInterface>();
22  params.addRequiredParam<SamplerName>("sampler",
23  "The sample from which to extract distribution data.");
24  params.addParam<bool>("output_column_and_row_sizes",
25  false,
26  "Whether to output the number of "
27  "columns and rows in the matrix in "
28  "the first two rows of output");
29  return params;
30 }
31 
32 SamplerData::SamplerData(const InputParameters & parameters)
33  : GeneralVectorPostprocessor(parameters),
34  SamplerInterface(this),
35  _sampler(getSampler("sampler")),
36  _output_col_row_sizes(getParam<bool>("output_column_and_row_sizes"))
37 {
38 }
39 
40 void
42 {
43  for (auto ptr : _sample_vectors)
44  ptr->clear();
45 }
46 
47 void
49 {
50  std::vector<DenseMatrix<Real>> data = _sampler.getSamples();
51  auto n = data.size();
52  if (_sample_vectors.empty())
53  {
54  _sample_vectors.resize(n);
55  for (auto i = beginIndex(data); i < n; ++i)
56  {
57  std::string name = "mat_" + std::to_string(i);
58  _sample_vectors[i] = &declareVector(name);
59  }
60  }
61 
62  for (auto i = beginIndex(data); i < n; ++i)
63  {
64  const std::size_t offset = _output_col_row_sizes ? 2 : 0;
65  const std::size_t vec_size = data[i].get_values().size() + offset;
66  _sample_vectors[i]->resize(vec_size);
68  {
69  (*_sample_vectors[i])[0] = data[i].n(); // number of columns
70  (*_sample_vectors[i])[1] = data[i].m(); // number of rows
71  }
72  std::copy(data[i].get_values().begin(),
73  data[i].get_values().end(),
74  _sample_vectors[i]->begin() + offset);
75  }
76 }
std::vector< VectorPostprocessorValue * > _sample_vectors
Storage for declared vectors.
Definition: SamplerData.h:32
SamplerData(const InputParameters &parameters)
Definition: SamplerData.C:32
virtual void initialize() override
Definition: SamplerData.C:41
const bool & _output_col_row_sizes
Whether to output the number of rows and columns in the first two rows of output. ...
Definition: SamplerData.h:38
Sampler & _sampler
The sampler to extract data.
Definition: SamplerData.h:35
virtual void execute() override
Definition: SamplerData.C:48
InputParameters validParams< SamplerData >()
Definition: SamplerData.C:16