27 params.
addParam<
unsigned int>(
"seed", 0,
"Random number generator initial seed");
38 "The maximum allowed number of items in the DenseMatrix returned by " 39 "getGlobalSamples method.");
41 "limit_get_local_samples",
43 "The maximum allowed number of items in the DenseMatrix returned by getLocalSamples method.");
45 "limit_get_next_local_row",
47 "The maximum allowed number of items in the std::vector returned by getNextLocalRow method.");
52 "This will ensure that the sampler is partitioned properly when " 53 "'MultiApp/*/min_procs_per_app' is specified. It is not recommended to use otherwise.");
57 "This will ensure that the sampler is partitioned properly when " 58 "'MultiApp/*/max_procs_per_app' is specified. It is not recommended to use otherwise.");
70 _min_procs_per_row(getParam<unsigned
int>(
"min_procs_per_row") > n_processors()
72 : getParam<unsigned
int>(
"min_procs_per_row")),
73 _max_procs_per_row(getParam<unsigned
int>(
"max_procs_per_row")),
77 _next_local_row_requires_state_restore(true),
81 _limit_get_global_samples(getParam<
dof_id_type>(
"limit_get_global_samples")),
82 _limit_get_local_samples(getParam<
dof_id_type>(
"limit_get_local_samples")),
83 _limit_get_next_local_row(getParam<
dof_id_type>(
"limit_get_next_local_row")),
84 _auto_advance_generators(true)
94 mooseError(
"The Sampler::init() method is called automatically and should not be called.");
100 const unsigned int seed = getParam<unsigned int>(
"seed");
102 seed_generator.
seed(0, seed);
105 for (std::size_t i = 0; i <
_n_seeds; ++i)
123 mooseError(
"Sampler has inconsistent partitionings for normal and batch mode.");
150 mooseError(
"The number of rows cannot be zero.");
160 mooseError(
"The number of columns cannot be zero.");
170 mooseError(
"The 'setNumberOfRandomSeeds()' method can not be called after the Sampler has been " 172 "this method should be called in the constructor of the Sampler object.");
175 mooseError(
"The number of seeds must be larger than zero.");
200 TIME_SECTION(
"getGlobalSamples", 1,
"Retrieving Global Samples");
206 "The number of entries in the DenseMatrix (",
208 ") exceeds the allowed limit of ",
224 TIME_SECTION(
"getLocalSamples", 1,
"Retrieving Local Samples");
230 "The number of entries in the DenseMatrix (",
232 ") exceeds the allowed limit of ",
262 "The number of entries in the std::vector (",
264 ") exceeds the allowed limit of ",
269 std::vector<Real> output(
_n_cols);
271 mooseAssert(output.size() ==
_n_cols,
"The row of sample data is not sized correctly.");
288 TIME_SECTION(
"computeSampleMatrix", 2,
"Computing Sample Matrix");
292 std::vector<Real> row(
_n_cols, 0);
294 mooseAssert(row.size() ==
_n_cols,
"The row of sample data is not sized correctly.");
296 "Changing the size of the sample must not occur during matrix access.");
304 TIME_SECTION(
"computeLocalSampleMatrix", 2,
"Computing Local Sample Matrix");
309 std::vector<Real> row(
_n_cols, 0);
311 mooseAssert(row.size() ==
_n_cols,
"The row of sample data is not sized correctly.");
313 "Changing the size of the sample must not occur during matrix access.");
327 "Changing the size of the sample must not occur during matrix access.");
334 TIME_SECTION(
"advanceGenerators", 2,
"Advancing Generators");
342 for (std::size_t i = 0; i < count; ++i)
362 mooseAssert(index <
_generator.
size(),
"The seed number index does not exists.");
369 mooseAssert(index <
_generator.
size(),
"The seed number index does not exists.");
412 mooseError(
"A call to 'setNumberOfRows()/Columns()' was made after initialization, as such the " 413 "expected Sampler output has changed and a new sample must be created. However, a " 414 "call to Sampler::reinit() was not performed. The renit() method is automatically " 415 "called during Sampler execution, which occurs according to the 'execute_on' " 416 "settings of the Sampler object. An adjustment to this parameter may be required. " 417 "It is recommended that calls to 'setNumberOfRows()/Columns() occur within the " 418 "Sampler::executeSetUp() method; this will ensure that the reinitialize is handled " 419 "correctly. Have a nice day.");
void setNumberOfRows(dof_id_type n_rows)
These methods must be called within the constructor of child classes to define the size of the matrix...
void init()
Functions called by MOOSE to setup the Sampler for use.
void advanceGeneratorsInternal(const dof_id_type count)
Advance method for internal use that considers the auto advance flag.
DenseMatrix< Real > getLocalSamples()
static uint32_t randl()
This method returns the next random number (long format) from the generator.
dof_id_type _local_row_begin
Global row index for start of data for this processor.
A MultiMooseEnum object to hold "execute_on" flags.
uint32_t getRandl(unsigned int index, uint32_t lower, uint32_t upper)
Get the next random integer from the generator within the specified range [lower, upper) ...
MooseRandom _generator
Random number generator, don't give users access. Control it via the interface from this class...
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index)=0
Base class must override this method to supply the sample distribution data.
static InputParameters validParams()
virtual void advanceGenerators(const dof_id_type count)
Method for advancing the random number generator(s) by the supplied number or calls to rand()...
dof_id_type _n_local_rows
Number of rows for this processor.
virtual void executeSetUp()
Callbacks for before and after execute.
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)
Returns app partitioning information relevant to the given rank for a multiapp scenario with the give...
DenseMatrix< Real > getGlobalSamples()
Return the sampled complete or distributed sample data.
Interface for objects that need to use samplers.
virtual void advanceGenerator(const unsigned int seed_index, const dof_id_type count)
std::vector< Real > getNextLocalRow()
Return the "next" local row.
virtual void sampleTearDown(const SampleMode)
dof_id_type getLocalRowBegin() const
Return the beginning/end local row index for this processor.
void checkReinitStatus() const
Helper function for reinit() errors.
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
const Parallel::Communicator & _communicator
virtual void computeLocalSampleMatrix(DenseMatrix< Real > &matrix)
const dof_id_type _max_procs_per_row
The maximum number of processors that are associated with a set of rows.
void restoreGeneratorState()
virtual void computeSampleMatrix(DenseMatrix< Real > &matrix)
Methods to populate the global or local sample matrix.
const dof_id_type _limit_get_next_local_row
Max number of entries for matrix returned by getNextLocalRow.
dof_id_type getNumberOfLocalRows() const
Real getRand(unsigned int index=0)
Get the next random number from the generator.
static InputParameters validParams()
Sampler(const InputParameters ¶meters)
auto max(const L &left, const R &right)
virtual void computeSampleRow(dof_id_type i, std::vector< Real > &data)
Method to populate a complete row of sample data.
processor_id_type n_processors() const
bool _needs_reinit
Flag to indicate if the reinit method should be called during execute.
const dof_id_type _limit_get_global_samples
Max number of entries for matrix returned by getGlobalSamples.
Every object that can be built by the factory should be derived from this class.
const dof_id_type _limit_get_local_samples
Max number of entries for matrix returned by getLocalSamples.
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Interface for objects that need to use distributions.
Interface to allow object to consume Reporter values.
void split(int color, int key, Communicator &target) const
void saveGeneratorState()
Here we save/restore generator states.
std::pair< LocalRankConfig, LocalRankConfig > _rank_config
The partitioning of the sampler matrix, built in reinit() first is for normal mode and send is for ba...
std::size_t _n_seeds
Number of seeds.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
static InputParameters validParams()
std::vector< Real > & get_values()
bool _has_executed
Flag for initial execute to allow the first set of random numbers to be always be the same...
Interface for objects interacting with the PerfGraph.
virtual LocalRankConfig constructRankConfig(bool batch_mode) const
This is where the sampler partitioning is defined.
std::size_t size()
Return the number of states.
dof_id_type getLocalRowEnd() const
const dof_id_type _min_procs_per_row
The minimum number of processors that are associated with a set of rows.
libMesh::Parallel::Communicator _local_comm
Communicator that was split based on samples that have rows.
dof_id_type _local_row_end
Global row index for end of data for this processor.
dof_id_type getNumberOfRows() const
Return the number of samples.
virtual void sampleSetUp(const SampleMode)
Setup method called prior and after looping through distributions.
void setAutoAdvanceGenerators(const bool state)
void setNumberOfCols(dof_id_type n_cols)
static void seed(unsigned int seed)
The method seeds the random number generator.
virtual void executeTearDown()
bool _initialized
Flag to indicate if the init method for this class was called.
static Real rand()
This method returns the next random number (Real format) from the generator.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
bool _auto_advance_generators
Flag for disabling automatic generator advancing.
bool _next_local_row_requires_state_restore
Flag for restoring state during getNextLocalRow iteration.
Holds app partitioning information relevant to the a particular rank for a multiapp scenario...
dof_id_type _n_rows
Total number of rows in the sample matrix.
static InputParameters validParams()
void execute()
Store the state of the MooseRandom generator so that new calls to getGlobalSamples/getLocalSamples me...
dof_id_type _n_cols
Total number of columns in the sample matrix.
processor_id_type processor_id() const
void ErrorVector unsigned int
dof_id_type getNumberOfCols() const
This class encapsulates a useful, consistent, cross-platform random number generator with multiple ut...
void setNumberOfRandomSeeds(std::size_t number)
Set the number of seeds required by the sampler.
dof_id_type _next_local_row
Iterator index for getNextLocalRow method.