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 7480 : MonteCarloSampler::validParams() 21 : { 22 7480 : InputParameters params = Sampler::validParams(); 23 7480 : params.addClassDescription("Monte Carlo Sampler."); 24 14960 : params.addRequiredParam<dof_id_type>("num_rows", "The number of rows per matrix to generate."); 25 14960 : 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 7480 : return params; 30 0 : } 31 : 32 4303 : MonteCarloSampler::MonteCarloSampler(const InputParameters & parameters) 33 : : Sampler(parameters), 34 8606 : _distribution_names(getParam<std::vector<DistributionName>>("distributions")) 35 : { 36 14516 : for (const DistributionName & name : _distribution_names) 37 10213 : _distributions.push_back(&getDistributionByName(name)); 38 : 39 12909 : setNumberOfRows(getParam<dof_id_type>("num_rows")); 40 4303 : setNumberOfCols(_distributions.size()); 41 4303 : } 42 : 43 : Real 44 509365 : MonteCarloSampler::computeSample(dof_id_type /*row_index*/, dof_id_type col_index) 45 : { 46 509365 : return _distributions[col_index]->quantile(getRand()); 47 : }