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

A class used to perform Monte Carlo sampling for performing Sobol sensitivity analysis. More...

#include <SobolSampler.h>

Inheritance diagram for SobolSampler:
[legend]

Public Types

enum  SampleMode { SampleMode::GLOBAL, SampleMode::LOCAL }
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 SobolSampler (const InputParameters &parameters)
 
bool resample () const
 Resampling flag, see SobolStatistics. More...
 
std::vector< RealgetNextLocalRow ()
 
dof_id_type getNumberOfRows () const
 
dof_id_type getNumberOfCols () const
 
dof_id_type getNumberOfLocalRows () const
 
const LocalRankConfiggetRankConfig (bool batch_mode) const
 
virtual bool isAdaptiveSamplingCompleted () const
 
libMesh::Parallel::CommunicatorgetLocalComm ()
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &name, const std::string *param=nullptr) const
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
T & getSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name) const
 
const VectorPostprocessorName & getVectorPostprocessorName (const std::string &param_name) const
 
DenseMatrix< RealgetGlobalSamples ()
 
DenseMatrix< RealgetGlobalSamples ()
 
DenseMatrix< RealgetLocalSamples ()
 
DenseMatrix< RealgetLocalSamples ()
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowEnd () const
 
dof_id_type getLocalRowEnd () const
 
const DistributiongetDistribution (const std::string &name) const
 
const T & getDistribution (const std::string &name) const
 
const DistributiongetDistribution (const std::string &name) const
 
