https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
20{
23 "Creates a mesh of 2D duct cells around a triangular lattice subassembly");
24 params.addRequiredParam<MeshGeneratorName>("input", "The corresponding subchannel mesh");
25 params.addParam<unsigned int>("block_id", 2, "Domain Index");
26 params.addRequiredParam<unsigned int>("n_cells", "The number of cells in the axial direction");
27 params.addParam<Real>("unheated_length_entry", 0.0, "Unheated length at entry [m]");
28 params.addRequiredParam<Real>("heated_length", "Heated length [m]");
29 params.addParam<Real>("unheated_length_exit", 0.0, "Unheated length at exit [m]");
30 params.addRequiredParam<Real>("pitch", "Pitch is the distance between adjacent pins [m]");
31 params.addRequiredParam<unsigned int>("nrings", "Number of fuel Pin rings in the assembly [-]");
32 params.addRequiredParam<Real>("flat_to_flat",
33 "Flat to flat distance for the hexagonal assembly [m]");
34 return params;
35}
36
38 : MeshGenerator(params),
39 _input(getMesh("input")),
40 _n_cells(getParam<unsigned int>("n_cells")),
41 _unheated_length_entry(getParam<Real>("unheated_length_entry")),
42 _heated_length(getParam<Real>("heated_length")),
43 _unheated_length_exit(getParam<Real>("unheated_length_exit")),
44 _block_id(getParam<unsigned int>("block_id")),
45 _pitch(getParam<Real>("pitch")),
46 _n_rings(getParam<unsigned int>("nrings")),
47 _flat_to_flat(getParam<Real>("flat_to_flat"))
48{
51
52 // Read by SCMTriCoreMeshGenerator to check that assemblies placed in a core do not overlap
53 declareMeshProperty<Real>("flat_to_flat", _flat_to_flat);
54 // Read by the SCM core mesh generators to warn about assemblies without a duct mesh
55 declareMeshProperty<bool>("duct_mesh", true);
56}
57
58std::unique_ptr<MeshBase>
60{
61 std::unique_ptr<MeshBase> mesh_base = std::move(_input);
62 mesh_base->set_mesh_dimension(3);
63
64 std::vector<Point> corners;
65 ductCorners(corners, _flat_to_flat, Point(0, 0, 0));
66 std::vector<Point> cross_sec;
67 ductCrossSec(cross_sec, corners, _n_rings, _pitch);
68 std::vector<Point> points;
69 ductPoints(points, cross_sec, _z_grid);
70 std::vector<std::vector<size_t>> elem_point_indices;
71 ductElems(elem_point_indices, _z_grid.size(), cross_sec.size());
72 std::vector<Node *> duct_nodes;
73 buildDuct(mesh_base, duct_nodes, points, elem_point_indices, _block_id);
74 mesh_base->set_subdomain_name(_block_id, name(), true);
75
76 mesh_base->prepare_for_use();
77
78 auto & sch_mesh = cast_ref<TriSubChannelMesh &>(*_mesh);
79 sch_mesh.setChannelToDuctMaps(duct_nodes);
80 sch_mesh._duct_mesh_exist = true;
81
82 return mesh_base;
83}
84
85void
86SCMTriDuctMeshGenerator::ductCorners(std::vector<Point> & corners,
87 Real flat_to_flat,
88 const Point & center) const
89{
90 corners.resize(TriSubChannelMesh::N_CORNERS);
91 Real r_corner = flat_to_flat / 2. / std::cos(libMesh::pi / 6.);
92 for (size_t i = 0; i < TriSubChannelMesh::N_CORNERS; i++)
93 {
94 Real theta = i * libMesh::pi / 3.;
95 Point corner = {r_corner * std::cos(theta), r_corner * std::sin(theta)};
96 corners[i] = center + corner;
97 }
98}
99
100void
101SCMTriDuctMeshGenerator::ductCrossSec(std::vector<Point> & cross_sec,
102 const std::vector<Point> & corners,
103 unsigned int nrings,
104 Real pitch) const
105{
106 cross_sec.clear();
107
108 if (pitch <= 0.0)
109 mooseError("The 'pitch' must be > 0.");
110
111 if (nrings < 2)
112 mooseError("The 'nrings' must be >= 2.");
113
114 // Side length of the regular hexagon (distance between adjacent corners)
115 const Real side_length = (corners[0] - corners[1]).norm();
116
117 // start_offset = (hexagon_side - (nrings - 2)*pitch) / 2
118 const Real start_offset = 0.5 * (side_length - (nrings - 2) * pitch);
119
120 // If this is negative, the requested layout cannot fit.
121 if (start_offset < 0.0)
122 mooseError("SCMTriDuctMeshGenerator: computed start_offset is negative (",
123 start_offset,
124 "). Check 'nrings', 'pitch', and duct side length.");
125
126 for (size_t i = 0; i < corners.size(); i++)
127 {
128 const Point left = corners[i];
129 const Point right = corners[(i + 1) % corners.size()];
130
131 // Always include the left corner
132 cross_sec.push_back(left);
133
134 // Unit direction along this side
135 const Point direc = (right - left).unit();
136
137 // Add exactly (nrings - 1) points after the left corner
138 // at start_offset + k*pitch, k = 0..(nrings-2)
139 for (const auto k : make_range(nrings - 1))
140 {
141 const Real offset_from_corner = start_offset + k * pitch;
142 cross_sec.push_back(left + direc * offset_from_corner);
143 }
144 }
145}
146
147size_t
148SCMTriDuctMeshGenerator::ductPointIndex(unsigned int points_per_layer,
149 unsigned int layer,
150 unsigned int point) const
151{
152 return layer * points_per_layer + point;
153}
154
155void
156SCMTriDuctMeshGenerator::ductPoints(std::vector<Point> & points,
157 const std::vector<Point> & cross_sec,
158 const std::vector<Real> & z_layers) const
159{
160 points.resize(cross_sec.size() * z_layers.size());
161 for (size_t i = 0; i < z_layers.size(); i++)
162 for (size_t j = 0; j < cross_sec.size(); j++)
163 points[ductPointIndex(cross_sec.size(), i, j)] =
164 Point(cross_sec[j](0), cross_sec[j](1), z_layers[i]);
165}
166
167void
168SCMTriDuctMeshGenerator::ductElems(std::vector<std::vector<size_t>> & elem_point_indices,
169 unsigned int n_layers,
170 unsigned int points_per_layer) const
171{
172 elem_point_indices.clear();
173 for (unsigned int i = 0; i < n_layers - 1; i++)
174 {
175 unsigned int bottom = i;
176 unsigned int top = i + 1;
177 for (unsigned int j = 0; j < points_per_layer; j++)
178 {
179 unsigned int left = j;
180 unsigned int right = (j + 1) % points_per_layer;
181 elem_point_indices.push_back({ductPointIndex(points_per_layer, bottom, left),
182 ductPointIndex(points_per_layer, bottom, right),
183 ductPointIndex(points_per_layer, top, right),
184 ductPointIndex(points_per_layer, top, left)});
185 }
186 }
187}
188
189void
190SCMTriDuctMeshGenerator::buildDuct(std::unique_ptr<MeshBase> & mesh,
191 std::vector<Node *> & duct_nodes,
192 const std::vector<Point> & points,
193 const std::vector<std::vector<size_t>> & elem_point_indices,
194 SubdomainID block) const
195{
196 // Create mesh nodes for all duct points and keep a local index -> Node* map
197 duct_nodes.clear();
198 duct_nodes.reserve(points.size());
199 for (const auto & p : points)
200 duct_nodes.push_back(mesh->add_point(p));
201
202 // Create QUAD4 surface elements using libMesh factory style
203 for (const auto & elem_indices : elem_point_indices)
204 {
205 mooseAssert(elem_indices.size() == 4,
206 "Expected 4 node indices per element when building QUAD4 elements.");
207
208 auto elem = Elem::build(ElemType::QUAD4);
209 elem->subdomain_id() = block;
210
211 // Set the 4 nodes of the QUAD4
212 for (unsigned int i = 0; i < 4; ++i)
213 {
214 const auto idx = elem_indices[i];
215 mooseAssert(idx < duct_nodes.size(), "Element node index out of range.");
216 elem->set_node(i, duct_nodes[idx]);
217 }
218
219 // Hand ownership to the mesh
220 mesh->add_elem(elem.release());
221 }
222}
const Real p
Point center
registerMooseObject("SubChannelApp", SCMTriDuctMeshGenerator)
void ErrorVector unsigned int
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)
MooseMesh *const _mesh
static InputParameters validParams()
const std::string & name() const
void mooseError(Args &&... args) const
Mesh generator for hexagonal duct.
const unsigned int _block_id
block index
const Real _flat_to_flat
the distance between flat surfaces of the duct facing each other
void ductPoints(std::vector< Point > &points, const std::vector< Point > &cross_sec, const std::vector< Real > &z_layers) const
Computes all 3D point locations used to construct the duct mesh.
void ductElems(std::vector< std::vector< size_t > > &elem_point_indices, unsigned int n_layers, unsigned int points_per_layer) const
Determines element connectivity for the duct mesh.
const unsigned int _n_rings
number of rings of fuel pins
const Real _pitch
Distance between the neighbor fuel pins, pitch.
const Real _unheated_length_exit
unheated length of the fuel Pin at the exit of the assembly
const unsigned int _n_cells
number of axial cells
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
Builds duct mesh nodes and elements and inserts them into the mesh.
std::unique_ptr< MeshBase > & _input
Mesh that comes from another generator.
std::unique_ptr< MeshBase > generate() override
size_t ductPointIndex(unsigned int points_per_layer, unsigned int layer, unsigned int point) const
Maps a duct cross-section point and axial layer to a linear point index.
const Real _unheated_length_entry
unheated length of the fuel Pin at the entry of the assembly
const Real _heated_length
heated length of the fuel Pin
void ductCorners(std::vector< Point > &corners, Real flat_to_flat, const Point &center) const
Computes the x-y corner coordinates of the duct cross-section.
void ductCrossSec(std::vector< Point > &cross_sec, const std::vector< Point > &corners, unsigned int nrings, Real pitch) const
Generates the points along the duct cross-section sides.
static InputParameters validParams()
SCMTriDuctMeshGenerator(const InputParameters &parameters)
std::vector< Real > _z_grid
axial location of nodes
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 const unsigned int N_CORNERS
number of corners in the duct x-sec
MeshBase & mesh
const Real pi