https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | 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
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 SobolSampler (const InputParameters &parameters)
 
bool resample () const
 Resampling flag, see SobolStatistics.
 
std::vector< Real > getSampleRow (dof_id_type row_index) const
 
Real getSample (dof_id_type row_index, dof_id_type col_index) const
 
dof_id_type getNumberOfRows () const
 
dof_id_type getNumberOfCols () const
 
dof_id_type getNumberOfLocalRows () const
 
const LocalRankConfig & getRankConfig (bool batch_mode) const
 
virtual bool isAdaptiveSamplingCompleted () const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObject > getSharedPtr ()
 
std::shared_ptr< const MooseObject > getSharedPtr () const
 
bool isKokkosObject () const
 
MooseApp & getMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParameters & parameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () 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 * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (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
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnum & getExecuteOnEnum () const
 
PerfGraph & perfGraph ()
 
T & getSampler (const std::string &name)
 
Sampler & getSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
Sampler & getSamplerByName (const SamplerName &name)
 
const VectorPostprocessorValue & getVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValue & getVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValue & getVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValue & getVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValue & getVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValue & getVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValue & getVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValue & getVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueOldByName (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< Real > getGlobalSamples ()
 
DenseMatrix< Real > getGlobalSamples ()
 
DenseMatrix< Real > getLocalSamples ()
 
DenseMatrix< Real > getLocalSamples ()
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowEnd () const
 
dof_id_type getLocalRowEnd () const
 
const Distribution & getDistribution (const std::string &name) const
 
const T & getDistribution (const std::string &name) const
 
const Distribution & getDistribution (const std::string &name) const
 
const T & getDistribution (const std::string &name) const
 
const Distribution & getDistributionByName (const DistributionName &name) const
 
const T & getDistributionByName (const std::string &name) const
 
const Distribution & getDistributionByName (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 ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) const 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.
 
void setNumberOfRandomSeeds (std::size_t number)
 
Real getRand (std::size_t n, unsigned int index=0) const
 
unsigned int getRandl (std::size_t n, unsigned int lower, unsigned int upper, unsigned int index=0) const
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data) const
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
void setAutoAdvanceGenerators (const bool state)
 
virtual void executeSetUp ()
 
virtual void executeTearDown ()
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
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 ReporterContextBase & getReporterContextBaseByName (const ReporterName &reporter_name) const
 
const ReporterName & getReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
T & declareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const T & getRestartableData (const std::string &data_name) const
 
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 
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 computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
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.
 
Sampler & _sampler_b
 Re-sample matrix.
 
const bool & _resample
 Flag for building the re-sampling matrix for computing second order sensitivity indices.
 
const dof_id_type _min_procs_per_row
 
const dof_id_type _max_procs_per_row
 
const bool & _enabled
 
MooseApp & _app
 
Factory & _factory
 
ActionFactory & _action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters & _pars
 
const ExecFlagEnum & _execute_enum
 
const ExecFlagType & _current_execute_flag
 
MooseApp & _pg_moose_app
 
const std::string _prefix
 
MooseApp & _restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 
const Parallel::Communicator & _communicator
 

Private Member Functions

void execute ()
 
void checkReinitStatus () const
 
void advanceGeneratorsInternal (const dof_id_type count)
 
const VectorPostprocessorValue & getVectorPostprocessorByNameHelper (const VectorPostprocessorName &name, const std::string &vector_name, bool broadcast, std::size_t t_index) const
 
const VectorPostprocessorContext< VectorPostprocessorValue > & getVectorPostprocessorContextByNameHelper (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool vectorPostprocessorsAdded () const
 
bool reportersAdded () const
 
void possiblyCheckHasReporter (const ReporterName &reporter_name, const std::string &param_name="") const
 
RestartableDataValue & registerRestartableDataOnApp (std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
 
void registerRestartableNameWithFilterOnApp (const std::string &name, Moose::RESTARTABLE_FILTER filter)
 
RestartableData< T > & declareRestartableDataHelper (const std::string &data_name, void *context, Args &&... args) const
 
void init ()
 
void init ()
 
void reinit ()
 
void reinit ()
 
void possiblyCheckHasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
void possiblyCheckHasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
void possiblyCheckHasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
void possiblyCheckHasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

const dof_id_type _num_matrices
 Number of matrices.
 
std::vector< std::unique_ptr< MooseRandomStateless > > & _generators
 
dof_id_type & _n_local_rows
 
dof_id_type & _local_row_begin
 
dof_id_type & _local_row_end
 
dof_id_type & _n_rows
 
dof_id_type & _n_cols
 
std::size_t _n_seeds
 
bool _initialized
 
bool _needs_reinit
 
bool & _has_executed
 
const dof_id_type _limit_get_global_samples
 
const dof_id_type _limit_get_local_samples
 
const dof_id_type _limit_get_row
 
std::pair< LocalRankConfig, LocalRankConfig > & _rank_config
 
bool _auto_advance_generators
 
const ParallelParamObject & _parent
 
const MooseBase & _si_moose_base
 
const FEProblemBase * _si_problem
 
ExecFlagEnum _empty_execute_enum
 
const InputParameters & _dni_params
 
FEProblemBase & _dni_feproblem
 
const MooseObject *const _dni_moose_object_ptr
 
const InputParameters & _si_params
 
FEProblemBase & _si_feproblem
 
THREAD_ID _si_tid
 
const bool _broadcast_by_default
 
const MooseObject & _vpi_moose_object
 
const FEProblemBase & _vpi_feproblem
 
const THREAD_ID _vpi_tid
 
const InputParameters & _ri_params
 
FEProblemBase & _ri_fe_problem_base
 
const ReporterData & _ri_reporter_data
 
const MooseObject & _ri_moose_object
 
const RestartableDataMapName _metaname
 
std::string _restartable_name
 

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}
const InputParameters & parameters() const
const std::string & name() const
void paramError(const std::string &param, Args... args) const
T & getSampler(const std::string &name)
void setNumberOfCols(dof_id_type n_cols)
dof_id_type getNumberOfRows() const
dof_id_type getNumberOfCols() const
void setNumberOfRows(dof_id_type n_rows)
Sampler & _sampler_a
Sampler matrix.
const bool & _resample
Flag for building the re-sampling matrix for computing second order sensitivity indices.
Sampler & _sampler_b
Re-sample matrix.
const dof_id_type _num_matrices
Number of matrices.

Member Function Documentation

◆ computeSample()

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

Implements Sampler.

Definition at line 50 of file SobolSampler.C.

51{
52 const dof_id_type base_row = row_index / _num_matrices;
53 const dof_id_type matrix_index = row_index % _num_matrices;
54
55 // M2 Matrix
56 if (matrix_index == 0)
57 return _sampler_b.getSample(base_row, col_index);
58
59 // M1 Matrix
60 else if (matrix_index == _num_matrices - 1)
61 return _sampler_a.getSample(base_row, col_index);
62
63 // N_-i Matrices
64 else if (matrix_index > getNumberOfCols())
65 {
66 if (col_index == (matrix_index - getNumberOfCols() - 1))
67 return _sampler_b.getSample(base_row, col_index);
68 else
69 return _sampler_a.getSample(base_row, col_index);
70 }
71
72 // N_i Matrices
73 else
74 {
75 if (col_index == matrix_index - 1)
76 return _sampler_a.getSample(base_row, col_index);
77 else
78 return _sampler_b.getSample(base_row, col_index);
79 }
80}
Real getSample(dof_id_type row_index, dof_id_type col_index) 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 83 of file SobolSampler.C.

84{
85 std::vector<LocalRankConfig> all_rc(processor_id() + 1);
86 for (processor_id_type r = 0; r <= processor_id(); ++r)
87 all_rc[r] = rankConfig(r,
92 batch_mode);
93 LocalRankConfig & rc = all_rc.back();
94
96 bool found_first = false;
97 for (auto it = all_rc.rbegin(); it != all_rc.rend(); ++it)
98 if (it->is_first_local_rank)
99 {
100 if (found_first)
101 rc.first_local_sim_index += it->num_local_sims * (_num_matrices - 1);
102 else
103 found_first = true;
104 }
105
106 if (!batch_mode)
107 {
110 }
111
112 return rc;
113}
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)
const dof_id_type _max_procs_per_row
const dof_id_type _min_procs_per_row
processor_id_type processor_id() const
processor_id_type n_processors() const
dof_id_type num_local_sims
dof_id_type first_local_sim_index
dof_id_type num_local_apps
dof_id_type first_local_app_index

◆ resample()

bool SobolSampler::resample ( ) const
inline

Resampling flag, see SobolStatistics.

Definition at line 31 of file SobolSampler.h.

31{ return _resample; }

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

◆ 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}
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()

Member Data Documentation

◆ _num_matrices

const dof_id_type SobolSampler::_num_matrices
private

Number of matrices.

Definition at line 54 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 50 of file SobolSampler.h.

Referenced by resample().

◆ _sampler_a

Sampler& SobolSampler::_sampler_a
protected

Sampler matrix.

Definition at line 44 of file SobolSampler.h.

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

◆ _sampler_b

Sampler& SobolSampler::_sampler_b
protected

Re-sample matrix.

Definition at line 47 of file SobolSampler.h.

Referenced by computeSample(), and SobolSampler().


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