LCOV - code coverage report
Current view: top level - src/mesh - TriInterWrapperMesh.C (source / functions) Hit Total Coverage
Test: idaholab/moose subchannel: #31405 (292dce) with base fef103 Lines: 40 93 43.0 %
Date: 2025-09-04 07:58:06 Functions: 5 11 45.5 %
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 "TriInterWrapperMesh.h"
      11             : #include <cmath>
      12             : #include "libmesh/node.h"
      13             : 
      14             : registerMooseObject("SubChannelApp", TriInterWrapperMesh);
      15             : 
      16             : InputParameters
      17          96 : TriInterWrapperMesh::validParams()
      18             : {
      19          96 :   InputParameters params = InterWrapperMesh::validParams();
      20          96 :   params.addClassDescription("Creates an inter-wrappper mesh container for a triangular "
      21             :                              "lattice subchannel arrangement");
      22          96 :   return params;
      23           0 : }
      24             : 
      25          48 : TriInterWrapperMesh::TriInterWrapperMesh(const InputParameters & params) : InterWrapperMesh(params)
      26             : {
      27          48 : }
      28             : 
      29           0 : TriInterWrapperMesh::TriInterWrapperMesh(const TriInterWrapperMesh & other_mesh)
      30             :   : InterWrapperMesh(other_mesh),
      31           0 :     _n_rings(other_mesh._n_rings),
      32           0 :     _n_channels(other_mesh._n_channels),
      33           0 :     _flat_to_flat(other_mesh._flat_to_flat),
      34           0 :     _duct_to_pin_gap(other_mesh._duct_to_pin_gap),
      35           0 :     _nodes(other_mesh._nodes),
      36           0 :     _duct_nodes(other_mesh._duct_nodes),
      37             :     _chan_to_duct_node_map(other_mesh._chan_to_duct_node_map),
      38             :     _duct_node_to_chan_map(other_mesh._duct_node_to_chan_map),
      39           0 :     _gap_to_chan_map(other_mesh._gap_to_chan_map),
      40           0 :     _gap_to_pin_map(other_mesh._gap_to_pin_map),
      41           0 :     _chan_to_gap_map(other_mesh._chan_to_gap_map),
      42           0 :     _sign_id_crossflow_map(other_mesh._sign_id_crossflow_map),
      43           0 :     _gij_map(other_mesh._gij_map),
      44           0 :     _subchannel_position(other_mesh._subchannel_position),
      45           0 :     _pin_position(other_mesh._pin_position),
      46           0 :     _pins_in_rings(other_mesh._pins_in_rings),
      47           0 :     _chan_to_pin_map(other_mesh._chan_to_pin_map),
      48           0 :     _n_assemblies(other_mesh._n_assemblies),
      49           0 :     _n_gaps(other_mesh._n_gaps),
      50           0 :     _subch_type(other_mesh._subch_type),
      51           0 :     _gap_type(other_mesh._gap_type),
      52           0 :     _gap_pairs_sf(other_mesh._gap_pairs_sf),
      53           0 :     _chan_pairs_sf(other_mesh._chan_pairs_sf),
      54           0 :     _pin_to_chan_map(other_mesh._pin_to_chan_map),
      55           0 :     _tight_side_bypass(other_mesh._tight_side_bypass)
      56             : {
      57           0 : }
      58             : 
      59             : std::unique_ptr<MooseMesh>
      60           0 : TriInterWrapperMesh::safeClone() const
      61             : {
      62           0 :   return _app.getFactory().copyConstruct(*this);
      63             : }
      64             : 
      65             : unsigned int
      66       75600 : TriInterWrapperMesh::getSubchannelIndexFromPoint(const Point & p) const
      67             : {
      68             :   Real distance0 = 1.0e+8;
      69             :   Real distance1;
      70             :   unsigned int j = 0;
      71             : 
      72     3250800 :   for (unsigned int i = 0; i < _n_channels; i++)
      73             :   {
      74     3175200 :     distance1 = std::sqrt(std::pow((p(0) - _subchannel_position[i][0]), 2.0) +
      75     3175200 :                           std::pow((p(1) - _subchannel_position[i][1]), 2.0));
      76             : 
      77     3175200 :     if (distance1 < distance0)
      78             :     {
      79             :       j = i;
      80             :       distance0 = distance1;
      81             :     } // if
      82             :   }   // for
      83       75600 :   return j;
      84             : }
      85             : 
      86             : unsigned int
      87           0 : TriInterWrapperMesh::channelIndex(const Point & /*point*/) const
      88             : {
      89             :   mooseAssert(false, "This is not implemented");
      90           0 :   return 0;
      91             : }
      92             : 
      93             : void
      94          48 : TriInterWrapperMesh::buildMesh()
      95             : {
      96          48 : }
      97             : 
      98             : unsigned int
      99           0 : TriInterWrapperMesh::getPinIndexFromPoint(const Point & /*p*/) const
     100             : {
     101             :   mooseAssert(false, "This is not implemented");
     102           0 :   return 0;
     103             : }
     104             : 
     105             : unsigned int
     106           0 : TriInterWrapperMesh::pinIndex(const Point & /*p*/) const
     107             : {
     108             :   mooseAssert(false, "This is not implemented");
     109           0 :   return 0;
     110             : }
     111             : 
     112             : void
     113          48 : TriInterWrapperMesh::rodPositions(std::vector<Point> & positions,
     114             :                                   unsigned int nrings,
     115             :                                   Real assembly_pitch,
     116             :                                   Point center)
     117             : {
     118             :   /// Defining parameters
     119             :   // distance: it is the distance to the next Pin
     120             :   //
     121             :   Real theta = 0.0;
     122             :   Real dtheta = 0.0;
     123             :   Real distance = 0.0;
     124             :   Real theta1 = 0.0;
     125             :   Real theta_corrected = 0.0;
     126             :   Real pi = libMesh::pi;
     127             :   unsigned int k = 0;
     128          48 :   positions.emplace_back(0.0, 0.0);
     129         153 :   for (unsigned int i = 1; i < nrings; i++)
     130             :   {
     131         105 :     dtheta = 2.0 * pi / (i * 6);
     132             :     theta = 0.0;
     133        1131 :     for (unsigned int j = 0; j < i * 6; j++)
     134             :     {
     135             :       k = k + 1;
     136        1026 :       theta1 = fmod(theta + 1.0e-10, pi / 3.0);
     137        1026 :       distance = std::sqrt(
     138        1026 :           (pow(i * assembly_pitch, 2) + pow(theta1 / dtheta * assembly_pitch, 2) -
     139        1026 :            2.0 * i * assembly_pitch * (theta1 / dtheta * assembly_pitch) * std::cos(pi / 3.0)));
     140        1026 :       theta_corrected = std::acos(1.0 / (i * assembly_pitch) / distance / 2.0 *
     141        1026 :                                   (std::pow(i * assembly_pitch, 2) + std::pow(distance, 2) -
     142             :                                    std::pow(theta1 / dtheta * assembly_pitch, 2)));
     143        1026 :       if (theta1 < 1.0e-6)
     144             :       {
     145             :         theta_corrected = theta;
     146             :       }
     147             :       else
     148             :       {
     149         396 :         if (theta > pi / 3.0 && theta <= 2.0 / 3.0 * pi)
     150          66 :           theta_corrected = theta_corrected + pi / 3.0;
     151         264 :         else if (theta > 2.0 / 3.0 * pi && theta <= pi)
     152          66 :           theta_corrected = theta_corrected + 2.0 / 3.0 * pi;
     153         264 :         else if (theta > pi && theta <= 4.0 / 3.0 * pi)
     154          66 :           theta_corrected = theta_corrected + pi;
     155         132 :         else if (theta > 4.0 / 3.0 * pi && theta <= 5.0 / 3.0 * pi)
     156          66 :           theta_corrected = theta_corrected + 4.0 / 3.0 * pi;
     157          66 :         else if (theta > 5.0 / 3.0 * pi && theta <= 2.0 * pi)
     158          66 :           theta_corrected = theta_corrected + 5.0 / 3.0 * pi;
     159             :       }
     160        2052 :       positions.emplace_back(center(0) + distance * std::cos(theta_corrected),
     161        1026 :                              center(1) + distance * std::sin(theta_corrected));
     162        1026 :       theta = theta + dtheta;
     163             :     } // j
     164             :   }   // i
     165          48 : }
     166             : 
     167             : void
     168           0 : TriInterWrapperMesh::setChannelToDuctMaps(const std::vector<Node *> & duct_nodes)
     169             : {
     170             :   const Real tol = 1e-10;
     171           0 :   for (size_t i = 0; i < duct_nodes.size(); i++)
     172             :   {
     173             :     int min_chan = 0;
     174             :     Real min_dist = std::numeric_limits<double>::max();
     175           0 :     Point ductpos((*duct_nodes[i])(0), (*duct_nodes[i])(1), 0);
     176           0 :     for (size_t j = 0; j < _subchannel_position.size(); j++)
     177             :     {
     178           0 :       Point chanpos(_subchannel_position[j][0], _subchannel_position[j][1], 0);
     179           0 :       auto dist = (chanpos - ductpos).norm();
     180           0 :       if (dist < min_dist)
     181             :       {
     182             :         min_dist = dist;
     183           0 :         min_chan = j;
     184             :       }
     185             :     }
     186             : 
     187           0 :     Node * chan_node = nullptr;
     188           0 :     for (auto cn : _nodes[min_chan])
     189             :     {
     190           0 :       if (std::abs((*cn)(2) - (*duct_nodes[i])(2)) < tol)
     191             :       {
     192           0 :         chan_node = cn;
     193           0 :         break;
     194             :       }
     195             :     }
     196             : 
     197           0 :     if (chan_node == nullptr)
     198           0 :       mooseError("failed to find matching channel node for duct node");
     199             : 
     200           0 :     _duct_node_to_chan_map[duct_nodes[i]] = chan_node;
     201           0 :     _chan_to_duct_node_map[chan_node] = duct_nodes[i];
     202             :   }
     203             : 
     204           0 :   _duct_nodes = duct_nodes;
     205           0 : }

Generated by: LCOV version 1.14