https://mooseframework.inl.gov
SCMQuadInterWrapperMeshGenerator.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 "QuadInterWrapperMesh.h"
12 #include "libmesh/edge_edge2.h"
13 #include <numeric>
14 
16 registerMooseObjectRenamed("SubChannelApp",
17  QuadInterWrapperMeshGenerator,
18  "06/30/2025 24:00",
20 
23 {
25  params.addClassDescription("Creates a mesh for the inter-wrapper around square subassemblies");
26  params.addRequiredParam<Real>("assembly_pitch", "Assembly Pitch [m]");
27  params.addRequiredParam<Real>("assembly_side_x",
28  "Outer side lengths of assembly in x [m] - including duct");
29  params.addRequiredParam<Real>("assembly_side_y",
30  "Outer side lengths of assembly in y [m] - including duct");
31  params.addParam<Real>("unheated_length_entry", 0.0, "Unheated length at entry [m]");
32  params.addRequiredParam<Real>("heated_length", "Heated length [m]");
33  params.addParam<Real>("unheated_length_exit", 0.0, "Unheated length at exit [m]");
34  params.addParam<Real>("Kij", 0.5, "Lateral form loss coefficient [-]");
35  params.addRequiredParam<unsigned int>("n_cells", "The number of cells in the axial direction");
36  params.addRequiredParam<unsigned int>("nx", "Number of assemblies in the x direction [-]");
37  params.addRequiredParam<unsigned int>("ny", "Number of assemblies in the y direction [-]");
38  params.addRequiredParam<Real>("side_bypass",
39  "Extra size of the bypass for the side assemblies [m]");
40  params.addParam<unsigned int>("block_id", 0, "Domain Index");
41  return params;
42 }
43 
45  : MeshGenerator(params),
46  _assembly_pitch(getParam<Real>("assembly_pitch")),
47  _assembly_side_x(getParam<Real>("assembly_side_x")),
48  _assembly_side_y(getParam<Real>("assembly_side_y")),
49  _unheated_length_entry(getParam<Real>("unheated_length_entry")),
50  _heated_length(getParam<Real>("heated_length")),
51  _unheated_length_exit(getParam<Real>("unheated_length_exit")),
52  _kij(getParam<Real>("Kij")),
53  _n_cells(getParam<unsigned int>("n_cells")),
54  _nx(getParam<unsigned int>("nx")),
55  _ny(getParam<unsigned int>("ny")),
56  _side_bypass_length(getParam<Real>("side_bypass")),
57  _n_channels((_nx + 1) * (_ny + 1)),
58  _n_gaps(_nx * (_ny + 1) + _ny * (_nx + 1)),
59  _n_assemblies(_nx * _ny),
60  _block_id(getParam<unsigned int>("block_id"))
61 {
62  // Converting number of assemblies into number of inter-wrapper flow channels
63  _nx += 1;
64  _ny += 1;
65 
66  if (_nx < 2 && _ny < 2)
67  mooseError(name(), ": The number of assemblies cannot be less than one in any direction. ");
68 
69  // Defining the total length from 3 axial sections
71 
72  // Defining the dz based in the total length and the specified number of axial cells
73  Real dz = L / _n_cells;
74  for (unsigned int i = 0; i < _n_cells + 1; i++)
75  _z_grid.push_back(dz * i);
76 
77  // Defining the array for axial resistances
78  _k_grid.resize(_n_channels, std::vector<Real>(_n_cells + 1));
79 
80  // Defining the size of the maps
81  _gap_to_chan_map.resize(_n_gaps);
82  _gapnodes.resize(_n_gaps);
87  _gij_map.resize(_n_gaps);
88 
89  // Defining the signs for positive and negative flows
90  Real positive_flow = 1.0;
91  Real negative_flow = -1.0;
92 
93  // Defining the subchannel types
94  _subch_type.resize(_n_channels);
95  for (unsigned int iy = 0; iy < _ny; iy++)
96  {
97  for (unsigned int ix = 0; ix < _nx; ix++)
98  {
99  unsigned int i_ch = _nx * iy + ix;
100  bool is_corner = (ix == 0 && iy == 0) || (ix == _nx - 1 && iy == 0) ||
101  (ix == 0 && iy == _ny - 1) || (ix == _nx - 1 && iy == _ny - 1);
102  bool is_edge = (ix == 0 || iy == 0 || ix == _nx - 1 || iy == _ny - 1);
103 
104  if (is_corner)
106  else if (is_edge)
108  else
110  }
111  }
112 
113  // Index the east-west gaps.
114  unsigned int i_gap = 0;
115  for (unsigned int iy = 0; iy < _ny; iy++)
116  {
117  for (unsigned int ix = 0; ix < _nx - 1; ix++)
118  {
119  unsigned int i_ch = _nx * iy + ix;
120  unsigned int j_ch = _nx * iy + (ix + 1);
121  _gap_to_chan_map[i_gap] = {i_ch, j_ch};
122  _chan_to_gap_map[i_ch].push_back(i_gap);
123  _chan_to_gap_map[j_ch].push_back(i_gap);
124  _sign_id_crossflow_map[i_ch].push_back(positive_flow);
125  _sign_id_crossflow_map[j_ch].push_back(negative_flow);
126 
127  // make a gap size map
128  if (iy == 0 || iy == _ny - 1)
130  else
132  ++i_gap;
133  }
134  }
135 
136  // Index the north-south gaps.
137  for (unsigned int iy = 0; iy < _ny - 1; iy++)
138  {
139  for (unsigned int ix = 0; ix < _nx; ix++)
140  {
141  unsigned int i_ch = _nx * iy + ix;
142  unsigned int j_ch = _nx * (iy + 1) + ix;
143  _gap_to_chan_map[i_gap] = {i_ch, j_ch};
144  _chan_to_gap_map[i_ch].push_back(i_gap);
145  _chan_to_gap_map[j_ch].push_back(i_gap);
146  _sign_id_crossflow_map[i_ch].push_back(positive_flow);
147  _sign_id_crossflow_map[j_ch].push_back(negative_flow);
148 
149  // make a gap size map
150  if (ix == 0 || ix == _nx - 1)
152  else
154  ++i_gap;
155  }
156  }
157 
158  // Make assembly to channel map
159  for (unsigned int iy = 0; iy < _ny - 1; iy++)
160  {
161  for (unsigned int ix = 0; ix < _nx - 1; ix++)
162  {
163  unsigned int i_pin = (_nx - 1) * iy + ix;
164  unsigned int i_chan_1 = _nx * iy + ix;
165  unsigned int i_chan_2 = _nx * (iy + 1) + ix;
166  unsigned int i_chan_3 = _nx * (iy + 1) + (ix + 1);
167  unsigned int i_chan_4 = _nx * iy + (ix + 1);
168  _pin_to_chan_map[i_pin].push_back(i_chan_1);
169  _pin_to_chan_map[i_pin].push_back(i_chan_2);
170  _pin_to_chan_map[i_pin].push_back(i_chan_3);
171  _pin_to_chan_map[i_pin].push_back(i_chan_4);
172  }
173  }
174 
175  // Make channel to assembly map
176  for (unsigned int iy = 0; iy < _ny; iy++) // row
177  {
178  for (unsigned int ix = 0; ix < _nx; ix++) // column
179  {
180  unsigned int i_ch = _nx * iy + ix;
181  // Corners contact 1/4 of one pin
182  if (iy == 0 && ix == 0)
183  {
184  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix);
185  }
186  else if (iy == _ny - 1 && ix == 0)
187  {
188  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix);
189  }
190  else if (iy == 0 && ix == _nx - 1)
191  {
192  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix - 1);
193  }
194  else if (iy == _ny - 1 && ix == _nx - 1)
195  {
196  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix - 1);
197  }
198  // Sides contact 1/4 of two pins
199  else if (iy == 0)
200  {
201  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix);
202  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix - 1);
203  }
204  else if (iy == _ny - 1)
205  {
206  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix);
207  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix - 1);
208  }
209  else if (ix == 0)
210  {
211  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix);
212  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix);
213  }
214  else if (ix == _nx - 1)
215  {
216  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix - 1);
217  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix - 1);
218  }
219  // interior contacts 1/4 of 4 pins
220  else
221  {
222  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix);
223  _chan_to_pin_map[i_ch].push_back((_nx - 1) * iy + ix - 1);
224  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix);
225  _chan_to_pin_map[i_ch].push_back((_nx - 1) * (iy - 1) + ix - 1);
226  }
227  }
228  }
229 
230  // Reduce reserved memory in the channel-to-gap map.
231  for (auto & gap : _chan_to_gap_map)
232  gap.shrink_to_fit();
233 
234  // Reduce reserved memory in the channel-to-pin map.
235  for (auto & pin : _chan_to_pin_map)
236  pin.shrink_to_fit();
237 
238  // Reduce reserved memory in the pin-to-channel map.
239  for (auto & pin : _pin_to_chan_map)
240  pin.shrink_to_fit();
241 
242  _console << "Inter-wrapper quad mesh initialized" << std::endl;
243 }
244 
245 std::unique_ptr<MeshBase>
247 {
248  auto mesh_base = buildMeshBaseObject();
249  BoundaryInfo & boundary_info = mesh_base->get_boundary_info();
250  mesh_base->set_spatial_dimension(3);
251  mesh_base->reserve_elem(_n_cells * _ny * _nx);
252  mesh_base->reserve_nodes((_n_cells + 1) * _ny * _nx);
253  _nodes.resize(_nx * _ny);
254  // Add the points in the shape of a rectilinear grid. The grid is regular
255  // on the xy-plane with a spacing of `pitch` between points. The grid along
256  // z is irregular to account for Pin spacers. Store pointers in the _nodes
257  // array so we can keep track of which points are in which channels.
258  Real offset_x = (_nx - 1) * _assembly_pitch / 2.0;
259  Real offset_y = (_ny - 1) * _assembly_pitch / 2.0;
260  unsigned int node_id = 0;
261  for (unsigned int iy = 0; iy < _ny; iy++)
262  {
263  for (unsigned int ix = 0; ix < _nx; ix++)
264  {
265  int i_ch = _nx * iy + ix;
266  _nodes[i_ch].reserve(_n_cells);
267  for (unsigned int iz = 0; iz < _n_cells + 1; iz++)
268  {
269  _nodes[i_ch].push_back(mesh_base->add_point(
270  Point(_assembly_pitch * ix - offset_x, _assembly_pitch * iy - offset_y, _z_grid[iz]),
271  node_id++));
272  }
273  }
274  }
275 
276  // Add the elements which in this case are 2-node edges that link each
277  // subchannel's nodes vertically.
278  unsigned int elem_id = 0;
279  for (unsigned int iy = 0; iy < _ny; iy++)
280  {
281  for (unsigned int ix = 0; ix < _nx; ix++)
282  {
283  for (unsigned int iz = 0; iz < _n_cells; iz++)
284  {
285  Elem * elem = new Edge2;
286  elem->subdomain_id() = _block_id;
287  elem->set_id(elem_id++);
288  elem = mesh_base->add_elem(elem);
289  const int indx1 = ((_n_cells + 1) * _nx) * iy + (_n_cells + 1) * ix + iz;
290  const int indx2 = ((_n_cells + 1) * _nx) * iy + (_n_cells + 1) * ix + (iz + 1);
291  elem->set_node(0, mesh_base->node_ptr(indx1));
292  elem->set_node(1, mesh_base->node_ptr(indx2));
293 
294  if (iz == 0)
295  boundary_info.add_side(elem, 0, 0);
296  if (iz == _n_cells - 1)
297  boundary_info.add_side(elem, 1, 1);
298  }
299  }
300  }
301 
302  boundary_info.sideset_name(0) = "inlet";
303  boundary_info.sideset_name(1) = "outlet";
304  boundary_info.nodeset_name(0) = "inlet";
305  boundary_info.nodeset_name(1) = "outlet";
306  mesh_base->subdomain_name(_block_id) = name();
307  mesh_base->prepare_for_use();
308 
309  // move the meta data into QuadInterWrapperMesh
310  auto & sch_mesh = static_cast<QuadInterWrapperMesh &>(*_mesh);
312 
313  sch_mesh._assembly_pitch = _assembly_pitch;
314  sch_mesh._assembly_side_x = _assembly_side_x;
315  sch_mesh._assembly_side_y = _assembly_side_y;
316  sch_mesh._heated_length = _heated_length;
317  sch_mesh._unheated_length_exit = _unheated_length_exit;
318  sch_mesh._z_grid = _z_grid;
319  sch_mesh._k_grid = _k_grid;
320  sch_mesh._kij = _kij;
321  sch_mesh._n_cells = _n_cells;
322  sch_mesh._nx = _nx;
323  sch_mesh._ny = _ny;
324  sch_mesh._side_bypass_length = _side_bypass_length;
325  sch_mesh._n_channels = _n_channels;
326  sch_mesh._n_gaps = _n_gaps;
327  sch_mesh._n_assemblies = _n_assemblies;
328  sch_mesh._nodes = _nodes;
329  sch_mesh._gapnodes = _gapnodes;
330  sch_mesh._gap_to_chan_map = _gap_to_chan_map;
331  sch_mesh._chan_to_gap_map = _chan_to_gap_map;
332  sch_mesh._chan_to_pin_map = _chan_to_pin_map;
333  sch_mesh._pin_to_chan_map = _pin_to_chan_map;
334  sch_mesh._sign_id_crossflow_map = _sign_id_crossflow_map;
335  sch_mesh._gij_map = _gij_map;
336  sch_mesh._subch_type = _subch_type;
337 
338  _console << "Inter-wrapper quad mesh generated" << std::endl;
339 
340  return mesh_base;
341 }
const Real & _kij
Lateral form loss coefficient.
std::vector< std::vector< Real > > _k_grid
axial form loss coefficient per computational cell
Real _unheated_length_entry
unheated length of the fuel Pin at the entry of the assembly
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::vector< EChannelType > _subch_type
Subchannel type.
std::vector< std::vector< double > > _sign_id_crossflow_map
Matrix used to give local sign to crossflow quantities.
std::vector< double > _gij_map
Vector to store gap size.
std::vector< std::pair< unsigned int, unsigned int > > _gap_to_chan_map
Defining the channel maps.
std::vector< std::vector< unsigned int > > _chan_to_gap_map
unsigned int _nx
Number of assemblies in the x direction.
const Real _unheated_length_exit
unheated length of the inter-wrapper section at the exit of the assembly
std::vector< std::vector< unsigned int > > _pin_to_chan_map
registerMooseObjectRenamed("SubChannelApp", QuadInterWrapperMeshGenerator, "06/30/2025 24:00", SCMQuadInterWrapperMeshGenerator)
virtual const std::string & name() const
const Real _assembly_side_x
Sides of the assemblies in the x and y direction.
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Real _side_bypass_length
Extra bypass lengths in the sides of the assembly.
unsigned int _ny
Number of assemblies in the y direction.
const unsigned int _n_gaps
Number of gaps per layer.
const Real _heated_length
heated length of the inter-wrapper section
std::vector< Real > _z_grid
axial location of nodes
static InputParameters validParams()
const unsigned int _n_channels
Total number of flow channels.
std::unique_ptr< MeshBase > generate() override
Creates the mesh of an inter-wrapper around square assemblies.
std::vector< std::vector< Node * > > _gapnodes
Nodes of the gaps.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int _n_assemblies
Number of assemblies.
const unsigned int _n_cells
number of axial cells
std::vector< std::vector< Node * > > _nodes
Channel nodes.
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const Real _assembly_pitch
Distance between the neighbor fuel assemblies, assembly pitch.
const Real _unheated_length_entry
unheated length of the inter-wrapper section at the entry of the assembly
const ConsoleStream _console
SCMQuadInterWrapperMeshGenerator(const InputParameters &parameters)
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
registerMooseObject("SubChannelApp", SCMQuadInterWrapperMeshGenerator)
void ErrorVector unsigned int
std::vector< std::vector< unsigned int > > _chan_to_pin_map
Class for Subchannel mesh generation in the square lattice geometry.