www.mooseframework.org
StochasticResults.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 "StochasticResults.h"
10 
11 // MOOSE includes
12 #include "Sampler.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<GeneralVectorPostprocessor>();
19  params.addClassDescription(
20  "Storage container for stochastic simulation results coming from a Postprocessor.");
21  params += validParams<SamplerInterface>();
22  return params;
23 }
24 
25 StochasticResults::StochasticResults(const InputParameters & parameters)
26  : GeneralVectorPostprocessor(parameters), SamplerInterface(this)
27 {
28 }
29 
30 void
32 {
33  mooseAssert(_sampler, "The _sampler pointer must be initialized via the init() method.");
34 
35  // Resize and zero vectors to the correct size, this allows the SamplerPostprocessorTransfer
36  // to set values in the vector directly.
37  std::vector<DenseMatrix<Real>> data = _sampler->getSamples();
38  for (auto i = beginIndex(data); i < data.size(); ++i)
39  _sample_vectors[i]->resize(data[i].m(), 0);
40 }
41 
42 VectorPostprocessorValue &
44 {
45  if (group >= _sample_vectors.size())
46  mooseError("The supplied sample index ", group, " does not exist.");
47  return *_sample_vectors[group];
48 }
49 
50 void
51 StochasticResults::init(Sampler & sampler)
52 {
53  _sampler = &sampler;
54  const std::vector<std::string> & names = _sampler->getSampleNames();
55  _sample_vectors.resize(names.size());
56  for (auto i = beginIndex(names); i < names.size(); ++i)
57  _sample_vectors[i] = &declareVector(names[i]);
58 }
void init(Sampler &_sampler)
Initialize storage based on the Sampler returned by the SamplerMultiApp.
StochasticResults(const InputParameters &parameters)
Sampler * _sampler
The sampler to extract data.
VectorPostprocessorValue & getVectorPostprocessorValueByGroup(unsigned int group)
Return the VectorPostprocessorValue for a given Sampler group index.
std::vector< VectorPostprocessorValue * > _sample_vectors
Storage for declared vectors.
virtual void initialize() override
InputParameters validParams< StochasticResults >()