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 3381 : CartesianProductSampler::validParams() 21 : { 22 3381 : InputParameters params = Sampler::validParams(); 23 3381 : params.addClassDescription("Provides complete Cartesian product for the supplied variables."); 24 6762 : 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 3381 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 28 3381 : return params; 29 0 : } 30 : 31 1965 : CartesianProductSampler::CartesianProductSampler(const InputParameters & parameters) 32 1965 : : Sampler(parameters) 33 : { 34 3930 : const std::vector<Real> & items = getParam<std::vector<Real>>("linear_space_items"); 35 1965 : 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 5464 : for (std::size_t i = 0; i < items.size(); i += 3) 42 : { 43 3499 : 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 3499 : 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 3499 : unsigned int div = static_cast<unsigned int>(items[i + 2]); 54 3499 : grid_items.emplace_back(std::vector<Real>(div)); 55 31622 : for (std::size_t j = 0; j < grid_items.back().size(); ++j) 56 28123 : grid_items.back()[j] = items[i] + j * items[i + 1]; 57 : } 58 : 59 3930 : _cp_ptr = std::make_unique<const StochasticTools::CartesianProduct<Real>>(grid_items); 60 1965 : setNumberOfRows(_cp_ptr->numRows()); 61 1965 : setNumberOfCols(_cp_ptr->numCols()); 62 1965 : } 63 : 64 : Real 65 586116 : CartesianProductSampler::computeSample(dof_id_type row_index, dof_id_type col_index) 66 : { 67 586116 : return _cp_ptr->computeValue(row_index, col_index); 68 : }