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

A class used to generate samples for a direct perturbation analysis. More...

#include <DirectPerturbationSampler.h>

Inheritance diagram for DirectPerturbationSampler:
[legend]

Public Types

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

Public Member Functions

 DirectPerturbationSampler (const InputParameters &parameters)
 
const MooseEnumperturbationMethod () const
 Return the requested perturbation method. More...
 
Real getAbsoluteInterval (const Real param_index) const
 Return the absolute perturbation interval for a given index. More...
 
Real getRelativeInterval (const Real param_index) const
 Return the relative perturbation interval for a given index. More...
 
Real getNominalValue (const Real param_index) const
 Return the nominal value of the parameter. 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 * queryParam (const std::string &name) 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 &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 ()
 
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
 Return the sample for the given row and column. 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)
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) 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 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

 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
 

Private Attributes

const std::vector< Real_nominal_values
 The nominal values of the parameters. More...
 
const std::vector< Real_relative_intervals
 The relative intervals that should be used for the perturbation of each parameter. More...
 
const MooseEnum _perturbation_method
 The method which is used for the perturbation (one-sided/two-sided) More...
 
std::vector< std::vector< Real > > _parameter_vectors
 The data matrix created using the parameters. More...
 
std::vector< Real_absolute_intervals
 The intervals for the perturbations. More...
 

Detailed Description

A class used to generate samples for a direct perturbation analysis.

Definition at line 17 of file DirectPerturbationSampler.h.

Constructor & Destructor Documentation

◆ DirectPerturbationSampler()

DirectPerturbationSampler::DirectPerturbationSampler ( const InputParameters parameters)

Definition at line 36 of file DirectPerturbationSampler.C.

38  _nominal_values(getParam<std::vector<Real>>("nominal_parameter_values")),
39  _relative_intervals(getParam<std::vector<Real>>("relative_perturbation_intervals")),
40  _perturbation_method(getParam<MooseEnum>("perturbation_method"))
41 {
42  // TODO: we need to add capability to do absolute intervals too, in case there is a material
43  // property with a nominal value of 0.0
44  for (const auto interval : _relative_intervals)
45  if (interval <= 0.0 || interval >= 1.0)
46  paramError("relative_perturbation_intervals",
47  "The relative perturbation interval must be between 0 and 1!");
48 
49  // The number of samples will always include an addition sample for the reference point
50  dof_id_type num_samples = 0;
51  if (_perturbation_method == "central_difference")
52  num_samples = 2 * _nominal_values.size() + 1;
53  else
54  num_samples = _nominal_values.size() + 1;
55 
56  // Adjusting the sample matrix
57  setNumberOfRows(num_samples);
59 
60  _absolute_intervals = std::vector<Real>(num_samples - 1, 0);
61  _parameter_vectors = std::vector<std::vector<Real>>(num_samples, _nominal_values);
62 
63  // Depending on what kind of perturbation we selected, the parameter values will change
64  if (_perturbation_method == "central_difference")
65  for (const auto i : index_range(_nominal_values))
66  {
68  // +1 because the first sample is the reference point
69  _parameter_vectors[2 * i + 1][i] += _absolute_intervals[i] / 2;
70  _parameter_vectors[2 * i + 2][i] -= _absolute_intervals[i] / 2;
71  }
72  else
73  for (const auto i : index_range(_nominal_values))
74  {
77  }
78 }
void setNumberOfRows(dof_id_type n_rows)
const MooseEnum _perturbation_method
The method which is used for the perturbation (one-sided/two-sided)
std::vector< Real > _absolute_intervals
The intervals for the perturbations.
Sampler(const InputParameters &parameters)
std::vector< std::vector< Real > > _parameter_vectors
The data matrix created using the parameters.
const T & getParam(const std::string &name) const
void paramError(const std::string &param, Args... args) const
void setNumberOfCols(dof_id_type n_cols)
const std::vector< Real > _nominal_values
The nominal values of the parameters.
const InputParameters & parameters() const
const std::vector< Real > _relative_intervals
The relative intervals that should be used for the perturbation of each parameter.
auto index_range(const T &sizable)
uint8_t dof_id_type

Member Function Documentation

◆ computeSample()

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

Return the sample for the given row and column.

Implements Sampler.

Definition at line 105 of file DirectPerturbationSampler.C.

