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