Line data Source code
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 : 13 : registerMooseObjectAliased("StochasticToolsApp", MonteCarloSampler, "MonteCarlo"); 14 : registerMooseObjectReplaced("StochasticToolsApp", 15 : MonteCarloSampler, 16 : "07/01/2020 00:00", 17 : MonteCarlo); 18 : 19 : InputParameters 20 2887 : MonteCarloSampler::validParams() 21 : { 22 2887 : InputParameters params = Sampler::validParams(); 23 2887 : params.addClassDescription("Monte Carlo Sampler."); 24 5774 : params.addRequiredParam<dof_id_type>("num_rows", "The number of rows per matrix to generate."); 25 5774 : 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 2887 : return params; 30 0 : } 31 : 32 1560 : MonteCarloSampler::MonteCarloSampler(const InputParameters & parameters) 33 : : Sampler(parameters), 34 3120 : _distribution_names(getParam<std::vector<DistributionName>>("distributions")) 35 : { 36 5232 : for (const DistributionName & name : _distribution_names) 37 3672 : _distributions.push_back(&getDistributionByName(name)); 38 : 39 4680 : setNumberOfRows(getParam<dof_id_type>("num_rows")); 40 1560 : setNumberOfCols(_distributions.size()); 41 1560 : } 42 : 43 : Real 44 230634 : MonteCarloSampler::computeSample(dof_id_type row_index, dof_id_type col_index) 45 : { 46 230634 : return _distributions[col_index]->quantile(getRand(row_index * getNumberOfCols() + col_index)); 47 : }