LCOV - code coverage report
Current view: top level - src/csg - CSGSurfaceList.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 48 54 88.9 %
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 "CSGSurfaceList.h"
      11             : #include "CSGPlane.h"
      12             : #include "CSGSphere.h"
      13             : #include "CSGXCylinder.h"
      14             : #include "CSGYCylinder.h"
      15             : #include "CSGZCylinder.h"
      16             : 
      17             : namespace CSG
      18             : {
      19             : 
      20         274 : CSGSurfaceList::CSGSurfaceList() {}
      21             : 
      22          12 : CSGSurfaceList::CSGSurfaceList(const CSGSurfaceList & other_surface_list)
      23             : {
      24          42 :   for (const auto & [name, surf] : other_surface_list.getSurfaceListMap())
      25          30 :     _surfaces.emplace(name, surf->clone());
      26          12 : }
      27             : 
      28             : CSGSurface &
      29         844 : CSGSurfaceList::getSurface(const std::string & name) const
      30             : {
      31         844 :   auto surf = _surfaces.find(name);
      32         844 :   if (surf == _surfaces.end())
      33           6 :     mooseError("No surface by name " + name + " exists in the geometry.");
      34             :   else
      35        1684 :     return *(surf->second);
      36             : }
      37             : 
      38             : std::vector<std::reference_wrapper<const CSGSurface>>
      39         106 : CSGSurfaceList::getAllSurfaces() const
      40             : {
      41         106 :   std::vector<std::reference_wrapper<const CSGSurface>> surfaces;
      42         710 :   for (auto it = _surfaces.begin(); it != _surfaces.end(); ++it)
      43         604 :     surfaces.push_back(*(it->second));
      44         106 :   return surfaces;
      45           0 : }
      46             : 
      47             : CSGSurface &
      48        1208 : CSGSurfaceList::addSurface(std::unique_ptr<CSGSurface> surf, const bool ignore_identical_surface)
      49             : {
      50        1208 :   auto surf_name = surf->getName();
      51        1208 :   if (ignore_identical_surface)
      52             :     // Check that surface already defined in _surfaces and if so, confirm it matches with input surf
      53           2 :     if (auto it = _surfaces.find(surf_name); it != _surfaces.end())
      54             :     {
      55           2 :       if (*surf == *it->second)
      56           2 :         return *it->second;
      57             :       else
      58           0 :         mooseError("Surface with name ",
      59             :                    surf_name,
      60             :                    " has the same name as an existing surface in CSGBase instance but cannot be "
      61             :                    "discarded as it is not an identical surface.");
      62             :     }
      63             : 
      64             :   // Otherwise, add the surface to the surface list. At this point, we don't expect the surface
      65             :   // to already be defined in the surface list
      66        1206 :   auto [it, inserted] = _surfaces.emplace(surf_name, std::move(surf));
      67        1206 :   if (!inserted)
      68          18 :     mooseError("Surface with name " + surf_name + " already exists in geometry.");
      69             : 
      70        1200 :   return *it->second;
      71        1208 : }
      72             : 
      73             : void
      74          88 : CSGSurfaceList::renameSurface(const CSGSurface & surface, const std::string & name)
      75             : {
      76             :   // check that this surface passed in is actually in the same surface that is in the surface list
      77          88 :   auto prev_name = surface.getName();
      78          88 :   auto it = _surfaces.find(prev_name);
      79          88 :   if (it == _surfaces.end() || it->second.get() != &surface)
      80          10 :     mooseError("Surface " + prev_name + " cannot be renamed to " + name +
      81             :                " as it does not exist in this CSGBase instance.");
      82             : 
      83          86 :   auto existing_surface = std::move(it->second);
      84          86 :   existing_surface->setName(name);
      85          86 :   _surfaces.erase(prev_name);
      86          88 :   addSurface(std::move(existing_surface));
      87          90 : }
      88             : 
      89             : bool
      90           8 : CSGSurfaceList::operator==(const CSGSurfaceList & other) const
      91             : {
      92           8 :   const auto all_surfs = this->getAllSurfaces();
      93           8 :   const auto other_surfs = other.getAllSurfaces();
      94             : 
      95             :   // Check that same number of surfaces are defined in both lists
      96           8 :   if (all_surfs.size() != other_surfs.size())
      97           2 :     return false;
      98             : 
      99             :   // Iterate through each CSGSurface in list and check equality of surface
     100             :   // with other list
     101          22 :   for (const auto & surf : all_surfs)
     102             :   {
     103          16 :     const auto & surf_name = surf.get().getName();
     104          16 :     if (!other.hasSurface(surf_name))
     105           0 :       return false;
     106          16 :     const auto & other_surf = other.getSurface(surf_name);
     107          16 :     if (surf.get() != other_surf)
     108           0 :       return false;
     109             :   }
     110           6 :   return true;
     111           8 : }
     112             : 
     113             : bool
     114           0 : CSGSurfaceList::operator!=(const CSGSurfaceList & other) const
     115             : {
     116           0 :   return !(*this == other);
     117             : }
     118             : 
     119             : } // namespace CSG

Generated by: LCOV version 1.14