const T & getDistribution (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const T & getDistributionByName (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const T & getDistributionByName (const std::string &name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 

Public Attributes

const ConsoleStream _console
 

Protected Types

enum  CommMethod
 

Protected Member Functions

virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) override
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) const override
 Sobol sampling should have a slightly different partitioning in order to keep the sample and resample samplers distributed and make computing indices more efficient. More...
 
void setNumberOfRandomSeeds (std::size_t number)
 
Real getRand (unsigned int index=0)
 
uint32_t getRandl (unsigned int index, uint32_t lower, uint32_t upper)
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
virtual void addVectorPostprocessorDependencyHelper (const VectorPostprocessorName &) const
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfCols (dof_id_type n_cols)
 
void setNumberOfCols (dof_id_type n_cols)
 
virtual void sampleSetUp (const SampleMode)
 
virtual void sampleSetUp (const SampleMode)
 
virtual void sampleTearDown (const SampleMode)
 
virtual void sampleTearDown (const SampleMode)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
void setAutoAdvanceGenerators (const bool state)
 
void setAutoAdvanceGenerators (const bool state)
 
void shuffle (std::vector< T > &data, const std::size_t seed_index=0, const CommMethod method=CommMethod::LOCAL)
 
void shuffle (std::vector< T > &data, const std::size_t seed_index=0, const CommMethod method=CommMethod::LOCAL)
 
virtual void executeSetUp ()
 
virtual void executeSetUp ()
 
virtual void executeTearDown ()
 
virtual void executeTearDown ()
 
void saveGeneratorState ()
 
void saveGeneratorState ()
 
void restoreGeneratorState ()
 
void restoreGeneratorState ()
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 

Protected Attributes

Sampler_sampler_a
 Sampler matrix. More...
 
Sampler_sampler_b
 Re-sample matrix. More...
 
const bool & _resample
 Flag for building the re-sampling matrix for computing second order sensitivity indices. More...
 
 NONE
 
 LOCAL
 
 SEMI_LOCAL
 
const dof_id_type _min_procs_per_row
 
const dof_id_type _max_procs_per_row
 
libMesh::Parallel::Communicator _local_comm
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 
std::vector< Real_row_a
 
std::vector< Real_row_b
 

Private Attributes

const dof_id_type _num_matrices
 Number of matrices. More...
 

Detailed Description

A class used to perform Monte Carlo sampling for performing Sobol sensitivity analysis.

The created matrices are stacked in the following order, following the nomenclature from Saltelli (2002), "Making best use of model evaluations to compute sensitivity indices"

with re-sampling: [M2, N_1, ..., N_n, N_-1, ..., N-n, M1] without re-sampling: [M2, N_1, ..., N_n, M1]

Definition at line 23 of file SobolSampler.h.

Constructor & Destructor Documentation

◆ SobolSampler()

SobolSampler::SobolSampler ( const InputParameters parameters)

Definition at line 27 of file SobolSampler.C.

29  _sampler_a(getSampler("sampler_a")),
30  _sampler_b(getSampler("sampler_b")),
31  _resample(getParam<bool>("resample")),
34 {
36  paramError("sampler_a", "The supplied Sampler objects must have the same number of columns.");
37 
39  paramError("sampler_a", "The supplied Sampler objects must have the same number of rows.");
40 
41  if (_sampler_a.name() == _sampler_b.name())
42  paramError("sampler_a", "The supplied sampler matrices must not be the same.");
43 
44  // Initialize this object
47 }
void setNumberOfRows(dof_id_type n_rows)
Sampler & _sampler_a
Sampler matrix.
Definition: SobolSampler.h:50
Sampler & _sampler_b
Re-sample matrix.
Definition: SobolSampler.h:53
virtual const std::string & name() const
Sampler(const InputParameters &parameters)
void paramError(const std::string &param, Args... args) const
dof_id_type getNumberOfRows() const
const dof_id_type _num_matrices
Number of matrices.
Definition: SobolSampler.h:60
void setNumberOfCols(dof_id_type n_cols)
T & getSampler(const std::string &name)
const InputParameters & parameters() const
const bool & _resample
Flag for building the re-sampling matrix for computing second order sensitivity indices.
Definition: SobolSampler.h:56
dof_id_type getNumberOfCols() const

Member Function Documentation

◆ computeSample()

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

Implements Sampler.

Definition at line 50 of file SobolSampler.C.

51 {
52  const dof_id_type matrix_index = row_index % _num_matrices;
53 
54  if (matrix_index == 0 && col_index == 0)
55  {
58  if (std::equal(_row_a.begin(), _row_a.end(), _row_b.begin()))
59  paramError("sampler_a", "The supplied sampler matrices must not be the same.");
60  }
61 
62  // M2 Matrix
63  if (matrix_index == 0)
64  return _row_b[col_index];
65 
66  // M1 Matrix
67  else if (matrix_index == _num_matrices - 1)
68  return _row_a[col_index];
69 
70  // N_-i Matrices
71  else if (matrix_index > getNumberOfCols())
72  {
73  if (col_index == (matrix_index - getNumberOfCols() - 1))
74  return _row_b[col_index];
75  else
76  return _row_a[col_index];
77  }
78 
79  // N_i Matrices
80  else if (matrix_index <= getNumberOfCols())
81  {
82  if (col_index == matrix_index - 1)
83  return _row_a[col_index];
84  else
85  return _row_b[col_index];
86  }
87 
88  mooseError("Invalid row and column index, if you are seeing this Zach messed up because this "
89  "should be impossible to reach.");
90  return 0;
91 }
Sampler & _sampler_a
Sampler matrix.
Definition: SobolSampler.h:50
Sampler & _sampler_b
Re-sample matrix.
Definition: SobolSampler.h:53
std::vector< Real > getNextLocalRow()
void paramError(const std::string &param, Args... args) const
const dof_id_type _num_matrices
Number of matrices.
Definition: SobolSampler.h:60
void mooseError(Args &&... args) const
std::vector< Real > _row_b
Definition: SobolSampler.h:46
std::vector< Real > _row_a
Definition: SobolSampler.h:45
dof_id_type getNumberOfCols() const
uint8_t dof_id_type

◆ constructRankConfig()

LocalRankConfig SobolSampler::constructRankConfig ( bool  batch_mode) const
overrideprotectedvirtual

Sobol sampling should have a slightly different partitioning in order to keep the sample and resample samplers distributed and make computing indices more efficient.

Reimplemented from Sampler.

Definition at line 94 of file SobolSampler.C.

95 {
96  std::vector<LocalRankConfig> all_rc(processor_id() + 1);
97  for (processor_id_type r = 0; r <= processor_id(); ++r)
98  all_rc[r] = rankConfig(r,
99  n_processors(),
103  batch_mode);
104  LocalRankConfig & rc = all_rc.back();
105 
107  bool found_first = false;
108  for (auto it = all_rc.rbegin(); it != all_rc.rend(); ++it)
109  if (it->is_first_local_rank)
110  {
111  if (found_first)
112  rc.first_local_sim_index += it->num_local_sims * (_num_matrices - 1);
113  else
114  found_first = true;
115  }
116 
117  if (!batch_mode)
118  {
121  }
122 
123  return rc;
124 }
Sampler & _sampler_a
Sampler matrix.
Definition: SobolSampler.h:50
LocalRankConfig rankConfig(processor_id_type rank, processor_id_type nprocs, dof_id_type napps, processor_id_type min_app_procs, processor_id_type max_app_procs, bool batch_mode=false)
dof_id_type first_local_app_index
const dof_id_type _max_procs_per_row
uint8_t processor_id_type
processor_id_type n_processors() const
dof_id_type num_local_sims
const dof_id_type _min_procs_per_row
dof_id_type getNumberOfRows() const
const dof_id_type _num_matrices
Number of matrices.
Definition: SobolSampler.h:60
dof_id_type num_local_apps
dof_id_type first_local_sim_index
processor_id_type processor_id() const

◆ resample()

bool SobolSampler::resample ( ) const
inline

Resampling flag, see SobolStatistics.

Definition at line 31 of file SobolSampler.h.

Referenced by SobolStatistics::execute(), and SobolReporter::store().

31 { return _resample; }
const bool & _resample
Flag for building the re-sampling matrix for computing second order sensitivity indices.
Definition: SobolSampler.h:56

◆ validParams()

InputParameters SobolSampler::validParams ( )
static

Definition at line 17 of file SobolSampler.C.

18 {
20  params.addClassDescription("Sobol variance-based sensitivity analysis Sampler.");
21  params.addParam<bool>("resample", true, "Create the re-sample matrix for second-order indices.");
22  params.addRequiredParam<SamplerName>("sampler_a", "The 'sample' matrix.");
23  params.addRequiredParam<SamplerName>("sampler_b", "The 're-sample' matrix.");
24  return params;
25 }
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _num_matrices

const dof_id_type SobolSampler::_num_matrices
private

Number of matrices.

Definition at line 60 of file SobolSampler.h.

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

◆ _resample

const bool& SobolSampler::_resample
protected

Flag for building the re-sampling matrix for computing second order sensitivity indices.

Definition at line 56 of file SobolSampler.h.

Referenced by resample().

◆ _row_a

std::vector<Real> SobolSampler::_row_a
protected

Sobol Monte Carlo rows

Definition at line 45 of file SobolSampler.h.

Referenced by computeSample().

◆ _row_b

std::vector<Real> SobolSampler::_row_b
protected

Definition at line 46 of file SobolSampler.h.

Referenced by computeSample().

◆ _sampler_a

Sampler& SobolSampler::_sampler_a
protected

Sampler matrix.

Definition at line 50 of file SobolSampler.h.

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

◆ _sampler_b

Sampler& SobolSampler::_sampler_b
protected

Re-sample matrix.

Definition at line 53 of file SobolSampler.h.

Referenced by computeSample(), and SobolSampler().


The documentation for this class was generated from the following files: