LCOV - code coverage report
Current view: top level - src/utils - DiscretePKAPDFBase.C (source / functions) Hit Total Coverage
Test: idaholab/magpie: 5710af Lines: 23 24 95.8 %
Date: 2025-07-21 23:34:39 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**********************************************************************/
       2             : /*                     DO NOT MODIFY THIS HEADER                      */
       3             : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
       4             : /*                                                                    */
       5             : /*            Copyright 2017 Battelle Energy Alliance, LLC            */
       6             : /*                        ALL RIGHTS RESERVED                         */
       7             : /**********************************************************************/
       8             : 
       9             : #include "DiscretePKAPDFBase.h"
      10             : #include "MooseError.h"
      11             : #include "MooseRandom.h"
      12             : 
      13           2 : DiscretePKAPDFBase::DiscretePKAPDFBase(const std::vector<unsigned int> & ZAID,
      14           2 :                                        const std::vector<Real> & energies)
      15           2 :   : _zaids(ZAID), _nZA(_zaids.size()), _energies(energies), _ng(_energies.size() - 1)
      16             : {
      17           2 : }
      18             : 
      19             : unsigned int
      20     1100000 : DiscretePKAPDFBase::sampleHelper(const MultiIndex<Real> & marginal_pdf,
      21             :                                  const MultiIndex<Real>::size_type indices) const
      22             : {
      23     1100000 :   if (marginal_pdf.dim() - indices.size() != 1)
      24           0 :     mooseError("For sampling the indices vector must reduce the marginal_pdf to a one-dimensional "
      25             :                "ladder function.");
      26     1100000 :   MultiIndex<Real>::size_type dimension(indices.size());
      27     2800000 :   for (unsigned int j = 0; j < indices.size(); ++j)
      28     1700000 :     dimension[j] = j;
      29     2200000 :   MultiIndex<Real> new_marginal_pdf = marginal_pdf.slice(dimension, indices);
      30     2200000 :   return sampleHelper(new_marginal_pdf);
      31     1100000 : }
      32             : 
      33             : unsigned int
      34     1800000 : DiscretePKAPDFBase::sampleHelper(const MultiIndex<Real> & marginal_pdf) const
      35             : {
      36             :   Real r = MooseRandom::rand();
      37     1800000 :   std::vector<unsigned int> index(1);
      38             :   unsigned int j = 0;
      39     3139692 :   for (; j < marginal_pdf.size()[0]; ++j)
      40             :   {
      41     3139692 :     index[0] = j;
      42     3139692 :     if (r <= marginal_pdf(index))
      43             :       break;
      44             :   }
      45     1800000 :   return j;
      46             : }
      47             : 
      48             : unsigned int
      49      500000 : DiscretePKAPDFBase::sampleHelper(const std::vector<Real> & marginal_pdf) const
      50             : {
      51             :   Real r = MooseRandom::rand();
      52      500000 :   std::vector<unsigned int> index(1);
      53             :   unsigned int j = 0;
      54   237696491 :   for (; j < marginal_pdf.size(); ++j)
      55             :   {
      56   237696491 :     if (r <= marginal_pdf[j])
      57             :       break;
      58             :   }
      59      500000 :   return j;
      60             : }

Generated by: LCOV version 1.14