Line data Source code
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 : InputParameters 13 892 : SubChannelMesh::validParams() 14 : { 15 892 : InputParameters params = MooseMesh::validParams(); 16 892 : params.addClassDescription("Base class for all mesh containers"); 17 892 : return params; 18 0 : } 19 : 20 446 : SubChannelMesh::SubChannelMesh(const InputParameters & params) 21 : : MooseMesh(params), 22 446 : _kij(0.0), 23 446 : _assembly_flow_area(0.0), 24 446 : _assembly_wetted_perimeter(0.0), 25 446 : _assembly_hydraulic_diameter(0.0) 26 : { 27 446 : } 28 : 29 0 : SubChannelMesh::SubChannelMesh(const SubChannelMesh & other_mesh) 30 : : MooseMesh(other_mesh), 31 0 : _pin_mesh_exist(other_mesh._pin_mesh_exist), 32 0 : _duct_mesh_exist(other_mesh._duct_mesh_exist), 33 0 : _unheated_length_entry(other_mesh._unheated_length_entry), 34 0 : _heated_length(other_mesh._heated_length), 35 0 : _unheated_length_exit(other_mesh._unheated_length_exit), 36 0 : _z_grid(other_mesh._z_grid), 37 0 : _k_grid(other_mesh._k_grid), 38 0 : _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 0 : _spacer_z(other_mesh._spacer_z), 42 0 : _spacer_k(other_mesh._spacer_k), 43 0 : _z_blockage(other_mesh._z_blockage), 44 0 : _index_blockage(other_mesh._index_blockage), 45 0 : _reduction_blockage(other_mesh._reduction_blockage), 46 0 : _kij(other_mesh._kij), 47 0 : _pitch(other_mesh._pitch), 48 0 : _pin_diameter(other_mesh._pin_diameter), 49 0 : _assembly_flow_area(other_mesh._assembly_flow_area), 50 0 : _assembly_wetted_perimeter(other_mesh._assembly_wetted_perimeter), 51 0 : _assembly_hydraulic_diameter(other_mesh._assembly_hydraulic_diameter), 52 0 : _n_cells(other_mesh._n_cells) 53 : { 54 0 : _subchannel_position = other_mesh._subchannel_position; 55 0 : } 56 : 57 : void 58 512 : SubChannelMesh::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 512 : Real L = unheated_length_entry + heated_length + unheated_length_exit; 65 512 : Real dz = L / n_cells; 66 11436 : for (unsigned int i = 0; i < n_cells + 1; i++) 67 10924 : z_grid.push_back(dz * i); 68 512 : } 69 : 70 : unsigned int 71 1124680 : SubChannelMesh::getZIndex(const Point & point) const 72 : { 73 1124680 : if (_z_grid.size() == 0) 74 0 : mooseError("_z_grid is empty."); 75 : 76 1124680 : if (point(2) <= _z_grid[0]) 77 : return 0; 78 1094422 : if (point(2) >= _z_grid[_z_grid.size() - 1]) 79 20863 : return _z_grid.size() - 1; 80 : 81 : unsigned int lo = 0; 82 1073559 : unsigned int hi = _z_grid.size(); 83 6144555 : while (lo < hi) 84 : { 85 5070996 : unsigned int mid = (lo + hi) / 2; 86 5070996 : if (std::abs(_z_grid[mid] - point(2)) < 1e-5) 87 1073559 : return mid; 88 3997437 : else if (_z_grid[mid] < point(2)) 89 : lo = mid; 90 : else 91 : hi = mid; 92 : } 93 : return lo; 94 : } 95 : 96 : Node * 97 559200 : SubChannelMesh::getDuctNodeFromChannel(Node * channel_node) const 98 : { 99 : auto it = _chan_to_duct_node_map.find(channel_node); 100 559200 : return (it == _chan_to_duct_node_map.end()) ? nullptr : it->second; 101 : } 102 : 103 : Node * 104 48840 : SubChannelMesh::getChannelNodeFromDuct(Node * duct_node) const 105 : { 106 : auto it = _duct_node_to_chan_map.find(duct_node); 107 48840 : return (it == _duct_node_to_chan_map.end()) ? nullptr : it->second; 108 : } 109 : 110 : void 111 82 : SubChannelMesh::setChannelToDuctMaps(const std::vector<Node *> & duct_nodes) 112 : { 113 82 : _duct_nodes.clear(); 114 : _chan_to_duct_node_map.clear(); 115 : _duct_node_to_chan_map.clear(); 116 : 117 82 : if (_z_grid.empty()) 118 0 : mooseError("setChannelToDuctMaps: _z_grid is empty; cannot match duct nodes by z."); 119 : 120 82 : if (_subchannel_position.empty()) 121 0 : mooseError( 122 : "setChannelToDuctMaps: _subchannel_position is empty; cannot map duct nodes to channels."); 123 : 124 42222 : for (size_t i = 0; i < duct_nodes.size(); ++i) 125 : { 126 42140 : 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 42140 : const Point ductpos((*dn)(0), (*dn)(1), 0.0); 133 : 134 9156216 : for (unsigned int j = 0; j < _subchannel_position.size(); ++j) 135 : { 136 9114076 : const Point chanpos(_subchannel_position[j][0], _subchannel_position[j][1], 0.0); 137 9114076 : const Real dist = (chanpos - ductpos).norm(); 138 : 139 9114076 : 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 42140 : const unsigned int iz = getZIndex(*dn); 148 42140 : Node * chan_node = getChannelNode(min_chan, iz); 149 : 150 : // 3) Store bidirectional mapping 151 42140 : _duct_node_to_chan_map[dn] = chan_node; 152 42140 : _chan_to_duct_node_map[chan_node] = dn; 153 : } 154 : 155 82 : _duct_nodes = duct_nodes; 156 82 : _duct_mesh_exist = true; 157 82 : }