LCOV - code coverage report
Current view: top level - src/csg - CSGUniverseList.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 35 36 97.2 %
Date: 2025-10-29 16:49:47 Functions: 6 6 100.0 %
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          95 : CSGUniverseList::CSGUniverseList()
      16             : {
      17             :   // create root universe by default when CSG object is initialized
      18          95 :   std::string root_name = "ROOT_UNIVERSE";
      19          95 :   auto root_universe = std::make_unique<CSGUniverse>(root_name, /* is_root = */ true);
      20          95 :   _root_universe = root_universe.get();
      21          95 :   _universes.insert(std::make_pair(root_name, std::move(root_universe)));
      22          95 : }
      23             : 
      24             : CSGUniverse &
      25         286 : CSGUniverseList::getUniverse(const std::string & name) const
      26             : {
      27         286 :   auto univ = _universes.find(name);
      28         286 :   if (univ == _universes.end())
      29           6 :     mooseError("No universe by name " + name + " exists in the geometry.");
      30             :   else
      31         568 :     return *(univ->second);
      32             : }
      33             : 
      34             : std::vector<std::reference_wrapper<const CSGUniverse>>
      35          66 : CSGUniverseList::getAllUniverses() const
      36             : {
      37          66 :   std::vector<std::reference_wrapper<const CSGUniverse>> univs;
      38         150 :   for (auto it = _universes.begin(); it != _universes.end(); ++it)
      39          84 :     univs.push_back(*(it->second.get()));
      40          66 :   return univs;
      41           0 : }
      42             : 
      43             : CSGUniverse &
      44          38 : CSGUniverseList::addUniverse(const std::string & name)
      45             : {
      46          38 :   return addUniverse(std::make_unique<CSGUniverse>(name));
      47             : }
      48             : 
      49             : CSGUniverse &
      50          50 : CSGUniverseList::addUniverse(std::unique_ptr<CSGUniverse> universe)
      51             : {
      52          50 :   auto name = universe->getName();
      53          50 :   auto [it, inserted] = _universes.emplace(name, std::move(universe));
      54          50 :   if (!inserted)
      55          12 :     mooseError("Universe with name " + name + " already exists in geometry.");
      56          92 :   return *it->second;
      57          50 : }
      58             : 
      59             : void
      60           8 : 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           8 :   auto prev_name = universe.getName();
      65           8 :   auto it = _universes.find(prev_name);
      66           8 :   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           6 :   auto existing_univ = std::move(it->second);
      71           6 :   existing_univ->setName(name);
      72           6 :   _universes.erase(prev_name);
      73           8 :   addUniverse(std::move(existing_univ));
      74          10 : }
      75             : 
      76             : } // namespace CSG

Generated by: LCOV version 1.14