LCOV - code coverage report
Current view: top level - src/mesh - QuadSubChannelMesh.C (source / functions) Hit Total Coverage
Test: idaholab/moose subchannel: #31405 (292dce) with base fef103 Lines: 44 68 64.7 %
Date: 2025-09-04 07:58:06 Functions: 8 10 80.0 %
Legend: Lines: hit not hit

          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 "QuadSubChannelMesh.h"
      11             : 
      12             : #include <cmath>
      13             : 
      14             : #include "libmesh/edge_edge2.h"
      15             : #include "libmesh/unstructured_mesh.h"
      16             : 
      17             : registerMooseObject("SubChannelApp", QuadSubChannelMesh);
      18             : 
      19             : InputParameters
      20         460 : QuadSubChannelMesh::validParams()
      21             : {
      22         460 :   InputParameters params = SubChannelMesh::validParams();
      23         460 :   params.addClassDescription("Creates an subchannel mesh container for a square "
      24             :                              "lattice arrangement");
      25         460 :   return params;
      26           0 : }
      27             : 
      28         230 : QuadSubChannelMesh::QuadSubChannelMesh(const InputParameters & params)
      29         230 :   : SubChannelMesh(params), _pin_mesh_exist(false)
      30             : {
      31         230 : }
      32             : 
      33           0 : QuadSubChannelMesh::QuadSubChannelMesh(const QuadSubChannelMesh & other_mesh)
      34             :   : SubChannelMesh(other_mesh),
      35           0 :     _nx(other_mesh._nx),
      36           0 :     _ny(other_mesh._ny),
      37           0 :     _n_channels(other_mesh._n_channels),
      38           0 :     _n_gaps(other_mesh._n_gaps),
      39           0 :     _n_pins(other_mesh._n_pins),
      40           0 :     _side_gap(other_mesh._side_gap),
      41           0 :     _nodes(other_mesh._nodes),
      42           0 :     _gapnodes(other_mesh._gapnodes),
      43           0 :     _gap_to_chan_map(other_mesh._gap_to_chan_map),
      44           0 :     _gap_to_pin_map(other_mesh._gap_to_pin_map),
      45           0 :     _chan_to_gap_map(other_mesh._chan_to_gap_map),
      46           0 :     _chan_to_pin_map(other_mesh._chan_to_pin_map),
      47           0 :     _pin_to_chan_map(other_mesh._pin_to_chan_map),
      48           0 :     _sign_id_crossflow_map(other_mesh._sign_id_crossflow_map),
      49           0 :     _gij_map(other_mesh._gij_map),
      50           0 :     _pin_mesh_exist(other_mesh._pin_mesh_exist)
      51             : {
      52           0 :   _subchannel_position = other_mesh._subchannel_position;
      53           0 :   if (_nx < 2 && _ny < 2)
      54           0 :     mooseError(name(),
      55             :                ": The number of subchannels cannot be less than 2 in both directions (x and y). "
      56             :                "Smallest assembly allowed is either 2X1 or 1X2. ");
      57           0 : }
      58             : 
      59             : std::unique_ptr<MooseMesh>
      60           0 : QuadSubChannelMesh::safeClone() const
      61             : {
      62           0 :   return _app.getFactory().copyConstruct(*this);
      63             : }
      64             : 
      65             : void
      66         230 : QuadSubChannelMesh::buildMesh()
      67             : {
      68         230 : }
      69             : 
      70             : unsigned int
      71      215998 : QuadSubChannelMesh::getSubchannelIndexFromPoint(const Point & p) const
      72             : {
      73      215998 :   Real offset_x = (_nx - 1) * _pitch / 2.0;
      74      215998 :   Real offset_y = (_ny - 1) * _pitch / 2.0;
      75      215998 :   unsigned int i = (p(0) + offset_x + 0.5 * _pitch) / _pitch;
      76      215998 :   unsigned int j = (p(1) + offset_y + 0.5 * _pitch) / _pitch;
      77      215998 :   return j * _nx + i;
      78             : }
      79             : 
      80             : unsigned int
      81     1089893 : QuadSubChannelMesh::channelIndex(const Point & pt) const
      82             : {
      83             :   // this is identical to getSubchannelIndexFromPoint, but when it is given a point "outside" the
      84             :   // normal subchannel geometry (i.e. a point that lies in a gap around the lattice) we still report
      85             :   // a valid subchannel index this is needed for transferring the solution onto a visualization mesh
      86             : 
      87     1089893 :   Real offset_x = (_nx - 1) * _pitch / 2.0;
      88     1089893 :   Real offset_y = (_ny - 1) * _pitch / 2.0;
      89     1089893 :   int i = (pt(0) + offset_x + 0.5 * _pitch) / _pitch;
      90     1089893 :   int j = (pt(1) + offset_y + 0.5 * _pitch) / _pitch;
      91             : 
      92     1089893 :   i = std::max(0, i);
      93     1089893 :   i = std::min(i, (int)(_nx - 1));
      94             : 
      95     1089893 :   j = std::max(0, j);
      96     1089893 :   j = std::min(j, (int)(_ny - 1));
      97             : 
      98     1089893 :   return j * _nx + i;
      99             : }
     100             : 
     101             : unsigned int
     102       39764 : QuadSubChannelMesh::getPinIndexFromPoint(const Point & p) const
     103             : {
     104       39764 :   Real offset_x = (_nx - 2) * _pitch / 2.0;
     105       39764 :   Real offset_y = (_ny - 2) * _pitch / 2.0;
     106       39764 :   unsigned int i = (p(0) + offset_x) / _pitch;
     107       39764 :   unsigned int j = (p(1) + offset_y) / _pitch;
     108       39764 :   return j * (_nx - 1) + i;
     109             : }
     110             : 
     111             : unsigned int
     112      156914 : QuadSubChannelMesh::pinIndex(const Point & p) const
     113             : {
     114      156914 :   Real offset_x = (_nx - 2) * _pitch / 2.0;
     115      156914 :   Real offset_y = (_ny - 2) * _pitch / 2.0;
     116      156914 :   unsigned int i = (p(0) + offset_x) / _pitch;
     117      156914 :   unsigned int j = (p(1) + offset_y) / _pitch;
     118      156914 :   return j * (_nx - 1) + i;
     119             : }
     120             : 
     121             : void
     122          25 : QuadSubChannelMesh::generatePinCenters(
     123             :     unsigned int nx, unsigned int ny, Real pitch, Real elev, std::vector<Point> & pin_centers)
     124             : {
     125             :   mooseAssert(nx >= 2, "Number of channels in x-direction must be 2 or more.");
     126             :   mooseAssert(ny >= 2, "Number of channels in y-direction must be 2 or more.");
     127             : 
     128          25 :   Real offset_x = (nx - 2) * pitch / 2.0;
     129          25 :   Real offset_y = (ny - 2) * pitch / 2.0;
     130          71 :   for (unsigned int iy = 0; iy < ny - 1; iy++)
     131         182 :     for (unsigned int ix = 0; ix < nx - 1; ix++)
     132         136 :       pin_centers.push_back(Point(pitch * ix - offset_x, pitch * iy - offset_y, elev));
     133          25 : }

Generated by: LCOV version 1.14