https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MonteCarloSampler.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "MonteCarloSampler.h"
11#include "Distribution.h"
12
13registerMooseObjectAliased("StochasticToolsApp", MonteCarloSampler, "MonteCarlo");
14registerMooseObjectReplaced("StochasticToolsApp",
16 "07/01/2020 00:00",
17 MonteCarlo);
18
21{
23 params.addClassDescription("Monte Carlo Sampler.");
24 params.addRequiredParam<dof_id_type>("num_rows", "The number of rows per matrix to generate.");
25 params.addRequiredParam<std::vector<DistributionName>>(
26 "distributions",
27 "The distribution names to be sampled, the number of distributions provided defines the "
28 "number of columns per matrix.");
29 return params;
30}
31
33 : Sampler(parameters),
34 _distribution_names(getParam<std::vector<DistributionName>>("distributions"))
35{
36 for (const DistributionName & name : _distribution_names)
38
39 setNumberOfRows(getParam<dof_id_type>("num_rows"));
41}
42
43Real
44MonteCarloSampler::computeSample(dof_id_type row_index, dof_id_type col_index)
45{
46 return _distributions[col_index]->quantile(getRand(row_index * getNumberOfCols() + col_index));
47}
registerMooseObjectReplaced("StochasticToolsApp", MonteCarloSampler, "07/01/2020 00:00", MonteCarlo)
registerMooseObjectAliased("StochasticToolsApp", MonteCarloSampler, "MonteCarlo")
const Distribution & getDistributionByName(const DistributionName &name) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
A class used to perform Monte Carlo Sampling.
std::vector< Distribution const * > _distributions
Storage for distribution objects to be utilized.
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override
Return the sample for the given row and column.
const std::vector< DistributionName > & _distribution_names
Distribution names.
static InputParameters validParams()
MonteCarloSampler(const InputParameters &parameters)
const std::string & name() const
void setNumberOfCols(dof_id_type n_cols)
Real getRand(std::size_t n, unsigned int index=0) const
static InputParameters validParams()
dof_id_type getNumberOfCols() const
void setNumberOfRows(dof_id_type n_rows)