https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
MorrisSampler Class Reference

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

#include <MorrisSampler.h>

Inheritance diagram for MorrisSampler:
[legend]

Public Types

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

Public Member Functions

 MorrisSampler (const InputParameters &parameters)
 
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
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () 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 InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool haveParameter (const std::string &name) 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 ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
TgetSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
TgetSamplerByName (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 TgetDistribution (const std::string &name) const
 
const DistributiongetDistribution (const std::string &name) const
 
const TgetDistribution (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (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) override
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) const override
 Morris 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 (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
 
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 ReporterContextBasegetReporterContextBaseByName (const ReporterName &reporter_name) 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 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)
 
virtual void executeSetUp ()
 
virtual void executeSetUp ()
 
virtual void executeTearDown ()
 
virtual void executeTearDown ()
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (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

const dof_id_type_num_trajectories
 Number of trajectories. More...
 
const unsigned int_num_levels
 Number of levels used for input space discretization. More...
 
std::vector< const Distribution * > _distributions
 Distribution to determine parameter from perturbations. More...
 
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
 
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
 
const Parallel::Communicator & _communicator
 

Private Member Functions

void updateBstar ()
 Function to calculate trajectories This is only called once per trajectory (_n_rows / (_n_cols + 1)) More...
 

Private Attributes

dof_id_type _curr_trajectory = std::numeric_limits<dof_id_type>::max()
 The trajectory the current _bstar represents. More...
 
RealEigenMatrix _b
 
RealEigenMatrix _pstar
 
RealEigenMatrix _j
 
RealEigenMatrix _dstar
 
RealEigenMatrix _xstar
 
RealEigenMatrix _bstar
 

Detailed Description

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

Definition at line 18 of file MorrisSampler.h.

Constructor & Destructor Documentation

◆ MorrisSampler()

MorrisSampler::MorrisSampler ( const InputParameters parameters)

Definition at line 39 of file MorrisSampler.C.

41  _num_trajectories(getParam<dof_id_type>("trajectories")),
42  _num_levels(getParam<unsigned int>("levels"))
43 
44 {
45  for (const auto & name : getParam<std::vector<DistributionName>>("distributions"))
47  const dof_id_type nc = _distributions.size();
48 
49  setNumberOfCols(nc);
51 
52  _b = RealEigenMatrix::Ones(nc + 1, nc).triangularView<Eigen::StrictlyLower>();
53  _pstar.resize(nc, nc);
54  _j.setOnes(nc + 1, nc);
55  _dstar.resize(nc, nc);
56  _xstar.resize(nc + 1, nc);
57  _bstar.resize(nc + 1, nc);
58 }
void setNumberOfRows(dof_id_type n_rows)
RealEigenMatrix _xstar
Definition: MorrisSampler.h:58
const T & getParam(const std::string &name) const
RealEigenMatrix _b
Definition: MorrisSampler.h:54
const InputParameters & parameters() const
const dof_id_type & _num_trajectories
Number of trajectories.
Definition: MorrisSampler.h:36
Sampler(const InputParameters &parameters)
std::vector< const Distribution * > _distributions
Distribution to determine parameter from perturbations.
Definition: MorrisSampler.h:40
const std::string & name() const
const unsigned int & _num_levels
Number of levels used for input space discretization.
Definition: MorrisSampler.h:38
RealEigenMatrix _bstar
Definition: MorrisSampler.h:59
const Distribution & getDistributionByName(const DistributionName &name) const
RealEigenMatrix _pstar
Definition: MorrisSampler.h:55
void setNumberOfCols(dof_id_type n_cols)
RealEigenMatrix _dstar
Definition: MorrisSampler.h:57
RealEigenMatrix _j
Definition: MorrisSampler.h:56
uint8_t dof_id_type

Member Function Documentation

◆ computeSample()

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

Implements Sampler.

Definition at line 61 of file MorrisSampler.C.

62 {
63  const dof_id_type traj = row_index / (getNumberOfCols() + 1);
64  const dof_id_type traj_ind = row_index % (getNumberOfCols() + 1);
65  if (traj != _curr_trajectory)
66  {
67  _curr_trajectory = traj;
68  updateBstar();
69  }
70  return _distributions[col_index]->quantile(_bstar(traj_ind, col_index));
71 }
std::vector< const Distribution * > _distributions
Distribution to determine parameter from perturbations.
Definition: MorrisSampler.h:40
void updateBstar()
Function to calculate trajectories This is only called once per trajectory (_n_rows / (_n_cols + 1)) ...
Definition: MorrisSampler.C:74
RealEigenMatrix _bstar
Definition: MorrisSampler.h:59
dof_id_type getNumberOfCols() const
dof_id_type _curr_trajectory
The trajectory the current _bstar represents.
Definition: MorrisSampler.h:50
uint8_t dof_id_type

◆ constructRankConfig()

LocalRankConfig MorrisSampler::constructRankConfig ( bool  batch_mode) const
overrideprotectedvirtual

Morris 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 110 of file MorrisSampler.C.

111 {
112  std::vector<LocalRankConfig> all_rc(processor_id() + 1);
113  for (processor_id_type r = 0; r <= processor_id(); ++r)
114  all_rc[r] = rankConfig(
116  LocalRankConfig & rc = all_rc.back();
117 
118  rc.num_local_sims *= _distributions.size() + 1;
119  bool found_first = false;
120  for (auto it = all_rc.rbegin(); it != all_rc.rend(); ++it)
121  if (it->is_first_local_rank)
122  {
123  if (found_first)
124  rc.first_local_sim_index += it->num_local_sims * _distributions.size();
125  else
126  found_first = true;
127  }
128 
129  if (!batch_mode)
130  {
133  }
134 
135  return rc;
136 }
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 & _num_trajectories
Number of trajectories.
Definition: MorrisSampler.h:36
dof_id_type first_local_app_index
const dof_id_type _max_procs_per_row
std::vector< const Distribution * > _distributions
Distribution to determine parameter from perturbations.
Definition: MorrisSampler.h:40
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 num_local_apps
dof_id_type first_local_sim_index
processor_id_type processor_id() const

◆ updateBstar()

void MorrisSampler::updateBstar ( )
private

Function to calculate trajectories This is only called once per trajectory (_n_rows / (_n_cols + 1))

Definition at line 74 of file MorrisSampler.C.

Referenced by computeSample().

75 {
76  mooseAssert(_curr_trajectory < _num_trajectories,
77  "Current trajectory index is greater than the prescribed number of trajectories.");
78 
79  const dof_id_type nc = getNumberOfCols(); // convenience
80  dof_id_type rn_ind = _curr_trajectory * nc * (nc + 1);
81 
82  _pstar.setZero();
83  // Which parameter to perturb
84  std::vector<dof_id_type> pchoice(nc);
85  std::iota(pchoice.begin(), pchoice.end(), 0);
86  for (dof_id_type c = 0; c < nc; ++c)
87  {
88  const unsigned int ind = nc > 1 ? getRandl(rn_ind++, 0, pchoice.size()) : 0;
89  _pstar(pchoice[ind], c) = 1.0;
90  pchoice.erase(pchoice.begin() + ind);
91  }
92 
93  _dstar.setZero();
94  // Direction of perturbation
95  for (dof_id_type c = 0; c < nc; ++c)
96  _dstar(c, c) = getRand(rn_ind++) < 0.5 ? -1.0 : 1.0;
97 
98  // Initial value
99  for (dof_id_type c = 0; c < nc; ++c)
100  {
101  const auto lind = getRandl(rn_ind++, 0, _num_levels / 2);
102  _xstar.col(c).setConstant((Real)lind * 1.0 / ((Real)_num_levels - 1));
103  }
104 
105  _bstar =
106  _xstar + _num_levels / 4.0 / (_num_levels - 1) * ((2.0 * _b * _pstar - _j) * _dstar + _j);
107 }
RealEigenMatrix _xstar
Definition: MorrisSampler.h:58
RealEigenMatrix _b
Definition: MorrisSampler.h:54
unsigned int getRandl(std::size_t n, unsigned int lower, unsigned int upper, unsigned int index=0) const
const dof_id_type & _num_trajectories
Number of trajectories.
Definition: MorrisSampler.h:36
Real getRand(std::size_t n, unsigned int index=0) const
const unsigned int & _num_levels
Number of levels used for input space discretization.
Definition: MorrisSampler.h:38
RealEigenMatrix _bstar
Definition: MorrisSampler.h:59
RealEigenMatrix _pstar
Definition: MorrisSampler.h:55
RealEigenMatrix _dstar
Definition: MorrisSampler.h:57
RealEigenMatrix _j
Definition: MorrisSampler.h:56
dof_id_type getNumberOfCols() const
dof_id_type _curr_trajectory
The trajectory the current _bstar represents.
Definition: MorrisSampler.h:50
uint8_t dof_id_type

◆ validParams()

InputParameters MorrisSampler::validParams ( )
static

Definition at line 16 of file MorrisSampler.C.

17 {
19  params.addClassDescription("Morris variance-based sensitivity analysis Sampler.");
20  params.addRequiredParam<std::vector<DistributionName>>(
21  "distributions",
22  "The distribution names to be sampled, the number of distributions provided defines the "
23  "number of columns per matrix.");
25  "trajectories",
26  "trajectories > 0",
27  "Number of unique trajectories to perform. The higher number of these usually means a more "
28  "accurate sensitivity evaluation, but it is proportional to the number of required model "
29  "evaluations: 'trajectoris' x (number of 'distributions' + 1).");
30  params.addRangeCheckedParam<unsigned int>(
31  "levels",
32  4,
33  "levels % 2 = 0 & levels > 0",
34  "The number of levels in the sampling. This determines the discretization of the input "
35  "space, more levels means finer discretization and more possible model perturbations.");
36  return params;
37 }
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
uint8_t dof_id_type

Member Data Documentation

◆ _b

RealEigenMatrix MorrisSampler::_b
private

Matrices used for trajectory computation

Definition at line 54 of file MorrisSampler.h.

Referenced by MorrisSampler(), and updateBstar().

◆ _bstar

RealEigenMatrix MorrisSampler::_bstar
private

Definition at line 59 of file MorrisSampler.h.

Referenced by computeSample(), MorrisSampler(), and updateBstar().

◆ _curr_trajectory

dof_id_type MorrisSampler::_curr_trajectory = std::numeric_limits<dof_id_type>::max()
private

The trajectory the current _bstar represents.

Definition at line 50 of file MorrisSampler.h.

Referenced by computeSample(), and updateBstar().

◆ _distributions

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

Distribution to determine parameter from perturbations.

Definition at line 40 of file MorrisSampler.h.

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

◆ _dstar

RealEigenMatrix MorrisSampler::_dstar
private

Definition at line 57 of file MorrisSampler.h.

Referenced by MorrisSampler(), and updateBstar().

◆ _j

RealEigenMatrix MorrisSampler::_j
private

Definition at line 56 of file MorrisSampler.h.

Referenced by MorrisSampler(), and updateBstar().

◆ _num_levels

const unsigned int& MorrisSampler::_num_levels
protected

Number of levels used for input space discretization.

Definition at line 38 of file MorrisSampler.h.

Referenced by updateBstar().

◆ _num_trajectories

const dof_id_type& MorrisSampler::_num_trajectories
protected

Number of trajectories.

Definition at line 36 of file MorrisSampler.h.

Referenced by constructRankConfig(), MorrisSampler(), and updateBstar().

◆ _pstar

RealEigenMatrix MorrisSampler::_pstar
private

Definition at line 55 of file MorrisSampler.h.

Referenced by MorrisSampler(), and updateBstar().

◆ _xstar

RealEigenMatrix MorrisSampler::_xstar
private

Definition at line 58 of file MorrisSampler.h.

Referenced by MorrisSampler(), and updateBstar().


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