https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SCMTriVisualizationAssemblyMeshGenerator.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
11#include "TriSubChannelMesh.h"
12#include <array>
13#include <cmath>
14#include <memory>
15#include "libmesh/cell_prism6.h"
16#include "libmesh/unstructured_mesh.h"
17
20 SCMDetailedTriAssemblyMeshGenerator,
21 "06/30/2027 24:00",
24 SCMDetailedTriSubChannelMeshGenerator,
25 "06/30/2027 24:00",
28 DetailedTriSubChannelMeshGenerator,
29 "06/30/2027 24:00",
32 SCMDetailedTriPinMeshGenerator,
33 "06/30/2027 24:00",
36 DetailedTriPinMeshGenerator,
37 "06/30/2027 24:00",
39
42{
45 "Creates a 3D visualization mesh of subchannels and pins in a triangular lattice "
46 "arrangement");
47 params.addRequiredParam<Real>("pitch", "Pitch [m]");
48 params.addRequiredParam<Real>("pin_diameter", "Rod diameter [m]");
49 params.addParam<Real>("unheated_length_entry", 0.0, "Unheated length at entry [m]");
50 params.addRequiredParam<Real>("heated_length", "Heated length [m]");
51 params.addParam<Real>("unheated_length_exit", 0.0, "Unheated length at exit [m]");
52 params.addRequiredParam<unsigned int>(
53 "nrings",
54 "Number of fuel-pin rings per assembly, counting the center pin as the first ring [-]");
55 params.addRequiredParam<Real>("flat_to_flat",
56 "Flat to flat distance for the hexagonal assembly [m]");
57 params.addRequiredParam<unsigned int>("n_cells", "The number of cells in the axial direction");
58 params.addRangeCheckedParam<unsigned int>("num_sectors",
59 16,
60 "num_sectors>=4",
61 "Number of azimuthal sectors used to discretize each "
62 "circular pin cross section.");
63 params.addParam<unsigned int>("block_id", 0, "Subchannel block id.");
64 params.deprecateParam("block_id", "subchannel_block_id", "07/01/2027");
65 params.addParam<unsigned int>("pin_block_id", 1, "Fuel pin block id.");
66 params.addParam<bool>("verbose_flag", false, "Flag to print out the mesh coordinates.");
67 return params;
68}
69
71 const InputParameters & parameters)
72 : MeshGenerator(parameters),
73 _unheated_length_entry(getParam<Real>("unheated_length_entry")),
74 _heated_length(getParam<Real>("heated_length")),
75 _unheated_length_exit(getParam<Real>("unheated_length_exit")),
76 _pitch(getParam<Real>("pitch")),
77 _pin_diameter(getParam<Real>("pin_diameter")),
78 _n_rings(getParam<unsigned int>("nrings")),
79 _flat_to_flat(getParam<Real>("flat_to_flat")),
80 _num_sectors(getParam<unsigned int>("num_sectors")),
81 _subchannel_block_id(getParam<unsigned int>("subchannel_block_id")),
82 _pin_block_id(getParam<unsigned int>("pin_block_id")),
83 _n_cells(getParam<unsigned int>("n_cells")),
84 _nrods(0),
85 _n_channels(0),
86 _verbose(getParam<bool>("verbose_flag")),
87 _elem_id(0)
88{
89 // Read by SCMTriCoreMeshGenerator to check that assemblies placed in a core do not overlap
90 declareMeshProperty<Real>("flat_to_flat", _flat_to_flat);
91
93
94 if (_n_rings < 2)
95 paramError("nrings",
96 "'nrings' must be at least 2. In this mesh generator, the center pin counts as "
97 "the first ring, so a 7-pin bundle uses nrings = 2.");
98
99 if (_n_cells == 0)
100 paramError("n_cells", "The number of axial cells must be greater than zero");
101
102 if (L <= 0.0)
103 mooseError("Total bundle length must be greater than zero");
104
105 Real dz = L / _n_cells;
106 for (unsigned int i = 0; i < _n_cells + 1; i++)
107 _z_grid.push_back(dz * i);
108
109 // x coordinate for the first position
110 Real x0 = 0.0;
111 // y coordinate for the first position
112 Real y0 = 0.0;
113 // x coordinate for the second position
114 Real x1 = 0.0;
115 // y coordinate for the second position dummy variable
116 Real y1 = 0.0;
117 // dummy variable
118 Real a1 = 0.0;
119 // dummy variable
120 Real a2 = 0.0;
121 // average x coordinate
122 Real avg_coor_x = 0.0;
123 // average y coordinate
124 Real avg_coor_y = 0.0;
125 // distance between two points
126 Real dist = 0.0;
127 // distance between two points
128 Real dist0 = 0.0;
129 // the indicator used while setting _gap_to_chan_map array
130 std::vector<std::pair<unsigned int, unsigned int>> gap_fill;
132 _nrods = _pin_position.size();
133 // assign the pins to the corresponding rings
134 unsigned int k = 0; // initialize the fuel Pin counter index
135 _pins_in_rings.resize(_n_rings);
136 _pins_in_rings[0].push_back(k++);
137 for (unsigned int i = 1; i < _n_rings; i++)
138 for (unsigned int j = 0; j < i * 6; j++)
139 _pins_in_rings[i].push_back(k++);
140 // Given the number of pins and number of fuel Pin rings, the number of subchannels can be
141 // computed as follows:
142 unsigned int chancount = 0;
143 // Summing internal channels
144 for (unsigned int j = 0; j < _n_rings - 1; j++)
145 chancount += j * 6;
146 // Adding external channels to the total count
147 _n_channels = chancount + _nrods - 1 + (_n_rings - 1) * 6 + 6;
148
149 // Utils for building the mesh
151 _subch_type.resize(_n_channels);
153
154 for (unsigned int i = 0; i < _n_channels; i++)
155 {
156 _subchannel_position[i].reserve(3);
157 for (unsigned int j = 0; j < 3; j++)
158 {
159 _subchannel_position.at(i).push_back(0.0);
160 }
161 }
162
163 // create the subchannels
164 k = 0; // initialize the subchannel counter index
165 for (unsigned int i = 1; i < _n_rings; i++)
166 {
167 // find the closest Pin at back ring
168 for (unsigned int j = 0; j < _pins_in_rings[i].size(); j++)
169 {
170 if (j == _pins_in_rings[i].size() - 1)
171 {
172 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j]);
173 _chan_to_pin_map[k].push_back(_pins_in_rings[i][0]);
174 avg_coor_x =
175 0.5 * (_pin_position[_pins_in_rings[i][j]](0) + _pin_position[_pins_in_rings[i][0]](0));
176 avg_coor_y =
177 0.5 * (_pin_position[_pins_in_rings[i][j]](1) + _pin_position[_pins_in_rings[i][0]](1));
178 }
179 else
180 {
181 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j]);
182 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j + 1]);
183 avg_coor_x = 0.5 * (_pin_position[_pins_in_rings[i][j]](0) +
184 _pin_position[_pins_in_rings[i][j + 1]](0));
185 avg_coor_y = 0.5 * (_pin_position[_pins_in_rings[i][j]](1) +
186 _pin_position[_pins_in_rings[i][j + 1]](1));
187 }
188 dist0 = 1.0e+5;
189 _chan_to_pin_map[k].push_back(_pins_in_rings[i - 1][0]);
190 for (unsigned int l = 0; l < _pins_in_rings[i - 1].size(); l++)
191 {
192 dist = std::sqrt(pow(_pin_position[_pins_in_rings[i - 1][l]](0) - avg_coor_x, 2) +
193 pow(_pin_position[_pins_in_rings[i - 1][l]](1) - avg_coor_y, 2));
194
195 if (dist < dist0)
196 {
197 _chan_to_pin_map[k][2] = _pins_in_rings[i - 1][l];
198 dist0 = dist;
199 }
200 }
202 _orientation_map.insert(std::make_pair(k, 0.0));
203 k = k + 1;
204 }
205
206 // find the closest Pin at front ring
207 for (unsigned int j = 0; j < _pins_in_rings[i].size(); j++)
208 {
209 if (j == _pins_in_rings[i].size() - 1)
210 {
211 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j]);
212 _chan_to_pin_map[k].push_back(_pins_in_rings[i][0]);
213 avg_coor_x =
214 0.5 * (_pin_position[_pins_in_rings[i][j]](0) + _pin_position[_pins_in_rings[i][0]](0));
215 avg_coor_y =
216 0.5 * (_pin_position[_pins_in_rings[i][j]](1) + _pin_position[_pins_in_rings[i][0]](1));
217 }
218 else
219 {
220 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j]);
221 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j + 1]);
222 avg_coor_x = 0.5 * (_pin_position[_pins_in_rings[i][j]](0) +
223 _pin_position[_pins_in_rings[i][j + 1]](0));
224 avg_coor_y = 0.5 * (_pin_position[_pins_in_rings[i][j]](1) +
225 _pin_position[_pins_in_rings[i][j + 1]](1));
226 }
227 // if the outermost ring, set the edge subchannels first... then the corner subchannels
228 if (i == _n_rings - 1)
229 {
230 // add edges
231 _subch_type[k] = EChannelType::EDGE; // an edge subchannel is created
232 k = k + 1;
233 if (j % i == 0)
234 {
235 // corner subchannel
236 _chan_to_pin_map[k].push_back(_pins_in_rings[i][j]);
238 k = k + 1;
239 }
240 // if not the outer most ring
241 }
242 else
243 {
244 dist0 = 1.0e+5;
245 _chan_to_pin_map[k].push_back(_pins_in_rings[i + 1][0]);
246 for (unsigned int l = 0; l < _pins_in_rings[i + 1].size(); l++)
247 {
248 dist = std::sqrt(pow(_pin_position[_pins_in_rings[i + 1][l]](0) - avg_coor_x, 2) +
249 pow(_pin_position[_pins_in_rings[i + 1][l]](1) - avg_coor_y, 2));
250 if (dist < dist0)
251 {
252 _chan_to_pin_map[k][2] = _pins_in_rings[i + 1][l];
253 dist0 = dist;
254 }
255 }
257 _orientation_map.insert(std::make_pair(k, libMesh::pi));
258 k = k + 1;
259 }
260 }
261 }
262
263 for (auto & pin : _chan_to_pin_map)
264 pin.shrink_to_fit();
265
266 // set the subchannel positions
267 Real _duct_to_pin_gap =
268 0.5 * (_flat_to_flat - (_n_rings - 1) * _pitch * std::sqrt(3.0) - _pin_diameter);
269 for (unsigned int i = 0; i < _n_channels; i++)
270 {
272 {
276 3.0;
280 3.0;
281 }
282 else if (_subch_type[i] == EChannelType::EDGE)
283 {
284 for (unsigned int j = 0; j < _n_channels; j++)
285 {
287 ((_chan_to_pin_map[i][0] == _chan_to_pin_map[j][0] &&
288 _chan_to_pin_map[i][1] == _chan_to_pin_map[j][1]) ||
289 (_chan_to_pin_map[i][0] == _chan_to_pin_map[j][1] &&
290 _chan_to_pin_map[i][1] == _chan_to_pin_map[j][0])))
291 {
292 x0 = _pin_position[_chan_to_pin_map[j][2]](0);
293 y0 = _pin_position[_chan_to_pin_map[j][2]](1);
294 }
295 else if (_subch_type[j] == EChannelType::CENTER &&
296 ((_chan_to_pin_map[i][0] == _chan_to_pin_map[j][0] &&
297 _chan_to_pin_map[i][1] == _chan_to_pin_map[j][2]) ||
298 (_chan_to_pin_map[i][0] == _chan_to_pin_map[j][2] &&
299 _chan_to_pin_map[i][1] == _chan_to_pin_map[j][0])))
300 {
301 x0 = _pin_position[_chan_to_pin_map[j][1]](0);
302 y0 = _pin_position[_chan_to_pin_map[j][1]](1);
303 }
304 else if (_subch_type[j] == EChannelType::CENTER &&
305 ((_chan_to_pin_map[i][0] == _chan_to_pin_map[j][1] &&
306 _chan_to_pin_map[i][1] == _chan_to_pin_map[j][2]) ||
307 (_chan_to_pin_map[i][0] == _chan_to_pin_map[j][2] &&
308 _chan_to_pin_map[i][1] == _chan_to_pin_map[j][1])))
309 {
310 x0 = _pin_position[_chan_to_pin_map[j][0]](0);
311 y0 = _pin_position[_chan_to_pin_map[j][0]](1);
312 }
313 x1 = 0.5 *
315 y1 = 0.5 *
317 a1 = _pin_diameter / 2.0 + _duct_to_pin_gap / 2.0;
318 a2 = std::sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) + a1;
319 _subchannel_position[i][0] = (a2 * x1 - a1 * x0) / (a2 - a1);
320 _subchannel_position[i][1] = (a2 * y1 - a1 * y0) / (a2 - a1);
321 } // j
322 }
323 else if (_subch_type[i] == EChannelType::CORNER)
324 {
325 x0 = _pin_position[0](0);
326 y0 = _pin_position[0](1);
327 x1 = _pin_position[_chan_to_pin_map[i][0]](0);
328 y1 = _pin_position[_chan_to_pin_map[i][0]](1);
329 a1 = _pin_diameter / 2.0 + _duct_to_pin_gap / 2.0;
330 a2 = std::sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) + a1;
331 _subchannel_position[i][0] = (a2 * x1 - a1 * x0) / (a2 - a1);
332 _subchannel_position[i][1] = (a2 * y1 - a1 * y0) / (a2 - a1);
333 }
334 }
335}
336
337void
338SCMTriVisualizationAssemblyMeshGenerator::generatePin(std::unique_ptr<MeshBase> & mesh_base,
339 const Point & center)
340{
341 const Real dalpha = 360. / _num_sectors;
342 const Real radius = _pin_diameter / 2.;
343
344 // Add a center node and radial boundary nodes on each axial level so each pin is discretized into
345 // triangular prism sectors.
346 std::vector<std::vector<Node *>> nodes;
347 nodes.resize(_n_cells + 1);
348 for (unsigned int k = 0; k < _n_cells + 1; k++)
349 {
350 const Real elev = _z_grid[k];
351 nodes[k].push_back(mesh_base->add_point(Point(center(0), center(1), elev)));
352 Real alpha = 0.;
353 for (unsigned int i = 0; i < _num_sectors; i++, alpha += dalpha)
354 {
355 const Real dx = radius * std::cos(alpha * M_PI / 180.);
356 const Real dy = radius * std::sin(alpha * M_PI / 180.);
357 nodes[k].push_back(mesh_base->add_point(Point(center(0) + dx, center(1) + dy, elev)));
358 }
359 }
360
361 // Add the pin volume elements, linking matching radial sectors between adjacent axial levels.
362 for (unsigned int k = 0; k < _n_cells; k++)
363 for (unsigned int i = 0; i < _num_sectors; i++)
364 {
365 Elem * elem = mesh_base->add_elem(std::make_unique<Prism6>());
366 elem->subdomain_id() = _pin_block_id;
367 elem->set_id(_elem_id++);
368 const unsigned int ctr_idx = 0;
369 const unsigned int idx1 = (i % _num_sectors) + 1;
370 const unsigned int idx2 = ((i + 1) % _num_sectors) + 1;
371 elem->set_node(0, nodes[k][ctr_idx]);
372 elem->set_node(1, nodes[k][idx1]);
373 elem->set_node(2, nodes[k][idx2]);
374 elem->set_node(3, nodes[k + 1][ctr_idx]);
375 elem->set_node(4, nodes[k + 1][idx1]);
376 elem->set_node(5, nodes[k + 1][idx2]);
377 }
378}
379
380std::unique_ptr<MeshBase>
382{
383 auto mesh_base = buildMeshBaseObject();
384 BoundaryInfo & boundary_info = mesh_base->get_boundary_info();
385 mesh_base->set_spatial_dimension(3);
386 // Define the resolution (the number of points used to represent a circle).
387 // This must be divisible by 4.
388 const unsigned int theta_res_triangle = 24; // TODO: parameterize
389 const unsigned int theta_res_square = 24; // TODO: parameterize
390 // Compute the number of points needed to represent one sixth and quadrant of a circle.
391 const unsigned int points_per_sixth = theta_res_triangle / 6 + 1;
392 const unsigned int points_per_quadrant = theta_res_square / 4 + 1;
393
394 // Compute the points needed to represent one axial cross-flow of a subchannel.
395 // For the center subchannel (sc) there is one center point plus the points from 3 side
396 // circles.
397 const unsigned int points_per_center = points_per_sixth * 3 + 1;
398 // For the corner sc there is one center point plus the points from 1 side circle plus 3
399 // corners
400 const unsigned int points_per_corner = points_per_sixth * 1 + 1 + 3;
401 // For the side sc there is one center point plus the points from 2 intersecting circles plus 2
402 // corners
403 const unsigned int points_per_side = points_per_quadrant * 2 + 1 + 2;
404
405 if (_verbose)
406 {
407 _console << "Points per center: " << points_per_center << std::endl;
408 _console << "Points per side: " << points_per_side << std::endl;
409 _console << "Points per corner: " << points_per_corner << std::endl;
410 }
411
412 // Compute the number of elements (Prism6) which combined base creates the sub-channel
413 // cross-section
414 const unsigned int elems_per_center = theta_res_triangle * 3 / 6 + 3; // TODO: check
415 const unsigned int elems_per_corner = theta_res_triangle / 6 + 4;
416 const unsigned int elems_per_side = 2 * theta_res_square / 4 + 4;
417 if (_verbose)
418 {
419 _console << "Elems per center: " << elems_per_center << std::endl;
420 _console << "Elems per side: " << elems_per_side << std::endl;
421 _console << "Elems per corner: " << elems_per_corner << std::endl;
422 }
423
424 // specify number and type of sub-channel
425 unsigned int n_corner = 6;
426 unsigned int n_side = (_n_rings - 1) * 6;
427 unsigned int n_center = _n_channels - n_side - n_corner;
428 if (_verbose)
429 {
430 _console << "Centers: " << n_center << std::endl;
431 _console << "Sides: " << n_side << std::endl;
432 _console << "Corners: " << n_corner << std::endl;
433 }
434
435 // Compute the total number of points and elements.
436 const unsigned int points_per_level =
437 n_corner * points_per_corner + n_side * points_per_side + n_center * points_per_center;
438 const unsigned int elems_per_level =
439 n_corner * elems_per_corner + n_side * elems_per_side + n_center * elems_per_center;
440 if (_verbose)
441 {
442 _console << "Points per level: " << points_per_level << std::endl;
443 _console << "Elements per level: " << elems_per_level << std::endl;
444 }
445 const unsigned int n_points = points_per_level * (_n_cells + 1);
446 const unsigned int n_elems = elems_per_level * _n_cells;
447 const unsigned int n_pins = _pin_position.size();
448 const unsigned int pin_points = n_pins > 0 ? (_n_cells + 1) * (_num_sectors + 1) * n_pins : 0;
449 const unsigned int pin_elems = n_pins > 0 ? _n_cells * _num_sectors * n_pins : 0;
450 if (_verbose)
451 {
452 _console << "Number of points: " << n_points << std::endl;
453 _console << "Number of elements: " << n_elems << std::endl;
454 }
455 mesh_base->reserve_nodes(n_points + pin_points);
456 mesh_base->reserve_elem(n_elems + pin_elems);
457 // Build an array of points arranged in a circle on the xy-plane. (last and first node overlap)
458 // We build for both the square discretization in the edges and the triangular discretization
459 // within the mesh
460 const Real radius = _pin_diameter / 2.0;
461 std::array<Point, theta_res_square + 1> circle_points_square;
462 {
463 Real theta = 0;
464 for (unsigned int i = 0; i < theta_res_square + 1; i++)
465 {
466 circle_points_square[i](0) = radius * std::cos(theta);
467 circle_points_square[i](1) = radius * std::sin(theta);
468 theta += 2.0 * libMesh::pi / theta_res_square;
469 }
470 }
471 std::array<Point, theta_res_triangle + 1> circle_points_triangle;
472 {
473 Real theta = 0;
474 for (unsigned int i = 0; i < theta_res_triangle + 1; i++)
475 {
476 circle_points_triangle[i](0) = radius * std::cos(theta);
477 circle_points_triangle[i](1) = radius * std::sin(theta);
478 theta += 2.0 * libMesh::pi / theta_res_triangle;
479 }
480 }
481 // Define "quadrant center" reference points. These will be the centers of
482 // the 3 circles that represent the fuel pins. These centers are
483 // offset a little bit so that in the final mesh, there is a tiny gap between
484 // neighboring subchannel cells. That allows us to easily map a solution to
485 // this detailed mesh with a nearest-neighbor search.
486 const Real shrink_factor = 0.99999;
487 // Quadrants are used only for the side and corner subchannels
488 Real _duct_to_pin_gap =
489 0.5 * (_flat_to_flat - (_n_rings - 1) * _pitch * std::sqrt(3.0) - _pin_diameter);
490 std::array<Point, 2> quadrant_centers_sides;
491 quadrant_centers_sides[0] = Point(
492 -_pitch * 0.5 * shrink_factor, -(_duct_to_pin_gap + _pin_diameter) * 0.5 * shrink_factor, 0);
493 quadrant_centers_sides[1] = Point(
494 _pitch * 0.5 * shrink_factor, -(_duct_to_pin_gap + _pin_diameter) * 0.5 * shrink_factor, 0);
495 std::array<Point, 1> quadrant_centers_corner;
496 quadrant_centers_corner[0] =
497 Point(-(_duct_to_pin_gap + _pin_diameter) * 0.5 * std::sin(libMesh::pi / 6) * shrink_factor,
498 -(_duct_to_pin_gap + _pin_diameter) * 0.5 * std::cos(libMesh::pi / 6) * shrink_factor,
499 0);
500 // Triangles are used for all center subchannels
501 std::array<Point, 3> triangle_centers;
502 triangle_centers[0] = Point(0, _pitch * std::cos(libMesh::pi / 6) * 2 / 3 * shrink_factor, 0);
503 triangle_centers[1] = Point(-_pitch * 0.5 * shrink_factor,
504 -_pitch * std::cos(libMesh::pi / 6) * 1 / 3 * shrink_factor,
505 0);
506 triangle_centers[2] = Point(
507 _pitch * 0.5 * shrink_factor, -_pitch * std::cos(libMesh::pi / 6) * 1 / 3 * shrink_factor, 0);
508
509 const unsigned int m_sixth = theta_res_triangle / 6;
510 const unsigned int m_quarter = theta_res_square / 4;
511 // Build an array of points that represent a cross section of a center subchannel
512 // cell. The points are ordered in this fashion:
513 // 3 1
514 // 2
515 // 0
516 // 4 5 8 9
517 // 6 7
518 std::array<Point, points_per_center> center_points{};
519 center_points[0] = Point(0, 0, 0);
520 {
521 unsigned int start;
522 for (unsigned int i = 0; i < 3; i++)
523 {
524 if (i == 0)
525 start = 5 * (m_sixth);
526 if (i == 1)
527 start = 1 * (m_sixth);
528 if (i == 2)
529 start = 3 * (m_sixth);
530 for (unsigned int ii = 0; ii < points_per_sixth; ii++)
531 {
532 auto c_pt = circle_points_triangle[start - ii];
533 center_points[i * points_per_sixth + ii + 1] = triangle_centers[i] + c_pt;
534 }
535 }
536 }
537
538 // Build an array of points that represent a cross section of a top left corner subchannel
539 // cell. The points are ordered in this fashion (x direction towards point 4, y direction towards
540 // point 6):
541 // 5 6
542 //
543 // 0
544 // 4 2 3
545 // 1
546 std::array<Point, points_per_corner> corner_points{};
547 corner_points[0] = Point(0, 0, 0);
548 {
549 for (unsigned int ii = 0; ii < points_per_sixth; ii++)
550 {
551 auto c_pt = circle_points_triangle[1 * m_quarter - ii];
552 corner_points[ii + 1] = quadrant_centers_corner[0] + c_pt;
553 }
554 Real side_short = (_duct_to_pin_gap + _pin_diameter) * 0.5;
555 Real side_long = (2.0 * _duct_to_pin_gap + _pin_diameter) * 0.5;
556 Real side_length = std::sqrt(std::pow(side_short, 2) + std::pow(side_long, 2) -
557 2 * side_short * side_long * std::cos(libMesh::pi / 6));
558 Real angle =
560 std::acos((-std::pow(side_long, 2) + std::pow(side_short, 2) + std::pow(side_length, 2)) /
561 (2 * side_short * side_length));
562 corner_points[points_per_sixth + 1] = Point(side_length * std::cos(angle) * shrink_factor,
563 -side_length * std::sin(angle) * shrink_factor,
564 0);
565 corner_points[points_per_sixth + 2] =
566 Point(side_length * std::sin(libMesh::pi / 2 - angle - libMesh::pi / 6) * shrink_factor *
567 std::tan(libMesh::pi / 6),
568 side_length * std::sin(libMesh::pi / 2 - angle - libMesh::pi / 6) * shrink_factor,
569 0);
570 corner_points[points_per_sixth + 3] =
571 Point(-side_length * std::cos(libMesh::pi / 2 - angle - libMesh::pi / 6) * shrink_factor,
572 side_length * std::sin(libMesh::pi / 2 - angle - libMesh::pi / 6) * shrink_factor,
573 0);
574 }
575
576 // Build an array of points that represent a cross-section of a top side subchannel
577 // cell. The points are ordered in this fashion:
578 // 8 7
579 //
580 // 0
581 // 1 2 5 6
582 // 3 4
583 std::array<Point, points_per_side> side_points{};
584 side_points[0] = Point(0, 0, 0);
585 {
586 for (unsigned int ii = 0; ii < points_per_quadrant; ii++)
587 {
588 auto c_pt = circle_points_square[m_quarter - ii];
589 side_points[ii + 1] = quadrant_centers_sides[0] + c_pt;
590 }
591 for (unsigned int ii = 0; ii < points_per_quadrant; ii++)
592 {
593 auto c_pt = circle_points_square[2 * m_quarter - ii];
594 side_points[points_per_quadrant + ii + 1] = quadrant_centers_sides[1] + c_pt;
595 }
596 side_points[2 * points_per_quadrant + 1] =
597 Point(_pitch * 0.5 * shrink_factor, 0.5 * _duct_to_pin_gap * shrink_factor, 0);
598 side_points[2 * points_per_quadrant + 2] =
599 Point(-_pitch * 0.5 * shrink_factor, 0.5 * _duct_to_pin_gap * shrink_factor, 0);
600 }
601
602 int point_counter = 0;
603 unsigned int node_id = 0;
604 for (unsigned int i = 0; i < _n_channels; i++)
605 {
606 // Real offset_x = _flat_to_flat / 2.0;
607 // Real offset_y = _flat_to_flat / 2.0;
608
610 {
611 for (auto z : _z_grid)
612 {
613 // Get height
614 Point z0{0, 0, z};
615
616 // Get suchannel position and assign to point
617 auto loc_position = getSubchannelPosition(i);
618 Point p0{loc_position[0], loc_position[1], 0};
619
620 // Determine orientation of current subchannel
621 auto subchannel_pins = getSubChannelPins(i);
622 Point subchannel_side =
623 getPinPosition(subchannel_pins[0]) + getPinPosition(subchannel_pins[1]);
624 Point base_center_orientation = {0, -1};
625
626 // Get rotation angle for current subchannel
627 Real dot_prod = 0;
628 for (unsigned int lp = 0; lp < 2; lp++)
629 dot_prod += base_center_orientation(lp) * subchannel_side(lp);
630 auto theta =
631 std::acos(dot_prod / (base_center_orientation.norm() * subchannel_side.norm()));
632 if (subchannel_side(0) < 0)
633 theta = 2.0 * libMesh::pi - theta;
634
635 // Real distance_side = subchannel_side.norm();
636 // Real distance_top = getPinPosition(subchannel_pins[2]).norm();
637 // if (distance_top > distance_side)
638 // theta += libMesh::pi * 0.0;
639
640 theta += _orientation_map[i];
641
642 theta = trunc((theta + (libMesh::pi / 6.0)) / (libMesh::pi / 3.0)) * libMesh::pi / 3.0;
643
644 if (_verbose)
645 {
646 if (z == 0)
647 {
648 _console << "Subchannel Position: " << p0 << std::endl;
649 auto pins = getSubChannelPins(i);
650 for (auto r : pins)
651 _console << r << " ";
652 _console << std::endl;
653 _console << "Theta: " << theta / libMesh::pi * 180. << std::endl;
654 }
655 }
656
657 // Assigning points for center channels
658 for (unsigned int i = 0; i < points_per_center; i++)
659 {
660 auto new_point = rotatePoint(center_points[i], theta) + p0 + z0;
661 if (_verbose)
662 {
663 if (z == 0)
664 _console << i << " - " << new_point << std::endl;
665 }
666 mesh_base->add_point(new_point, node_id++);
667 point_counter += 1;
668 }
669 }
670 }
672 {
673 for (auto z : _z_grid)
674 {
675 // Get height
676 Point z0{0, 0, z};
677
678 // Get suchannel position and assign to point
679 auto loc_position = getSubchannelPosition(i);
680 Point p0{loc_position[0], loc_position[1], 0};
681
682 // Determine orientation of current subchannel
683 auto subchannel_pins = getSubChannelPins(i);
684 Point subchannel_side =
685 getPinPosition(subchannel_pins[0]) + getPinPosition(subchannel_pins[1]);
686 Point base_center_orientation = {0, 1};
687
688 // Get rotation angle for current subchannel
689 Real dot_prod = 0;
690 for (unsigned int lp = 0; lp < 2; lp++)
691 dot_prod += base_center_orientation(lp) * subchannel_side(lp);
692 auto theta =
693 std::acos(dot_prod / (base_center_orientation.norm() * subchannel_side.norm()));
694 if (subchannel_side(0) > 0)
695 theta = 2. * libMesh::pi - theta;
696 theta = trunc((theta + (libMesh::pi / 6.0)) / (libMesh::pi / 3.0)) * libMesh::pi / 3.0;
697
698 if (_verbose)
699 {
700 if (z == 0)
701 {
702 _console << "Subchannel Position: " << p0 << std::endl;
703 auto pins = getSubChannelPins(i);
704 for (auto r : pins)
705 _console << r << " ";
706 _console << std::endl;
707 _console << "Theta: " << theta * 180 / libMesh::pi << std::endl;
708 }
709 }
710
711 // Assigning points for center channels
712 for (unsigned int i = 0; i < points_per_side; i++)
713 {
714 auto new_point = rotatePoint(side_points[i], theta) + p0 + z0;
715 if (_verbose)
716 {
717 if (z == 0)
718 _console << i << " - " << new_point << std::endl;
719 }
720 mesh_base->add_point(new_point, node_id++);
721 point_counter += 1;
722 }
723 }
724 }
725 else // getSubchannelType(i) == EChannelType::CORNER
726 {
727 for (auto z : _z_grid)
728 {
729 // Get height
730 Point z0{0, 0, z};
731
732 // Get suchannel position and assign to point
733 auto loc_position = getSubchannelPosition(i);
734 Point p0{loc_position[0], loc_position[1], 0};
735
736 // Determine orientation of current subchannel
737 auto subchannel_pins = getSubChannelPins(i);
738 Point subchannel_side = getPinPosition(subchannel_pins[0]);
739 Point base_center_orientation = {1, 1};
740
741 // Get rotation angle for current subchannel
742 Real dot_prod = 0;
743 for (unsigned int lp = 0; lp < 2; lp++)
744 dot_prod += base_center_orientation(lp) * subchannel_side(lp);
745 auto theta =
746 std::acos(dot_prod / (base_center_orientation.norm() * subchannel_side.norm()));
747 if (subchannel_side(0) > 0)
748 theta = 2. * libMesh::pi - theta;
749 theta = trunc((theta + (libMesh::pi / 6.0)) / (libMesh::pi / 3.0)) * libMesh::pi / 3.0;
750
751 if (_verbose)
752 {
753 if (z == 0)
754 {
755 _console << "Subchannel Position: " << p0 << std::endl;
756 auto pins = getSubChannelPins(i);
757 for (auto r : pins)
758 _console << r << " ";
759 _console << std::endl;
760 _console << "Theta: " << theta * 180 / libMesh::pi << std::endl;
761 }
762 }
763
764 // Assigning points for center channels
765 for (unsigned int i = 0; i < points_per_corner; i++)
766 {
767 auto new_point = rotatePoint(corner_points[i], theta) + p0 + z0;
768 if (_verbose)
769 {
770 if (z == 0)
771 _console << i << " - " << new_point << std::endl;
772 }
773 mesh_base->add_point(new_point, node_id++);
774 point_counter += 1;
775 }
776 }
777 }
778 } // i
779 if (_verbose)
780 _console << "Point counter: " << point_counter << std::endl;
781
782 int element_counter = 0;
783 unsigned int elem_id = 0;
784 unsigned int number_of_corner = 0;
785 unsigned int number_of_side = 0;
786 unsigned int number_of_center = 0;
787 unsigned int elems_per_channel = 0;
788 unsigned int points_per_channel = 0;
789 for (unsigned int i = 0; i < _n_channels; i++)
790 {
791 auto subch_type = getSubchannelType(i);
792 if (subch_type == EChannelType::CORNER)
793 {
794 number_of_corner++;
795 elems_per_channel = elems_per_corner;
796 points_per_channel = points_per_corner;
797 if (_verbose)
798 _console << "Corner" << std::endl;
799 }
800 else if (subch_type == EChannelType::EDGE)
801 {
802 number_of_side++;
803 elems_per_channel = elems_per_side;
804 points_per_channel = points_per_side;
805 if (_verbose)
806 _console << "Edge" << std::endl;
807 }
808 else if (subch_type == EChannelType::CENTER)
809 {
810 number_of_center++;
811 elems_per_channel = elems_per_center;
812 points_per_channel = points_per_center;
813 if (_verbose)
814 _console << "Center" << std::endl;
815 }
816 for (unsigned int iz = 0; iz < _n_cells; iz++)
817 {
818 unsigned int elapsed_points = number_of_corner * points_per_corner * (_n_cells + 1) +
819 number_of_side * points_per_side * (_n_cells + 1) +
820 number_of_center * points_per_center * (_n_cells + 1) -
821 points_per_channel * (_n_cells + 1);
822 // index of the central node at base of cell
823 unsigned int indx1 = iz * points_per_channel + elapsed_points;
824 // index of the central node at top of cell
825 unsigned int indx2 = (iz + 1) * points_per_channel + elapsed_points;
826
827 for (unsigned int i = 0; i < elems_per_channel; i++)
828 {
829 Elem * elem = mesh_base->add_elem(std::make_unique<Prism6>());
830 elem->subdomain_id() = _subchannel_block_id;
831 elem->set_id(elem_id++);
832
833 if (_verbose)
834 _console << "Node 0: " << *mesh_base->node_ptr(indx1) << std::endl;
835
836 elem->set_node(0, mesh_base->node_ptr(indx1));
837 elem->set_node(1, mesh_base->node_ptr(indx1 + i + 1));
838 if (i != elems_per_channel - 1)
839 elem->set_node(2, mesh_base->node_ptr(indx1 + i + 2));
840 else
841 elem->set_node(2, mesh_base->node_ptr(indx1 + 1));
842
843 elem->set_node(3, mesh_base->node_ptr(indx2));
844 elem->set_node(4, mesh_base->node_ptr(indx2 + i + 1));
845 if (i != elems_per_channel - 1)
846 elem->set_node(5, mesh_base->node_ptr(indx2 + i + 2));
847 else
848 elem->set_node(5, mesh_base->node_ptr(indx2 + 1));
849
850 if (iz == 0)
851 boundary_info.add_side(elem, 0, 0);
852 if (iz == _n_cells - 1)
853 boundary_info.add_side(elem, 4, 1);
854
855 element_counter += 1;
856 }
857 }
858 }
859 if (_verbose)
860 _console << "Element counter: " << element_counter << std::endl;
861 boundary_info.sideset_name(0) = "inlet";
862 boundary_info.sideset_name(1) = "outlet";
863 mesh_base->set_subdomain_name(_subchannel_block_id, "subchannel", true);
864 if (n_pins > 0)
865 {
866 _elem_id = mesh_base->n_elem();
867 for (auto & ctr : _pin_position)
868 generatePin(mesh_base, ctr);
869 }
870 if (n_pins > 0)
871 mesh_base->set_subdomain_name(_pin_block_id, "fuel_pins", true);
872 if (_verbose)
873 _console << "Mesh assembly done" << std::endl;
874 mesh_base->prepare_for_use();
875
876 return mesh_base;
877}
878
879Point
881{
882 std::vector<std::vector<Real>> A(3, std::vector<Real>(3));
883
884 A[0] = {std::cos(theta), -std::sin(theta), 0.0};
885 A[1] = {std::sin(theta), std::cos(theta), 0.0};
886 A[2] = {0.0, 0.0, 1.0};
887
888 Point rotated_vector = Point(0.0, 0.0, 0.0);
889 for (unsigned int i = 0; i < 3; i++)
890 for (unsigned int j = 0; j < 3; j++)
891 rotated_vector(i) += A[i][j] * b(j);
892
893 return rotated_vector;
894}
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Point center
registerMooseObjectRenamed("SubChannelApp", SCMDetailedTriAssemblyMeshGenerator, "06/30/2027 24:00", SCMTriVisualizationAssemblyMeshGenerator)
registerMooseObject("SubChannelApp", SCMTriVisualizationAssemblyMeshGenerator)
void ErrorVector unsigned int
const ConsoleStream _console
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void deprecateParam(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
static InputParameters validParams()
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
Mesh generator that builds a 3D mesh representing triangular subchannels and pins.
Point rotatePoint(Point b, Real theta)
rotate a point by theta radians about the origin
const unsigned int _num_sectors
Number of azimuthal sectors used to discretize each circular pin cross section.
EChannelType getSubchannelType(unsigned int index) const
returns the type of the subchannel given the index
const unsigned int _n_rings
Number of rings in the geometry.
std::map< unsigned int, Real > _orientation_map
map inner and outer rings
const unsigned int _n_cells
Number of cells in the axial direction.
const unsigned int _subchannel_block_id
Subchannel subdomain ID.
Point getPinPosition(unsigned int i)
returns the position of pin given pin index
SCMTriVisualizationAssemblyMeshGenerator(const InputParameters &parameters)
std::vector< EChannelType > _subch_type
Subchannel type.
const bool _verbose
Flag to print out the detailed mesh assembly and coordinates.
const Real _unheated_length_entry
unheated length of the fuel Pin at the entry of the assembly
std::vector< std::vector< Real > > _subchannel_position
x,y coordinates of the subchannels
const Real _unheated_length_exit
unheated length of the fuel Pin at the exit of the assembly
virtual std::unique_ptr< MeshBase > generate() override
std::vector< std::vector< unsigned int > > _pins_in_rings
fuel pins that are belonging to each ring
std::vector< std::vector< unsigned int > > _chan_to_pin_map
stores the fuel pins belonging to each subchannel
std::vector< unsigned int > getSubChannelPins(unsigned int i)
returns the index of neighboring pins given subchannel index
const Real _flat_to_flat
Half of gap between adjacent assemblies.
void generatePin(std::unique_ptr< MeshBase > &mesh_base, const Point &center)
Generate one detailed fuel pin volume centered at the supplied point.
std::vector< Real > getSubchannelPosition(unsigned int i)
returns the position of subchannel given pin index
std::vector< Point > _pin_position
x,y coordinates of the fuel pins
const Real _pitch
Distance between the neighbor fuel pins, pitch.
static void pinPositions(std::vector< Point > &positions, unsigned int nrings, Real pitch, Point center)
Calculates and stores the pin positions/centers for a hexagonal assembly containing the given number ...
const Real pi
const Real radius