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 "CartesianGridPositions.h" 11 : 12 : registerMooseObject("ReactorApp", CartesianGridPositions); 13 : 14 : InputParameters 15 90 : CartesianGridPositions::validParams() 16 : { 17 90 : InputParameters params = Positions::validParams(); 18 90 : params.addClassDescription("Create positions along a Cartesian grid."); 19 : 20 180 : params.addRequiredParam<Point>("center", "Center of the Cartesian grid"); 21 180 : params.addRequiredRangeCheckedParam<Real>("dx", "dx>0", "Lattice extent in the X direction"); 22 180 : params.addRequiredRangeCheckedParam<Real>("dy", "dy>0", "Lattice extent in the Y direction"); 23 180 : params.addRequiredRangeCheckedParam<Real>("dz", "dz>0", "Lattice extent in the Z direction"); 24 180 : params.addRequiredRangeCheckedParam<unsigned int>( 25 : "nx", "nx>0", "Number of points in the X direction"); 26 180 : params.addRequiredRangeCheckedParam<unsigned int>( 27 : "ny", "ny>0", "Number of points in the Y direction"); 28 180 : params.addRequiredRangeCheckedParam<unsigned int>( 29 : "nz", "nz>0", "Number of points in the Z direction"); 30 : 31 : // Pattern for selecting some lattice positions 32 180 : 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 180 : 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 90 : params.set<bool>("auto_sort") = false; 42 : // All functors defined on all processes for now 43 90 : params.set<bool>("auto_broadcast") = false; 44 : 45 90 : return params; 46 0 : } 47 : 48 45 : CartesianGridPositions::CartesianGridPositions(const InputParameters & parameters) 49 : : Positions(parameters), 50 45 : _center(getParam<Point>("center")), 51 90 : _dx(getParam<Real>("dx")), 52 90 : _dy(getParam<Real>("dy")), 53 90 : _dz(getParam<Real>("dz")), 54 90 : _nx(getParam<unsigned int>("nx")), 55 90 : _ny(getParam<unsigned int>("ny")), 56 90 : _nz(getParam<unsigned int>("nz")), 57 90 : _pattern(getParam<std::vector<std::vector<std::vector<unsigned int>>>>("pattern")), 58 45 : _include_in_pattern( 59 90 : std::set<unsigned int>(getParam<std::vector<unsigned int>>("include_in_pattern").begin(), 60 135 : getParam<std::vector<unsigned int>>("include_in_pattern").end())) 61 : { 62 45 : if ((_include_in_pattern.empty() && _pattern.size()) || 63 36 : (_include_in_pattern.size() && _pattern.empty())) 64 0 : 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 81 : for (const auto include : _include_in_pattern) 69 : { 70 : bool found = false; 71 81 : for (const auto iz : index_range(_pattern)) 72 135 : for (const auto iy : index_range(_pattern[iz])) 73 : { 74 90 : const auto row = _pattern[iz][iy]; 75 : 76 90 : if (std::find(row.begin(), row.end(), include) != row.end()) 77 : found = true; 78 90 : } 79 36 : if (!found) 80 0 : paramError("include_in_pattern", 81 0 : "Pattern item " + std::to_string(include) + 82 : " to include is not present in the pattern"); 83 : } 84 : // Check size of pattern 85 45 : if (_pattern.size()) 86 : { 87 36 : if (_pattern.size() != _nz) 88 0 : mooseError("Wrong pattern size in Z direction: ", _pattern.size()); 89 81 : for (const auto & column : _pattern) 90 45 : if (column.size() != _ny) 91 0 : mooseError("Wrong pattern size in Y direction: ", column.size()); 92 81 : for (const auto & column : _pattern) 93 135 : for (const auto & row : column) 94 90 : if (row.size() != _nx) 95 0 : mooseError("Wrong pattern size in X direction: ", row.size()); 96 : } 97 : 98 : // Obtain the positions by evaluating the functors 99 45 : initialize(); 100 : // Sort if needed (user-specified) 101 45 : finalize(); 102 45 : } 103 : 104 : void 105 45 : CartesianGridPositions::initialize() 106 : { 107 45 : clearPositions(); 108 : 109 : // Count the number of positions we do not need to include 110 : unsigned int n_exclusions = 0; 111 45 : if (_include_in_pattern.size()) 112 81 : for (const auto iz : index_range(_pattern)) 113 135 : for (const auto iy : index_range(_pattern[iz])) 114 360 : for (const auto ix : index_range(_pattern[iz][iy])) 115 : if (!_include_in_pattern.count(_pattern[iz][iy][ix])) 116 63 : n_exclusions++; 117 45 : const auto n_positions = _nx * _ny * _nz - n_exclusions; 118 45 : _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 99 : for (const auto iz : make_range(_nz)) 124 162 : for (const auto iy : make_range(_ny)) 125 432 : for (const auto ix : make_range(_nx)) 126 : { 127 324 : if (!_pattern.size() || !_include_in_pattern.size() || 128 270 : _include_in_pattern.count(_pattern[iz][iy][ix])) 129 261 : _positions[pos_i++] = _center + Point(_dx / 2 * ((2. * ix + 1) / _nx - 1), 130 261 : _dy / 2 * ((2. * iy + 1) / _ny - 1), 131 261 : _dz / 2 * ((2. * iz + 1) / _nz - 1)); 132 : } 133 45 : _initialized = true; 134 45 : }