106 {
107  return _parameter_vectors[row_index][col_index];
108 }
std::vector< std::vector< Real > > _parameter_vectors
The data matrix created using the parameters.

◆ getAbsoluteInterval()

Real DirectPerturbationSampler::getAbsoluteInterval ( const Real  param_index) const

Return the absolute perturbation interval for a given index.

Definition at line 81 of file DirectPerturbationSampler.C.

82 {
83  mooseAssert(param_index < _absolute_intervals.size(),
84  "We don't have the required absolute interval!");
85  return _absolute_intervals[param_index];
86 }
std::vector< Real > _absolute_intervals
The intervals for the perturbations.

◆ getNominalValue()

Real DirectPerturbationSampler::getNominalValue ( const Real  param_index) const

Return the nominal value of the parameter.

Definition at line 97 of file DirectPerturbationSampler.C.

98 {
99  mooseAssert(param_index < _nominal_values.size(),
100  "We don't have the required nominal values for the given parameter!");
101  return _nominal_values[param_index];
102 }
const std::vector< Real > _nominal_values
The nominal values of the parameters.

◆ getRelativeInterval()

Real DirectPerturbationSampler::getRelativeInterval ( const Real  param_index) const

Return the relative perturbation interval for a given index.

Definition at line 89 of file DirectPerturbationSampler.C.

90 {
91  mooseAssert(param_index < _absolute_intervals.size(),
92  "We don't have the required relative interval!");
93  return _relative_intervals[param_index];
94 }
std::vector< Real > _absolute_intervals
The intervals for the perturbations.
const std::vector< Real > _relative_intervals
The relative intervals that should be used for the perturbation of each parameter.

◆ perturbationMethod()

const MooseEnum& DirectPerturbationSampler::perturbationMethod ( ) const
inline

Return the requested perturbation method.

Definition at line 25 of file DirectPerturbationSampler.h.

25 { return _perturbation_method; }
const MooseEnum _perturbation_method
The method which is used for the perturbation (one-sided/two-sided)

◆ validParams()

InputParameters DirectPerturbationSampler::validParams ( )
static

Definition at line 16 of file DirectPerturbationSampler.C.

17 {
19  params.addClassDescription(
20  "Sampler that creates samples for a direct perturbation-based sensitivity study.");
21  params.addRequiredParam<std::vector<Real>>(
22  "nominal_parameter_values",
23  "The nominal values of the parameters around which we shall perturb them.");
24  params.addParam<std::vector<Real>>(
25  "relative_perturbation_intervals",
26  {0.01},
27  "The numbers by which the nominal values are multiplied to get a perturbed value.");
28  MooseEnum perturbation_type("central_difference forward_difference", "central_difference");
29  params.addParam<MooseEnum>("perturbation_method",
30  perturbation_type,
31  "The perturbation method to use for creating samples.");
32 
33  return params;
34 }
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

◆ _absolute_intervals

std::vector<Real> DirectPerturbationSampler::_absolute_intervals
private

The intervals for the perturbations.

Definition at line 54 of file DirectPerturbationSampler.h.

Referenced by DirectPerturbationSampler(), getAbsoluteInterval(), and getRelativeInterval().

◆ _nominal_values

const std::vector<Real> DirectPerturbationSampler::_nominal_values
private

The nominal values of the parameters.

Definition at line 42 of file DirectPerturbationSampler.h.

Referenced by DirectPerturbationSampler(), and getNominalValue().

◆ _parameter_vectors

std::vector<std::vector<Real> > DirectPerturbationSampler::_parameter_vectors
private

The data matrix created using the parameters.

Definition at line 51 of file DirectPerturbationSampler.h.

Referenced by computeSample(), and DirectPerturbationSampler().

◆ _perturbation_method

const MooseEnum DirectPerturbationSampler::_perturbation_method
private

The method which is used for the perturbation (one-sided/two-sided)

Definition at line 48 of file DirectPerturbationSampler.h.

Referenced by DirectPerturbationSampler(), and perturbationMethod().

◆ _relative_intervals

const std::vector<Real> DirectPerturbationSampler::_relative_intervals
private

The relative intervals that should be used for the perturbation of each parameter.

Definition at line 45 of file DirectPerturbationSampler.h.

Referenced by DirectPerturbationSampler(), and getRelativeInterval().


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