www.mooseframework.org
Sampler.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef SAMPLER_H
16 #define SAMPLER_H
17 
18 #include "libmesh/dense_matrix.h"
19 
20 // MOOSE includes
21 #include "MooseObject.h"
22 #include "MooseRandom.h"
23 #include "SetupInterface.h"
24 #include "DistributionInterface.h"
25 #include "Distribution.h"
26 
27 class Sampler;
28 
29 template <>
31 
47 {
48 public:
50 
56  struct Location
57  {
58  Location(const unsigned int & s, const unsigned int & r) : _sample(s), _row(r) {}
59 
61 
64  unsigned int sample() const { return _sample; }
65  unsigned int row() const { return _row; }
67 
68  private:
70  const unsigned int _sample;
71 
73  const unsigned int _row;
74  };
75 
79  const std::vector<DistributionName> & getDistributionNames() const { return _distribution_names; }
80 
82 
85  virtual void sampleSetUp(){};
86  virtual void sampleTearDown(){};
88 
92  std::vector<DenseMatrix<Real>> getSamples();
93 
100  const std::vector<std::string> & getSampleNames() const { return _sample_names; }
101 
107  void setSampleNames(const std::vector<std::string> & names);
108 
113  void execute();
114 
122  Sampler::Location getLocation(unsigned int global_index);
123 
128  unsigned int getTotalNumberOfRows();
129 
130 protected:
138  double rand(unsigned int index = 0);
139 
145  virtual std::vector<DenseMatrix<Real>> sample() = 0;
146 
153  void setNumberOfRequiedRandomSeeds(const std::size_t & number);
154 
159  void reinit(const std::vector<DenseMatrix<Real>> & data);
160 
162  std::vector<Distribution *> _distributions;
163 
165  const std::vector<DistributionName> & _distribution_names;
166 
168  std::vector<std::string> _sample_names;
169 
170 private:
174 
177 
179  const unsigned int & _seed;
180 
182  std::vector<unsigned int> _offsets;
183 
185  unsigned int _total_rows;
186 };
187 
188 #endif /* SAMPLER_H */
double rand(unsigned int index=0)
Get the next random number from the generator.
Definition: Sampler.C:101
MooseRandom _generator
Random number generator, don&#39;t give users access we want to control it via the interface from this cl...
Definition: Sampler.h:173
void setSampleNames(const std::vector< std::string > &names)
Set the sample names.
Definition: Sampler.C:124
unsigned int _total_rows
Total number of rows.
Definition: Sampler.h:185
virtual void sampleSetUp()
Setup method called prior and after looping through distributions.
Definition: Sampler.h:85
This is the base class for Samplers.
Definition: Sampler.h:46
unsigned int getTotalNumberOfRows()
Return the number of samples.
Definition: Sampler.C:155
std::vector< unsigned int > _offsets
Data offsets for computing location based on global index.
Definition: Sampler.h:182
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< DistributionName > & getDistributionNames() const
Return the list of distribution names.
Definition: Sampler.h:79
Sampler(const InputParameters &parameters)
Definition: Sampler.C:39
std::vector< Distribution * > _distributions
Map used to store the perturbed parameters and their corresponding distributions. ...
Definition: Sampler.h:162
Simple object for storing the sampler location (see SamplerMultiApp).
Definition: Sampler.h:56
Location(const unsigned int &s, const unsigned int &r)
Definition: Sampler.h:58
void setNumberOfRequiedRandomSeeds(const std::size_t &number)
Set the number of seeds required by the sampler.
Definition: Sampler.C:108
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
Sampler::Location getLocation(unsigned int global_index)
Return the Sample::Location for the given multi app index.
Definition: Sampler.C:135
Interface for objects that need to use distributions.
const unsigned int & _seed
Initial random number seed.
Definition: Sampler.h:179
std::vector< std::string > _sample_names
Sample names.
Definition: Sampler.h:168
virtual void sampleTearDown()
Definition: Sampler.h:86
void reinit(const std::vector< DenseMatrix< Real >> &data)
Reinitialize the offsets and row counts.
Definition: Sampler.C:63
MooseRandom _seed_generator
Seed generator.
Definition: Sampler.h:176
unsigned int sample() const
Accessors for the sample and row numbers.
Definition: Sampler.h:64
const unsigned int _row
Row number for the given sample matrix.
Definition: Sampler.h:73
unsigned int row() const
Definition: Sampler.h:65
const unsigned int _sample
Sample number (i.e., the index in the matrix)
Definition: Sampler.h:70
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
std::vector< DenseMatrix< Real > > getSamples()
Return the sampled distribution data.
Definition: Sampler.C:78
InputParameters validParams< Sampler >()
Definition: Sampler.C:25
const std::vector< DistributionName > & _distribution_names
Distribution names.
Definition: Sampler.h:165
void execute()
Store the state of the MooseRandom generator so that new calls to getSamples will create new numbers...
Definition: Sampler.C:53
This class encapsulates a useful, consistent, cross-platform random number generator with multiple ut...
Definition: MooseRandom.h:42
const std::vector< std::string > & getSampleNames() const
Return the sample names, by default &#39;sample_0, sample_1, etc.
Definition: Sampler.h:100