https://mooseframework.inl.gov
CSGBase.C
Go to the documentation of this file.
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 "CSGBase.h"
11 #include "CSGUtils.h"
12 #include "JsonIO.h"
13 
14 namespace CSG
15 {
16 
18  : _surface_list(CSGSurfaceList()),
19  _cell_list(CSGCellList()),
20  _universe_list(CSGUniverseList()),
21  _lattice_list(CSGLatticeList())
22 {
23 }
24 
25 CSGBase::CSGBase(const CSGBase & other_base)
26  : _surface_list(other_base.getSurfaceList()),
27  _cell_list(CSGCellList()),
28  _universe_list(CSGUniverseList()),
29  _lattice_list(CSGLatticeList())
30 {
31  // Iterate through all cell references from the other CSGBase instance and
32  // create new CSGCell pointers based on these references. This is done
33  // recursively to properly handle cells with universe fills
34  for (const auto & [name, cell] : other_base.getCellList().getCellListMap())
35  addCellToList(*cell);
36 
37  // Link all cells in other_base root universe to current root universe
38  for (auto & root_cell : other_base.getRootUniverse().getAllCells())
39  {
40  const auto & list_cell = _cell_list.getCell(root_cell.get().getName());
41  addCellToUniverse(getRootUniverse(), list_cell);
42  }
43 
44  // Iterate through all universe references from the other CSGBase instance and
45  // create new CSGUniverse pointers based on these references. This is done in case
46  // any universe exist in the universe list that are not connected to the cell list.
47  for (const auto & [name, univ] : other_base.getUniverseList().getUniverseListMap())
48  addUniverseToList(*univ);
49 
50  // Iterate through all lattice references from the other CSGBase instance and
51  // create new CSGLattice pointers based on these references.
52  for (const auto & [name, lattice] : other_base.getLatticeList().getLatticeListMap())
53  addLatticeToList(*lattice);
54 }
55 
57 
58 void
60 {
61  if (!checkSurfaceInBase(surface))
62  mooseError("Surface with name ",
63  surface.getName(),
64  " cannot be deleted as it is different from the surface of the same name in the "
65  "CSGBase instance.");
66 
67  // Check if surface is used in region definition of existing cells
68  for (const auto & cell_ref : _cell_list.getAllCells())
69  {
70  const auto & cell = cell_ref.get();
71  const auto & cell_region = cell.getRegion();
72  const auto & region_surfaces = cell_region.getSurfaces();
73  for (const auto & region_surf : region_surfaces)
74  if (region_surf.get() == surface)
75  mooseError("Cannot delete surface with name ",
76  surface.getName(),
77  " as it is used in region definition of cell with name ",
78  cell.getName());
79  }
80 
81  _surface_list.getSurfaceListMap().erase(surface.getName());
82 }
83 
84 const CSGCell &
86 {
87  // If cell has already been created, we just return a reference to it
88  const auto name = cell.getName();
89  if (_cell_list.hasCell(name))
90  return _cell_list.getCell(name);
91 
92  // Otherwise if the cell has material or void cell, we can create it directly
93  const auto fill_type = cell.getFillType();
94  const auto region = cell.getRegion();
95  if (fill_type == "VOID")
96  return _cell_list.addVoidCell(name, region);
97  else if (fill_type == "CSG_MATERIAL")
98  {
99  const auto mat_name = cell.getFillMaterial();
100  return _cell_list.addMaterialCell(name, mat_name, region);
101  }
102  else if (fill_type == "LATTICE")
103  {
104  // add lattice recursively to capture all linked universes in the lattice
105  const CSGLattice & lattice = addLatticeToList(cell.getFillLattice());
106  return _cell_list.addLatticeCell(name, lattice, region);
107  }
108  // Otherwise if the cell has a universe fill, we need to recursively define
109  // all linked universes and cells first before defining this cell
110  else if (fill_type == "UNIVERSE")
111  {
112  const auto & univ = addUniverseToList(cell.getFillUniverse());
113  return _cell_list.addUniverseCell(name, univ, region);
114  }
115  else
116  mooseError("Cell " + name + " has unrecognized fill type " + fill_type);
117 }
118 
119 const CSGUniverse &
121 {
122  // If universe has already been created, we just return a reference to it
123  const auto name = univ.getName();
126 
127  // Otherwise we create a new universe based on its associated cells.
128  // addCellToList is called recursively in case associated cells have not
129  // been added to the cell list yet.
130  const auto univ_cells = univ.getAllCells();
131  std::vector<std::reference_wrapper<const CSGCell>> current_univ_cells;
132  for (const auto & univ_cell : univ_cells)
133  current_univ_cells.push_back(addCellToList(univ_cell));
134  return createUniverse(name, current_univ_cells);
135 }
136 
137 const CSGLattice &
139 {
140  // If lattice has already been created, we just return a reference to it
141  const auto name = lattice.getName();
143  return _lattice_list.getLattice(name);
144 
145  // Clone the lattice (associated universes need to be transferred and set)
146  auto cloned_lattice = lattice.clone();
147 
148  // If lattice has associated universes, we need to add them to this CSGBase instance as well.
149  // addUniverseToList is called recursively in case associated universes have not been added to
150  // the universe list yet.
151  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> current_univ_map;
152  for (const auto & univ_list : lattice.getUniverses())
153  {
154  std::vector<std::reference_wrapper<const CSGUniverse>> current_univ_list;
155  for (const auto & univ_ref : univ_list)
156  current_univ_list.push_back(addUniverseToList(univ_ref.get()));
157  current_univ_map.push_back(current_univ_list);
158  }
159 
160  // Set universes only if lattice has universes defined
161  if (current_univ_map.size() > 0)
162  cloned_lattice->setUniverses(current_univ_map);
163 
164  // Update reference to outer universe if it exists
165  if (lattice.getOuterType() == "UNIVERSE")
166  {
167  const auto & outer_univ_ref = addUniverseToList(lattice.getOuterUniverse());
168  cloned_lattice->updateOuter(outer_univ_ref);
169  }
170 
171  // Use addLattice to add the cloned lattice
172  return addLattice(std::move(cloned_lattice));
173 }
174 
175 void
177 {
178  if (!checkLatticeInBase(lattice))
179  mooseError("Lattice with name ",
180  lattice.getName(),
181  " cannot be deleted as it is different from the lattice of the same name in the "
182  "CSGBase instance.");
183 
184  // Check if lattice is used as fill in existing cells
185  for (const auto & cell_ref : _cell_list.getAllCells())
186  {
187  const auto & cell = cell_ref.get();
188  if ((cell.getFillType() == "LATTICE") && (cell.getFillLattice() == lattice))
189  mooseError("Cannot delete lattice with name ",
190  lattice.getName(),
191  " as it is used as the fill of cell with name ",
192  cell.getName());
193  }
194 
195  _lattice_list.getLatticeListMap().erase(lattice.getName());
196 }
197 
198 const CSGCell &
199 CSGBase::createCell(const std::string & name,
200  const std::string & mat_name,
201  const CSGRegion & region,
202  const CSGUniverse * add_to_univ)
203 {
204  checkRegionSurfaces(region);
205  auto & cell = _cell_list.addMaterialCell(name, mat_name, region);
206  if (add_to_univ)
207  addCellToUniverse(*add_to_univ, cell);
208  else
210  return cell;
211 }
212 
213 const CSGCell &
214 CSGBase::createCell(const std::string & name,
215  const CSGRegion & region,
216  const CSGUniverse * add_to_univ)
217 {
218  checkRegionSurfaces(region);
219  auto & cell = _cell_list.addVoidCell(name, region);
220  if (add_to_univ)
221  addCellToUniverse(*add_to_univ, cell);
222  else
224  return cell;
225 }
226 
227 const CSGCell &
228 CSGBase::createCell(const std::string & name,
229  const CSGUniverse & fill_univ,
230  const CSGRegion & region,
231  const CSGUniverse * add_to_univ)
232 {
233  checkRegionSurfaces(region);
234  if (add_to_univ && (&fill_univ == add_to_univ))
235  mooseError("Cell " + name +
236  " cannot be filled with the same universe to which it is being added.");
237 
238  auto & cell = _cell_list.addUniverseCell(name, fill_univ, region);
239  if (add_to_univ)
240  addCellToUniverse(*add_to_univ, cell);
241  else
243  return cell;
244 }
245 
246 const CSGCell &
247 CSGBase::createCell(const std::string & name,
248  const CSGLattice & fill_lattice,
249  const CSGRegion & region,
250  const CSGUniverse * add_to_univ)
251 {
252  checkRegionSurfaces(region);
253 
254  // check that cell is not being added to a universe that exists in the lattice itself
255  if (add_to_univ)
256  for (auto univ_list : fill_lattice.getUniverses())
257  for (const auto & univ_ref : univ_list)
258  {
259  const CSGUniverse & univ_in_lattice = univ_ref.get();
260  if (&univ_in_lattice == add_to_univ)
261  mooseError("Cell " + name +
262  " cannot be filled with a lattice containing the same universe to which it is "
263  "being added.");
264  }
265 
266  auto & cell = _cell_list.addLatticeCell(name, fill_lattice, region);
267  if (add_to_univ)
268  addCellToUniverse(*add_to_univ, cell);
269  else
271  return cell;
272 }
273 
274 void
276 {
277  if (!checkCellInBase(cell))
278  mooseError("Cell with name ",
279  cell.getName(),
280  " cannot be deleted as it is different from the cell of the same name in the "
281  "CSGBase instance.");
282 
283  // Check if cell exists in any existing universes. Cell will be removed from these universes
284  for (const auto & univ_ref : _universe_list.getAllUniverses())
285  {
286  const auto & univ = univ_ref.get();
287  const auto & univ_cells = univ.getAllCells();
288  for (const auto & univ_cell : univ_cells)
289  if (cell == univ_cell.get() && univ != getRootUniverse())
290  {
291  mooseWarning("Removing cell ",
292  cell.getName(),
293  " from universe with name ",
294  univ.getName(),
295  " before cell deletion.");
296  auto & univ_to_modify = _universe_list.getUniverse(univ.getName());
297  univ_to_modify.removeCell(cell.getName());
298  }
299  }
300 
301  _cell_list.getCellListMap().erase(cell.getName());
302 }
303 
304 void
305 CSGBase::updateCellRegion(const CSGCell & cell, const CSGRegion & region)
306 {
307  checkRegionSurfaces(region);
308  if (!checkCellInBase(cell))
309  mooseError("The region of cell with name " + cell.getName() +
310  " that is being updated is different " +
311  "from the cell of the same name in the CSGBase instance.");
312  auto & list_cell = _cell_list.getCell(cell.getName());
313  list_cell.updateRegion(region);
314 }
315 
316 void
318 {
319  if (!checkCellInBase(cell))
320  mooseError("The fill of cell with name " + cell.getName() +
321  " that is being updated is different " +
322  "from the cell of the same name in the CSGBase instance.");
323  auto & list_cell = _cell_list.getCell(cell.getName());
324  list_cell.resetCellFill();
325 }
326 
327 void
328 CSGBase::updateCellFill(const CSGCell & cell, const std::string & mat_name)
329 {
330  if (!checkCellInBase(cell))
331  mooseError("The region of cell with name " + cell.getName() +
332  " that is being updated is different " +
333  "from the cell of the same name in the CSGBase instance.");
334  auto & list_cell = _cell_list.getCell(cell.getName());
335  list_cell.updateCellFill(mat_name);
336 }
337 
338 void
339 CSGBase::updateCellFill(const CSGCell & cell, const CSGUniverse * univ)
340 {
341  if (!checkUniverseInBase(*univ))
342  mooseError("Universe with name ",
343  univ->getName(),
344  " is being used as a cell fill that is different from the universe of the same name "
345  "in the CSGBase instance.");
346  if (!checkCellInBase(cell))
347  mooseError("The fill of cell with name " + cell.getName() +
348  " that is being updated is different " +
349  "from the cell of the same name in the CSGBase instance.");
350  auto & list_cell = _cell_list.getCell(cell.getName());
351  list_cell.updateCellFill(univ);
352 }
353 
354 void
355 CSGBase::updateCellFill(const CSGCell & cell, const CSGLattice * lattice)
356 {
357  if (!checkLatticeInBase(*lattice))
358  mooseError("Lattice with name ",
359  lattice->getName(),
360  " is being used as a cell fill that is different from the lattice of the same name "
361  "in the CSGBase instance.");
362  if (!checkCellInBase(cell))
363  mooseError("The fill of cell with name " + cell.getName() +
364  " that is being updated is different " +
365  "from the cell of the same name in the CSGBase instance.");
366  auto & list_cell = _cell_list.getCell(cell.getName());
367  list_cell.updateCellFill(lattice);
368 }
369 
370 const CSGUniverse &
371 CSGBase::createUniverse(const std::string & name,
372  std::vector<std::reference_wrapper<const CSGCell>> & cells)
373 {
374  auto & univ = _universe_list.addUniverse(name);
375  addCellsToUniverse(univ, cells); // performs a check that cells are a part of this base
376  return univ;
377 }
378 
379 void
381 {
382  if (!checkUniverseInBase(univ))
383  mooseError("Universe with name ",
384  univ.getName(),
385  " cannot be deleted as it is different from the universe of the same name in the "
386  "CSGBase instance.");
387 
388  // Check if universe is the root universe
389  if (univ == getRootUniverse())
390  mooseError("Cannot delete root universe from CSGBase instance");
391 
392  // Check if universe is used in any existing lattices
393  for (const auto & lat : _lattice_list.getAllLattices())
394  {
395  const auto & lattice_univs = lat.get().getUniqueUniverses();
396  for (const auto & lat_univ : lattice_univs)
397  if (univ == lat_univ.get())
398  mooseError("Cannot delete universe with name ",
399  univ.getName(),
400  " as it is used in lattice with name ",
401  lat.get().getName());
402  if ((lat.get().getOuterType() == "UNIVERSE") && (lat.get().getOuterUniverse() == univ))
403  mooseError("Cannot delete universe with name ",
404  univ.getName(),
405  " as it is used as the outer universe of lattice with name ",
406  lat.get().getName());
407  }
408 
409  // Check if universe is used as fill in existing cells
410  for (const auto & cell_ref : _cell_list.getAllCells())
411  {
412  const auto & cell = cell_ref.get();
413  if ((cell.getFillType() == "UNIVERSE") && (cell.getFillUniverse() == univ))
414  mooseError("Cannot delete universe with name ",
415  univ.getName(),
416  " as it is used as the fill of cell with name ",
417  cell.getName());
418  }
419 
420  _universe_list.getUniverseListMap().erase(univ.getName());
421 }
422 
423 void
424 CSGBase::addCellToUniverse(const CSGUniverse & universe, const CSGCell & cell)
425 {
426  // make sure cell is a part of this CSGBase instance
427  if (!checkCellInBase(cell))
428  mooseError("A cell named " + cell.getName() + " is being added to universe " +
429  universe.getName() +
430  " that is different from the cell of the same name in the CSGBase instance.");
431  // make sure universe is a part of this CSGBase instance
432  if (!checkUniverseInBase(universe))
433  mooseError("Cells are being added to a universe named " + universe.getName() +
434  " that is different " +
435  "from the universe of the same name in the CSGBase instance.");
436  auto & univ = _universe_list.getUniverse(universe.getName());
437  univ.addCell(cell);
438 }
439 
440 void
442  std::vector<std::reference_wrapper<const CSGCell>> & cells)
443 {
444  for (auto & c : cells)
445  addCellToUniverse(universe, c);
446 }
447 
448 void
449 CSGBase::removeCellFromUniverse(const CSGUniverse & universe, const CSGCell & cell)
450 {
451  // make sure cell is a part of this CSGBase instance
452  if (!checkCellInBase(cell))
453  mooseError("A cell named " + cell.getName() + " is being removed from universe " +
454  universe.getName() +
455  " that is different from the cell of the same name in the CSGBase instance.");
456  // make sure universe is a part of this CSGBase instance
457  if (!checkUniverseInBase(universe))
458  mooseError("Cells are being removed from a universe named " + universe.getName() +
459  " that is different " +
460  "from the universe of the same name in the CSGBase instance.");
461  auto & univ = _universe_list.getUniverse(universe.getName());
462  univ.removeCell(cell.getName());
463 }
464 
465 void
467  std::vector<std::reference_wrapper<const CSGCell>> & cells)
468 {
469  for (auto & c : cells)
470  removeCellFromUniverse(universe, c);
471 }
472 
473 void
474 CSGBase::setLatticeOuter(const CSGLattice & lattice, const std::string & outer_name)
475 {
476  auto name = lattice.getName();
477  if (!checkLatticeInBase(lattice))
478  mooseError("Cannot set outer for lattice " + name +
479  ". Lattice is different from the lattice of the same name in the "
480  "CSGBase instance.");
482 }
483 
484 void
485 CSGBase::setLatticeOuter(const CSGLattice & lattice, const CSGUniverse & outer_univ)
486 {
487  auto name = lattice.getName();
488  if (!checkLatticeInBase(lattice))
489  mooseError("Cannot set outer universe for lattice " + name +
490  ". Lattice is different from the lattice of the same name in the "
491  "CSGBase instance.");
492  if (!checkUniverseInBase(outer_univ))
493  mooseError("Cannot set outer universe for lattice " + name + ". Outer universe " +
494  outer_univ.getName() + " is not in the CSGBase instance.");
496 }
497 
498 void
500 {
501  auto name = lattice.getName();
502  if (!checkLatticeInBase(lattice))
503  mooseError("Cannot reset outer for lattice " + name +
504  ". Lattice is different from the lattice of the same name in the "
505  "CSGBase instance.");
507 }
508 
509 void
511  const CSGUniverse & universe,
512  std::pair<int, int> index)
513 {
514  auto name = lattice.getName();
515  if (!checkLatticeInBase(lattice))
516  mooseError("Cannot set universe at index for lattice " + name +
517  ". Lattice is different from the lattice of the same name in the "
518  "CSGBase instance.");
519  if (!checkUniverseInBase(universe))
520  mooseError("Cannot add universe " + universe.getName() + " to lattice " + lattice.getName() +
521  ". Universe is not in the CSGBase instance.");
523 }
524 
525 void
527  const CSGLattice & lattice,
528  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> & universes)
529 {
530  auto name = lattice.getName();
531  if (!checkLatticeInBase(lattice))
532  mooseError("Cannot set universes for lattice " + name +
533  ". Lattice is different from the lattice of the same name in the "
534  "CSGBase instance.");
535  // make sure all universes are a part of this base instance
536  for (auto univ_list : universes)
537  for (const CSGUniverse & univ : univ_list)
538  if (!checkUniverseInBase(univ))
539  mooseError("Cannot set universes for lattice " + name + ". Universe " + univ.getName() +
540  " is not in the CSGBase instance.");
542 }
543 
544 void
546  TransformationType type,
547  const std::tuple<Real, Real, Real> & values)
548 {
549  // Use std::visit to handle each type in the variant
550  std::visit(
551  [&](const auto & obj)
552  {
553  using T = std::decay_t<decltype(obj.get())>;
554 
555  // Handle each CSG object type differently because each needs to check that it exists in
556  // this base instance
557  if constexpr (std::is_same_v<T, CSGCell>)
558  {
559  const CSGCell & cell = obj.get();
560  if (!checkCellInBase(cell))
561  mooseError("Cannot apply transformation to cell ",
562  cell.getName(),
563  " that is not in this CSGBase instance.");
564 
565  // Get non-const reference and apply transformation
566  CSGCell & mutable_cell = _cell_list.getCell(cell.getName());
567  mooseAssert(mutable_cell == cell, "Mutable cell does not match const cell passed in.");
568  mutable_cell.addTransformation(type, values);
569  }
570  else if constexpr (std::is_same_v<T, CSGSurface>)
571  {
572  const CSGSurface & surface = obj.get();
573  if (!checkSurfaceInBase(surface))
574  mooseError("Cannot apply transformation to surface ",
575  surface.getName(),
576  " that is not in this CSGBase instance.");
577 
578  // Get non-const reference and apply transformation
579  CSGSurface & mutable_surface = _surface_list.getSurface(surface.getName());
580  mooseAssert(mutable_surface == surface,
581  "Mutable surface does not match const surface passed in.");
582  mutable_surface.addTransformation(type, values);
583  }
584  else if constexpr (std::is_same_v<T, CSGUniverse>)
585  {
586  const CSGUniverse & universe = obj.get();
587  if (!checkUniverseInBase(universe))
588  mooseError("Cannot apply transformation to universe ",
589  universe.getName(),
590  " that is not in this CSGBase instance.");
591 
592  // Get non-const reference and apply transformation
593  CSGUniverse & mutable_universe = _universe_list.getUniverse(universe.getName());
594  mooseAssert(mutable_universe == universe,
595  "Mutable universe does not match const universe passed in.");
596  mutable_universe.addTransformation(type, values);
597  }
598  else if constexpr (std::is_same_v<T, CSGLattice>)
599  {
600  const CSGLattice & lattice = obj.get();
601  if (!checkLatticeInBase(lattice))
602  mooseError("Cannot apply transformation to lattice ",
603  lattice.getName(),
604  " that is not in this CSGBase instance.");
605 
606  // Get non-const reference and apply transformation
607  CSGLattice & mutable_lattice = _lattice_list.getLattice(lattice.getName());
608  mooseAssert(mutable_lattice == lattice,
609  "Mutable lattice does not match const lattice passed in.");
610  mutable_lattice.addTransformation(type, values);
611  }
612  else if constexpr (std::is_same_v<T, CSGRegion>)
613  {
614  // iterate on the surfaces of the region and apply the transformation to those surfaces
615  const CSGRegion & region = obj.get();
616  const auto surfaces = region.getSurfaces();
617  for (const CSGSurface & surface : surfaces)
618  {
619  if (!checkSurfaceInBase(surface))
620  mooseError("Cannot apply transformation to region with surface ",
621  surface.getName(),
622  " that is not in this CSGBase instance.");
623  addTransformation(surface, type, values);
624  }
625  }
626  else
627  mooseError("Transformation not implemented for this object type: ", typeid(T).name());
628  },
629  csg_object);
630 }
631 
632 void
634  RotationAxisType axis,
635  const Real angle)
636 {
637  // convert to the Euler angles (phi, theta, psi) based on axis
638  Real phi = 0.0;
639  Real theta = 0.0;
640  Real psi = 0.0;
641 
642  switch (axis)
643  {
644  case RotationAxisType::X:
645  theta = angle;
646  break;
647  case RotationAxisType::Y:
648  phi = 90.0;
649  theta = angle;
650  psi = -90.0;
651  break;
652  case RotationAxisType::Z:
653  phi = angle;
654  break;
655  default:
656  mooseError("Invalid axis type provided for axis rotation.");
657  }
658 
659  addTransformation(csg_object, TransformationType::ROTATION, std::make_tuple(phi, theta, psi));
660 }
661 
662 void
663 CSGBase::joinOtherBase(std::unique_ptr<CSGBase> base, const bool ignore_identical_components)
664 {
665  // If we are ignoring identical incoming CSG components, we need to update any references
666  // stored by these components to point to the references of the pre-existing CSGBase object
667  if (ignore_identical_components)
669  joinSurfaceList(base->getSurfaceList(), ignore_identical_components);
670  joinCellList(base->getCellList(), ignore_identical_components);
671  joinLatticeList(base->getLatticeList(), ignore_identical_components);
672  joinUniverseList(base->getUniverseList(), ignore_identical_components);
673 }
674 
675 void
676 CSGBase::joinOtherBase(std::unique_ptr<CSGBase> base,
677  const bool ignore_identical_components,
678  const std::string & new_root_name_join)
679 {
680  // If we are ignoring identical incoming CSG components, we need to update any references
681  // stored by these components to point to the references of the pre-existing CSGBase object
682  if (ignore_identical_components)
684  joinSurfaceList(base->getSurfaceList(), ignore_identical_components);
685  joinCellList(base->getCellList(), ignore_identical_components);
686  joinLatticeList(base->getLatticeList(), ignore_identical_components);
687  joinUniverseList(base->getUniverseList(), ignore_identical_components, new_root_name_join);
688 }
689 
690 void
691 CSGBase::joinOtherBase(std::unique_ptr<CSGBase> base,
692  const bool ignore_identical_components,
693  const std::string & new_root_name_base,
694  const std::string & new_root_name_join)
695 {
696  // If we are ignoring identical incoming CSG components, we need to update any references
697  // stored by these components to point to the references of the pre-existing CSGBase object
698  if (ignore_identical_components)
700  joinSurfaceList(base->getSurfaceList(), ignore_identical_components);
701  joinCellList(base->getCellList(), ignore_identical_components);
702  joinLatticeList(base->getLatticeList(), ignore_identical_components);
704  base->getUniverseList(), ignore_identical_components, new_root_name_base, new_root_name_join);
705 }
706 
707 void
709 {
710  // Iterate through all incoming surfaces and track which ones have names already
711  // defined within this CSGSurfaceList object
712  std::map<std::string, std::reference_wrapper<const CSGSurface>> identical_surface_refs;
713  auto & surf_list_map = incoming_base.getSurfaceList().getSurfaceListMap();
714  for (const auto & [surf_name, surf_ptr] : surf_list_map)
715  if (hasSurface(surf_name))
716  identical_surface_refs.insert({surf_name, getSurfaceByName(surf_name)});
717 
718  // Iterate through all incoming cells and track which ones have names already
719  // defined within this CSGCellList object
720  std::map<std::string, std::reference_wrapper<const CSGCell>> identical_cell_refs;
721  auto & cell_list_map = incoming_base.getCellList().getCellListMap();
722  for (const auto & [cell_name, cell_ptr] : cell_list_map)
723  if (hasCell(cell_name))
724  identical_cell_refs.insert({cell_name, getCellByName(cell_name)});
725 
726  // Iterate through all incoming universes and track which ones have names already
727  // defined within this CSGUniverseList object
728  std::map<std::string, std::reference_wrapper<const CSGUniverse>> identical_universe_refs;
729  auto & universe_list_map = incoming_base.getUniverseList().getUniverseListMap();
730  for (const auto & [univ_name, univ_ptr] : universe_list_map)
731  if (hasUniverse(univ_name))
732  identical_universe_refs.insert({univ_name, getUniverseByName(univ_name)});
733 
734  // Iterate through all incoming lattices and track which ones have names already
735  // defined within this CSGLatticeList object
736  std::map<std::string, std::reference_wrapper<const CSGLattice>> identical_lattice_refs;
737  auto & lattice_list_map = incoming_base.getLatticeList().getLatticeListMap();
738  for (const auto & [lat_name, lat_ptr] : lattice_list_map)
739  if (hasLattice(lat_name))
740  identical_lattice_refs.insert({lat_name, getLatticeByName(lat_name)});
741 
742  // Update all surface, cell, universe, and lattice references of incoming base to those of this
743  // base
744  if (!identical_surface_refs.empty())
745  replaceSurfaceRefsByName(identical_surface_refs, incoming_base);
746 
747  if (!identical_cell_refs.empty())
748  replaceCellRefsByName(identical_cell_refs, incoming_base);
749 
750  if (!identical_universe_refs.empty())
751  replaceUniverseRefsByName(identical_universe_refs, incoming_base);
752 
753  if (!identical_lattice_refs.empty())
754  replaceLatticeRefsByName(identical_lattice_refs, incoming_base);
755 }
756 
757 void
759  std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs,
760  CSGBase & base)
761 {
762  // Update surface references of cell regions to those of this base
763  for (auto & [cell_name, cell_ptr] : base.getCellList().getCellListMap())
764  cell_ptr->updateCellRegionSurfaces(identical_surface_refs);
765 }
766 
767 void
769  std::map<std::string, std::reference_wrapper<const CSGCell>> & identical_cell_refs,
770  CSGBase & base)
771 {
772  // Update cell references of universes to those of this base
773  for (auto & [univ_name, univ_ptr] : base.getUniverseList().getUniverseListMap())
774  for (auto & [cell_name, cell_ref] : identical_cell_refs)
775  if (univ_ptr->hasCell(cell_name))
776  {
777  univ_ptr->removeCell(cell_name);
778  univ_ptr->addCell(cell_ref);
779  }
780 }
781 
782 void
784  std::map<std::string, std::reference_wrapper<const CSGUniverse>> & identical_universe_refs,
785  CSGBase & base)
786 {
787  // Update universe references of cells to those of this base
788  for (auto & [cell_name, cell_ptr] : base.getCellList().getCellListMap())
789  {
790  const auto fill_type = cell_ptr->getFillType();
791  const auto fill_name = cell_ptr->getFillName();
792  if ((fill_type == "UNIVERSE") &&
793  (identical_universe_refs.find(fill_name) != identical_universe_refs.end()))
794  {
795  const CSGUniverse * univ_ptr = &identical_universe_refs.at(fill_name).get();
796  cell_ptr->updateCellFill(univ_ptr);
797  }
798  }
799 
800  // Update universe references of lattices to those of this base
801  for (auto & [lat_name, lat_ptr] : base.getLatticeList().getLatticeListMap())
802  for (auto & [univ_name, univ_ref] : identical_universe_refs)
803  {
804  // Check if universe belongs to lattice
805  if (lat_ptr->hasUniverse(univ_name))
806  {
807  // If so, replace all instances of this universe in the lattice
808  const auto univ_indices = lat_ptr->getUniverseIndices(univ_name);
809  for (const auto & index : univ_indices)
810  lat_ptr->setUniverseAtIndex(univ_ref, index);
811  }
812  // Check if universe belongs to lattice outer
813  if ((lat_ptr->getOuterType() == "UNIVERSE") &&
814  (lat_ptr->getOuterUniverse().getName() == univ_name))
815  lat_ptr->updateOuter(univ_ref);
816  }
817 }
818 
819 void
821  std::map<std::string, std::reference_wrapper<const CSGLattice>> & identical_lattice_refs,
822  CSGBase & base)
823 {
824  // Update lattice references of cells to those of this base
825  for (auto & [cell_name, cell_ptr] : base.getCellList().getCellListMap())
826  {
827  const auto fill_type = cell_ptr->getFillType();
828  const auto fill_name = cell_ptr->getFillName();
829  if ((fill_type == "LATTICE") &&
830  (identical_lattice_refs.find(fill_name) != identical_lattice_refs.end()))
831  {
832  const CSGLattice * lat_ptr = &identical_lattice_refs.at(fill_name).get();
833  cell_ptr->updateCellFill(lat_ptr);
834  }
835  }
836 }
837 
838 void
839 CSGBase::joinSurfaceList(CSGSurfaceList & surf_list, const bool ignore_identical_surfaces)
840 {
841  auto & surf_list_map = surf_list.getSurfaceListMap();
842  for (auto & s : surf_list_map)
843  _surface_list.addSurface(std::move(s.second), ignore_identical_surfaces);
844 }
845 
846 void
847 CSGBase::joinCellList(CSGCellList & cell_list, const bool ignore_identical_cells)
848 {
849  auto & cell_list_map = cell_list.getCellListMap();
850  for (auto & c : cell_list_map)
851  _cell_list.addCell(std::move(c.second), ignore_identical_cells);
852 }
853 
854 void
855 CSGBase::joinLatticeList(CSGLatticeList & lattice_list, const bool ignore_identical_lattices)
856 {
857  auto & lat_list_map = lattice_list.getLatticeListMap();
858  for (auto & lat : lat_list_map)
859  _lattice_list.addLattice(std::move(lat.second), ignore_identical_lattices);
860 }
861 
862 void
863 CSGBase::joinUniverseList(CSGUniverseList & univ_list, const bool ignore_identical_universes)
864 {
865  // case 1: incoming root is joined into existing root; no new universes are created
866  auto & univ_list_map = univ_list.getUniverseListMap();
867  auto & root = getRootUniverse(); // this root universe
868  for (auto & u : univ_list_map)
869  {
870  if (u.second->isRoot())
871  {
872  // add existing cells to current root instead of creating new universe
873  auto all_cells = u.second->getAllCells();
874  for (auto & cell : all_cells)
875  addCellToUniverse(root, cell);
876  }
877  else // unique non-root universe to add to list
878  _universe_list.addUniverse(std::move(u.second), ignore_identical_universes);
879  }
880 }
881 
882 void
884  const bool ignore_identical_universes,
885  const std::string & new_root_name_incoming)
886 {
887  // case 2: incoming root is turned into new universe and existing root remains root
888 
889  // add incoming universes to current Base
890  auto & all_univs = univ_list.getUniverseListMap();
891  for (auto & u : all_univs)
892  {
893  if (u.second->isRoot())
894  {
895  // create new universe from incoming root universe
896  auto all_cells = u.second->getAllCells();
897  createUniverse(new_root_name_incoming, all_cells);
898  }
899  else // unique non-root universe to add to list
900  _universe_list.addUniverse(std::move(u.second), ignore_identical_universes);
901  }
902 }
903 
904 void
906  const bool ignore_identical_universes,
907  const std::string & new_root_name_base,
908  const std::string & new_root_name_incoming)
909 {
910  // case 3: each root universe becomes a new universe and a new root is created
911 
912  // make a new universe from the existing root universe
913  auto & root = getRootUniverse();
914  auto root_cells = root.getAllCells();
915  createUniverse(new_root_name_base, root_cells);
916  removeCellsFromUniverse(root, root_cells);
917 
918  // add incoming universes to current Base
919  auto & all_univs = univ_list.getUniverseListMap();
920  for (auto & u : all_univs)
921  {
922  if (u.second->isRoot())
923  {
924  // create new universe from incoming root universe
925  auto all_cells = u.second->getAllCells();
926  createUniverse(new_root_name_incoming, all_cells);
927  }
928  else // unique non-root universe to add to list
929  _universe_list.addUniverse(std::move(u.second), ignore_identical_universes);
930  }
931 }
932 
933 void
935 {
936  const auto surfs = region.getSurfaces();
937  for (const CSGSurface & s : surfs)
938  {
939  if (!checkSurfaceInBase(s))
940  mooseError("Region is being set with a surface named " + s.getName() +
941  " that is different from the surface of the same name in the CSGBase instance.");
942  }
943 }
944 
945 bool
947 {
948  auto name = surface.getName();
949  // if no surface by this name exists, an error will be produced by getSurface
950  auto & list_surf = _surface_list.getSurface(name);
951  // return whether that the surface in the list is the same as the surface provided (in memory)
952  return &surface == &list_surf;
953 }
954 
955 bool
957 {
958  auto name = cell.getName();
959  // if no cell by this name exists, an error will be produced by getCell
960  auto & list_cell = _cell_list.getCell(name);
961  // return whether that the cell in the list is the same as the cell provided (in memory)
962  return &cell == &list_cell;
963 }
964 
965 bool
967 {
968  auto name = universe.getName();
969  // if no universe by this name exists, an error will be produced by getUniverse
970  auto & list_univ = _universe_list.getUniverse(name);
971  // return whether that the universe in the list is the same as the universe provided (in memory)
972  return &universe == &list_univ;
973 }
974 
975 bool
977 {
978  auto name = lattice.getName();
979  // if no lattice by this name exists, an error will be produced by getLattice
980  auto & list_lattice = _lattice_list.getLattice(name);
981  // return whether that the lattice in the list is the same as the lattice provided (in memory)
982  return &lattice == &list_lattice;
983 }
984 
985 void
987 {
988  std::vector<std::string> linked_universe_names;
989  std::vector<std::string> linked_cell_names;
990 
991  // Recursively figure out which universe names are linked to root universe
992  getLinkedUniverses(getRootUniverse(), linked_universe_names, linked_cell_names);
993 
994  // Iterate through all universes in universe list and check that they exist in universes linked
995  // to root universe
996  for (const CSGUniverse & univ : getAllUniverses())
997  if (std::find(linked_universe_names.begin(), linked_universe_names.end(), univ.getName()) ==
998  linked_universe_names.end())
999  mooseWarning("Universe with name ", univ.getName(), " is not linked to root universe.");
1000 
1001  // Iterate through all cells in cell list and check that they exist in cells linked
1002  // to root universe
1003  for (const CSGCell & cell : getAllCells())
1004  if (std::find(linked_cell_names.begin(), linked_cell_names.end(), cell.getName()) ==
1005  linked_cell_names.end())
1006  mooseWarning("Cell with name ", cell.getName(), " is not linked to root universe.");
1007 }
1008 
1009 void
1011  std::vector<std::string> & linked_universe_names,
1012  std::vector<std::string> & linked_cell_names) const
1013 {
1014  linked_universe_names.push_back(univ.getName());
1015  const auto & univ_cells = univ.getAllCells();
1016  for (const CSGCell & cell : univ_cells)
1017  {
1018  linked_cell_names.push_back(cell.getName());
1019  if (cell.getFillType() == "UNIVERSE")
1020  getLinkedUniverses(cell.getFillUniverse(), linked_universe_names, linked_cell_names);
1021  else if (cell.getFillType() == "LATTICE")
1022  {
1023  const auto & lattice = cell.getFillLattice();
1024  for (const auto & univ_list : lattice.getUniverses())
1025  for (const auto & univ_ref : univ_list)
1026  {
1027  const CSGUniverse & lattice_univ = univ_ref.get();
1028  getLinkedUniverses(lattice_univ, linked_universe_names, linked_cell_names);
1029  }
1030 
1031  if (lattice.getOuterType() == "UNIVERSE")
1032  {
1033  const CSGUniverse & outer_univ = lattice.getOuterUniverse();
1034  getLinkedUniverses(outer_univ, linked_universe_names, linked_cell_names);
1035  }
1036  }
1037  }
1038 }
1039 
1040 nlohmann::json
1042 {
1043  // Check that orphaned universes do not exist in universe list of CSGBase object
1045 
1046  nlohmann::json csg_json;
1047 
1048  csg_json["surfaces"] = {};
1049  csg_json["cells"] = {};
1050  csg_json["universes"] = {};
1051 
1052  // get all surfaces information
1053  auto all_surfs = getAllSurfaces();
1054  for (const CSGSurface & s : all_surfs)
1055  {
1056  const auto & surf_name = s.getName();
1057  const auto & coeffs = s.getCoeffs();
1058  csg_json["surfaces"][surf_name] = {{"type", s.getSurfaceType()}, {"coefficients", {}}};
1059  for (const auto & c : coeffs)
1060  csg_json["surfaces"][surf_name]["coefficients"][c.first] = c.second;
1061  // include any information about transformations if present
1062  if (s.getTransformations().size() > 0)
1063  csg_json["surfaces"][surf_name]["transformations"] = s.getTransformationsAsStrings();
1064  }
1065 
1066  // Print out cell information
1067  auto all_cells = getAllCells();
1068  for (const CSGCell & c : all_cells)
1069  {
1070  const auto & cell_name = c.getName();
1071  const auto & cell_region_infix = c.getRegion().toInfixJSON();
1072  const auto & cell_region_postfix = c.getRegion().toPostfixStringList();
1073  const auto & cell_filltype = c.getFillType();
1074  const auto & fill_name = c.getFillName();
1075  csg_json["cells"][cell_name]["filltype"] = cell_filltype;
1076  csg_json["cells"][cell_name]["region_infix"] = cell_region_infix;
1077  csg_json["cells"][cell_name]["region_postfix"] = cell_region_postfix;
1078  csg_json["cells"][cell_name]["fill"] = fill_name;
1079  // include any information about transformations if present
1080  if (c.getTransformations().size())
1081  csg_json["cells"][cell_name]["transformations"] = c.getTransformationsAsStrings();
1082  }
1083 
1084  // Print out universe information
1085  auto all_univs = getAllUniverses();
1086  for (const CSGUniverse & u : all_univs)
1087  {
1088  const auto & univ_name = u.getName();
1089  const auto & univ_cells = u.getAllCells();
1090  csg_json["universes"][univ_name]["cells"] = {};
1091  for (const CSGCell & c : univ_cells)
1092  csg_json["universes"][univ_name]["cells"].push_back(c.getName());
1093  if (u.isRoot())
1094  csg_json["universes"][univ_name]["root"] = u.isRoot();
1095  // include any information about transformations if present
1096  if (u.getTransformations().size())
1097  csg_json["universes"][univ_name]["transformations"] = u.getTransformationsAsStrings();
1098  }
1099 
1100  // print out lattice information if lattices exist
1101  auto all_lats = getAllLattices();
1102  if (all_lats.size())
1103  {
1104  csg_json["lattices"] = {};
1105  for (const CSGLattice & lat : all_lats)
1106  {
1107  const auto & lat_name = lat.getName();
1108  csg_json["lattices"][lat_name] = {};
1109  csg_json["lattices"][lat_name]["type"] = lat.getType();
1110  const auto & outer_type = lat.getOuterType();
1111  csg_json["lattices"][lat_name]["outertype"] = outer_type;
1112  if (outer_type == "UNIVERSE")
1113  csg_json["lattices"][lat_name]["outer"] = lat.getOuterUniverse().getName();
1114  else if (outer_type == "CSG_MATERIAL")
1115  csg_json["lattices"][lat_name]["outer"] = lat.getOuterMaterial();
1116  // write out any additional attributes
1117  csg_json["lattices"][lat_name]["attributes"] = {};
1118  const auto & lat_attrs = lat.getAttributes();
1119  for (const auto & attr : lat_attrs)
1120  csg_json["lattices"][lat_name]["attributes"][attr.first] = attr.second;
1121  // write the map of universe names: list of lists
1122  csg_json["lattices"][lat_name]["universes"] = lat.getUniverseNameMap();
1123  // include any information about transformations if present
1124  if (lat.getTransformations().size())
1125  csg_json["lattices"][lat_name]["transformations"] = lat.getTransformationsAsStrings();
1126  }
1127  }
1128 
1129  return csg_json;
1130 }
1131 
1132 bool
1133 CSGBase::operator==(const CSGBase & other) const
1134 {
1135  const auto & surf_list = this->getSurfaceList();
1136  const auto & other_surf_list = other.getSurfaceList();
1137  const auto & cell_list = this->getCellList();
1138  const auto & other_cell_list = other.getCellList();
1139  const auto & univ_list = this->getUniverseList();
1140  const auto & other_univ_list = other.getUniverseList();
1141  const auto & lat_list = this->getLatticeList();
1142  const auto & other_lat_list = other.getLatticeList();
1143  return (surf_list == other_surf_list) && (cell_list == other_cell_list) &&
1144  (univ_list == other_univ_list) && (lat_list == other_lat_list);
1145 }
1146 
1147 bool
1148 CSGBase::operator!=(const CSGBase & other) const
1149 {
1150  return !(*this == other);
1151 }
1152 } // namespace CSG
std::string name(const ElemQuality q)
void updateIncomingCSGReferences(CSGBase &incoming_base)
update references of incoming CSGbase to point to those of existing CSGBase object.
Definition: CSGBase.C:708
const std::string & getName() const
Get the name of surface.
Definition: CSGSurface.h:95
bool hasUniverse(const std::string &name) const
Check if a universe with given name exists in CSGBase object.
Definition: CSGBase.h:392
const CSGLattice & getFillLattice() const
Get the cell fill if fill type is LATTICE.
Definition: CSGCell.C:76
bool checkLatticeInBase(const CSGLattice &lattice) const
Definition: CSGBase.C:976
void setUniverseAtLatticeIndex(const CSGLattice &lattice, const CSGUniverse &universe, std::pair< int, int > index)
set location in the lattice to be the provided universe
Definition: CSGBase.C:510
CSGLattice & addLattice(std::unique_ptr< CSGLattice > lattice, const bool ignore_identical_lattice=false)
add an existing lattice to list.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
const CSGUniverse & getFillUniverse() const
Get the cell fill if fill type is UNIVERSE.
Definition: CSGCell.C:58
CSGCell & getCell(const std::string &name) const
Get the CSGCell by name.
Definition: CSGCellList.C:44
const std::string & getName() const
Get the cell name.
Definition: CSGCell.h:112
std::vector< std::reference_wrapper< const CSGUniverse > > getAllUniverses() const
Get all the universes in CSGBase instance.
std::vector< std::reference_wrapper< const CSGUniverse > > getAllUniverses() const
Get all universe objects.
Definition: CSGBase.h:370
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 ...
Definition: CSGBase.C:783
CSGUniverseList _universe_list
List of universes associated with CSG object.
Definition: CSGBase.h:903
const std::string getFillType() const
Get the type of fill for the cell.
Definition: CSGCell.h:77
void updateRegion(const CSGRegion &region)
Definition: CSGCell.h:170
void updateCellFill(const std::string &mat_name)
Set the cell fill to a material name.
Definition: CSGCell.C:94
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection...
Definition: CSGRegion.h:22
CSGCellList creates a container for CSGCell objects to pass to CSGBase object.
Definition: CSGCellList.h:20
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::unordered_map< std::string, std::unique_ptr< CSGCell > > & getCellListMap()
Get non-const map of all names to cells in cell list.
Definition: CSGCellList.h:92
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:345
const CSGLatticeList & getLatticeList() const
Get a const reference to the CSGLatticeList object.
Definition: CSGBase.h:720
const CSGCell & createCell(const std::string &name, const std::string &mat_name, const CSGRegion &region, const CSGUniverse *add_to_univ=nullptr)
Create a Material Cell object.
Definition: CSGBase.C:199
void setLatticeOuter(const CSGLattice &lattice, const std::string &outer_name)
Set the outer fill for the lattice to the material name provided.
Definition: CSGBase.C:474
const CSGUniverse & getOuterUniverse() const
Get the outer universe if outer type is UNIVERSE.
Definition: CSGLattice.C:111
void joinSurfaceList(CSGSurfaceList &surf_list, const bool ignore_identical_surfaces)
join a separate CSGSurfaceList object to this one
Definition: CSGBase.C:839
void deleteLattice(const CSGLattice &lattice)
Remove a Lattice object passed in by reference from the stored lattice list.
Definition: CSGBase.C:176
void setUniverseAtIndex(const CSGUniverse &universe, const std::pair< int, int > index)
replace the element at specified index in the lattice with the provided CSGUniverse.
Definition: CSGLattice.C:30
const CSGSurface & getSurfaceByName(const std::string &name) const
Get a Surface object by name.
Definition: CSGBase.h:108
CSGCell & addVoidCell(const std::string &name, const CSGRegion &region)
Add a Void Cell object cell list.
Definition: CSGCellList.C:53
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
Definition: CSGCellList.C:83
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:27
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices() const
Get all lattice objects.
Definition: CSGBase.h:496
bool operator==(const CSGBase &other) const
Operator overload for checking if two CSGBase objects are equal.
Definition: CSGBase.C:1133
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells() const
Get list of the all cells in the universe.
Definition: CSGUniverse.h:73
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices() const
Get all the lattices in CSGBase instance.
const std::string & getName() const
Get the name of lattice.
Definition: CSGLattice.h:62
CSGSurface & getSurface(const std::string &name) const
Get a surface by name.
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).
Definition: CSGBase.C:633
CSGSurfaceList _surface_list
List of surfaces associated with CSG object.
Definition: CSGBase.h:897
TransformationType
Enumeration of transformation types that can be applied to CSG objects.
void addTransformation(const CSGObjectVariant &csg_object, TransformationType type, const std::tuple< Real, Real, Real > &values)
Apply a transformation to a CSG object.
Definition: CSGBase.C:545
void resetCellFill()
Reset the cell fill to void.
Definition: CSGCell.C:85
nlohmann::json generateOutput() const
generate the JSON representation output for the CSG object
Definition: CSGBase.C:1041
CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.
void updateCellFill(const CSGCell &cell, const std::string &mat_name)
change the fill of the specified cell to a material fill
Definition: CSGBase.C:328
std::vector< std::reference_wrapper< const CSGSurface > > getSurfaces() const
Get the list of surfaces associated with the region.
Definition: CSGRegion.C:266
CSGCell & addMaterialCell(const std::string &name, const std::string &mat_name, const CSGRegion &region)
Add a Material Cell object to cell list.
Definition: CSGCellList.C:59
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.
Definition: CSGBase.C:1010
void joinLatticeList(CSGLatticeList &lattice_list, const bool ignore_identical_lattices)
join a separate CSGLatticeList object to this one
Definition: CSGBase.C:855
void removeCell(const std::string &name)
remove a cell of the specified name from the universe
Definition: CSGUniverse.C:59
CSGCell & addUniverseCell(const std::string &name, const CSGUniverse &univ, const CSGRegion &region)
Add a Universe Cell object to cell list.
Definition: CSGCellList.C:67
CSGUniverse & getUniverse(const std::string &name) const
Get a Universe from the list by its name.
CSGLattice is the abstract class for defining lattices.
Definition: CSGLattice.h:34
bool hasLattice(const std::string &name) const
return whether lattice with given name exists in lattice list
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:80
void addCellsToUniverse(const CSGUniverse &universe, std::vector< std::reference_wrapper< const CSGCell >> &cells)
Add a list of cells to an existing universe.
Definition: CSGBase.C:441
const CSGUniverse & getRootUniverse() const
Get the Root Universe object.
Definition: CSGBase.h:279
void updateCellRegion(const CSGCell &cell, const CSGRegion &region)
change the region of the specified cell
Definition: CSGBase.C:305
CSGUniverseList creates a container for CSGUniverse objects to pass to CSGBase.
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > & getLatticeListMap()
Get map of all names to lattices in lattice list.
void resetOuter()
reset the outer fill around the lattice elements to be VOID
Definition: CSGLattice.C:145
void joinOtherBase(std::unique_ptr< CSGBase > base, const bool ignore_identical_components)
Join another CSGBase object to this one.
Definition: CSGBase.C:663
CSGCell & addLatticeCell(const std::string &name, const CSGLattice &lattice, const CSGRegion &region)
Add a Lattice Cell object to cell list.
Definition: CSGCellList.C:75
void joinCellList(CSGCellList &cell_list, const bool ignore_identical_cells)
join a separate CSGCellList object to this one
Definition: CSGBase.C:847
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...
Definition: CSGBase.h:403
const CSGUniverse & addUniverseToList(const CSGUniverse &univ)
Add a new universe to the universe list based on a universe reference.
Definition: CSGBase.C:120
CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf, const bool ignore_identical_surface=false)
add a surface object to existing SurfaceList.
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition: CSGCellList.C:18
void removeCellsFromUniverse(const CSGUniverse &universe, std::vector< std::reference_wrapper< const CSGCell >> &cells)
Remove a list of cells from an existing universe.
Definition: CSGBase.C:466
void setLatticeUniverses(const CSGLattice &lattice, std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> &universes)
Set provided universes as the layout of the lattice.
Definition: CSGBase.C:526
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...
Definition: CSGBase.C:820
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...
Definition: CSGBase.C:758
bool hasSurface(const std::string &name) const
Check if a surface with given name exists in CSGBase object.
Definition: CSGBase.h:119
void updateOuter(const std::string &outer_name)
Update the outer of the lattice to be the provided material name.
Definition: CSGLattice.C:137
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...
Definition: CSGBase.C:863
bool hasCell(const std::string &name) const
Check if a cell with given name exists in CSGBase object.
Definition: CSGBase.h:222
CSGUniverse & addUniverse(const std::string &name)
create an empty universe
bool checkUniverseInBase(const CSGUniverse &universe) const
Definition: CSGBase.C:966
bool hasLattice(const std::string &name) const
Check if a lattice with given name exists in CSGBase object.
Definition: CSGBase.h:529
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell...
Definition: CSGCell.h:29
bool operator!=(const CSGBase &other) const
Operator overload for checking if two CSGBase objects are not equal.
Definition: CSGBase.C:1148
void checkRegionSurfaces(const CSGRegion &region) const
Definition: CSGBase.C:934
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 > > CSGObjectVariant
Define a variant type that can hold references to different CSG object types.
Definition: CSGBase.h:45
bool checkSurfaceInBase(const CSGSurface &surface) const
Definition: CSGBase.C:946
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CSGCellList _cell_list
List of cells associated with CSG object.
Definition: CSGBase.h:900
void deleteUniverse(const CSGUniverse &univ)
Remove a Universe object passed in by reference from the stored universe list.
Definition: CSGBase.C:380
CSGLatticeList _lattice_list
List of lattices associated with CSG object.
Definition: CSGBase.h:906
const CSGCell & getCellByName(const std::string &name) const
Get a Cell object by name.
Definition: CSGBase.h:214
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > & getSurfaceListMap()
Get non-const map of all names to surfaces in surface list.
void resetLatticeOuter(const CSGLattice &lattice)
reset the outer fill for the lattice to VOID
Definition: CSGBase.C:499
const LatticeType & getLatticeByName(const std::string &name)
Get a lattice object of the specified type by name This is a templated method with a default type of ...
Definition: CSGBase.h:513
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > getUniverses() const
Get the arrangement of CSGUniverses in the lattice.
Definition: CSGLattice.h:97
const CSGSurfaceList & getSurfaceList() const
Get a const reference to the CSGSurfaceList object.
Definition: CSGBase.h:678
bool checkCellInBase(const CSGCell &cell) const
Definition: CSGBase.C:956
CSGSurfaceList is a container for storing CSGSurface objects in the CSGBase object.
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface...
Definition: CSGSurface.h:26
const CSGRegion & getRegion() const
Get the cell region.
Definition: CSGCell.h:119
bool hasUniverse(const std::string &name) const
return whether universe with given name exists in universe list
CSGBase()
Default constructor.
Definition: CSGBase.C:17
const CSGCell & addCellToList(const CSGCell &cell)
Add a new cell to the cell list based on a cell reference.
Definition: CSGBase.C:85
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 & createUniverse(const std::string &name)
Create an empty Universe object.
Definition: CSGBase.h:308
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...
Definition: CSGBase.C:768
const CSGCellList & getCellList() const
Get a const reference to the CSGCellList object.
Definition: CSGBase.h:692
void deleteCell(const CSGCell &cell)
Remove a Cell object passed in by reference from the stored cell list.
Definition: CSGBase.C:275
void addCellToUniverse(const CSGUniverse &universe, const CSGCell &cell)
Add a cell to an existing universe.
Definition: CSGBase.C:424
const std::string & getFillMaterial() const
Get the cell fill material name if fill fype is CSG_MATERIAL.
Definition: CSGCell.C:67
const CSGLattice & addLatticeToList(const CSGLattice &lattice)
Add a new lattice to the lattice list based on a lattice reference.
Definition: CSGBase.C:138
void checkUniverseLinking() const
Check universes linked to root universe match universes defined in _universe_list.
Definition: CSGBase.C:986
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all cell objects.
Definition: CSGBase.h:203
~CSGBase()
Destructor.
Definition: CSGBase.C:56
const std::string getOuterType() const
Get the type of outer that fills the space around the lattice elements.
Definition: CSGLattice.h:76
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model...
Definition: CSGBase.h:51
void deleteSurface(const CSGSurface &surface)
Remove a Surface object passed in by reference from the stored surface list.
Definition: CSGBase.C:59
const CSGUniverseList & getUniverseList() const
Get a const reference to the CSGUniverseList object.
Definition: CSGBase.h:706
virtual std::unique_ptr< CSGLattice > clone() const =0
bool hasCell(const std::string &name) const
return whether cell with given name exists in cell list
Definition: CSGCellList.h:85
void resetCellFill(const CSGCell &cell)
reset the fill of the specified cell to void
Definition: CSGBase.C:317
const CSGUniverse & getUniverseByName(const std::string &name)
Get a universe object by name.
Definition: CSGBase.h:381
CSGLattice & getLattice(const std::string &name) const
Get a Lattice from the list by its name.
RotationAxisType
Enumeration of axis types for rotations.
Definition: CSGBase.h:30
void removeCellFromUniverse(const CSGUniverse &universe, const CSGCell &cell)
Remove a cell from an existing universe.
Definition: CSGBase.C:449
void addCell(const CSGCell &cell)
add cell to universe
Definition: CSGUniverse.C:28
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get all surface objects.
Definition: CSGBase.h:97
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > & getUniverseListMap()
Get non-const map of all names to universes in universe list.