www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SobolSampler Class Reference

A class used to perform Monte Carlo Sampling. More...

#include <SobolSampler.h>

Inheritance diagram for SobolSampler:
[legend]

Public Member Functions

 SobolSampler (const InputParameters &parameters)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) override
 
virtual void sampleSetUp () override
 
virtual void sampleTearDown () override
 

Protected Attributes

std::vector< Distribution const * > _distributions
 Storage for distribution objects to be utilized. More...
 
const std::vector< DistributionName > & _distribution_names
 Distribution names. More...
 
const dof_id_type _num_rows_per_matrix
 The number of rows per matrix. More...
 
DenseMatrix< Real > _a_matrix
 
DenseMatrix< Real > _b_matrix
 

Detailed Description

A class used to perform Monte Carlo Sampling.

Definition at line 21 of file SobolSampler.h.

Constructor & Destructor Documentation

◆ SobolSampler()

SobolSampler::SobolSampler ( const InputParameters &  parameters)

Definition at line 30 of file SobolSampler.C.

31  : Sampler(parameters),
32  _a_matrix(0, 0),
33  _b_matrix(0, 0),
34  _distribution_names(getParam<std::vector<DistributionName>>("distributions")),
35  _num_rows_per_matrix(getParam<dof_id_type>("num_rows"))
36 {
37  setNumberOfRandomSeeds(2);
38 
39  for (const DistributionName & name : _distribution_names)
40  _distributions.push_back(&getDistributionByName(name));
41 
42  setNumberOfCols(_distribution_names.size());
43  setNumberOfRows(_num_rows_per_matrix * (_distribution_names.size() + 2));
44 }

Member Function Documentation

◆ computeSample()

Real SobolSampler::computeSample ( dof_id_type  row_index,
dof_id_type  col_index 
)
overrideprotectedvirtual

Definition at line 60 of file SobolSampler.C.

61 {
62  dof_id_type matrix_index = row_index / _num_rows_per_matrix;
63  dof_id_type r = row_index - matrix_index * _num_rows_per_matrix;
64 
65  if (matrix_index == 0)
66  return _a_matrix(r, col_index);
67  else if (matrix_index == 1)
68  return _b_matrix(r, col_index);
69  else if (col_index == matrix_index - 2)
70  return _b_matrix(r, col_index);
71  else
72  return _a_matrix(r, col_index);
73 }

◆ sampleSetUp()

void SobolSampler::sampleSetUp ( )
overrideprotectedvirtual

Definition at line 47 of file SobolSampler.C.

48 {
49  _a_matrix.resize(_num_rows_per_matrix, getNumberOfCols());
50  _b_matrix.resize(_num_rows_per_matrix, getNumberOfCols());
51  for (dof_id_type i = 0; i < _num_rows_per_matrix; ++i)
52  for (dof_id_type j = 0; j < getNumberOfCols(); ++j)
53  {
54  _a_matrix(i, j) = _distributions[j]->quantile(this->getRand(0));
55  _b_matrix(i, j) = _distributions[j]->quantile(this->getRand(1));
56  }
57 }

◆ sampleTearDown()

void SobolSampler::sampleTearDown ( )
overrideprotectedvirtual

Definition at line 76 of file SobolSampler.C.

77 {
78  _a_matrix.resize(0, 0);
79  _b_matrix.resize(0, 0);
80 }

◆ validParams()

InputParameters SobolSampler::validParams ( )
static

Definition at line 18 of file SobolSampler.C.

19 {
20  InputParameters params = Sampler::validParams();
21  params.addClassDescription("Sobol variance-based sensitivity analysis Sampler.");
22  params.addRequiredParam<dof_id_type>("num_rows", "The number of rows per matrix to generate.");
23  params.addRequiredParam<std::vector<DistributionName>>(
24  "distributions",
25  "The distribution names to be sampled, the number of distributions provided defines the "
26  "number of columns per matrix.");
27  return params;
28 }

Member Data Documentation

◆ _a_matrix

DenseMatrix<Real> SobolSampler::_a_matrix
protected

Sobol Monte Carlo matrices, these are sized and cleared to avoid keeping large matrices around

Definition at line 35 of file SobolSampler.h.

Referenced by computeSample(), sampleSetUp(), and sampleTearDown().

◆ _b_matrix

DenseMatrix<Real> SobolSampler::_b_matrix
protected

Definition at line 36 of file SobolSampler.h.

Referenced by computeSample(), sampleSetUp(), and sampleTearDown().

◆ _distribution_names

const std::vector<DistributionName>& SobolSampler::_distribution_names
protected

Distribution names.

Definition at line 43 of file SobolSampler.h.

Referenced by SobolSampler().

◆ _distributions

std::vector<Distribution const *> SobolSampler::_distributions
protected

Storage for distribution objects to be utilized.

Definition at line 40 of file SobolSampler.h.

Referenced by sampleSetUp(), and SobolSampler().

◆ _num_rows_per_matrix

const dof_id_type SobolSampler::_num_rows_per_matrix
protected

The number of rows per matrix.

Definition at line 46 of file SobolSampler.h.

Referenced by computeSample(), sampleSetUp(), and SobolSampler().


The documentation for this class was generated from the following files:
SobolSampler::_distribution_names
const std::vector< DistributionName > & _distribution_names
Distribution names.
Definition: SobolSampler.h:43
SobolSampler::_b_matrix
DenseMatrix< Real > _b_matrix
Definition: SobolSampler.h:36
SobolSampler::_num_rows_per_matrix
const dof_id_type _num_rows_per_matrix
The number of rows per matrix.
Definition: SobolSampler.h:46
SobolSampler::_distributions
std::vector< Distribution const * > _distributions
Storage for distribution objects to be utilized.
Definition: SobolSampler.h:40
validParams
InputParameters validParams()
name
const std::string name
Definition: Setup.h:21
SobolSampler::_a_matrix
DenseMatrix< Real > _a_matrix
Definition: SobolSampler.h:35