LCOV - code coverage report
Current view: top level - src/utils - VectorOfVectorCalculators.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 12 14 85.7 %
Date: 2025-07-25 05:00:46 Functions: 2 2 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 "VectorOfVectorCalculators.h"
      11             : 
      12             : namespace StochasticTools
      13             : {
      14             : 
      15             : template <typename InType, typename OutType>
      16             : std::vector<std::vector<std::vector<OutType>>>
      17          16 : Percentile<std::vector<std::vector<InType>>, std::vector<std::vector<OutType>>>::compute(
      18             :     const std::vector<std::vector<InType>> & data, const bool is_distributed)
      19             : {
      20             :   // Bootstrap estimates
      21          16 :   const auto values = this->computeBootstrapEstimates(data, is_distributed);
      22             : 
      23             :   // Extract percentiles
      24             :   std::vector<std::vector<std::vector<OutType>>> output;
      25          16 :   if (this->processor_id() == 0)
      26          30 :     for (const Real & level : this->_levels)
      27             :     {
      28          20 :       long unsigned int index = std::lrint(level * (this->_replicates - 1));
      29          20 :       output.push_back(values[index]);
      30             :     }
      31             : 
      32          16 :   return output;
      33          16 : }
      34             : 
      35             : template <typename InType, typename OutType>
      36             : std::unique_ptr<
      37             :     BootstrapCalculator<std::vector<std::vector<InType>>, std::vector<std::vector<OutType>>>>
      38          16 : BootstrapCalculatorBuilder<std::vector<std::vector<InType>>, std::vector<std::vector<OutType>>>::
      39             :     build(const MooseEnum & item,
      40             :           const libMesh::ParallelObject & other,
      41             :           const std::vector<Real> & levels,
      42             :           unsigned int replicates,
      43             :           unsigned int seed,
      44             :           StochasticTools::Calculator<std::vector<std::vector<InType>>,
      45             :                                       std::vector<std::vector<OutType>>> & calc)
      46             : {
      47             :   std::unique_ptr<
      48             :       BootstrapCalculator<std::vector<std::vector<InType>>, std::vector<std::vector<OutType>>>>
      49             :       ptr = nullptr;
      50          16 :   if (item == "percentile")
      51          16 :     ptr = std::make_unique<
      52             :         Percentile<std::vector<std::vector<InType>>, std::vector<std::vector<OutType>>>>(
      53             :         other, item, levels, replicates, seed, calc);
      54             :   else
      55           0 :     ::mooseError("Failed to create Statistics::BootstrapCalculator object for ", item);
      56             : 
      57          16 :   return ptr;
      58           0 : }
      59             : 
      60             : #define createVectorOfVectorCalculators(InType, OutType)                                           \
      61             :   template class Percentile<std::vector<std::vector<InType>>, std::vector<std::vector<OutType>>>;  \
      62             :   template struct BootstrapCalculatorBuilder<std::vector<std::vector<InType>>,                     \
      63             :                                              std::vector<std::vector<OutType>>>
      64             : 
      65             : createVectorOfVectorCalculators(std::vector<Real>, Real);
      66             : }

Generated by: LCOV version 1.14