https://mooseframework.inl.gov
SCMTriDuctMeshGenerator.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 <cmath>
13 #include "libmesh/face_quad4.h"
14 #include "libmesh/unstructured_mesh.h"
15 
17 registerMooseObjectRenamed("SubChannelApp",
18  TriDuctMeshGenerator,
19  "06/30/2025 24:00",
21 
24 {
26  params.addClassDescription(
27  "Creates a mesh of 1D duct cells around a triangular lattice subassembly");
28  params.addRequiredParam<MeshGeneratorName>("input", "The corresponding subchannel mesh");
29  params.addParam<unsigned int>("block_id", 2, "Domain Index");
30  params.addRequiredParam<unsigned int>("n_cells", "The number of cells in the axial direction");
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.addRequiredParam<Real>("pitch", "Pitch [m]");
35  params.addRequiredParam<unsigned int>("nrings", "Number of fuel Pin rings per assembly [-]");
36  params.addRequiredParam<Real>("flat_to_flat",
37  "Flat to flat distance for the hexagonal assembly [m]");
38  return params;
39 }
40 
42  : MeshGenerator(params),
43  _input(getMesh("input")),
44  _n_cells(getParam<unsigned int>("n_cells")),
45  _unheated_length_entry(getParam<Real>("unheated_length_entry")),
46  _heated_length(getParam<Real>("heated_length")),
47  _unheated_length_exit(getParam<Real>("unheated_length_exit")),
48  _block_id(getParam<unsigned int>("block_id")),
49  _pitch(getParam<Real>("pitch")),
50  _n_rings(getParam<unsigned int>("nrings")),
51  _flat_to_flat(getParam<Real>("flat_to_flat"))
52 {
55 }
56 
57 std::unique_ptr<MeshBase>
59 {
60  std::unique_ptr<MeshBase> mesh_base = std::move(_input);
61  if (!mesh_base)
62  mooseError("SCMTriDuctMeshGenerator has to be connected to a sub channel mesh generator.");
63 
64  mesh_base->set_mesh_dimension(3);
65 
66  std::vector<Point> corners;
67  ductCorners(corners, _flat_to_flat, Point(0, 0, 0));
68  std::vector<Point> xsec;
69  ductXsec(xsec, corners, _n_rings, _pitch, _flat_to_flat);
70  std::vector<Point> points;
71  ductPoints(points, xsec, _z_grid);
72  std::vector<std::vector<size_t>> elem_point_indices;
73  ductElems(elem_point_indices, _z_grid.size(), xsec.size());
74  std::vector<Node *> duct_nodes;
75  buildDuct(mesh_base, duct_nodes, points, elem_point_indices, _block_id);
76  mesh_base->subdomain_name(_block_id) = name();
77 
78  mesh_base->prepare_for_use();
79 
80  auto & sch_mesh = static_cast<TriSubChannelMesh &>(*_mesh);
81  sch_mesh.setChannelToDuctMaps(duct_nodes);
82  sch_mesh._duct_mesh_exist = true;
83 
84  return mesh_base;
85 }
86 
87 void
88 SCMTriDuctMeshGenerator::ductCorners(std::vector<Point> & corners,
89  Real flat_to_flat,
90  const Point & center) const
91 {
92  corners.resize(TriSubChannelMesh::N_CORNERS);
93  Real r_corner = flat_to_flat / 2. / std::cos(libMesh::pi / 6.);
94  for (size_t i = 0; i < TriSubChannelMesh::N_CORNERS; i++)
95  {
96  Real theta = i * libMesh::pi / 3.;
97  Point corner = {r_corner * std::cos(theta), r_corner * std::sin(theta)};
98  corners[i] = center + corner;
99  }
100 }
101 
102 void
103 SCMTriDuctMeshGenerator::ductXsec(std::vector<Point> & xsec,
104  const std::vector<Point> & corners,
105  unsigned int nrings,
106  Real pitch,
107  Real flat_to_flat) const
108 {
109  xsec.clear();
110 
111  Real r_corner = flat_to_flat / 2. / std::cos(libMesh::pi / 6.);
112  Real start_offset = (r_corner - (nrings - 2) * pitch) * std::sin(libMesh::pi / 6.);
113  Real side_length = (corners[0] - corners[1]).norm();
114 
115  for (size_t i = 0; i < corners.size(); i++)
116  {
117  auto left = corners[i];
118  auto right = corners[(i + 1) % corners.size()];
119  xsec.push_back(left);
120  auto direc = (right - left).unit();
121  for (Real offset_from_corner = start_offset; offset_from_corner < side_length;
122  offset_from_corner += pitch)
123  xsec.push_back(left + direc * offset_from_corner);
124  }
125 }
126 
127 size_t
128 SCMTriDuctMeshGenerator::ductPointIndex(unsigned int points_per_layer,
129  unsigned int layer,
130  unsigned int point) const
131 {
132  return layer * points_per_layer + point;
133 }
134 
135 void
136 SCMTriDuctMeshGenerator::ductPoints(std::vector<Point> & points,
137  const std::vector<Point> & xsec,
138  const std::vector<Real> & z_layers) const
139 {
140  points.resize(xsec.size() * z_layers.size());
141  for (size_t i = 0; i < z_layers.size(); i++)
142  for (size_t j = 0; j < xsec.size(); j++)
143  points[ductPointIndex(xsec.size(), i, j)] = Point(xsec[j](0), xsec[j](1), z_layers[i]);
144 }
145 
146 void
147 SCMTriDuctMeshGenerator::ductElems(std::vector<std::vector<size_t>> & elem_point_indices,
148  unsigned int n_layers,
149  unsigned int points_per_layer) const
150 {
151  elem_point_indices.clear();
152  for (unsigned int i = 0; i < n_layers - 1; i++)
153  {
154  unsigned int bottom = i;
155  unsigned int top = i + 1;
156  for (unsigned int j = 0; j < points_per_layer; j++)
157  {
158  unsigned int left = j;
159  unsigned int right = (j + 1) % points_per_layer;
160  elem_point_indices.push_back({ductPointIndex(points_per_layer, bottom, left),
161  ductPointIndex(points_per_layer, bottom, right),
162  ductPointIndex(points_per_layer, top, right),
163  ductPointIndex(points_per_layer, top, left)});
164  }
165  }
166 }
167 
168 void
169 SCMTriDuctMeshGenerator::buildDuct(std::unique_ptr<MeshBase> & mesh,
170  std::vector<Node *> & duct_nodes,
171  const std::vector<Point> & points,
172  const std::vector<std::vector<size_t>> & elem_point_indices,
173  SubdomainID block) const
174 {
175  for (size_t i = 0; i < points.size(); i++)
176  duct_nodes.push_back(mesh->add_point(points[i]));
177 
178  for (auto & elem_indices : elem_point_indices)
179  {
180  auto elem = mesh->add_elem(new Quad4());
181  elem->subdomain_id() = block;
182  for (size_t i = 0; i < elem_indices.size(); i++)
183  elem->set_node(i, duct_nodes[elem_indices[i]]);
184  }
185 }
void ductElems(std::vector< std::vector< size_t >> &elem_point_indices, unsigned int n_layers, unsigned int points_per_layer) const
Calculates the groups of points/nodes that comprise each element in the duct mesh.
const Real _unheated_length_entry
unheated length of the fuel Pin at the entry of the assembly
T & getMesh(MooseMesh &mesh)
function to cast mesh
Definition: SCM.h:35
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
MeshBase & mesh
void setChannelToDuctMaps(const std::vector< Node *> &duct_nodes)
Function that gets the channel node from the duct node.
static const unsigned int N_CORNERS
number of corners in the duct x-sec
std::unique_ptr< MeshBase > generate() override
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Real _flat_to_flat
the distance between flat surfaces of the duct facing each other
const Real _unheated_length_exit
unheated length of the fuel Pin at the exit of the assembly
static void generateZGrid(Real unheated_length_entry, Real heated_length, Real unheated_length_exit, unsigned int n_cells, std::vector< Real > &z_grid)
Generate the spacing in z-direction using heated and unteaded lengths.
static InputParameters validParams()
const unsigned int _n_cells
number of axial cells
static const std::string pitch
const unsigned int _block_id
block index
registerMooseObject("SubChannelApp", SCMTriDuctMeshGenerator)
std::unique_ptr< MeshBase > & _input
Mesh that comes from another generator.
registerMooseObjectRenamed("SubChannelApp", TriDuctMeshGenerator, "06/30/2025 24:00", SCMTriDuctMeshGenerator)
auto norm(const T &a) -> decltype(std::abs(a))
static InputParameters validParams()
void buildDuct(std::unique_ptr< MeshBase > &mesh, std::vector< Node *> &duct_nodes, const std::vector< Point > &points, const std::vector< std::vector< size_t >> &elem_point_indices, SubdomainID block) const
buildDuct generates and adds mesh node and element objects to the given mesh corresponding to the giv...
const Real _pitch
Distance between the neighbor fuel pins, pitch.
Mesh class for triangular, edge and corner subchannels for hexagonal lattice fuel assemblies...
const unsigned int _n_rings
number of rings of fuel pins
void ductPoints(std::vector< Point > &points, const std::vector< Point > &xsec, const std::vector< Real > &z_layers) const
Calculates all the point/node positions that will be used to form elements making the duct...
SCMTriDuctMeshGenerator(const InputParameters &parameters)
void ductCorners(std::vector< Point > &corners, Real flat_to_flat, const Point &center) const
calculate the x-y coordinates of the corner points for the duct cross section.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > _z_grid
axial location of nodes
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
size_t ductPointIndex(unsigned int points_per_layer, unsigned int layer, unsigned int point) const
Returns an index into the vector of point/node positions used/generated by ductPoints.
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
const Real _heated_length
heated length of the fuel Pin
void ErrorVector unsigned int
static const std::string center
Definition: NS.h:28
void ductXsec(std::vector< Point > &xsec, const std::vector< Point > &corners, unsigned int nrings, Real pitch, Real flat_to_flat) const
calcultes the points around the duct cross section boundary (perpendicular to z axis) using assembly ...
const Real pi
Mesh generator for hexagonal duct.