LCOV - code coverage report
Current view: top level - src/csg - CSGUniverse.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 41 48 85.4 %
Date: 2025-10-29 16:49:47 Functions: 7 8 87.5 %
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 "CSGUniverse.h"
      11             : 
      12             : namespace CSG
      13             : {
      14             : 
      15         145 : CSGUniverse::CSGUniverse(const std::string & name, bool is_root) : _name(name), _is_root(is_root) {}
      16             : 
      17          10 : CSGUniverse::CSGUniverse(const std::string & name, std::vector<CSGCell *> & cells, bool is_root)
      18          10 :   : _name(name), _is_root(is_root)
      19             : {
      20          34 :   for (auto cell : cells)
      21          24 :     addCell(*cell);
      22          10 : }
      23             : 
      24             : void
      25         151 : CSGUniverse::addCell(const CSGCell & cell)
      26             : {
      27         151 :   auto cell_name = cell.getName();
      28         151 :   if (!hasCell(cell_name))
      29         149 :     _cells.push_back(cell);
      30             :   else
      31          12 :     mooseWarning("Universe " + getName() + " already contains a cell by name " + cell_name + ". " +
      32             :                  "Skipping cell insertion for cell with duplicate name.");
      33         151 : }
      34             : 
      35             : const CSGCell &
      36           4 : CSGUniverse::getCell(const std::string & name)
      37             : {
      38           4 :   if (!hasCell(name))
      39          10 :     mooseError("Cell with name " + name + " does not exist in universe " + _name + ".");
      40           2 :   for (const CSGCell & cell : _cells)
      41           2 :     if (cell.getName() == name)
      42           2 :       return cell;
      43           0 :   mooseError("Should not reach here.");
      44             : }
      45             : 
      46             : bool
      47         217 : CSGUniverse::hasCell(const std::string & name) const
      48             : {
      49         345 :   for (const CSGCell & cell : _cells)
      50         178 :     if (cell.getName() == name)
      51          50 :       return true;
      52         167 :   return false;
      53             : }
      54             : 
      55             : void
      56          12 : CSGUniverse::removeCell(const std::string & name)
      57             : {
      58          12 :   if (!hasCell(name))
      59          12 :     mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " +
      60           8 :                _name + ".");
      61          14 :   for (auto it = _cells.begin(); it != _cells.end(); ++it)
      62          14 :     if (it->get().getName() == name)
      63             :     {
      64          10 :       _cells.erase(it);
      65          10 :       break;
      66             :     }
      67          10 : }
      68             : 
      69             : bool
      70           6 : CSGUniverse::operator==(const CSGUniverse & other) const
      71             : {
      72           6 :   const bool names_eq = this->getName() == other.getName();
      73           6 :   if (names_eq)
      74             :   {
      75           6 :     const auto & all_cells = getAllCells();
      76           6 :     const auto & other_cells = other.getAllCells();
      77           6 :     const bool num_cells_eq = all_cells.size() == other_cells.size();
      78           6 :     if (num_cells_eq)
      79             :     {
      80           6 :       for (unsigned int i = 0; i < all_cells.size(); ++i)
      81           0 :         if (all_cells[i].get() != other_cells[i].get())
      82           0 :           return false;
      83           6 :       return true;
      84             :     }
      85             :     else
      86           0 :       return false;
      87             :   }
      88             :   else
      89           0 :     return false;
      90             : }
      91             : 
      92             : bool
      93           0 : CSGUniverse::operator!=(const CSGUniverse & other) const
      94             : {
      95           0 :   return !(*this == other);
      96             : }
      97             : 
      98             : } // namespace CSG

Generated by: LCOV version 1.14