19#include "nlohmann/json.h"
22#include "gtest/gtest.h"
41typedef std::variant<std::reference_wrapper<const CSGSurface>,
42 std::reference_wrapper<const CSGCell>,
43 std::reference_wrapper<const CSGUniverse>,
44 std::reference_wrapper<const CSGRegion>,
45 std::reference_wrapper<const CSGLattice>,
46 std::reference_wrapper<const CSGEngUnit>>
72 std::unique_ptr<CSGBase>
clone()
const {
return std::make_unique<CSGBase>(*
this); }
139 const std::string & mat_name,
199 std::vector<std::reference_wrapper<const CSGCell>>
getAllCells()
const
311 std::vector<std::reference_wrapper<const CSGCell>> & cells);
336 std::vector<std::reference_wrapper<const CSGCell>> & cells);
353 std::vector<std::reference_wrapper<const CSGCell>> & cells);
392 template <
typename LatticeType = CSGLattice>
393 const LatticeType &
addLattice(std::unique_ptr<LatticeType> lattice)
395 static_assert(std::is_base_of_v<CSGLattice, LatticeType>,
"Is not a CSGLattice");
397 auto universes = lattice->getUniverses();
398 for (
auto univ_list : universes)
401 mooseError(
"Cannot add lattice " + lattice->getName() +
" of type " + lattice->getType() +
402 ". Universe " + univ.getName() +
" is not in the CSGBase instance.");
404 if (lattice->getOuterType() ==
"UNIVERSE")
406 const CSGUniverse & outer_univ = lattice->getOuterUniverse();
408 mooseError(
"Cannot add lattice " + lattice->getName() +
" of type " + lattice->getType() +
409 ". Outer universe " + outer_univ.
getName() +
" is not in the CSGBase instance.");
412 return dynamic_cast<LatticeType &
>(lat_ref);
432 std::pair<int, int> index);
443 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> & universes);
503 template <
typename LatticeType = CSGLattice>
507 const LatticeType * typed_lattice =
dynamic_cast<const LatticeType *
>(&lattice);
509 mooseError(
"Cannot get lattice " + name +
". Lattice is not of specified type " +
510 MooseUtils::prettyCppType<LatticeType>());
511 return *typed_lattice;
533 template <
typename T>
536 static_assert(std::is_base_of_v<CSGEngUnit, T>,
"T must derive from CSGEngUnit");
537 static_assert(std::is_base_of_v<CSGSurface, T> || std::is_base_of_v<CSGCell, T> ||
538 std::is_base_of_v<CSGUniverse, T>,
539 "T must also derive from CSGSurface, CSGCell, or CSGUniverse");
542 T * raw = unit.get();
550 "An engineering unit with name '", raw->getName(),
"' already exists in geometry.");
553 if constexpr (std::is_base_of_v<CSGSurface, T>)
555 else if constexpr (std::is_base_of_v<CSGCell, T>)
564 else if constexpr (std::is_base_of_v<CSGUniverse, T>)
591 template <
typename EngUnitType = CSGEngUnit>
595 const EngUnitType * typed_unit =
dynamic_cast<const EngUnitType *
>(&unit);
597 mooseError(
"Cannot get engineering unit " + name +
598 ". Engineering unit is not of specified type " +
599 MooseUtils::prettyCppType<EngUnitType>());
729 void joinOtherBase(std::unique_ptr<CSGBase> base,
const bool ignore_identical_components);
744 const bool ignore_identical_components,
745 const std::string & new_root_name_join);
762 const bool ignore_identical_components,
763 const std::string & new_root_name_base,
764 const std::string & new_root_name_join);
788 const std::tuple<Real, Real, Real> &
values);
804 const std::tuple<Real, Real, Real> &
values)
816 const std::tuple<Real, Real, Real> & distances)
845 const std::tuple<Real, Real, Real> & angles)
900 const std::tuple<Real, Real, Real> &
values)
956 std::vector<std::string> & linked_universe_names,
957 std::vector<std::string> & linked_cell_names)
const;
1033 std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs,
1045 std::map<std::string, std::reference_wrapper<const CSGCell>> & identical_cell_refs,
1058 std::map<std::string, std::reference_wrapper<const CSGUniverse>> & identical_universe_refs,
1070 std::map<std::string, std::reference_wrapper<const CSGLattice>> & identical_lattice_refs,
1129 const bool ignore_identical_universes,
1130 const std::string & new_root_name_incoming);
1146 const bool ignore_identical_universes,
1147 const std::string & new_root_name_base,
1148 const std::string & new_root_name_incoming);
1267#ifdef MOOSE_UNIT_TEST
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
std::array< Real, 2 > values
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model.
FRIEND_TEST(CSGBaseTest, testUniverseLinking)
const CSGSurfaceList & getSurfaceList() const
Get a const reference to the CSGSurfaceList object.
CSGUniverseList & getUniverseList()
Get a non-const reference to the CSGUniverseList object.
void replaceUniverseRefsByName(std::map< std::string, std::reference_wrapper< const CSGUniverse > > &identical_universe_refs, CSGBase &base)
update universe references of incoming CSGbase to point to those of existing CSGBase object based on ...
void prepareCellDeletion(const CSGCell &cell)
warn and remove cell from any universe that contains it
FRIEND_TEST(CSGBaseTest, testCellEngUnitAddErrors)
bool checkCellInBase(const CSGCell &cell) const
check that cell being accessed is a part of this CSGBase instance
const CSGCell & addCellToList(const CSGCell &cell)
Add a new cell to the cell list based on a cell reference.
const CSGCellList & getCellList() const
Get a const reference to the CSGCellList object.
CSGCellList _cell_list
List of cells associated with CSG object.
void deleteCell(const CSGCell &cell)
Remove a Cell object passed in by reference from the stored cell list.
const CSGSurface & getSurfaceByName(const std::string &name) const
Get a Surface object by name.
void applyScaling(const CSGEngUnit &unit, const std::tuple< Real, Real, Real > &values)
Scale a CSGEngUnit object in the specified x, y, and z directions.
CSGLatticeList & getLatticeList()
Get the CSGLatticeList object.
std::unique_ptr< CSGBase > clone() const
Create a deep copy of this CSGBase instance.
bool checkUniverseInBase(const CSGUniverse &universe) const
check that universe being accessed is a part of this CSGBase instance
const CSGLattice & addLatticeToList(const CSGLattice &lattice)
Add a new lattice to the lattice list based on a lattice reference.
void joinUniverseList(CSGUniverseList &univ_list, const bool ignore_identical_universes)
join a separate CSGUniverseList object to this one; root universes from univ_list will be combined in...
std::vector< std::reference_wrapper< const CSGEngUnit > > getAllEngUnits() const
Get all engineering units of all types in CSGBase.
void updateIncomingCSGReferences(CSGBase &incoming_base)
update references of incoming CSGbase to point to those of existing CSGBase object.
void renameSurface(const CSGSurface &surface, const std::string &name)
rename the specified surface
const CSGUniverse & addUniverseToList(const CSGUniverse &univ)
Add a new universe to the universe list based on a universe reference.
void replaceLatticeRefsByName(std::map< std::string, std::reference_wrapper< const CSGLattice > > &identical_lattice_refs, CSGBase &base)
update lattice references of incoming CSGbase to point to those of existing CSGBase object based on C...
std::vector< std::reference_wrapper< const CSGUniverseEngUnit > > getAllUniverseEngUnits() const
Get all universe-like engineering units.
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all cell objects.
void getLinkedUniverses(const CSGUniverse &univ, std::vector< std::string > &linked_universe_names, std::vector< std::string > &linked_cell_names) const
Recursive method to retrieve all universes and cells linked to current universe.
void applyAxisRotation(const CSGEngUnit &unit, RotationAxisType axis, const Real angle)
Apply a rotation to a CSGEngUnit object about a specified axis (X, Y, Z).
void applyTranslation(const CSGObjectVariant &csg_object, const std::tuple< Real, Real, Real > &distances)
Apply a translation to a CSG object in the specified x, y, and z directions.
CSGSurfaceList _surface_list
List of surfaces associated with CSG object.
bool hasUniverse(const std::string &name) const
Check if a universe with given name exists in CSGBase object.
CSGSurfaceList & getSurfaceList()
Get a non-const reference to the CSGSurfaceList object.
void applyRotation(const CSGEngUnit &unit, const std::tuple< Real, Real, Real > &angles)
Apply a rotation to a CSG object using (phi, theta, psi) angle notation (in degrees).
void expandAllEngUnitsCycle(std::set< std::set< std::string > > &all_type_sets)
Recursive implementation of expandAllEngUnits().
bool hasLattice(const std::string &name) const
Check if a lattice with given name exists in CSGBase object.
const CSGUniverseList & getUniverseList() const
Get a const reference to the CSGUniverseList object.
void expandAllEngUnits()
Expand all registered engineering units into basic CSG objects.
void applyAxisRotation(const CSGObjectVariant &csg_object, RotationAxisType axis, const Real angle)
Apply a rotation to a CSG object about a specified axis (X, Y, Z).
CSGLatticeList _lattice_list
List of lattices associated with CSG object.
void checkRegionSurfaces(const CSGRegion ®ion) const
check that surfaces used in this region are a part of this CSGBase instance
void renameEngUnit(const CSGEngUnit &unit, const std::string &name)
Rename the specified engineering unit.
std::vector< std::reference_wrapper< const CSGUniverse > > getAllUniverses() const
Get all universe objects.
CSGEngUnitList _eng_unit_list
Container for all associated engineering units.
const CSGUniverse & getUniverseByName(const std::string &name)
Get a universe object by name.
const CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a unique surface pointer to this base instance
FRIEND_TEST(CSGBaseTest, testCheckRegionSurfaces)
Friends for unit testing.
void setUniverseAtLatticeIndex(const CSGLattice &lattice, const CSGUniverse &universe, std::pair< int, int > index)
set location in the lattice to be the provided universe
void joinCellList(CSGCellList &cell_list, const bool ignore_identical_cells)
join a separate CSGCellList object to this one
void joinLatticeList(CSGLatticeList &lattice_list, const bool ignore_identical_lattices)
join a separate CSGLatticeList object to this one
void removeCellsFromUniverse(const CSGUniverse &universe, std::vector< std::reference_wrapper< const CSGCell > > &cells)
Remove a list of cells from an existing universe.
void joinOtherBase(std::unique_ptr< CSGBase > base, const bool ignore_identical_components)
Join another CSGBase object to this one.
void renameUniverse(const CSGUniverse &universe, const std::string &name)
rename the specified universe
FRIEND_TEST(CSGBaseTest, testUnivEngUnitAddErrors)
void resetCellFill(const CSGCell &cell)
reset the fill of the specified cell to void
const EngUnitType & getEngUnitByName(const std::string &name) const
Get a engineering unit object of the specified type by name.
bool hasEngUnit(const std::string &name) const
Check if an engineeering unit with given name exists in CSGBase object.
void rebuildEngUnitList()
rebuilds the list of raw pointers to engineering units by iterating through the surface,...
const LatticeType & addLattice(std::unique_ptr< LatticeType > lattice)
add a unique lattice pointer to this base instance; universes that make the lattice must already be a...
void prepareUniverseDeletion(const CSGUniverse &universe) const
error if universe is the root, used in any lattice, or used as a cell fill
void replaceUniverseRefs(const CSGUniverse &old_univ, const CSGUniverse &new_univ)
Replace all cell fills and lattice elements/outers referencing old_univ with new_univ.
void addTransformation(const CSGEngUnit &unit, TransformationType type, const std::tuple< Real, Real, Real > &values)
Apply a transformation to a CSGEngUnit object.
bool hasSurface(const std::string &name) const
Check if a surface with given name exists in CSGBase object.
const CSGLatticeList & getLatticeList() const
Get a const reference to the CSGLatticeList object.
void applyScaling(const CSGObjectVariant &csg_object, const std::tuple< Real, Real, Real > &values)
Scale a CSG object in the specified x, y, and z directions.
CSGRegion expandEngUnit(const CSGSurfaceEngUnit &unit)
Expand a surface-like engineering unit into basic CSGSurface(s) and return the CSGRegion representing...
void deleteLattice(const CSGLattice &lattice)
Remove a Lattice object passed in by reference from the stored lattice list.
void renameCell(const CSGCell &cell, const std::string &name)
rename the specified cell
void applyTranslation(const CSGEngUnit &unit, const std::tuple< Real, Real, Real > &distances)
Apply a translation to a CSGEngUnit object in the specified x, y, and z directions.
void renameRootUniverse(const std::string &name)
rename the root universe for this instance (default is ROOT_UNIVERSE)
const LatticeType & getLatticeByName(const std::string &name)
Get a lattice object of the specified type by name.
const CSGEngUnitList & getEngUnitList() const
Get a const reference to the CSGEngUnitList object.
void addCellsToUniverse(const CSGUniverse &universe, std::vector< std::reference_wrapper< const CSGCell > > &cells)
Add a list of cells to an existing universe.
void resetLatticeOuter(const CSGLattice &lattice)
reset the outer fill for the lattice to VOID
const CSGUniverse & createUniverse(const std::string &name)
Create an empty Universe object.
bool hasCell(const std::string &name) const
Check if a cell with given name exists in CSGBase object.
const CSGUniverse & getRootUniverse() const
Get the Root Universe object.
const CSGUniverseEngUnit * universeToEngUnit(const CSGUniverse &univ) const
Returns the CSGUniverseEngUnit pointer if univ is an eng unit, nullptr otherwise.
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices() const
Get all lattice objects.
void removeCellFromUniverse(const CSGUniverse &universe, const CSGCell &cell)
Remove a cell from an existing universe.
std::vector< std::reference_wrapper< const CSGCellEngUnit > > getAllCellEngUnits() const
Get all cell-like engineering units in CSGBase.
void replaceCellRefs(const CSGCell &old_cell, const CSGCell &new_cell)
Replace all old_cell references with new_cell across all universes in the base.
bool checkSurfaceInBase(const CSGSurface &surface) const
check that surface being accessed is a part of this CSGBase instance
void setLatticeUniverses(const CSGLattice &lattice, std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > &universes)
Set provided universes as the layout of the lattice.
bool operator==(const CSGBase &other) const
Operator overload for checking if two CSGBase objects are equal.
void replaceCellRefsByName(std::map< std::string, std::reference_wrapper< const CSGCell > > &identical_cell_refs, CSGBase &base)
update cell references of incoming CSGbase to point to those of existing CSGBase object based on CSGC...
void deleteSurface(const CSGSurface &surface)
Remove a Surface object passed in by reference from the stored surface list.
void applyRotation(const CSGObjectVariant &csg_object, const std::tuple< Real, Real, Real > &angles)
Apply a rotation to a CSG object using (phi, theta, psi) angle notation (in degrees).
FRIEND_TEST(CSGBaseTest, testAddGetSurface)
void replaceSurfaceRefsWithRegion(const CSGSurface &old_surf, const CSGRegion &sub_region)
Replace all region occurrences of old_surf with the tokens from sub_region across all cells in the ba...
void addCellToUniverse(const CSGUniverse &universe, const CSGCell &cell)
Add a cell to an existing universe.
const CSGSurfaceEngUnit * surfaceToEngUnit(const CSGSurface &surf) const
Returns the CSGSurfaceEngUnit pointer if surf is an eng unit, nullptr otherwise.
void prepareSurfaceDeletion(const CSGSurface &surface) const
error if surface is referenced in any cell region
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get all surface objects.
void replaceSurfaceRefsByName(std::map< std::string, std::reference_wrapper< const CSGSurface > > &identical_surface_refs, CSGBase &base)
update surface references of incoming CSGBase to point to those of existing CSGBase object based on C...
void updateCellRegion(const CSGCell &cell, const CSGRegion ®ion)
change the region of the specified cell
std::vector< std::reference_wrapper< const CSGSurfaceEngUnit > > getAllSurfaceEngUnits() const
Get all surface-like engineering units in CSGBase.
void setLatticeOuter(const CSGLattice &lattice, const std::string &outer_name)
Set the outer fill for the lattice to the material name provided.
bool areUniversesLinked() const
Check whether all universes and cells in this CSGBase are reachable from the root universe through th...
const T & addEngUnit(std::unique_ptr< T > unit, const CSGUniverse *add_to_univ=nullptr)
Add an engineering unit (surface-, cell-, or universe-like object) to this CSGBase.
const CSGCell & createCell(const std::string &name, const std::string &mat_name, const CSGRegion ®ion, const CSGUniverse *add_to_univ=nullptr)
Create a Material Cell object.
bool checkEngUnitInBase(const CSGEngUnit &unit) const
check that engineering unit being accessed is a part of this CSGBase instance
bool operator!=(const CSGBase &other) const
Operator overload for checking if two CSGBase objects are not equal.
CSGBase()
Default constructor.
const CSGCellEngUnit * cellToEngUnit(const CSGCell &cell) const
Returns the CSGCellEngUnit pointer if cell is an eng unit, nullptr otherwise.
void renameLattice(const CSGLattice &lattice, const std::string &name)
rename the lattice
void joinSurfaceList(CSGSurfaceList &surf_list, const bool ignore_identical_surfaces)
join a separate CSGSurfaceList object to this one
void deleteEngUnit(const CSGEngUnit &unit)
Remove an engineering unit passed in by reference from the stored engineering unit list.
CSGSurface & getSurface(const std::string &name)
Get a Surface object by name.
void checkUniverseLinking() const
Check universes linked to root universe match universes defined in _universe_list.
FRIEND_TEST(CSGBaseTest, testEngUnitLinking)
bool checkLatticeInBase(const CSGLattice &lattice) const
check that lattice being accessed is a part of this CSGBase instance
const CSGCell & getCellByName(const std::string &name) const
Get a Cell object by name.
CSGUniverseList _universe_list
List of universes associated with CSG object.
nlohmann::json generateOutput() const
generate the JSON representation output for the CSG object
CSGCellList & getCellList()
Get a non-const reference to the CSGCellList object.
void addTransformation(const CSGObjectVariant &csg_object, TransformationType type, const std::tuple< Real, Real, Real > &values)
Apply a transformation to a CSG object.
void updateCellFill(const CSGCell &cell, const std::string &mat_name)
change the fill of the specified cell to a material fill
void deleteUniverse(const CSGUniverse &univ)
Remove a Universe object passed in by reference from the stored universe list.
CSGCellEngUnit is an abstract base class for "engineering units" that are cell-like.
CSGCellList creates a container for CSGCell objects to pass to CSGBase object.
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
bool hasCell(const std::string &name) const
return whether cell with given name exists in cell list
CSGCell & getCell(const std::string &name) const
Get the CSGCell by name.
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell,...
CSGEngUnitList is a non-owning index of CSGEngUnit objects stored in the type lists (CSGSurfaceList,...
CSGEngUnit & addEngUnit(CSGEngUnit &unit)
Register an engineering unit in this index.
std::vector< std::reference_wrapper< const CSGSurfaceEngUnit > > getAllSurfaceEngUnits() const
Get all surface-like engineering units.
CSGEngUnit & getEngUnit(const std::string &name) const
Get an engineering unit by name.
std::vector< std::reference_wrapper< const CSGUniverseEngUnit > > getAllUniverseEngUnits() const
Get all universe-like engineering units.
std::vector< std::reference_wrapper< const CSGEngUnit > > getAllEngUnits() const
Get all engineering units of all types in the list.
std::vector< std::reference_wrapper< const CSGCellEngUnit > > getAllCellEngUnits() const
Get all cell-like engineering units.
bool hasEngUnit(const std::string &name) const
Return whether an engineering unit with the given name exists in this list.
CSGEngUnit is the abstract base class for all "engineering unit" types in the CSG system.
CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.
CSGLattice & addLattice(std::unique_ptr< CSGLattice > lattice, const bool ignore_identical_lattice=false)
add an existing lattice to list.
void renameLattice(const CSGLattice &lattice, const std::string &name)
rename the specified lattice
CSGLattice & getLattice(const std::string &name) const
Get a Lattice from the list by its name.
bool hasLattice(const std::string &name) const
return whether lattice with given name exists in lattice list
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices() const
Get all the lattices in CSGBase instance.
CSGLattice is the abstract class for defining lattices.
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection,...
CSGSurfaceEngUnit is an abstract base class for "engineering units" that can be used as surfaces in c...
CSGSurfaceList is a container for storing CSGSurface objects in the CSGBase object.
CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf, const bool ignore_identical_surface=false)
add a surface object to existing SurfaceList.
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get list of references to all surfaces in surface list.
CSGSurface & getSurface(const std::string &name) const
Get a surface by name.
bool hasSurface(const std::string &name) const
return whether surface with given name exists in surface list
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface,...
CSGUniverseEngUnit is an abstract base class for "engineering units" that are universe-like.
CSGUniverseList creates a container for CSGUniverse objects to pass to CSGBase.
std::vector< std::reference_wrapper< const CSGUniverse > > getAllUniverses() const
Get all the universes in CSGBase instance.
const CSGUniverse & getRoot() const
Get the root universe.
bool hasUniverse(const std::string &name) const
return whether universe with given name exists in universe list
CSGUniverse & getUniverse(const std::string &name) const
Get a Universe from the list by its name.
CSGUniverse & addUniverse(const std::string &name)
create an empty universe
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe,...
const std::string & getName() const
Get the name of the universe.
std::variant< std::reference_wrapper< const CSGSurface >, std::reference_wrapper< const CSGCell >, std::reference_wrapper< const CSGUniverse >, std::reference_wrapper< const CSGRegion >, std::reference_wrapper< const CSGLattice >, std::reference_wrapper< const CSGEngUnit > > CSGObjectVariant
Define a variant type that can hold references to different CSG object types.
TransformationType
Enumeration of transformation types that can be applied to CSG objects.
RotationAxisType
Enumeration of axis types for rotations.