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
14{
16 params.addClassDescription("Base class for all mesh containers");
17 return params;
18}
19
21 : MooseMesh(params),
22 _kij(0.0),
23 _assembly_flow_area(0.0),
24 _assembly_wetted_perimeter(0.0),
25 _assembly_hydraulic_diameter(0.0)
26{
27}
28
30 : MooseMesh(other_mesh),
31 _pin_mesh_exist(other_mesh._pin_mesh_exist),
32 _duct_mesh_exist(other_mesh._duct_mesh_exist),
33 _unheated_length_entry(other_mesh._unheated_length_entry),
34 _heated_length(other_mesh._heated_length),
35 _unheated_length_exit(other_mesh._unheated_length_exit),
36 _z_grid(other_mesh._z_grid),
37 _k_grid(other_mesh._k_grid),
38 _duct_nodes(other_mesh._duct_nodes),
39 _chan_to_duct_node_map(other_mesh._chan_to_duct_node_map),
40 _duct_node_to_chan_map(other_mesh._duct_node_to_chan_map),
41 _spacer_z(other_mesh._spacer_z),
42 _spacer_k(other_mesh._spacer_k),
43 _z_blockage(other_mesh._z_blockage),
44 _index_blockage(other_mesh._index_blockage),
45 _reduction_blockage(other_mesh._reduction_blockage),
46 _kij(other_mesh._kij),
47 _pitch(other_mesh._pitch),
48 _pin_diameter(other_mesh._pin_diameter),
49 _assembly_flow_area(other_mesh._assembly_flow_area),
50 _assembly_wetted_perimeter(other_mesh._assembly_wetted_perimeter),
51 _assembly_hydraulic_diameter(other_mesh._assembly_hydraulic_diameter),
52 _n_cells(other_mesh._n_cells)
53{
55}
56
57void
58SubChannelMesh::generateZGrid(Real unheated_length_entry,
59 Real heated_length,
60 Real unheated_length_exit,
61 unsigned int n_cells,
62 std::vector<Real> & z_grid)
63{
64 Real L = unheated_length_entry + heated_length + unheated_length_exit;
65 Real dz = L / n_cells;
66 for (unsigned int i = 0; i < n_cells + 1; i++)
67 z_grid.push_back(dz * i);
68}
69
70unsigned int
71SubChannelMesh::getZIndex(const Point & point) const
72{
73 if (_z_grid.size() == 0)
74 mooseError("_z_grid is empty.");
75
76 if (point(2) <= _z_grid[0])
77 return 0;
78 if (point(2) >= _z_grid[_z_grid.size() - 1])
79 return _z_grid.size() - 1;
80
81 unsigned int lo = 0;
82 unsigned int hi = _z_grid.size();
83 while (lo < hi)
84 {
85 unsigned int mid = (lo + hi) / 2;
86 if (std::abs(_z_grid[mid] - point(2)) < 1e-5)
87 return mid;
88 else if (_z_grid[mid] < point(2))
89 lo = mid;
90 else
91 hi = mid;
92 }
93 return lo;
94}
95
96Node *
98{
99 auto it = _chan_to_duct_node_map.find(channel_node);
100 return (it == _chan_to_duct_node_map.end()) ? nullptr : it->second;
101}
102
103Node *
105{
106 auto it = _duct_node_to_chan_map.find(duct_node);
107 return (it == _duct_node_to_chan_map.end()) ? nullptr : it->second;
108}
109
110void
111SubChannelMesh::setChannelToDuctMaps(const std::vector<Node *> & duct_nodes)
112{
113 _duct_nodes.clear();
116
117 if (_z_grid.empty())
118 mooseError("setChannelToDuctMaps: _z_grid is empty; cannot match duct nodes by z.");
119
120 if (_subchannel_position.empty())
122 "setChannelToDuctMaps: _subchannel_position is empty; cannot map duct nodes to channels.");
123
124 for (size_t i = 0; i < duct_nodes.size(); ++i)
125 {
126 Node * dn = duct_nodes[i];
127
128 // 1) Find closest subchannel center in XY
129 unsigned int min_chan = 0;
130 Real min_dist = std::numeric_limits<Real>::max();
131
132 const Point ductpos((*dn)(0), (*dn)(1), 0.0);
133
134 for (unsigned int j = 0; j < _subchannel_position.size(); ++j)
135 {
136 const Point chanpos(_subchannel_position[j][0], _subchannel_position[j][1], 0.0);
137 const Real dist = (chanpos - ductpos).norm();
138
139 if (dist < min_dist)
140 {
141 min_dist = dist;
142 min_chan = j;
143 }
144 }
145
146 // 2) Find channel node at the same z using getZIndex + virtual accessor
147 const unsigned int iz = getZIndex(*dn);
148 Node * chan_node = getChannelNode(min_chan, iz);
149
150 // 3) Store bidirectional mapping
151 _duct_node_to_chan_map[dn] = chan_node;
152 _chan_to_duct_node_map[chan_node] = dn;
153 }
154
155 _duct_nodes = duct_nodes;
156 _duct_mesh_exist = true;
157}
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.
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