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 "Cartesian1DSampler.h" 11 : 12 : registerMooseObjectAliased("StochasticToolsApp", Cartesian1DSampler, "Cartesian1D"); 13 : 14 : InputParameters 15 56 : Cartesian1DSampler::validParams() 16 : { 17 56 : InputParameters params = Sampler::validParams(); 18 56 : params.addClassDescription("Provides complete Cartesian product for the supplied variables."); 19 112 : params.addRequiredParam<std::vector<Real>>( 20 : "linear_space_items", 21 : "A list of triplets, each item should include the min, step size, and number of steps."); 22 112 : params.addRequiredParam<std::vector<Real>>("nominal_values", "Nominal values for each column."); 23 56 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 24 56 : return params; 25 0 : } 26 : 27 39 : Cartesian1DSampler::Cartesian1DSampler(const InputParameters & parameters) 28 78 : : Sampler(parameters), _nominal_values(getParam<std::vector<Real>>("nominal_values")) 29 : { 30 78 : const std::vector<Real> & items = getParam<std::vector<Real>>("linear_space_items"); 31 39 : if (items.size() % 3 != 0) 32 4 : paramError("linear_space_items", 33 : "The number of numeric items must be divisible by 3; min, max, divisions for each " 34 : "item are required."); 35 35 : const dof_id_type num_cols = items.size() / 3; 36 35 : if (_nominal_values.size() != num_cols) 37 4 : paramError("nominal_values", 38 : "The number of values specified must match the number of triplets in " 39 : "'linear_space_items'."); 40 : 41 31 : _grid_range.resize(num_cols + 1, 0); 42 31 : _grid_items.resize(num_cols); 43 : dof_id_type num_rows = 0; 44 100 : for (std::size_t i = 0; i < items.size(); i += 3) 45 : { 46 77 : if (items[i + 2] != std::floor(items[i + 2])) 47 4 : paramError("linear_space_items", 48 : "The third entry for each item must be an integer; it provides the number of " 49 : "entries in the resulting item vector."); 50 : 51 73 : if (items[i + 2] < 0) 52 4 : paramError("linear_space_items", 53 : "The third entry for each item must be positive; it provides the number of " 54 : "entries in the resulting item vector."); 55 : 56 69 : const dof_id_type col = i / 3; 57 69 : const dof_id_type ng = static_cast<dof_id_type>(items[i + 2]); 58 : 59 69 : num_rows += ng; 60 69 : _grid_range[col + 1] = num_rows; 61 69 : _grid_items[col].resize(ng); 62 276 : for (const auto & j : make_range(ng)) 63 207 : _grid_items[col][j] = items[i] + j * items[i + 1]; 64 : } 65 : 66 23 : setNumberOfRows(num_rows); 67 23 : setNumberOfCols(num_cols); 68 23 : } 69 : 70 : Real 71 297 : Cartesian1DSampler::computeSample(dof_id_type row_index, dof_id_type col_index) 72 : { 73 297 : if (row_index >= _grid_range[col_index] && row_index < _grid_range[col_index + 1]) 74 99 : return _grid_items[col_index][row_index - _grid_range[col_index]]; 75 : else 76 198 : return _nominal_values[col_index]; 77 : }