LCOV - code coverage report
Current view: top level - src/csg - CSGUniverseList.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 46 52 88.5 %
Date: 2026-05-29 20:35:17 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 "CSGUniverseList.h"
      11             : 
      12             : namespace CSG
      13             : {
      14             : 
      15         286 : CSGUniverseList::CSGUniverseList()
      16             : {
      17             :   // create root universe by default when CSG object is initialized
      18         286 :   std::string root_name = "ROOT_UNIVERSE";
      19         286 :   auto root_universe = std::make_unique<CSGUniverse>(root_name, /* is_root = */ true);
      20         286 :   _root_universe = root_universe.get();
      21         286 :   _universes.insert(std::make_pair(root_name, std::move(root_universe)));
      22         286 : }
      23             : 
      24             : CSGUniverse &
      25        1836 : CSGUniverseList::getUniverse(const std::string & name) const
      26             : {
      27        1836 :   auto univ = _universes.find(name);
      28        1836 :   if (univ == _universes.end())
      29           6 :     mooseError("No universe by name " + name + " exists in the geometry.");
      30             :   else
      31        3668 :     return *(univ->second);
      32             : }
      33             : 
      34             : std::vector<std::reference_wrapper<const CSGUniverse>>
      35         194 : CSGUniverseList::getAllUniverses() const
      36             : {
      37         194 :   std::vector<std::reference_wrapper<const CSGUniverse>> univs;
      38         708 :   for (auto it = _universes.begin(); it != _universes.end(); ++it)
      39         514 :     univs.push_back(*(it->second.get()));
      40         194 :   return univs;
      41           0 : }
      42             : 
      43             : CSGUniverse &
      44         208 : CSGUniverseList::addUniverse(const std::string & name)
      45             : {
      46         208 :   return addUniverse(std::make_unique<CSGUniverse>(name));
      47             : }
      48             : 
      49             : CSGUniverse &
      50         380 : CSGUniverseList::addUniverse(std::unique_ptr<CSGUniverse> universe)
      51             : {
      52         380 :   auto name = universe->getName();
      53         380 :   auto [it, inserted] = _universes.emplace(name, std::move(universe));
      54         380 :   if (!inserted)
      55          12 :     mooseError("Universe with name " + name + " already exists in geometry.");
      56         752 :   return *it->second;
      57         380 : }
      58             : 
      59             : void
      60          56 : CSGUniverseList::renameUniverse(const CSGUniverse & universe, const std::string & name)
      61             : {
      62             :   // check that this universe passed in is actually in the same universe that is in the universe
      63             :   // list
      64          56 :   auto prev_name = universe.getName();
      65          56 :   auto it = _universes.find(prev_name);
      66          56 :   if (it == _universes.end() || it->second.get() != &universe)
      67          10 :     mooseError("Universe " + prev_name + " cannot be renamed to " + name +
      68             :                " as it does not exist in this CSGBase instance.");
      69             : 
      70          54 :   auto existing_univ = std::move(it->second);
      71          54 :   existing_univ->setName(name);
      72          54 :   _universes.erase(prev_name);
      73          56 :   addUniverse(std::move(existing_univ));
      74          58 : }
      75             : 
      76             : bool
      77           4 : CSGUniverseList::operator==(const CSGUniverseList & other) const
      78             : {
      79           4 :   const auto all_univs = this->getAllUniverses();
      80           4 :   const auto other_univs = other.getAllUniverses();
      81             : 
      82             :   // Check that same number of universes are defined in both lists
      83           4 :   if (all_univs.size() != other_univs.size())
      84           0 :     return false;
      85             : 
      86             :   // Iterate through each CSGUniverse in list and check equality of universe
      87             :   // with other list
      88          20 :   for (const auto & univ : all_univs)
      89             :   {
      90          16 :     const auto & univ_name = univ.get().getName();
      91          16 :     if (!other.hasUniverse(univ_name))
      92           0 :       return false;
      93          16 :     const auto & other_univ = other.getUniverse(univ_name);
      94          16 :     if (univ.get() != other_univ)
      95           0 :       return false;
      96             :   }
      97           4 :   return true;
      98           4 : }
      99             : 
     100             : bool
     101           0 : CSGUniverseList::operator!=(const CSGUniverseList & other) const
     102             : {
     103           0 :   return !(*this == other);
     104             : }
     105             : 
     106             : } // namespace CSG

Generated by: LCOV version 1.14