LCOV - code coverage report
Current view: top level - src/samplers - CartesianProductSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #32971 (54bef8) with base c6cf66 Lines: 23 27 85.2 %
Date: 2026-05-29 20:40:35 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 "CartesianProductSampler.h"
      11             : #include "Distribution.h"
      12             : 
      13             : registerMooseObjectAliased("StochasticToolsApp", CartesianProductSampler, "CartesianProduct");
      14             : registerMooseObjectReplaced("StochasticToolsApp",
      15             :                             CartesianProductSampler,
      16             :                             "07/01/2020 00:00",
      17             :                             CartesianProduct);
      18             : 
      19             : InputParameters
      20        1587 : CartesianProductSampler::validParams()
      21             : {
      22        1587 :   InputParameters params = Sampler::validParams();
      23        1587 :   params.addClassDescription("Provides complete Cartesian product for the supplied variables.");
      24        3174 :   params.addRequiredParam<std::vector<Real>>(
      25             :       "linear_space_items",
      26             :       "A list of triplets, each item should include the min, step size, and number of steps.");
      27        1587 :   params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
      28        1587 :   return params;
      29           0 : }
      30             : 
      31         866 : CartesianProductSampler::CartesianProductSampler(const InputParameters & parameters)
      32         866 :   : Sampler(parameters)
      33             : {
      34        1732 :   const std::vector<Real> & items = getParam<std::vector<Real>>("linear_space_items");
      35         866 :   if (items.size() % 3 != 0)
      36           0 :     paramError("linear_space_items",
      37             :                "The number of numeric items must be divisible by 3; min, max, divisions for each "
      38             :                "item are required.");
      39             : 
      40             :   std::vector<std::vector<Real>> grid_items;
      41        2428 :   for (std::size_t i = 0; i < items.size(); i += 3)
      42             :   {
      43        1562 :     if (items[i + 2] != std::floor(items[i + 2]))
      44           0 :       paramError("linear_space_items",
      45             :                  "The third entry for each item must be an integer; it provides the number of "
      46             :                  "entries in the resulting item vector.");
      47             : 
      48        1562 :     if (items[i + 2] < 0)
      49           0 :       paramError("linear_space_items",
      50             :                  "The third entry for each item must be positive; it provides the number of "
      51             :                  "entries in the resulting item vector.");
      52             : 
      53        1562 :     unsigned int div = static_cast<unsigned int>(items[i + 2]);
      54        1562 :     grid_items.emplace_back(std::vector<Real>(div));
      55       12973 :     for (std::size_t j = 0; j < grid_items.back().size(); ++j)
      56       11411 :       grid_items.back()[j] = items[i] + j * items[i + 1];
      57             :   }
      58             : 
      59        1732 :   _cp_ptr = std::make_unique<const StochasticTools::CartesianProduct<Real>>(grid_items);
      60         866 :   setNumberOfRows(_cp_ptr->numRows());
      61         866 :   setNumberOfCols(_cp_ptr->numCols());
      62         866 : }
      63             : 
      64             : Real
      65      302723 : CartesianProductSampler::computeSample(dof_id_type row_index, dof_id_type col_index)
      66             : {
      67      302723 :   return _cp_ptr->computeValue(row_index, col_index);
      68             : }

Generated by: LCOV version 1.14