LCOV - code coverage report
Current view: top level - src/csg - CSGLatticeList.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 39 45 86.7 %
Date: 2026-05-29 20:35:17 Functions: 6 7 85.7 %
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 "CSGLatticeList.h"
      11             : 
      12             : namespace CSG
      13             : {
      14             : 
      15         286 : CSGLatticeList::CSGLatticeList() {}
      16             : 
      17             : CSGLattice &
      18         162 : CSGLatticeList::getLattice(const std::string & name) const
      19             : {
      20         162 :   auto lat = _lattices.find(name);
      21         162 :   if (lat == _lattices.end())
      22           6 :     mooseError("No lattice by name " + name + " exists in the geometry.");
      23             :   else
      24         320 :     return *(lat->second);
      25             : }
      26             : 
      27             : std::vector<std::reference_wrapper<const CSGLattice>>
      28         124 : CSGLatticeList::getAllLattices() const
      29             : {
      30         124 :   std::vector<std::reference_wrapper<const CSGLattice>> lattices;
      31         212 :   for (auto it = _lattices.begin(); it != _lattices.end(); ++it)
      32          88 :     lattices.push_back(*(it->second.get()));
      33         124 :   return lattices;
      34           0 : }
      35             : 
      36             : CSGLattice &
      37         184 : CSGLatticeList::addLattice(std::unique_ptr<CSGLattice> lattice)
      38             : {
      39         184 :   auto name = lattice->getName();
      40         184 :   auto [it, inserted] = _lattices.emplace(name, std::move(lattice));
      41         184 :   if (!inserted)
      42           6 :     mooseError("Lattice with name " + name + " already exists in geometry.");
      43         364 :   return *it->second;
      44         184 : }
      45             : 
      46             : void
      47          22 : CSGLatticeList::renameLattice(const CSGLattice & lattice, const std::string & name)
      48             : {
      49             :   // check that this lattice passed in is actually in the same lattice that is in the lattice list
      50          22 :   auto prev_name = lattice.getName();
      51          22 :   auto it = _lattices.find(prev_name);
      52          22 :   if (it == _lattices.end() || it->second.get() != &lattice)
      53          10 :     mooseError("Lattice " + prev_name + " cannot be renamed to " + name +
      54             :                " as it does not exist in this CSGBase instance.");
      55             : 
      56          20 :   auto existing_lat = std::move(it->second);
      57          20 :   existing_lat->setName(name);
      58          20 :   _lattices.erase(prev_name);
      59          22 :   addLattice(std::move(existing_lat));
      60          24 : }
      61             : 
      62             : bool
      63           4 : CSGLatticeList::operator==(const CSGLatticeList & other) const
      64             : {
      65           4 :   const auto all_lats = this->getAllLattices();
      66           4 :   const auto other_lats = other.getAllLattices();
      67             : 
      68             :   // Check that same number of lattices are defined in both lists
      69           4 :   if (all_lats.size() != other_lats.size())
      70           0 :     return false;
      71             : 
      72             :   // Iterate through each CSGLattices in list and check equality of each cell
      73             :   // with other list
      74           8 :   for (const auto & lat : all_lats)
      75             :   {
      76           4 :     const auto & lat_name = lat.get().getName();
      77           4 :     if (!other.hasLattice(lat_name))
      78           0 :       return false;
      79           4 :     const auto & other_lat = other.getLattice(lat_name);
      80           4 :     if (lat.get() != other_lat)
      81           0 :       return false;
      82             :   }
      83           4 :   return true;
      84           4 : }
      85             : 
      86             : bool
      87           0 : CSGLatticeList::operator!=(const CSGLatticeList & other) const
      88             : {
      89           0 :   return !(*this == other);
      90             : }
      91             : 
      92             : } // namespace CSG

Generated by: LCOV version 1.14