https://mooseframework.inl.gov
CSGBase.h
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 #pragma once
11 
12 #include "CSGSurfaceList.h"
13 #include "CSGRegion.h"
14 #include "CSGCellList.h"
15 #include "CSGUniverseList.h"
16 #include "nlohmann/json.h"
17 
18 #ifdef MOOSE_UNIT_TEST
19 #include "gtest/gtest.h"
20 #endif
21 
22 namespace CSG
23 {
24 
29 class CSGBase
30 {
31 public:
35  CSGBase();
36 
40  CSGBase(const CSGBase & other_base);
41 
45  ~CSGBase();
46 
48  std::unique_ptr<CSGBase> clone() const { return std::make_unique<CSGBase>(*this); }
49 
57  const CSGSurface & addSurface(std::unique_ptr<CSGSurface> surf)
58  {
59  return _surface_list.addSurface(std::move(surf));
60  }
61 
67  std::vector<std::reference_wrapper<const CSGSurface>> getAllSurfaces() const
68  {
70  }
71 
78  const CSGSurface & getSurfaceByName(const std::string & name) const
79  {
81  }
82 
89  void renameSurface(const CSGSurface & surface, const std::string & name)
90  {
92  }
93 
104  const CSGCell & createCell(const std::string & name,
105  const std::string & mat_name,
106  const CSGRegion & region,
107  const CSGUniverse * add_to_univ = nullptr);
108 
118  const CSGCell & createCell(const std::string & name,
119  const CSGRegion & region,
120  const CSGUniverse * add_to_univ = nullptr);
121 
132  const CSGCell & createCell(const std::string & name,
133  const CSGUniverse & fill_univ,
134  const CSGRegion & region,
135  const CSGUniverse * add_to_univ = nullptr);
136 
142  std::vector<std::reference_wrapper<const CSGCell>> getAllCells() const
143  {
144  return _cell_list.getAllCells();
145  }
146 
153  const CSGCell & getCellByName(const std::string & name) const { return _cell_list.getCell(name); }
154 
161  void renameCell(const CSGCell & cell, const std::string & name)
162  {
163  _cell_list.renameCell(cell, name);
164  }
165 
172  void updateCellRegion(const CSGCell & cell, const CSGRegion & region);
173 
179  const CSGUniverse & getRootUniverse() const { return _universe_list.getRoot(); }
180 
186  void renameRootUniverse(const std::string & name)
187  {
189  }
190 
197  void renameUniverse(const CSGUniverse & universe, const std::string & name)
198  {
200  }
201 
208  const CSGUniverse & createUniverse(const std::string & name)
209  {
211  }
212 
220  const CSGUniverse & createUniverse(const std::string & name,
221  std::vector<std::reference_wrapper<const CSGCell>> & cells);
222 
229  void addCellToUniverse(const CSGUniverse & universe, const CSGCell & cell);
230 
237  void addCellsToUniverse(const CSGUniverse & universe,
238  std::vector<std::reference_wrapper<const CSGCell>> & cells);
239 
246  void removeCellFromUniverse(const CSGUniverse & universe, const CSGCell & cell);
247 
254  void removeCellsFromUniverse(const CSGUniverse & universe,
255  std::vector<std::reference_wrapper<const CSGCell>> & cells);
256 
262  std::vector<std::reference_wrapper<const CSGUniverse>> getAllUniverses() const
263  {
265  }
266 
273  const CSGUniverse & getUniverseByName(const std::string & name)
274  {
276  }
277 
285  void joinOtherBase(std::unique_ptr<CSGBase> base);
286 
297  void joinOtherBase(std::unique_ptr<CSGBase> base, std::string & new_root_name_join);
298 
311  void joinOtherBase(std::unique_ptr<CSGBase> base,
312  const std::string & new_root_name_base,
313  const std::string & new_root_name_join);
314 
319  nlohmann::json generateOutput() const;
320 
322  bool operator==(const CSGBase & other) const;
323 
325  bool operator!=(const CSGBase & other) const;
326 
327 private:
337  CSGSurface & getSurface(const std::string & name) { return _surface_list.getSurface(name); }
338 
340  void checkUniverseLinking() const;
341 
348  void getLinkedUniverses(const CSGUniverse & univ,
349  std::vector<std::string> & linked_universe_names) const;
350 
356  const CSGSurfaceList & getSurfaceList() const { return _surface_list; }
357 
364 
370  const CSGCellList & getCellList() const { return _cell_list; }
371 
378 
384  const CSGUniverseList & getUniverseList() const { return _universe_list; }
385 
392 
398  void joinSurfaceList(CSGSurfaceList & surf_list);
399 
405  void joinCellList(CSGCellList & cell_list);
406 
413  void joinUniverseList(CSGUniverseList & univ_list);
414 
424  void joinUniverseList(CSGUniverseList & univ_list, const std::string & new_root_name_incoming);
425 
437  void joinUniverseList(CSGUniverseList & univ_list,
438  const std::string & new_root_name_base,
439  const std::string & new_root_name_incoming);
440 
441  // check that surfaces used in this region are a part of this CSGBase instance
442  void checkRegionSurfaces(const CSGRegion & region) const;
443 
444  // check that cell being accessed is a part of this CSGBase instance
445  bool checkCellInBase(const CSGCell & cell) const;
446 
447  // check that universe being accessed is a part of this CSGBase instance
448  bool checkUniverseInBase(const CSGUniverse & universe) const;
449 
456  const CSGCell & addCellToList(const CSGCell & cell);
457 
464  const CSGUniverse & addUniverseToList(const CSGUniverse & univ);
465 
468 
471 
474 
475 #ifdef MOOSE_UNIT_TEST
476  FRIEND_TEST(CSGBaseTest, testCheckRegionSurfaces);
479  FRIEND_TEST(CSGBaseTest, testAddGetSurface);
480  FRIEND_TEST(CSGBaseTest, testUniverseLinking);
482 #endif
483 };
484 } // namespace CSG
std::string name(const ElemQuality q)
void joinCellList(CSGCellList &cell_list)
join a separate CSGCellList object to this one
Definition: CSGBase.C:249
void renameUniverse(const CSGUniverse &universe, const std::string &name)
rename the specified universe
Definition: CSGBase.h:197
CSGCell & getCell(const std::string &name) const
Get the CSGCell by name.
Definition: CSGCellList.C:28
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:262
CSGUniverseList _universe_list
List of universes associated with CSG object.
Definition: CSGBase.h:473
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection...
Definition: CSGRegion.h:21
CSGCellList creates a container for CSGCell objects to pass to CSGBase object.
Definition: CSGCellList.h:20
std::unique_ptr< CSGBase > clone() const
Create a deep copy of this CSGBase instance.
Definition: CSGBase.h:48
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:93
void joinUniverseList(CSGUniverseList &univ_list)
join a separate CSGUniverseList object to this one; root universes from univ_list will be combined in...
Definition: CSGBase.C:257
void joinOtherBase(std::unique_ptr< CSGBase > base)
Join another CSGBase object to this one.
Definition: CSGBase.C:212
const CSGSurface & getSurfaceByName(const std::string &name) const
Get a Surface object by name.
Definition: CSGBase.h:78
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
Definition: CSGCellList.C:59
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:26
bool operator==(const CSGBase &other) const
Operator overload for checking if two CSGBase objects are equal.
Definition: CSGBase.C:441
CSGSurface & getSurface(const std::string &name) const
Get a surface by name.
CSGSurfaceList _surface_list
List of surfaces associated with CSG object.
Definition: CSGBase.h:467
void getLinkedUniverses(const CSGUniverse &univ, std::vector< std::string > &linked_universe_names) const
Recursive method to retrieve all universes linked to current universe.
Definition: CSGBase.C:378
nlohmann::json generateOutput() const
generate the JSON representation output for the CSG object
Definition: CSGBase.C:389
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get list of references to all surfaces in surface list.
CSGUniverse & getUniverse(const std::string &name) const
Get a Universe from the list by its name.
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:179
const CSGUniverse & getRootUniverse() const
Get the Root Universe object.
Definition: CSGBase.h:179
void updateCellRegion(const CSGCell &cell, const CSGRegion &region)
change the region of the specified cell
Definition: CSGBase.C:141
CSGUniverseList creates a container for CSGUniverse objects to pass to CSGBase.
void renameSurface(const CSGSurface &surface, const std::string &name)
rename the specified surface
FRIEND_TEST(CSGBaseTest, testCheckRegionSurfaces)
Friends for unit testing.
void renameCell(const CSGCell &cell, const std::string &name)
rename the specified cell
Definition: CSGBase.h:161
const CSGUniverse & getRoot() const
Get the root universe.
const CSGUniverse & addUniverseToList(const CSGUniverse &univ)
Add a new universe to the universe list based on a universe reference.
Definition: CSGBase.C:75
void renameRootUniverse(const std::string &name)
rename the root universe for this instance (default is ROOT_UNIVERSE)
Definition: CSGBase.h:186
void joinSurfaceList(CSGSurfaceList &surf_list)
join a separate CSGSurfaceList object to this one
Definition: CSGBase.C:238
const CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a unique surface pointer to this base instance
Definition: CSGBase.h:57
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:204
CSGSurface & getSurface(const std::string &name)
Get a Surface object by name.
Definition: CSGBase.h:337
CSGUniverse & addUniverse(const std::string &name)
create an empty universe
bool checkUniverseInBase(const CSGUniverse &universe) const
Definition: CSGBase.C:352
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell...
Definition: CSGCell.h:27
bool operator!=(const CSGBase &other) const
Operator overload for checking if two CSGBase objects are not equal.
Definition: CSGBase.C:454
void checkRegionSurfaces(const CSGRegion &region) const
Definition: CSGBase.C:325
CSGCellList _cell_list
List of cells associated with CSG object.
Definition: CSGBase.h:470
CSGCellList & getCellList()
Get a non-const reference to the CSGCellList object.
Definition: CSGBase.h:377
const CSGCell & getCellByName(const std::string &name) const
Get a Cell object by name.
Definition: CSGBase.h:153
void renameUniverse(const CSGUniverse &universe, const std::string &name)
rename the specified universe
CSGUniverseList & getUniverseList()
Get a non-const reference to the CSGUniverseList object.
Definition: CSGBase.h:391
const CSGSurfaceList & getSurfaceList() const
Get a const reference to the CSGSurfaceList object.
Definition: CSGBase.h:356
void renameCell(const CSGCell &cell, const std::string &name)
rename the specified cell
Definition: CSGCellList.C:68
bool checkCellInBase(const CSGCell &cell) const
Definition: CSGBase.C:342
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
CSGBase()
Default constructor.
Definition: CSGBase.C:15
CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a surface object to existing SurfaceList.
const CSGCell & addCellToList(const CSGCell &cell)
Add a new cell to the cell list based on a cell reference.
Definition: CSGBase.C:48
const CSGUniverse & createUniverse(const std::string &name)
Create an empty Universe object.
Definition: CSGBase.h:208
const CSGCellList & getCellList() const
Get a const reference to the CSGCellList object.
Definition: CSGBase.h:370
void addCellToUniverse(const CSGUniverse &universe, const CSGCell &cell)
Add a cell to an existing universe.
Definition: CSGBase.C:162
CSGSurfaceList & getSurfaceList()
Get a non-const reference to the CSGSurfaceList object.
Definition: CSGBase.h:363
void checkUniverseLinking() const
Check universes linked to root universe match universes defined in _universe_list.
Definition: CSGBase.C:362
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all cell objects.
Definition: CSGBase.h:142
~CSGBase()
Destructor.
Definition: CSGBase.C:45
void renameSurface(const CSGSurface &surface, const std::string &name)
rename the specified surface
Definition: CSGBase.h:89
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model...
Definition: CSGBase.h:29
const CSGUniverseList & getUniverseList() const
Get a const reference to the CSGUniverseList object.
Definition: CSGBase.h:384
const CSGUniverse & getUniverseByName(const std::string &name)
Get a universe object by name.
Definition: CSGBase.h:273
void removeCellFromUniverse(const CSGUniverse &universe, const CSGCell &cell)
Remove a cell from an existing universe.
Definition: CSGBase.C:187
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get all surface objects.
Definition: CSGBase.h:67