https://mooseframework.inl.gov
CartesianGridPositions.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 "CartesianGridPositions.h"
11 
13 
16 {
18  params.addClassDescription("Create positions along a Cartesian grid.");
19 
20  params.addRequiredParam<Point>("center", "Center of the Cartesian grid");
21  params.addRequiredRangeCheckedParam<Real>("dx", "dx>0", "Lattice extent in the X direction");
22  params.addRequiredRangeCheckedParam<Real>("dy", "dy>0", "Lattice extent in the Y direction");
23  params.addRequiredRangeCheckedParam<Real>("dz", "dz>0", "Lattice extent in the Z direction");
24  params.addRequiredRangeCheckedParam<unsigned int>(
25  "nx", "nx>0", "Number of points in the X direction");
26  params.addRequiredRangeCheckedParam<unsigned int>(
27  "ny", "ny>0", "Number of points in the Y direction");
28  params.addRequiredRangeCheckedParam<unsigned int>(
29  "nz", "nz>0", "Number of points in the Z direction");
30 
31  // Pattern for selecting some lattice positions
32  params.addRangeCheckedParam<std::vector<std::vector<std::vector<unsigned int>>>>(
33  "pattern",
34  {},
35  "pattern>=0",
36  "A double-indexed Cartesian-shaped array starting with the upper-left corner.");
37  params.addParam<std::vector<unsigned int>>(
38  "include_in_pattern", {}, "A vector of the numbers in the pattern to include");
39 
40  // Use user-provided ordering
41  params.set<bool>("auto_sort") = false;
42  // All functors defined on all processes for now
43  params.set<bool>("auto_broadcast") = false;
44 
45  return params;
46 }
47 
49  : Positions(parameters),
50  _center(getParam<Point>("center")),
51  _dx(getParam<Real>("dx")),
52  _dy(getParam<Real>("dy")),
53  _dz(getParam<Real>("dz")),
54  _nx(getParam<unsigned int>("nx")),
55  _ny(getParam<unsigned int>("ny")),
56  _nz(getParam<unsigned int>("nz")),
57  _pattern(getParam<std::vector<std::vector<std::vector<unsigned int>>>>("pattern")),
58  _include_in_pattern(
59  std::set<unsigned int>(getParam<std::vector<unsigned int>>("include_in_pattern").begin(),
60  getParam<std::vector<unsigned int>>("include_in_pattern").end()))
61 {
62  if ((_include_in_pattern.empty() && _pattern.size()) ||
63  (_include_in_pattern.size() && _pattern.empty()))
64  paramError(
65  "include_in_pattern",
66  "The 'pattern' parameter and the include_in_pattern must be both specified or both not "
67  "specified by the user.");
68  for (const auto include : _include_in_pattern)
69  {
70  bool found = false;
71  for (const auto iz : index_range(_pattern))
72  for (const auto iy : index_range(_pattern[iz]))
73  {
74  const auto row = _pattern[iz][iy];
75 
76  if (std::find(row.begin(), row.end(), include) != row.end())
77  found = true;
78  }
79  if (!found)
80  paramError("include_in_pattern",
81  "Pattern item " + std::to_string(include) +
82  " to include is not present in the pattern");
83  }
84  // Check size of pattern
85  if (_pattern.size())
86  {
87  if (_pattern.size() != _nz)
88  mooseError("Wrong pattern size in Z direction: ", _pattern.size());
89  for (const auto & column : _pattern)
90  if (column.size() != _ny)
91  mooseError("Wrong pattern size in Y direction: ", column.size());
92  for (const auto & column : _pattern)
93  for (const auto & row : column)
94  if (row.size() != _nx)
95  mooseError("Wrong pattern size in X direction: ", row.size());
96  }
97 
98  // Obtain the positions by evaluating the functors
99  initialize();
100  // Sort if needed (user-specified)
101  finalize();
102 }
103 
104 void
106 {
107  clearPositions();
108 
109  // Count the number of positions we do not need to include
110  unsigned int n_exclusions = 0;
111  if (_include_in_pattern.size())
112  for (const auto iz : index_range(_pattern))
113  for (const auto iy : index_range(_pattern[iz]))
114  for (const auto ix : index_range(_pattern[iz][iy]))
115  if (!_include_in_pattern.count(_pattern[iz][iy][ix]))
116  n_exclusions++;
117  const auto n_positions = _nx * _ny * _nz - n_exclusions;
118  _positions.resize(n_positions);
119 
120  // Fill the positions by retrieving the pin centers at indices included in the pattern (if
121  // specified)
122  unsigned int pos_i = 0;
123  for (const auto iz : make_range(_nz))
124  for (const auto iy : make_range(_ny))
125  for (const auto ix : make_range(_nx))
126  {
127  if (!_pattern.size() || !_include_in_pattern.size() ||
128  _include_in_pattern.count(_pattern[iz][iy][ix]))
129  _positions[pos_i++] = _center + Point(_dx / 2 * ((2. * ix + 1) / _nx - 1),
130  _dy / 2 * ((2. * iy + 1) / _ny - 1),
131  _dz / 2 * ((2. * iz + 1) / _nz - 1));
132  }
133  _initialized = true;
134 }
const unsigned int _nz
Number of points along the Z direction.
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
static InputParameters validParams()
std::set< unsigned int > _include_in_pattern
List of the pattern locations to include. Include all if empty.
const Real _dx
Extent of the lattice in the X direction.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void clearPositions()
T & set(const std::string &name, bool quiet_mode=false)
registerMooseObject("ReactorApp", CartesianGridPositions)
Creates positions (points) following an Cartesian grid.
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool _initialized
const Point _center
Center of the lattice.
CartesianGridPositions(const InputParameters &parameters)
static InputParameters validParams()
const unsigned int _ny
Number of points along the Y direction.
const Real _dy
Extent of the lattice in the Y direction.
std::vector< Point > & _positions
const Real _dz
Extent of the lattice in the Z direction.
void paramError(const std::string &param, Args... args) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
std::vector< std::vector< std::vector< unsigned int > > > _pattern
2D pattern of the pins to select (if specified)
virtual void finalize() override
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const unsigned int _nx
Number of points along the X direction.
void ErrorVector unsigned int
auto index_range(const T &sizable)