LCOV - code coverage report
Current view: top level - include/csg - CSGHexagonalLattice.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 4 6 66.7 %
Date: 2026-05-29 20:35:17 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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             : #pragma once
      11             : 
      12             : #include "CSGLattice.h"
      13             : 
      14             : #ifdef MOOSE_UNIT_TEST
      15             : #include "gtest/gtest.h"
      16             : #endif
      17             : 
      18             : namespace CSG
      19             : {
      20             : 
      21             : /**
      22             :  * CSGHexagonalLattice is the class for constructing hexagonal lattices of CSGUniverses
      23             :  * arranged in concentric hexagonal rings
      24             :  */
      25             : class CSGHexagonalLattice : public CSGLattice
      26             : {
      27             : public:
      28             :   /**
      29             :    * Construct a new CSGHexagonalLattice from a map of universes. Universes should be arranged
      30             :    * by rows and correspond to a hexagonal lattice with x-orientation.
      31             :    *
      32             :    * @param name unique identifying name of lattice
      33             :    * @param pitch flat-to-flat distance for one hexagonal lattice element
      34             :    * @param universes row-wise ragged vector of universes representing hex pattern
      35             :    * @param outer optional outer universe or material name that fills space around lattice elements.
      36             :    *              If not provided, outer is assumed to be VOID.
      37             :    */
      38             :   CSGHexagonalLattice(const std::string & name,
      39             :                       Real pitch,
      40             :                       std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes,
      41             :                       const std::optional<OuterVariant> & outer = std::nullopt);
      42             : 
      43             :   /**
      44             :    * Construct a new empty CSGHexagonalLattice with the specified pitch.
      45             :    * NOTE: must call setLatticeUniverses to populate universe map.
      46             :    *
      47             :    * @param name unique identifying name of lattice
      48             :    * @param pitch flat-to-flat distance for one hexagonal lattice element
      49             :    * @param outer optional outer universe or material name that fills space around lattice elements.
      50             :    *              If not provided, outer is assumed to be VOID.
      51             :    */
      52             :   CSGHexagonalLattice(const std::string & name,
      53             :                       Real pitch,
      54             :                       const std::optional<OuterVariant> & outer = std::nullopt);
      55             : 
      56             :   /**
      57             :    * Destructor
      58             :    */
      59          74 :   virtual ~CSGHexagonalLattice() = default;
      60             : 
      61             :   /**
      62             :    * @brief clone this hexagonal lattice
      63             :    *
      64             :    * @return std::unique_ptr<CSGLattice> unique pointer to cloned hexagonal lattice
      65             :    */
      66           0 :   std::unique_ptr<CSGLattice> clone() const override
      67             :   {
      68           0 :     return std::make_unique<CSGHexagonalLattice>(*this);
      69             :   }
      70             : 
      71             :   /**
      72             :    * @brief Get attributes that define the lattice (excluding the universe map).
      73             :    *  - nrow: number of rows in the hex lattice (int)
      74             :    *  - pitch: pitch of the lattice element (Real)
      75             :    *
      76             :    * @return map of string dimension name to value of that dimension
      77             :    */
      78             :   virtual std::unordered_map<std::string, AttributeVariant> getAttributes() const override;
      79             : 
      80             :   /**
      81             :    * @brief check if provided index in row-column form is valid for the given hexagonal lattice
      82             :    *
      83             :    * @param index in row-column form
      84             :    * @return true if valid, otherwise false
      85             :    */
      86             :   virtual bool isValidIndex(const std::pair<int, int> index) const override;
      87             : 
      88             :   /**
      89             :    * @brief check if the arrangement of the provided universes is valid for the hexagonal lattice
      90             :    * given the number or rows/rings defined for the lattice. Universes should be listed by row,
      91             :    * starting from the top, and assume an x-orientation arrangment.
      92             :    *
      93             :    * @param universes list of lists of universes that define the arrangement of the lattice
      94             :    * @return true if valid, otherwise false
      95             :    */
      96             :   virtual bool isValidUniverseMap(
      97             :       std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) const override;
      98             : 
      99             :   /**
     100             :    * @brief get number of rows in the lattices
     101             :    *
     102             :    * @return number of rows
     103             :    */
     104           8 :   unsigned int getNRows() const { return _nrow; }
     105             : 
     106             :   /**
     107             :    * @brief get number of rings in the lattice
     108             :    *
     109             :    * @return number of rings
     110             :    */
     111           4 :   unsigned int getNRings() const { return _nring; }
     112             : 
     113             :   /**
     114             :    * @brief Given an index in ring-position form, get the corresponding row-column index. The
     115             :    * ring-position form assumes the outermost ring is the 0th ring and is indexed starting from the
     116             :    * rightmost position of the ring and proceeding counter-clockwise around the ring. The row-column
     117             :    * form assumes the top row is the 0th row and is indexed from left to right.
     118             :    *
     119             :    * Example of corresponding indices for a hexagonal lattice with 3 rings (5 rows):
     120             :    *
     121             :    * Row-Column Form:
     122             :    *        (0,0)  (0,1)  (0,2)
     123             :    *     (1,0)  (1,1)  (1,2)  (1,3)
     124             :    * (2,0)  (2,1)  (2,2)  (2,3)  (2,4)
     125             :    *     (3,0)  (3,1)  (3,2)  (3,3)
     126             :    *        (4,0)  (4,1)  (4,2)
     127             :    *
     128             :    * Ring-Position Form:
     129             :    *       (0,8)  (0,9)  (0,10)
     130             :    *    (0,7)  (1,4)  (1,5)  (0,11)
     131             :    * (0,6)  (1,3)  (2,0)  (1,0)  (0,0)
     132             :    *    (0,5)  (1,2)  (1,1)  (0,1)
     133             :    *       (0,4)  (0,3)  (0,2)
     134             :    *
     135             :    * @param index in ring-position form
     136             :    * @return index in row-column form
     137             :    */
     138             :   std::pair<int, int> getRowIndexFromRingIndex(const std::pair<int, int> & row_col_index) const;
     139             : 
     140             :   /**
     141             :    * @brief Given an index in row-column form, get the corresponding ring-position index. The
     142             :    * row-column form assumes the top row is the 0th row and is indexed from left to right. The
     143             :    * ring-position form assumes the outermost ring is the 0th ring and is indexed starting from the
     144             :    * rightmost position of the ring and proceeding counter-clockwise around the ring.
     145             :    *
     146             :    * Example of corresponding indices for a hexagonal lattice with 3 rings (5 rows):
     147             :    *
     148             :    * Row-Column Form:
     149             :    *        (0,0)  (0,1)  (0,2)
     150             :    *     (1,0)  (1,1)  (1,2)  (1,3)
     151             :    * (2,0)  (2,1)  (2,2)  (2,3)  (2,4)
     152             :    *     (3,0)  (3,1)  (3,2)  (3,3)
     153             :    *        (4,0)  (4,1)  (4,2)
     154             :    *
     155             :    * Ring-Position Form:
     156             :    *       (0,8)  (0,9)  (0,10)
     157             :    *    (0,7)  (1,4)  (1,5)  (0,11)
     158             :    * (0,6)  (1,3)  (2,0)  (1,0)  (0,0)
     159             :    *    (0,5)  (1,2)  (1,1)  (0,1)
     160             :    *       (0,4)  (0,3)  (0,2)
     161             :    *
     162             :    * @param index in row-column form
     163             :    * @return index in ring-position form
     164             :    */
     165             :   std::pair<int, int> getRingIndexFromRowIndex(const std::pair<int, int> & row_col_index) const;
     166             : 
     167             :   /**
     168             :    * @brief get the pitch of the lattice
     169             :    *
     170             :    * @return pitch
     171             :    */
     172           6 :   Real getPitch() const { return _pitch; }
     173             : 
     174             :   /**
     175             :    * @brief set the pitch of the lattice
     176             :    *
     177             :    * @param pitch new pitch value
     178             :    */
     179             :   void setPitch(Real pitch);
     180             : 
     181             : protected:
     182             :   /// compare the attributes returned in getAttributes of this lattice to another lattice
     183             :   virtual bool compareAttributes(const CSGLattice & other) const override;
     184             : 
     185             :   /**
     186             :    * @brief build a mapping of row-column indices to ring-position indices for quick conversion and
     187             :    * look-up. Sets the _row_to_ring_map variable.
     188             :    */
     189             :   void buildIndexMap();
     190             : 
     191             :   /**
     192             :    * @brief set the universes that define the lattice layout
     193             :    *
     194             :    * @param universes list of list of universes to set as the lattice map
     195             :    */
     196             :   virtual void setUniverses(
     197             :       std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) override;
     198             : 
     199             :   /// lattice pitch (flat-to-flat distance between adjacent hex elements)
     200             :   Real _pitch;
     201             : 
     202             :   /// number of rows in the hexagonal lattice (must be odd), should be consistent with the number of rings
     203             :   unsigned int _nrow;
     204             : 
     205             :   /// number of rings in the hexagonal lattice, should be consistent with the number of rows
     206             :   unsigned int _nring;
     207             : 
     208             :   /// map of row-column indices to ring-position indices for quick conversion and look-up
     209             :   std::map<std::pair<unsigned int, unsigned int>, std::pair<unsigned int, unsigned int>>
     210             :       _row_to_ring_map;
     211             : 
     212             : #ifdef MOOSE_UNIT_TEST
     213             :   /// Friends for unit testing
     214             :   ///@{
     215             :   FRIEND_TEST(CSGLatticeTest, testHexSetUniverses);
     216             :   FRIEND_TEST(CSGLatticeTest, testConvertRowsRings);
     217             :   ///@}
     218             : #endif
     219             : };
     220             : 
     221             : /// methods to help convert between number of rows and rings
     222             : /// get the total number of rings from the number of rows
     223             : unsigned int nRowToRing(int nrow);
     224             : 
     225             : /// get the total number of rows from the number of rings
     226             : unsigned int nRingToRow(int nring);
     227             : 
     228             : } // namespace CSG

Generated by: LCOV version 1.14