LCOV - code coverage report
Current view: top level - src/samplers - MonteCarloSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 15 16 93.8 %
Date: 2025-07-25 05:00:46 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14