https://mooseframework.inl.gov
Cartesian1DSampler.C
Go to the documentation of this file.
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 
16 {
18  params.addClassDescription("Provides complete Cartesian product for the supplied variables.");
19  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  params.addRequiredParam<std::vector<Real>>("nominal_values", "Nominal values for each column.");
23  params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
24  return params;
25 }
26 
28  : Sampler(parameters), _nominal_values(getParam<std::vector<Real>>("nominal_values"))
29 {
30  const std::vector<Real> & items = getParam<std::vector<Real>>("linear_space_items");
31  if (items.size() % 3 != 0)
32  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  const dof_id_type num_cols = items.size() / 3;
36  if (_nominal_values.size() != num_cols)
37  paramError("nominal_values",
38  "The number of values specified must match the number of triplets in "
39  "'linear_space_items'.");
40 
41  _grid_range.resize(num_cols + 1, 0);
42  _grid_items.resize(num_cols);
43  dof_id_type num_rows = 0;
44  for (std::size_t i = 0; i < items.size(); i += 3)
45  {
46  if (items[i + 2] != std::floor(items[i + 2]))
47  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  if (items[i + 2] < 0)
52  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  const dof_id_type col = i / 3;
57  const dof_id_type ng = static_cast<dof_id_type>(items[i + 2]);
58 
59  num_rows += ng;
60  _grid_range[col + 1] = num_rows;
61  _grid_items[col].resize(ng);
62  for (const auto & j : make_range(ng))
63  _grid_items[col][j] = items[i] + j * items[i + 1];
64  }
65 
66  setNumberOfRows(num_rows);
67  setNumberOfCols(num_cols);
68 }
69 
70 Real
72 {
73  if (row_index >= _grid_range[col_index] && row_index < _grid_range[col_index + 1])
74  return _grid_items[col_index][row_index - _grid_range[col_index]];
75  else
76  return _nominal_values[col_index];
77 }
void setNumberOfRows(dof_id_type n_rows)
Similar to CartesianProduct, this object creates a sampling scheme that produces a grid of samples...
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
std::vector< dof_id_type > _grid_range
The range of rows in which to apply the grid for each column.
Cartesian1DSampler(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
registerMooseObjectAliased("StochasticToolsApp", Cartesian1DSampler, "Cartesian1D")
void paramError(const std::string &param, Args... args) const
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override
Return the sample for the given row and column.
std::vector< std::vector< Real > > _grid_items
The values to use when sampling from a column&#39;s grid.
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void setNumberOfCols(dof_id_type n_cols)
IntRange< T > make_range(T beg, T end)
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
uint8_t dof_id_type
const std::vector< Real > & _nominal_values
The values to use when not sampling from a column&#39;s grid.
const ExecFlagType EXEC_INITIAL