LCOV - code coverage report
Current view: top level - src/csg - CSGCellList.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 48 52 92.3 %
Date: 2026-05-29 20:35:17 Functions: 10 11 90.9 %
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             : #include "CSGCellList.h"
      11             : 
      12             : namespace CSG
      13             : {
      14             : 
      15         286 : CSGCellList::CSGCellList() {}
      16             : 
      17             : CSGCell &
      18         679 : CSGCellList::addCell(std::unique_ptr<CSGCell> cell)
      19             : {
      20         679 :   auto name = cell->getName();
      21         679 :   auto [it, inserted] = _cells.emplace(name, std::move(cell));
      22         679 :   if (!inserted)
      23          12 :     mooseError("Cell with name " + name + " already exists in geometry.");
      24        1350 :   return *it->second;
      25         679 : }
      26             : 
      27             : CSGCell &
      28         743 : CSGCellList::getCell(const std::string & name) const
      29             : {
      30         743 :   if (_cells.find(name) == _cells.end())
      31           6 :     mooseError("No cell by name " + name + " exists in the geometry.");
      32             :   else
      33         741 :     return *(_cells.find(name)->second);
      34             : }
      35             : 
      36             : CSGCell &
      37          98 : CSGCellList::addVoidCell(const std::string & name, const CSGRegion & region)
      38             : {
      39          98 :   return addCell(std::make_unique<CSGCell>(name, region));
      40             : }
      41             : 
      42             : CSGCell &
      43         141 : CSGCellList::addMaterialCell(const std::string & name,
      44             :                              const std::string & mat_name,
      45             :                              const CSGRegion & region)
      46             : {
      47         141 :   return addCell(std::make_unique<CSGCell>(name, mat_name, region));
      48             : }
      49             : 
      50             : CSGCell &
      51          28 : CSGCellList::addUniverseCell(const std::string & name,
      52             :                              const CSGUniverse & univ,
      53             :                              const CSGRegion & region)
      54             : {
      55          28 :   return addCell(std::make_unique<CSGCell>(name, &univ, region));
      56             : }
      57             : 
      58             : CSGCell &
      59          66 : CSGCellList::addLatticeCell(const std::string & name,
      60             :                             const CSGLattice & lattice,
      61             :                             const CSGRegion & region)
      62             : {
      63          66 :   return addCell(std::make_unique<CSGCell>(name, &lattice, region));
      64             : }
      65             : 
      66             : std::vector<std::reference_wrapper<const CSGCell>>
      67         210 : CSGCellList::getAllCells() const
      68             : {
      69         210 :   std::vector<std::reference_wrapper<const CSGCell>> cells;
      70         814 :   for (auto it = _cells.begin(); it != _cells.end(); ++it)
      71         604 :     cells.push_back(*(it->second));
      72         210 :   return cells;
      73           0 : }
      74             : 
      75             : void
      76         118 : CSGCellList::renameCell(const CSGCell & cell, const std::string & name)
      77             : {
      78             :   // check that this cell passed in is actually in the same cell that is in the cell list
      79         118 :   auto prev_name = cell.getName();
      80         118 :   auto it = _cells.find(prev_name);
      81         118 :   if (it == _cells.end() || it->second.get() != &cell)
      82          10 :     mooseError("Cell " + prev_name + " cannot be renamed to " + name +
      83             :                " as it does not exist in this CSGBase instance.");
      84             : 
      85         116 :   auto existing_cell = std::move(_cells.find(prev_name)->second);
      86         116 :   existing_cell->setName(name);
      87         116 :   _cells.erase(prev_name);
      88         118 :   addCell(std::move(existing_cell));
      89         120 : }
      90             : 
      91             : bool
      92           6 : CSGCellList::operator==(const CSGCellList & other) const
      93             : {
      94           6 :   const auto all_cells = this->getAllCells();
      95           6 :   const auto other_cells = other.getAllCells();
      96             : 
      97             :   // Check that same number of cells are defined in both lists
      98           6 :   if (all_cells.size() != other_cells.size())
      99           0 :     return false;
     100             : 
     101             :   // Iterate through each CSGCell in list and check equality of each cell
     102             :   // with other list
     103          22 :   for (const auto & cell : all_cells)
     104             :   {
     105          18 :     const auto & cell_name = cell.get().getName();
     106          18 :     if (!other.hasCell(cell_name))
     107           2 :       return false;
     108          18 :     const auto & other_cell = other.getCell(cell_name);
     109          18 :     if (cell.get() != other_cell)
     110           2 :       return false;
     111             :   }
     112           4 :   return true;
     113           6 : }
     114             : 
     115             : bool
     116           0 : CSGCellList::operator!=(const CSGCellList & other) const
     117             : {
     118           0 :   return !(*this == other);
     119             : }
     120             : 
     121             : } // namespace CSG

Generated by: LCOV version 1.14