26 : _surface_list(other_base.getSurfaceList()),
83 "' is a CSGSurfaceEngUnit and must be added via addEngUnit(), not addSurface().");
92 const auto & cell = cell_ref.get();
93 for (
const auto & region_surf : cell.getRegion().getSurfaces())
94 if (region_surf.get() == surface)
97 " as it is used in region definition of cell with name ",
108 " cannot be deleted as it is different from the surface of the same name in the "
109 "CSGBase instance.");
121 const auto name = cell.
getName();
129 "' is a CSGCellEngUnit and must be added via addEngUnit(), not addCellToList().");
134 if (fill_type ==
"VOID")
136 else if (fill_type ==
"CSG_MATERIAL")
141 else if (fill_type ==
"LATTICE")
149 else if (fill_type ==
"UNIVERSE")
155 mooseError(
"Cell " + name +
" has unrecognized fill type " + fill_type);
162 const auto name = univ.
getName();
170 "' is a CSGUniverseEngUnit and must be added via addEngUnit(), not "
171 "addUniverseToList().");
177 std::vector<std::reference_wrapper<const CSGCell>> current_univ_cells;
178 for (
const auto & univ_cell : univ_cells)
187 const auto name = lattice.
getName();
192 auto cloned_lattice = lattice.
clone();
197 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> current_univ_map;
200 std::vector<std::reference_wrapper<const CSGUniverse>> current_univ_list;
201 for (
const auto & univ_ref : univ_list)
203 current_univ_map.push_back(current_univ_list);
207 if (current_univ_map.size() > 0)
208 cloned_lattice->setUniverses(current_univ_map);
214 cloned_lattice->updateOuter(outer_univ_ref);
227 " cannot be deleted as it is different from the lattice of the same name in the "
228 "CSGBase instance.");
233 const auto & cell = cell_ref.get();
234 if ((cell.getFillType() ==
"LATTICE") && (cell.getFillLattice() == lattice))
235 mooseError(
"Cannot delete lattice with name ",
237 " as it is used as the fill of cell with name ",
246 const std::string & mat_name,
280 if (add_to_univ && (&fill_univ == add_to_univ))
282 " cannot be filled with the same universe to which it is being added.");
303 for (
const auto & univ_ref : univ_list)
305 const CSGUniverse & univ_in_lattice = univ_ref.get();
306 if (&univ_in_lattice == add_to_univ)
308 " cannot be filled with a lattice containing the same universe to which it is "
325 const auto & univ = univ_ref.get();
326 for (
const auto & univ_cell : univ.getAllCells())
327 if (cell == univ_cell.get())
334 " from universe with name ",
336 " before cell deletion.");
348 " cannot be deleted as it is different from the cell of the same name in the "
349 "CSGBase instance.");
363 "' because it is a CSGCellEngUnit.");
368 " that is being updated is different " +
369 "from the cell of the same name in the CSGBase instance.");
380 "' because it is a CSGCellEngUnit.");
384 " that is being updated is different " +
385 "from the cell of the same name in the CSGBase instance.");
396 "' because it is a CSGCellEngUnit.");
400 " that is being updated is different " +
401 "from the cell of the same name in the CSGBase instance.");
412 "' because it is a CSGCellEngUnit.");
417 " is being used as a cell fill that is different from the universe of the same name "
418 "in the CSGBase instance.");
421 " that is being updated is different " +
422 "from the cell of the same name in the CSGBase instance.");
433 "' because it is a CSGCellEngUnit.");
438 " is being used as a cell fill that is different from the lattice of the same name "
439 "in the CSGBase instance.");
442 " that is being updated is different " +
443 "from the cell of the same name in the CSGBase instance.");
450 std::vector<std::reference_wrapper<const CSGCell>> & cells)
461 mooseError(
"Cannot delete root universe from CSGBase instance");
466 for (
const auto & lat_univ : lat.get().getUniqueUniverses())
467 if (univ == lat_univ.get())
468 mooseError(
"Cannot delete universe with name ",
470 " as it is used in lattice with name ",
471 lat.get().getName());
472 if ((lat.get().getOuterType() ==
"UNIVERSE") && (lat.get().getOuterUniverse() == univ))
473 mooseError(
"Cannot delete universe with name ",
475 " as it is used as the outer universe of lattice with name ",
476 lat.get().getName());
482 const auto & cell = cell_ref.get();
483 if ((cell.getFillType() ==
"UNIVERSE") && (cell.getFillUniverse() == univ))
484 mooseError(
"Cannot delete universe with name ",
486 " as it is used as the fill of cell with name ",
497 " cannot be deleted as it is different from the universe of the same name in the "
498 "CSGBase instance.");
512 "' cannot add cells because it is a CSGUniverseEngUnit.");
518 " that is different from the cell of the same name in the CSGBase instance.");
522 " that is different " +
523 "from the universe of the same name in the CSGBase instance.");
530 std::vector<std::reference_wrapper<const CSGCell>> & cells)
532 for (
auto & c : cells)
541 mooseError(
"A cell named " + cell.
getName() +
" is being removed from universe " +
543 " that is different from the cell of the same name in the CSGBase instance.");
546 mooseError(
"Cells are being removed from a universe named " + universe.
getName() +
547 " that is different " +
548 "from the universe of the same name in the CSGBase instance.");
557 std::vector<std::reference_wrapper<const CSGCell>> & cells)
559 for (
auto & c : cells)
568 mooseError(
"Cannot set outer for lattice " + name +
569 ". Lattice is different from the lattice of the same name in the "
570 "CSGBase instance.");
579 mooseError(
"Cannot set outer universe for lattice " + name +
580 ". Lattice is different from the lattice of the same name in the "
581 "CSGBase instance.");
583 mooseError(
"Cannot set outer universe for lattice " + name +
". Outer universe " +
584 outer_univ.
getName() +
" is not in the CSGBase instance.");
593 mooseError(
"Cannot reset outer for lattice " + name +
594 ". Lattice is different from the lattice of the same name in the "
595 "CSGBase instance.");
602 std::pair<int, int> index)
606 mooseError(
"Cannot set universe at index for lattice " + name +
607 ". Lattice is different from the lattice of the same name in the "
608 "CSGBase instance.");
611 ". Universe is not in the CSGBase instance.");
618 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> & universes)
622 mooseError(
"Cannot set universes for lattice " + name +
623 ". Lattice is different from the lattice of the same name in the "
624 "CSGBase instance.");
626 for (
auto univ_list : universes)
629 mooseError(
"Cannot set universes for lattice " + name +
". Universe " + univ.getName() +
630 " is not in the CSGBase instance.");
637 const std::tuple<Real, Real, Real> &
values)
641 [&](
const auto & obj)
643 using T = std::decay_t<
decltype(obj.get())>;
647 if constexpr (std::is_same_v<T, CSGCell>)
649 const CSGCell & cell = obj.get();
651 mooseError(
"Cannot apply transformation to cell ",
653 " that is not in this CSGBase instance.");
657 mooseAssert(mutable_cell == cell,
"Mutable cell does not match const cell passed in.");
660 else if constexpr (std::is_same_v<T, CSGSurface>)
664 mooseError(
"Cannot apply transformation to surface ",
666 " that is not in this CSGBase instance.");
670 mooseAssert(mutable_surface == surface,
671 "Mutable surface does not match const surface passed in.");
674 else if constexpr (std::is_same_v<T, CSGUniverse>)
678 mooseError(
"Cannot apply transformation to universe ",
680 " that is not in this CSGBase instance.");
684 mooseAssert(mutable_universe == universe,
685 "Mutable universe does not match const universe passed in.");
688 else if constexpr (std::is_same_v<T, CSGLattice>)
692 mooseError(
"Cannot apply transformation to lattice ",
694 " that is not in this CSGBase instance.");
698 mooseAssert(mutable_lattice == lattice,
699 "Mutable lattice does not match const lattice passed in.");
702 else if constexpr (std::is_same_v<T, CSGRegion>)
710 mooseError(
"Cannot apply transformation to region with surface ",
712 " that is not in this CSGBase instance.");
716 else if constexpr (std::is_same_v<T, CSGEngUnit>)
720 mooseError(
"Cannot apply transformation to engineering unit ",
722 " that is not in this CSGBase instance.");
726 s->addTransformation(type,
values);
728 c->addTransformation(type,
values);
730 u->addTransformation(type,
values);
734 "' has an unrecognized type for transformation.");
737 mooseError(
"Transformation not implemented for this object type: ",
typeid(T).name());
766 mooseError(
"Invalid axis type provided for axis rotation.");
777 if (ignore_identical_components)
780 joinCellList(base->getCellList(), ignore_identical_components);
789 const bool ignore_identical_components,
790 const std::string & new_root_name_join)
794 if (ignore_identical_components)
797 joinCellList(base->getCellList(), ignore_identical_components);
799 joinUniverseList(base->getUniverseList(), ignore_identical_components, new_root_name_join);
806 const bool ignore_identical_components,
807 const std::string & new_root_name_base,
808 const std::string & new_root_name_join)
812 if (ignore_identical_components)
815 joinCellList(base->getCellList(), ignore_identical_components);
818 base->getUniverseList(), ignore_identical_components, new_root_name_base, new_root_name_join);
828 std::map<std::string, std::reference_wrapper<const CSGSurface>> identical_surface_refs;
830 for (
const auto & [surf_name, surf_ptr] : surf_list_map)
836 std::map<std::string, std::reference_wrapper<const CSGCell>> identical_cell_refs;
837 auto & cell_list_map = incoming_base.getCellList().getCellListMap();
838 for (
const auto & [cell_name, cell_ptr] : cell_list_map)
839 if (hasCell(cell_name))
840 identical_cell_refs.insert({cell_name, getCellByName(cell_name)});
844 std::map<std::string, std::reference_wrapper<const CSGUniverse>> identical_universe_refs;
845 auto & universe_list_map = incoming_base.getUniverseList().getUniverseListMap();
846 for (
const auto & [univ_name, univ_ptr] : universe_list_map)
847 if (hasUniverse(univ_name))
848 identical_universe_refs.insert({univ_name, getUniverseByName(univ_name)});
852 std::map<std::string, std::reference_wrapper<const CSGLattice>> identical_lattice_refs;
853 auto & lattice_list_map = incoming_base.getLatticeList().getLatticeListMap();
854 for (
const auto & [lat_name, lat_ptr] : lattice_list_map)
855 if (hasLattice(lat_name))
856 identical_lattice_refs.insert({lat_name, getLatticeByName(lat_name)});
860 if (!identical_surface_refs.empty())
861 replaceSurfaceRefsByName(identical_surface_refs, incoming_base);
863 if (!identical_cell_refs.empty())
864 replaceCellRefsByName(identical_cell_refs, incoming_base);
866 if (!identical_universe_refs.empty())
867 replaceUniverseRefsByName(identical_universe_refs, incoming_base);
869 if (!identical_lattice_refs.empty())
870 replaceLatticeRefsByName(identical_lattice_refs, incoming_base);
874CSGBase::replaceSurfaceRefsByName(
875 std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs,
880 cell_ptr->updateCellRegionSurfaces(identical_surface_refs);
884CSGBase::replaceCellRefsByName(
885 std::map<std::string, std::reference_wrapper<const CSGCell>> & identical_cell_refs,
890 for (
auto & [cell_name, cell_ref] : identical_cell_refs)
891 if (univ_ptr->hasCell(cell_name))
893 univ_ptr->removeCell(cell_name);
894 univ_ptr->addCell(cell_ref);
899CSGBase::replaceUniverseRefsByName(
900 std::map<std::string, std::reference_wrapper<const CSGUniverse>> & identical_universe_refs,
906 const auto fill_type = cell_ptr->getFillType();
907 const auto fill_name = cell_ptr->getFillName();
908 if ((fill_type ==
"UNIVERSE") &&
909 (identical_universe_refs.find(fill_name) != identical_universe_refs.end()))
911 const CSGUniverse * univ_ptr = &identical_universe_refs.at(fill_name).get();
912 cell_ptr->updateCellFill(univ_ptr);
918 for (
auto & [univ_name, univ_ref] : identical_universe_refs)
921 if (lat_ptr->hasUniverse(univ_name))
924 const auto univ_indices = lat_ptr->getUniverseIndices(univ_name);
925 for (
const auto & index : univ_indices)
926 lat_ptr->setUniverseAtIndex(univ_ref, index);
929 if ((lat_ptr->getOuterType() ==
"UNIVERSE") &&
930 (lat_ptr->getOuterUniverse().getName() == univ_name))
931 lat_ptr->updateOuter(univ_ref);
936CSGBase::replaceLatticeRefsByName(
937 std::map<std::string, std::reference_wrapper<const CSGLattice>> & identical_lattice_refs,
943 const auto fill_type = cell_ptr->getFillType();
944 const auto fill_name = cell_ptr->getFillName();
945 if ((fill_type ==
"LATTICE") &&
946 (identical_lattice_refs.find(fill_name) != identical_lattice_refs.end()))
948 const CSGLattice * lat_ptr = &identical_lattice_refs.at(fill_name).get();
949 cell_ptr->updateCellFill(lat_ptr);
955CSGBase::joinSurfaceList(
CSGSurfaceList & surf_list,
const bool ignore_identical_surfaces)
958 for (
auto & s : surf_list_map)
959 _surface_list.addSurface(std::move(s.second), ignore_identical_surfaces);
963CSGBase::joinCellList(
CSGCellList & cell_list,
const bool ignore_identical_cells)
966 for (
auto & c : cell_list_map)
967 _cell_list.addCell(std::move(c.second), ignore_identical_cells);
971CSGBase::joinLatticeList(
CSGLatticeList & lattice_list,
const bool ignore_identical_lattices)
974 for (
auto & lat : lat_list_map)
975 _lattice_list.addLattice(std::move(lat.second), ignore_identical_lattices);
979CSGBase::rebuildEngUnitList()
985 for (
auto & [name, surf] : _surface_list.getSurfaceListMap())
987 _eng_unit_list.addEngUnit(*eu);
988 for (
auto & [name, cell] : _cell_list.getCellListMap())
990 _eng_unit_list.addEngUnit(*eu);
991 for (
auto & [name, univ] : _universe_list.getUniverseListMap())
993 _eng_unit_list.addEngUnit(*eu);
997CSGBase::joinUniverseList(
CSGUniverseList & univ_list,
const bool ignore_identical_universes)
1001 auto & root = getRootUniverse();
1002 for (
auto & u : univ_list_map)
1004 if (u.second->isRoot())
1007 auto all_cells = u.second->getAllCells();
1008 for (
auto & cell : all_cells)
1009 addCellToUniverse(root, cell);
1012 _universe_list.addUniverse(std::move(u.second), ignore_identical_universes);
1018 const bool ignore_identical_universes,
1019 const std::string & new_root_name_incoming)
1025 for (
auto & u : all_univs)
1027 if (u.second->isRoot())
1030 auto all_cells = u.second->getAllCells();
1031 createUniverse(new_root_name_incoming, all_cells);
1034 _universe_list.addUniverse(std::move(u.second), ignore_identical_universes);
1040 const bool ignore_identical_universes,
1041 const std::string & new_root_name_base,
1042 const std::string & new_root_name_incoming)
1047 auto & root = getRootUniverse();
1048 auto root_cells = root.getAllCells();
1049 createUniverse(new_root_name_base, root_cells);
1050 removeCellsFromUniverse(root, root_cells);
1054 for (
auto & u : all_univs)
1056 if (u.second->isRoot())
1059 auto all_cells = u.second->getAllCells();
1060 createUniverse(new_root_name_incoming, all_cells);
1063 _universe_list.addUniverse(std::move(u.second), ignore_identical_universes);
1073 if (!checkSurfaceInBase(s))
1074 mooseError(
"Region is being set with a surface named " + s.getName() +
1075 " that is different from the surface of the same name in the CSGBase instance.");
1082 auto name = surface.
getName();
1084 auto & list_surf = _surface_list.getSurface(name);
1086 return &surface == &list_surf;
1090CSGBase::checkCellInBase(
const CSGCell & cell)
const
1094 auto & list_cell = _cell_list.getCell(name);
1096 return &cell == &list_cell;
1102 auto name = universe.
getName();
1104 auto & list_univ = _universe_list.getUniverse(name);
1106 return &universe == &list_univ;
1112 auto name = lattice.
getName();
1114 auto & list_lattice = _lattice_list.getLattice(name);
1116 return &lattice == &list_lattice;
1122 const auto & name = unit.
getName();
1124 const auto & list_unit = _eng_unit_list.getEngUnit(name);
1126 return &unit == &list_unit;
1130CSGBase::renameEngUnit(
const CSGEngUnit & unit,
const std::string & name)
1136 renameSurface(*surf, name);
1137 else if (
const auto * cell =
dynamic_cast<const CSGCellEngUnit *
>(&unit))
1138 renameCell(*cell, name);
1140 renameUniverse(*univ, name);
1143 "Engineering unit '", unit.
getName(),
"' has an unrecognized type and cannot be renamed.");
1147CSGBase::renameSurface(
const CSGSurface & surface,
const std::string & name)
1151 if (surfaceToEngUnit(surface))
1152 if (_eng_unit_list.hasEngUnit(name))
1153 mooseError(
"Cannot rename surface " + surface.
getName() +
" to " + name +
". " +
1154 surface.
getName() +
" is an engineering unit and a unit with name " + name +
1155 " already exists.");
1157 _surface_list.renameSurface(surface, name);
1161CSGBase::renameCell(
const CSGCell & cell,
const std::string & name)
1165 if (cellToEngUnit(cell))
1166 if (_eng_unit_list.hasEngUnit(name))
1168 " is an engineering unit and a unit with name " + name +
" already exists.");
1170 _cell_list.renameCell(cell, name);
1174CSGBase::renameUniverse(
const CSGUniverse & universe,
const std::string & name)
1178 if (universeToEngUnit(universe))
1179 if (_eng_unit_list.hasEngUnit(name))
1180 mooseError(
"Cannot rename universe " + universe.
getName() +
" to " + name +
". " +
1181 universe.
getName() +
" is an engineering unit and a unit with name " + name +
1182 " already exists.");
1184 _universe_list.renameUniverse(universe, name);
1188CSGBase::checkUniverseLinking()
const
1190 std::vector<std::string> linked_universe_names;
1191 std::vector<std::string> linked_cell_names;
1194 getLinkedUniverses(getRootUniverse(), linked_universe_names, linked_cell_names);
1198 for (
const CSGUniverse & univ : getAllUniverses())
1199 if (std::find(linked_universe_names.begin(), linked_universe_names.end(), univ.getName()) ==
1200 linked_universe_names.end())
1201 mooseWarning(
"Universe with name ", univ.getName(),
" is not linked to root universe.");
1205 for (
const CSGCell & cell : getAllCells())
1206 if (std::find(linked_cell_names.begin(), linked_cell_names.end(), cell.getName()) ==
1207 linked_cell_names.end())
1208 mooseWarning(
"Cell with name ", cell.getName(),
" is not linked to root universe.");
1212CSGBase::areUniversesLinked()
const
1214 std::vector<std::string> linked_univs, linked_cells;
1215 getLinkedUniverses(getRootUniverse(), linked_univs, linked_cells);
1217 for (
const CSGUniverse & univ : getAllUniverses())
1218 if (std::find(linked_univs.begin(), linked_univs.end(), univ.getName()) == linked_univs.end())
1221 for (
const CSGCell & cell : getAllCells())
1222 if (std::find(linked_cells.begin(), linked_cells.end(), cell.getName()) == linked_cells.end())
1230 std::vector<std::string> & linked_universe_names,
1231 std::vector<std::string> & linked_cell_names)
const
1233 linked_universe_names.push_back(univ.
getName());
1235 for (
const CSGCell & cell : univ_cells)
1237 linked_cell_names.push_back(cell.getName());
1238 if (cell.getFillType() ==
"UNIVERSE")
1239 getLinkedUniverses(cell.getFillUniverse(), linked_universe_names, linked_cell_names);
1240 else if (cell.getFillType() ==
"LATTICE")
1242 const auto & lattice = cell.getFillLattice();
1243 for (
const auto & univ_list : lattice.getUniverses())
1244 for (
const auto & univ_ref : univ_list)
1246 const CSGUniverse & lattice_univ = univ_ref.get();
1247 getLinkedUniverses(lattice_univ, linked_universe_names, linked_cell_names);
1250 if (lattice.getOuterType() ==
"UNIVERSE")
1252 const CSGUniverse & outer_univ = lattice.getOuterUniverse();
1253 getLinkedUniverses(outer_univ, linked_universe_names, linked_cell_names);
1262 if (!checkEngUnitInBase(unit))
1265 " cannot be deleted as it is different from the engineering unit of the same name "
1266 "in the CSGBase instance.");
1270 deleteSurface(
static_cast<const CSGSurface &
>(*surf_unit));
1271 else if (
const auto * cell_unit =
dynamic_cast<const CSGCellEngUnit *
>(&unit))
1272 deleteCell(
static_cast<const CSGCell &
>(*cell_unit));
1274 deleteUniverse(
static_cast<const CSGUniverse &
>(*univ_unit));
1277 "Engineering unit '", unit.
getName(),
"' has an unrecognized type and cannot be deleted.");
1281CSGBase::expandAllEngUnits()
1283 std::set<std::set<std::string>> all_type_sets;
1284 expandAllEngUnitsCycle(all_type_sets);
1288CSGBase::expandAllEngUnitsCycle(std::set<std::set<std::string>> & all_type_sets)
1298 std::set<std::string> current_types;
1299 for (
const auto & u : getAllEngUnits())
1300 current_types.insert(u.get().getUnitType());
1302 if (all_type_sets.count(
1304 mooseError(
"Circular dependency detected in engineering unit expansion");
1306 all_type_sets.insert(current_types);
1310 std::vector<const CSGSurfaceEngUnit *> surfs;
1311 std::vector<const CSGCellEngUnit *> cells;
1312 std::vector<const CSGUniverseEngUnit *> univs;
1313 for (
const auto & u : getAllSurfaceEngUnits())
1314 surfs.push_back(&u.get());
1315 for (
const auto & u : getAllCellEngUnits())
1316 cells.push_back(&u.get());
1317 for (
const auto & u : getAllUniverseEngUnits())
1318 univs.push_back(&u.get());
1321 for (
const auto * s : surfs)
1323 for (
const auto * c : cells)
1325 for (
const auto * u : univs)
1330 if (!getAllEngUnits().empty())
1331 expandAllEngUnitsCycle(all_type_sets);
1348 auto unit_base = mutable_unit.getBase();
1349 if ((unit_base.getAllCells().size() > 0) || (unit_base.getAllUniverses().size() > 1))
1351 mutable_unit.getName(),
1353 mutable_unit.getUnitType(),
1354 " contains either cells or universes (beyond the root universe) after expansion, "
1355 "but should only contain surfaces.");
1358 joinOtherBase(mutable_unit.releaseBase(),
false);
1361 CSGRegion expanded_region = mutable_unit.getExpandedRegion();
1364 const auto & trans =
static_cast<const CSGSurface &
>(mutable_unit).getTransformations();
1366 for (
const auto & surf_ref : expanded_region.
getSurfaces())
1368 CSGSurface & mutable_surf = _surface_list.getSurface(surf_ref.get().getName());
1369 for (
const auto & [trans_type,
values] : trans)
1374 replaceSurfaceRefsWithRegion(
static_cast<const CSGSurface &
>(mutable_unit), expanded_region);
1378 deleteEngUnit(unit);
1379 return expanded_region;
1397 const CSGCell & expanded_cell = mutable_unit.getExpandedCell();
1400 joinOtherBase(mutable_unit.releaseBase(),
false);
1403 const auto & trans =
static_cast<const CSGCell &
>(mutable_unit).getTransformations();
1406 CSGCell & mutable_cell = _cell_list.getCell(expanded_cell.
getName());
1407 for (
const auto & [trans_type,
values] : trans)
1413 if (getRootUniverse().hasCell(expanded_cell.
getName()))
1414 removeCellFromUniverse(getRootUniverse(), expanded_cell);
1417 replaceCellRefs(
static_cast<const CSGCell &
>(mutable_unit), expanded_cell);
1420 deleteEngUnit(unit);
1421 return expanded_cell;
1427 auto unit_name = unit.
getName();
1432 auto & mutable_unit =
static_cast<CSGUniverseEngUnit &
>(_universe_list.getUniverse(unit_name));
1441 auto & pre_join_univ = mutable_unit.getExpandedUniverse();
1442 auto expanded_name = pre_join_univ.getName();
1451 auto unit_base = mutable_unit.releaseBase();
1452 if (expanded_name == getRootUniverse().getName())
1455 auto new_expanded_name = unit_name +
"_expanded_root";
1458 " has an expanded root universe named " + expanded_name +
1459 ", which is identical to the name of the current root universe. The expanded "
1460 "universe will be renamed " +
1461 new_expanded_name +
".");
1464 unit_base->renameRootUniverse(new_expanded_name);
1465 expanded_name = new_expanded_name;
1471 joinOtherBase(std::move(unit_base),
false, expanded_name);
1475 const CSGUniverse & expanded_univ = getUniverseByName(expanded_name);
1478 const auto & trans =
static_cast<const CSGUniverse &
>(mutable_unit).getTransformations();
1482 for (
const auto & [trans_type,
values] : trans)
1487 replaceUniverseRefs(
static_cast<const CSGUniverse &
>(mutable_unit), expanded_univ);
1490 deleteEngUnit(unit);
1491 return expanded_univ;
1498 for (
const auto & cell_ref : getAllCells())
1500 const CSGCell & cell = cell_ref.get();
1502 updateCellFill(cell, &new_univ);
1506 for (
const auto & lat_ref : getAllLattices())
1510 setLatticeOuter(lat, new_univ);
1513 for (std::size_t row = 0; row < lat_map.size(); ++row)
1514 for (std::size_t col = 0; col < lat_map[row].size(); ++col)
1515 if (lat_map[row][col].get() == old_univ)
1516 setUniverseAtLatticeIndex(lat, new_univ, {
static_cast<int>(row),
static_cast<int>(col)});
1520 if (getRootUniverse() == old_univ)
1521 _universe_list._root_universe = &new_univ;
1527 for (
const auto & univ_ref : getAllUniverses())
1531 if (&cell_ref.get() == &old_cell)
1533 removeCellFromUniverse(univ, old_cell);
1534 addCellToUniverse(univ, new_cell);
1542 for (
const auto & cell_ref : getAllCells())
1544 const CSGCell & cell = cell_ref.get();
1546 if (new_region.
getRegionType() == CSGRegion::RegionType::EMPTY)
1550 updateCellRegion(cell, new_region);
1555CSGBase::generateOutput()
const
1558 checkUniverseLinking();
1560 nlohmann::json csg_json;
1562 csg_json[
"surfaces"] = {};
1563 csg_json[
"cells"] = {};
1564 csg_json[
"universes"] = {};
1567 auto all_surfs = getAllSurfaces();
1570 if (surfaceToEngUnit(s))
1572 const auto & surf_name = s.getName();
1573 const auto & coeffs = s.getCoeffs();
1574 csg_json[
"surfaces"][surf_name] = {{
"type", s.getSurfaceType()}, {
"coefficients", {}}};
1575 for (
const auto & c : coeffs)
1576 csg_json[
"surfaces"][surf_name][
"coefficients"][c.first] = c.second;
1578 if (s.getTransformations().size() > 0)
1579 csg_json[
"surfaces"][surf_name][
"transformations"] = s.getTransformationsAsStrings();
1584 if (csg_json[
"surfaces"].empty())
1585 csg_json.erase(
"surfaces");
1588 auto all_cells = getAllCells();
1589 for (
const CSGCell & c : all_cells)
1591 if (cellToEngUnit(c))
1593 const auto & cell_name = c.getName();
1594 const auto & cell_region_infix = c.getRegion().toInfixJSON();
1595 const auto & cell_region_postfix = c.getRegion().toPostfixStringList();
1596 const auto & cell_filltype = c.getFillType();
1597 const auto & fill_name = c.getFillName();
1598 csg_json[
"cells"][cell_name][
"filltype"] = cell_filltype;
1599 csg_json[
"cells"][cell_name][
"region_infix"] = cell_region_infix;
1600 csg_json[
"cells"][cell_name][
"region_postfix"] = cell_region_postfix;
1601 csg_json[
"cells"][cell_name][
"fill"] = fill_name;
1603 if (c.getTransformations().size())
1604 csg_json[
"cells"][cell_name][
"transformations"] = c.getTransformationsAsStrings();
1609 if (csg_json[
"cells"].empty())
1610 csg_json.erase(
"cells");
1613 auto all_univs = getAllUniverses();
1616 if (universeToEngUnit(u))
1618 const auto & univ_name = u.getName();
1619 const auto & univ_cells = u.getAllCells();
1620 csg_json[
"universes"][univ_name][
"cells"] = {};
1621 for (
const CSGCell & c : univ_cells)
1622 csg_json[
"universes"][univ_name][
"cells"].push_back(c.getName());
1624 csg_json[
"universes"][univ_name][
"root"] = u.isRoot();
1626 if (u.getTransformations().size())
1627 csg_json[
"universes"][univ_name][
"transformations"] = u.getTransformationsAsStrings();
1631 auto all_lats = getAllLattices();
1632 if (all_lats.size())
1634 csg_json[
"lattices"] = {};
1637 const auto & lat_name = lat.getName();
1638 csg_json[
"lattices"][lat_name] = {};
1639 csg_json[
"lattices"][lat_name][
"type"] = lat.getType();
1640 const auto & outer_type = lat.getOuterType();
1641 csg_json[
"lattices"][lat_name][
"outertype"] = outer_type;
1642 if (outer_type ==
"UNIVERSE")
1643 csg_json[
"lattices"][lat_name][
"outer"] = lat.getOuterUniverse().getName();
1644 else if (outer_type ==
"CSG_MATERIAL")
1645 csg_json[
"lattices"][lat_name][
"outer"] = lat.getOuterMaterial();
1647 csg_json[
"lattices"][lat_name][
"attributes"] = {};
1648 const auto & lat_attrs = lat.getAttributes();
1649 for (
const auto & attr : lat_attrs)
1650 csg_json[
"lattices"][lat_name][
"attributes"][attr.first] = attr.second;
1652 csg_json[
"lattices"][lat_name][
"universes"] = lat.getUniverseNameMap();
1654 if (lat.getTransformations().size())
1655 csg_json[
"lattices"][lat_name][
"transformations"] = lat.getTransformationsAsStrings();
1660 auto all_units = getAllEngUnits();
1661 if (all_units.size())
1663 csg_json[
"units"] = {};
1666 const auto & unit_name = unit.getName();
1667 csg_json[
"units"][unit_name] = {};
1669 csg_json[
"units"][unit_name][
"unit_type"] = unit.getUnitType();
1670 csg_json[
"units"][unit_name][
"behavior"] = unit.getBehavior();
1672 csg_json[
"units"][unit_name][
"attributes"] = {};
1673 const auto & unit_attrs = unit.getAttributes();
1674 for (
const auto & attr : unit_attrs)
1675 csg_json[
"units"][unit_name][
"attributes"][attr.first] = attr.second;
1676 if (unit.getTransformations().size())
1677 csg_json[
"units"][unit_name][
"transformations"] = unit.getTransformationsAsStrings();
1687 const auto & surf_list = this->getSurfaceList();
1689 const auto & cell_list = this->getCellList();
1690 const auto & other_cell_list = other.
getCellList();
1691 const auto & univ_list = this->getUniverseList();
1693 const auto & lat_list = this->getLatticeList();
1695 const auto & eng_unit_list = this->getEngUnitList();
1697 return (surf_list == other_surf_list) && (cell_list == other_cell_list) &&
1698 (univ_list == other_univ_list) && (lat_list == other_lat_list) &&
1699 (eng_unit_list == other_eng_unit_list);
1705 return !(*
this == other);
void mooseInfoRepeated(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
std::array< Real, 2 > values
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model.
const CSGSurfaceList & getSurfaceList() const
Get a const reference to the CSGSurfaceList object.
void prepareCellDeletion(const CSGCell &cell)
warn and remove cell from any universe that contains it
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.
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...
void updateIncomingCSGReferences(CSGBase &incoming_base)
update references of incoming CSGbase to point to those of existing CSGBase object.
const CSGUniverse & addUniverseToList(const CSGUniverse &univ)
Add a new universe to the universe list based on a universe reference.
std::vector< std::reference_wrapper< const CSGUniverseEngUnit > > getAllUniverseEngUnits() const
Get all universe-like engineering units.
CSGSurfaceList _surface_list
List of surfaces associated with CSG object.
const CSGUniverseList & getUniverseList() const
Get a const reference to the CSGUniverseList object.
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
CSGEngUnitList _eng_unit_list
Container for all associated engineering units.
const CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a unique surface pointer to this base instance
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 resetCellFill(const CSGCell &cell)
reset the fill of the specified cell to void
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
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 deleteLattice(const CSGLattice &lattice)
Remove a Lattice object passed in by reference from the stored lattice list.
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.
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.
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.
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.
void deleteSurface(const CSGSurface &surface)
Remove a Surface object passed in by reference from the stored surface list.
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
void updateCellRegion(const CSGCell &cell, const CSGRegion ®ion)
change the region of the specified cell
void setLatticeOuter(const CSGLattice &lattice, const std::string &outer_name)
Set the outer fill for the lattice to the material name provided.
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
CSGBase()
Default constructor.
const CSGCellEngUnit * cellToEngUnit(const CSGCell &cell) const
Returns the CSGCellEngUnit pointer if cell is an eng unit, nullptr otherwise.
void joinSurfaceList(CSGSurfaceList &surf_list, const bool ignore_identical_surfaces)
join a separate CSGSurfaceList object to this one
bool checkLatticeInBase(const CSGLattice &lattice) const
check that lattice being accessed is a part of this CSGBase instance
CSGUniverseList _universe_list
List of universes associated with CSG 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.
void expandUnit() override=0
Create the CSGCell and any other necessary components in _internal_base.
const std::string & getName() const override
Satisfy CSGEngUnit::getName() (resolved via CSGCell::getName())
CSGCellList creates a container for CSGCell objects to pass to CSGBase object.
std::unordered_map< std::string, std::unique_ptr< CSGCell > > & getCellListMap()
Get non-const map of all names to cells in cell list.
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
CSGCell & addLatticeCell(const std::string &name, const CSGLattice &lattice, const CSGRegion ®ion)
Add a Lattice Cell object to cell list.
bool hasCell(const std::string &name) const
return whether cell with given name exists in cell list
CSGCell & addVoidCell(const std::string &name, const CSGRegion ®ion)
Add a Void Cell object cell list.
CSGCell & addMaterialCell(const std::string &name, const std::string &mat_name, const CSGRegion ®ion)
Add a Material Cell object to cell list.
CSGCell & getCell(const std::string &name) const
Get the CSGCell by name.
CSGCell & addUniverseCell(const std::string &name, const CSGUniverse &univ, const CSGRegion ®ion)
Add a Universe Cell object to cell list.
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,...
const CSGRegion & getRegion() const
Get the cell region.
const std::string & getName() const
Get the cell name.
const CSGLattice & getFillLattice() const
Get the cell fill if fill type is LATTICE.
const std::string getFillType() const
Get the type of fill for the cell.
void resetCellFill()
Reset the cell fill to void.
void updateRegion(const CSGRegion ®ion)
void updateCellFill(const std::string &mat_name)
Set the cell fill to a material name.
const CSGUniverse & getFillUniverse() const
Get the cell fill if fill type is UNIVERSE.
const std::string & getFillMaterial() const
Get the cell fill material name if fill fype is CSG_MATERIAL.
CSGEngUnitList is a non-owning index of CSGEngUnit objects stored in the type lists (CSGSurfaceList,...
void removeEngUnit(const CSGEngUnit &unit)
Remove an engineering unit from this index by address.
CSGEngUnit & getEngUnit(const std::string &name) const
Get an engineering unit by name.
CSGEngUnit is the abstract base class for all "engineering unit" types in the CSG system.
virtual const std::string & getName() const =0
Get the unique instance name of this engineering unit.
CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.
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.
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > & getLatticeListMap()
Get map of all names to lattices in lattice list.
CSGLattice is the abstract class for defining lattices.
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > getUniverses() const
Get the arrangement of CSGUniverses in the lattice.
virtual std::unique_ptr< CSGLattice > clone() const =0
void updateOuter(const std::string &outer_name)
Update the outer of the lattice to be the provided material name.
const std::string & getName() const
Get the name of lattice.
const std::string getOuterType() const
Get the type of outer that fills the space around the lattice elements.
virtual void setUniverses(std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > universes)=0
assign the vectors of universes as the lattice elements
const CSGUniverse & getOuterUniverse() const
Get the outer universe if outer type is UNIVERSE.
void resetOuter()
reset the outer fill around the lattice elements to be VOID
void setUniverseAtIndex(const CSGUniverse &universe, const std::pair< int, int > index)
replace the element at specified index in the lattice with the provided CSGUniverse.
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection,...
RegionType getRegionType() const
Get the region type.
void replaceWithSubRegion(const CSGSurface &old_surf, const CSGRegion &sub_region)
Replace all occurrences of old_surf in this region's postfix token stream with the tokens of sub_regi...
std::vector< std::reference_wrapper< const CSGSurface > > getSurfaces() const
Get the list of surfaces associated with the region.
CSGSurfaceEngUnit is an abstract base class for "engineering units" that can be used as surfaces in c...
void expandUnit() override=0
Create and add the concrete CSGSurface(s) in _internal_base.
const std::string & getName() const override
Satisfy CSGEngUnit::getName() – resolved via CSGSurface::getName()
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.
CSGSurface & getSurface(const std::string &name) const
Get a surface by name.
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > & getSurfaceListMap()
Get non-const map of all names to surfaces in surface list.
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface,...
const std::string & getName() const
Get the name of surface.
CSGUniverseEngUnit is an abstract base class for "engineering units" that are universe-like.
void expandUnit() override=0
Populate _internal_base with the CSGUniverse and any supporting objects.
const std::string & getName() const override
Satisfy CSGEngUnit::getName() (resolved via CSGUniverse::getName())
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.
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > & getUniverseListMap()
Get non-const map of all names to universes in universe list.
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.
void addCell(const CSGCell &cell)
add cell to universe
void removeCell(const std::string &name)
remove a cell of the specified name from the universe
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells() const
Get list of the all cells in 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.