LCOV - code coverage report
Current view: top level - src/csg - CSGCell.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 77 78 98.7 %
Date: 2026-05-29 20:35:17 Functions: 15 15 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 "CSGCell.h"
      11             : #include "CSGUniverse.h"
      12             : #include "CSGLattice.h"
      13             : #include "CSGUtils.h"
      14             : 
      15             : namespace CSG
      16             : {
      17             : 
      18         152 : CSGCell::CSGCell(const std::string & name, const CSGRegion & region)
      19        1064 :   : _name(name), _fill_name(""), _region(region)
      20             : {
      21         152 :   CSGUtils::checkValidCSGName(name);
      22         152 :   _fill_type = "VOID";
      23         152 : }
      24             : 
      25         155 : CSGCell::CSGCell(const std::string & name, const std::string & mat_name, const CSGRegion & region)
      26         775 :   : _name(name), _fill_name(mat_name), _region(region)
      27             : {
      28         155 :   CSGUtils::checkValidCSGName(name);
      29         155 :   _fill_type = "CSG_MATERIAL";
      30         155 : }
      31             : 
      32          44 : CSGCell::CSGCell(const std::string & name, const CSGUniverse * univ, const CSGRegion & region)
      33         308 :   : _name(name), _fill_name(""), _region(region), _fill_universe(univ)
      34             : {
      35          44 :   CSGUtils::checkValidCSGName(name);
      36          44 :   _fill_type = "UNIVERSE";
      37          44 : }
      38             : 
      39          68 : CSGCell::CSGCell(const std::string & name, const CSGLattice * lattice, const CSGRegion & region)
      40         476 :   : _name(name), _fill_name(""), _region(region), _fill_lattice(lattice)
      41             : {
      42          68 :   CSGUtils::checkValidCSGName(name);
      43          68 :   _fill_type = "LATTICE";
      44          68 : }
      45             : 
      46             : const std::string &
      47         442 : CSGCell::getFillName() const
      48             : {
      49         442 :   if (getFillType() == "UNIVERSE")
      50          70 :     return _fill_universe->getName();
      51         372 :   else if (getFillType() == "LATTICE")
      52          76 :     return _fill_lattice->getName();
      53             :   else
      54         296 :     return _fill_name;
      55             : }
      56             : 
      57             : const CSGUniverse &
      58         126 : CSGCell::getFillUniverse() const
      59             : {
      60         126 :   if (getFillType() != "UNIVERSE")
      61          24 :     mooseError("Cell '" + getName() + "' has " + getFillType() + " fill, not UNIVERSE.");
      62             :   else
      63         122 :     return *_fill_universe;
      64             : }
      65             : 
      66             : const std::string &
      67          80 : CSGCell::getFillMaterial() const
      68             : {
      69          80 :   if (getFillType() != "CSG_MATERIAL")
      70          24 :     mooseError("Cell '" + getName() + "' has " + getFillType() + " fill, not CSG_MATERIAL.");
      71             :   else
      72          76 :     return _fill_name;
      73             : }
      74             : 
      75             : const CSGLattice &
      76         164 : CSGCell::getFillLattice() const
      77             : {
      78         164 :   if (getFillType() != "LATTICE")
      79           0 :     mooseError("Cell '" + getName() + "' has " + getFillType() + " fill, not LATTICE.");
      80             :   else
      81         164 :     return *_fill_lattice;
      82             : }
      83             : 
      84             : void
      85          20 : CSGCell::resetCellFill()
      86             : {
      87          20 :   _fill_name = "";
      88          20 :   _fill_universe = nullptr;
      89          20 :   _fill_lattice = nullptr;
      90          20 :   _fill_type = "VOID";
      91          20 : }
      92             : 
      93             : void
      94           4 : CSGCell::updateCellFill(const std::string & mat_name)
      95             : {
      96           4 :   resetCellFill();
      97           4 :   _fill_type = "CSG_MATERIAL";
      98           4 :   _fill_name = mat_name;
      99           4 : }
     100             : 
     101             : void
     102           4 : CSGCell::updateCellFill(const CSGUniverse * univ)
     103             : {
     104           4 :   resetCellFill();
     105           4 :   _fill_type = "UNIVERSE";
     106           4 :   _fill_universe = univ;
     107           4 : }
     108             : 
     109             : void
     110           4 : CSGCell::updateCellFill(const CSGLattice * lattice)
     111             : {
     112           4 :   resetCellFill();
     113           4 :   _fill_type = "LATTICE";
     114           4 :   _fill_lattice = lattice;
     115           4 : }
     116             : 
     117             : void
     118           2 : CSGCell::updateCellRegionSurfaces(
     119             :     std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs)
     120             : {
     121           2 :   _region.updateSurfaceReferences(identical_surface_refs);
     122           2 : }
     123             : 
     124             : bool
     125         214 : CSGCell::operator==(const CSG::CSGCell & other) const
     126             : {
     127         214 :   const auto name_eq = this->getName() == other.getName();
     128         214 :   const auto region_eq = this->getRegion() == other.getRegion();
     129             :   const auto fill_type_eq =
     130         214 :       (this->getFillType() == other.getFillType()) && (this->getFillName() == other.getFillName());
     131         214 :   const auto transformations_eq = this->getTransformations() == other.getTransformations();
     132         214 :   if (name_eq && region_eq && fill_type_eq && transformations_eq)
     133             :   {
     134          80 :     if (this->getFillType() == "CSG_MATERIAL")
     135          18 :       return this->getFillMaterial() == other.getFillMaterial();
     136          62 :     else if (this->getFillType() == "UNIVERSE")
     137          14 :       return this->getFillUniverse() == other.getFillUniverse();
     138          48 :     else if (this->getFillType() == "LATTICE")
     139          14 :       return this->getFillLattice() == other.getFillLattice();
     140             :     else
     141          34 :       return true;
     142             :   }
     143             :   else
     144         134 :     return false;
     145             : }
     146             : 
     147             : bool
     148         192 : CSGCell::operator!=(const CSG::CSGCell & other) const
     149             : {
     150         192 :   return !(*this == other);
     151             : }
     152             : 
     153             : } // namespace CSG

Generated by: LCOV version 1.14