LCOV - code coverage report
Current view: top level - include/csg - CSGLattice.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 7 7 100.0 %
Date: 2026-05-29 20:35:17 Functions: 6 7 85.7 %
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 "CSGUniverse.h"
      13             : #include "CSGTransformationHelper.h"
      14             : #include "JsonIO.h"
      15             : #include <variant>
      16             : #include <optional>
      17             : 
      18             : #ifdef MOOSE_UNIT_TEST
      19             : #include "gtest/gtest.h"
      20             : #endif
      21             : 
      22             : namespace CSG
      23             : {
      24             : 
      25             : /**
      26             :  * Type definition for a variant that can hold either a CSGUniverse reference or a string
      27             :  * for use as the outer parameter in lattice constructors
      28             :  */
      29             : typedef std::variant<std::reference_wrapper<const CSGUniverse>, std::string> OuterVariant;
      30             : 
      31             : /**
      32             :  * CSGLattice is the abstract class for defining lattices.
      33             :  */
      34             : class CSGLattice : public CSGTransformationHelper
      35             : {
      36             : public:
      37             :   /**
      38             :    * @brief Construct a new CSGLattice of specific type
      39             :    *
      40             :    * @param name unique name of lattice
      41             :    * @param lattice_type type of lattice
      42             :    * @param outer optional outer universe or material name that fills space around lattice elements.
      43             :    *              If not provided, outer is assumed to be VOID.
      44             :    */
      45             :   CSGLattice(const std::string & name,
      46             :              const std::string & lattice_type,
      47             :              const std::optional<OuterVariant> & outer = std::nullopt);
      48             : 
      49             :   /**
      50             :    * Destructor
      51             :    */
      52         280 :   virtual ~CSGLattice() = default;
      53             : 
      54             :   // Pure virtual clone method that derived classes must implement
      55             :   virtual std::unique_ptr<CSGLattice> clone() const = 0;
      56             : 
      57             :   /**
      58             :    * @brief Get the name of lattice
      59             :    *
      60             :    * @return std::string name of lattice
      61             :    */
      62         898 :   const std::string & getName() const { return _name; }
      63             : 
      64             :   /**
      65             :    * @brief Get the lattice type
      66             :    *
      67             :    * @return std::string type of lattice
      68             :    */
      69         482 :   const std::string & getType() const { return _lattice_type; }
      70             : 
      71             :   /**
      72             :    * @brief Get the type of outer that fills the space around the lattice elements
      73             :    *
      74             :    * @return string of outer type: CSG_MATERIAL, UNIVERSE, or VOID
      75             :    */
      76         840 :   const std::string getOuterType() const { return _outer_type; }
      77             : 
      78             :   /**
      79             :    * @brief Get the outer universe if outer type is UNIVERSE
      80             :    *
      81             :    * @return Reference to CSGUniverse
      82             :    */
      83             :   const CSGUniverse & getOuterUniverse() const;
      84             : 
      85             :   /**
      86             :    * @brief Get the outer material name if outer fype is CSG_MATERIAL
      87             :    *
      88             :    * @return name of the CSG material fill
      89             :    */
      90             :   const std::string & getOuterMaterial() const;
      91             : 
      92             :   /**
      93             :    * @brief Get the arrangement of CSGUniverses in the lattice
      94             :    *
      95             :    * @return list of list of universes in their lattice arrangement
      96             :    */
      97         392 :   std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> getUniverses() const
      98             :   {
      99         392 :     return _universe_map;
     100             :   }
     101             : 
     102             :   /**
     103             :    * @brief Get the arrangement of CSGUniverses in the lattice as their names
     104             :    *
     105             :    * @return list of list of universe names
     106             :    */
     107             :   const std::vector<std::vector<std::string>> getUniverseNameMap() const;
     108             : 
     109             :   /**
     110             :    * @brief whether or not the universe of the specified name exists in the lattice
     111             :    *
     112             :    * @param name of universe to search for
     113             :    *
     114             :    * @return true if universe of that name exists in lattice
     115             :    */
     116             :   bool hasUniverse(const std::string & name) const;
     117             : 
     118             :   /**
     119             :    * @brief Get attributes that define the lattice (excluding the universe map).
     120             :    *
     121             :    * @return map of string attribute name to value of that attribute
     122             :    */
     123             :   virtual std::unordered_map<std::string, AttributeVariant>
     124             :   getAttributes() const = 0; // pure virtual function
     125             : 
     126             :   /**
     127             :    * @brief Checks if the given index location is a valid index for the lattice
     128             :    *
     129             :    * @param index location
     130             :    * @return true if index is valid for the lattice
     131             :    */
     132             :   virtual bool isValidIndex(const std::pair<int, int> index) const = 0; // Pure virtual function
     133             : 
     134             :   /**
     135             :    * @brief Get the universe located at the given index
     136             :    *
     137             :    * @param index pair of ints that specify the location in lattice
     138             :    * @return universe at the specified location
     139             :    */
     140             :   const CSGUniverse & getUniverseAtIndex(const std::pair<int, int> index);
     141             : 
     142             :   /**
     143             :    * @brief get all locations in lattice where universe of the specified name exists
     144             :    *
     145             :    * @param univ_name name of universe
     146             :    * @return vector of locations (pairs of ints)
     147             :    */
     148             :   const std::vector<std::pair<unsigned int, unsigned int>>
     149             :   getUniverseIndices(const std::string & univ_name) const;
     150             : 
     151             :   /**
     152             :    * @brief check that any provided list of list of CSGUniverses are the correct dimensions for the
     153             :    * type of lattice
     154             :    *
     155             :    * @param universes list of list of universes to be used to define the lattice structure
     156             :    * @return true if universe dimensions are valid
     157             :    */
     158             :   virtual bool
     159             :   isValidUniverseMap(std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
     160             :       const = 0; // pure virtual function
     161             : 
     162             :   /**
     163             :    * @brief reset the outer fill around the lattice elements to be VOID
     164             :    */
     165             :   void resetOuter();
     166             : 
     167             :   /**
     168             :    * @brief Get the list of unique universe objects in the lattice
     169             :    *
     170             :    * @return list of references to unique CSGUniverse objects
     171             :    */
     172             :   const std::vector<std::reference_wrapper<const CSGUniverse>> getUniqueUniverses() const;
     173             : 
     174             :   /// Operator overload for checking if two CSGLattice objects are equal
     175             :   bool operator==(const CSGLattice & other) const;
     176             : 
     177             :   /// Operator overload for checking if two CSGLattice objects are not equal
     178             :   bool operator!=(const CSGLattice & other) const;
     179             : 
     180             : protected:
     181             :   // set the name of the lattices - intentionally not public because
     182             :   // name needs to be managed at the CSGLatticeList level
     183          22 :   void setName(const std::string & name) { _name = name; }
     184             : 
     185             :   /// @brief assign the vectors of universes as the lattice elements
     186             :   /// @param universes vector of vectors of universes to be set as lattice elements, ordering depends on derived class
     187             :   virtual void
     188             :   setUniverses(std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) = 0;
     189             : 
     190             :   /**
     191             :    * @brief replace the element at specified index in the lattice with the provided CSGUniverse.
     192             :    * This will check that the _universe_map has been initialized and that the index is valid.
     193             :    *
     194             :    * @param universe universe to add to the lattice at the location index
     195             :    * @param index location in lattice replace with provided universe
     196             :    */
     197             :   void setUniverseAtIndex(const CSGUniverse & universe, const std::pair<int, int> index);
     198             : 
     199             :   /// helper function to compare the attributes of the lattice type
     200             :   virtual bool compareAttributes(const CSGLattice & other) const = 0; // pure virtual
     201             : 
     202             :   /**
     203             :    * @brief Update the outer of the lattice to be the provided material name. This will change outer
     204             :    * type to CSG_MATERIAL even if it was a different type previously.
     205             :    *
     206             :    * @param outer_name name of CSG material that will fill space around lattice elements
     207             :    */
     208             :   void updateOuter(const std::string & outer_name);
     209             : 
     210             :   /**
     211             :    * @brief Update the outer of the lattice to be the provided universe. This will change outer type
     212             :    * to UNIVERSE even if it was a different type previously.
     213             :    *
     214             :    * @param outer_universe pointer to outer universe that will fill space around lattice elements
     215             :    */
     216             :   void updateOuter(const CSGUniverse & outer_universe);
     217             : 
     218             :   /// Name of lattice
     219             :   std::string _name;
     220             : 
     221             :   /// Type of lattice
     222             :   const std::string _lattice_type;
     223             : 
     224             :   /// Universes in the arrangement of how they appear in the lattice; dimensions depends on lattice type
     225             :   std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> _universe_map;
     226             : 
     227             :   /// An enum for type of outer fill for lattice
     228             :   mutable std::string _outer_type;
     229             : 
     230             :   /// name of the outer material
     231             :   mutable std::string _outer_material;
     232             : 
     233             :   /// outer object if fill is CSGUniverse
     234             :   const CSGUniverse * _outer_universe;
     235             : 
     236             :   // CSGLatticeList needs to be friend to access setName()
     237             :   friend class CSGLatticeList;
     238             :   // CSGBase needed for access updateAttributes()
     239             :   friend class CSGBase;
     240             : 
     241             : #ifdef MOOSE_UNIT_TEST
     242             :   /// Friends for unit testing
     243             :   ///@{
     244             :   FRIEND_TEST(CSGLatticeTest, testSetName);
     245             :   FRIEND_TEST(CSGLatticeTest, testUpdateOuter);
     246             :   FRIEND_TEST(CSGBaseTest, testAddLattice);
     247             :   FRIEND_TEST(CSGLatticeTest, testCartLatticeEquality);
     248             :   ///@}
     249             : #endif
     250             : };
     251             : }

Generated by: LCOV version 1.14