https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SubChannelMesh.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
10#include "SubChannelMesh.h"
11
12#include <algorithm>
13
16{
18 params.addClassDescription("Base class for all mesh containers");
19 return params;
20}
21
23 : MooseMesh(params),
24 _kij(0.0),
25 _assembly_flow_area(0.0),
26 _assembly_wetted_perimeter(0.0),
27 _assembly_hydraulic_diameter(0.0)
28{
29}
30
32 : MooseMesh(other_mesh),
33 _pin_mesh_exist(other_mesh._pin_mesh_exist),
34 _duct_mesh_exist(other_mesh._duct_mesh_exist),
35 _unheated_length_entry(other_mesh._unheated_length_entry),
36 _heated_length(other_mesh._heated_length),
37 _unheated_length_exit(other_mesh._unheated_length_exit),
38 _z_grid(other_mesh._z_grid),
39 _k_grid(other_mesh._k_grid),
40 _duct_nodes(other_mesh._duct_nodes),
41 _chan_to_duct_node_map(other_mesh._chan_to_duct_node_map),
42 _duct_node_to_chan_map(other_mesh._duct_node_to_chan_map),
43 _spacer_z(other_mesh._spacer_z),
44 _spacer_k(other_mesh._spacer_k),
45 _z_blockage(other_mesh._z_blockage),
46 _index_blockage(other_mesh._index_blockage),
47 _reduction_blockage(other_mesh._reduction_blockage),
48 _kij(other_mesh._kij),
49 _pitch(other_mesh._pitch),
50 _pin_diameter(other_mesh._pin_diameter),
51 _assembly_flow_area(other_mesh._assembly_flow_area),
52 _assembly_wetted_perimeter(other_mesh._assembly_wetted_perimeter),
53 _assembly_hydraulic_diameter(other_mesh._assembly_hydraulic_diameter),
54 _n_cells(other_mesh._n_cells)
55{
57}
58
59void
60SubChannelMesh::generateZGrid(Real unheated_length_entry,
61 Real heated_length,
62 Real unheated_length_exit,
63 unsigned int n_cells,
64 std::vector<Real> & z_grid)
65{
66 Real L = unheated_length_entry + heated_length + unheated_length_exit;
67 Real dz = L / n_cells;
68 for (unsigned int i = 0; i < n_cells + 1; i++)
69 z_grid.push_back(dz * i);
70}
71
72unsigned int
73SubChannelMesh::getZIndex(const Point & point) const
74{
75 if (_z_grid.size() == 0)
76 mooseError("_z_grid is empty.");
77
78 if (point(2) <= _z_grid[0])
79 return 0;
80 if (point(2) >= _z_grid[_z_grid.size() - 1])
81 return _z_grid.size() - 1;
82
83 unsigned int lo = 0;
84 unsigned int hi = _z_grid.size();
85 while (lo < hi)
86 {
87 unsigned int mid = (lo + hi) / 2;
88 if (std::abs(_z_grid[mid] - point(2)) < 1e-5)
89 return mid;
90 else if (_z_grid[mid] < point(2))
91 lo = mid;
92 else
93 hi = mid;
94 }
95 return lo;
96}
97
98std::pair<unsigned int, Real>
100{
101 mooseAssert(_z_grid.size() > 1, "The axial grid needs at least one cell.");
102 const auto n_cells = _z_grid.size() - 1;
103 if (z <= _z_grid.front())
104 return {0, 0.0};
105 if (z >= _z_grid.back())
106 return {n_cells - 1, 1.0};
107 // First grid point strictly above z; the cell starts one point below it
108 const auto it = std::upper_bound(_z_grid.begin(), _z_grid.end(), z);
109 const unsigned int iz = std::distance(_z_grid.begin(), it) - 1;
110 return {iz, (z - _z_grid[iz]) / (_z_grid[iz + 1] - _z_grid[iz])};
111}
112
113Node *
115{
116 auto it = _chan_to_duct_node_map.find(channel_node);
117 return (it == _chan_to_duct_node_map.end()) ? nullptr : it->second;
118}
119
120Node *
122{
123 auto it = _duct_node_to_chan_map.find(duct_node);
124 return (it == _duct_node_to_chan_map.end()) ? nullptr : it->second;
125}
126
127void
128SubChannelMesh::setChannelToDuctMaps(const std::vector<Node *> & duct_nodes)
129{
130 _duct_nodes.clear();
133
134 if (_z_grid.empty())
135 mooseError("setChannelToDuctMaps: _z_grid is empty; cannot match duct nodes by z.");
136
137 if (_subchannel_position.empty())
139 "setChannelToDuctMaps: _subchannel_position is empty; cannot map duct nodes to channels.");
140
141 for (size_t i = 0; i < duct_nodes.size(); ++i)
142 {
143 Node * dn = duct_nodes[i];
144
145 // 1) Find closest subchannel center in XY
146 unsigned int min_chan = 0;
147 Real min_dist = std::numeric_limits<Real>::max();
148
149 const Point ductpos((*dn)(0), (*dn)(1), 0.0);
150
151 for (unsigned int j = 0; j < _subchannel_position.size(); ++j)
152 {
153 const Point chanpos(_subchannel_position[j][0], _subchannel_position[j][1], 0.0);
154 const Real dist = (chanpos - ductpos).norm();
155
156 if (dist < min_dist)
157 {
158 min_dist = dist;
159 min_chan = j;
160 }
161 }
162
163 // 2) Find channel node at the same z using getZIndex + virtual accessor
164 const unsigned int iz = getZIndex(*dn);
165 Node * chan_node = getChannelNode(min_chan, iz);
166
167 // 3) Store bidirectional mapping
168 _duct_node_to_chan_map[dn] = chan_node;
169 _chan_to_duct_node_map[chan_node] = dn;
170 }
171
172 _duct_nodes = duct_nodes;
173 _duct_mesh_exist = true;
174}
void addClassDescription(const std::string &doc_string)
void mooseError(Args &&... args) const
static InputParameters validParams()
Base class for subchannel meshes.
std::vector< Real > _z_grid
axial location of nodes
std::vector< Node * > _duct_nodes
A list of all mesh nodes that form the (elements of) the duct mesh that surrounds the pins/subchannel...
static InputParameters validParams()
std::map< Node *, Node * > _chan_to_duct_node_map
Maps between channel nodes and duct nodes.
Node * getChannelNodeFromDuct(Node *duct_node) const
Function that gets the channel node from the duct node.
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.
std::vector< std::vector< Real > > _subchannel_position
x,y coordinates of the subchannel centroids
Node * getDuctNodeFromChannel(Node *channel_node) const
Function that gets the duct node from the channel node.
std::map< Node *, Node * > _duct_node_to_chan_map
void setChannelToDuctMaps(const std::vector< Node * > &duct_nodes)
Function that sets the channel-to-duct maps.
virtual unsigned int getZIndex(const Point &point) const
Get axial index of point.
std::pair< unsigned int, Real > getAxialInterpolation(Real z) const
Get the axial cell containing height z and the linear interpolation weight within it.
virtual Node * getChannelNode(unsigned int i_chan, unsigned int iz) const =0
Get the subchannel mesh node for a given channel index and elevation index.
SubChannelMesh(const InputParameters &parameters)
dof_id_type n_cells