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 54 : Cartesian1DSampler::validParams() 16 : { 17 54 : InputParameters params = Sampler::validParams(); 18 54 : params.addClassDescription("Provides complete Cartesian product for the supplied variables."); 19 108 : 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 108 : params.addRequiredParam<std::vector<Real>>("nominal_values", "Nominal values for each column."); 23 54 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 24 54 : return params; 25 0 : } 26 : 27 38 : Cartesian1DSampler::Cartesian1DSampler(const InputParameters & parameters) 28 76 : : Sampler(parameters), _nominal_values(getParam<std::vector<Real>>("nominal_values")) 29 : { 30 76 : const std::vector<Real> & items = getParam<std::vector<Real>>("linear_space_items"); 31 38 : 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 34 : const dof_id_type num_cols = items.size() / 3; 36 34 : 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 30 : _grid_range.resize(num_cols + 1, 0); 42 30 : _grid_items.resize(num_cols); 43 : dof_id_type num_rows = 0; 44 96 : for (std::size_t i = 0; i < items.size(); i += 3) 45 : { 46 74 : 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 70 : 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 66 : const dof_id_type col = i / 3; 57 66 : const dof_id_type ng = static_cast<dof_id_type>(items[i + 2]); 58 : 59 66 : num_rows += ng; 60 66 : _grid_range[col + 1] = num_rows; 61 66 : _grid_items[col].resize(ng); 62 264 : for (const auto & j : make_range(ng)) 63 198 : _grid_items[col][j] = items[i] + j * items[i + 1]; 64 : } 65 : 66 22 : setNumberOfRows(num_rows); 67 22 : setNumberOfCols(num_cols); 68 22 : } 69 : 70 : Real 71 270 : Cartesian1DSampler::computeSample(dof_id_type row_index, dof_id_type col_index) 72 : { 73 270 : if (row_index >= _grid_range[col_index] && row_index < _grid_range[col_index + 1]) 74 90 : return _grid_items[col_index][row_index - _grid_range[col_index]]; 75 : else 76 180 : return _nominal_values[col_index]; 77 : }