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();
41 
49  const CSGSurface & addSurface(std::unique_ptr<CSGSurface> surf)
50  {
51  return _surface_list.addSurface(std::move(surf));
52  }
53 
59  std::vector<std::reference_wrapper<const CSGSurface>> getAllSurfaces() const
60  {
62  }
63 
70  const CSGSurface & getSurfaceByName(const std::string & name) const
71  {
73  }
74 
81  void renameSurface(const CSGSurface & surface, const std::string & name)
82  {
84  }
85 
96  const CSGCell & createCell(const std::string & name,
97  const std::string & mat_name,
98  const CSGRegion & region,
99  const CSGUniverse * add_to_univ = nullptr);
100 
110  const CSGCell & createCell(const std::string & name,
111  const CSGRegion & region,
112  const CSGUniverse * add_to_univ = nullptr);
113 
124  const CSGCell & createCell(const std::string & name,
125  const CSGUniverse & fill_univ,
126  const CSGRegion & region,
127  const CSGUniverse * add_to_univ = nullptr);
128 
134  std::vector<std::reference_wrapper<const CSGCell>> getAllCells() const
135  {
136  return _cell_list.getAllCells();
137  }
138 
145  const CSGCell & getCellByName(const std::string & name) const { return _cell_list.getCell(name); }
146 
153  void renameCell(const CSGCell & cell, const std::string & name)
154  {
155  _cell_list.renameCell(cell, name);
156  }
157 
164  void updateCellRegion(const CSGCell & cell, const CSGRegion & region);
165 
171  const CSGUniverse & getRootUniverse() const { return _universe_list.getRoot(); }
172 
178  void renameRootUniverse(const std::string & name)
179  {
181  }
182 
189  void renameUniverse(const CSGUniverse & universe, const std::string & name)
190  {
192  }
193 
200  const CSGUniverse & createUniverse(const std::string & name)
201  {
203  }
204 
212  const CSGUniverse & createUniverse(const std::string & name,
213  std::vector<std::reference_wrapper<const CSGCell>> & cells);
214 
221  void addCellToUniverse(const CSGUniverse & universe, const CSGCell & cell);
222 
229  void addCellsToUniverse(const CSGUniverse & universe,
230  std::vector<std::reference_wrapper<const CSGCell>> & cells);
231 
238  void removeCellFromUniverse(const CSGUniverse & universe, const CSGCell & cell);
239 
246  void removeCellsFromUniverse(const CSGUniverse & universe,
247  std::vector<std::reference_wrapper<const CSGCell>> & cells);
248 
254  std::vector<std::reference_wrapper<const CSGUniverse>> getAllUniverses() const
255  {
257  }
258 
265  const CSGUniverse & getUniverseByName(const std::string & name)
266  {
268  }
269 
277  void joinOtherBase(std::unique_ptr<CSGBase> base);
278 
289  void joinOtherBase(std::unique_ptr<CSGBase> base, std::string & new_root_name_join);
290 
303  void joinOtherBase(std::unique_ptr<CSGBase> base,
304  const std::string & new_root_name_base,
305  const std::string & new_root_name_join);
306 
311  nlohmann::json generateOutput() const;
312 
313 private:
323  CSGSurface & getSurface(const std::string & name) { return _surface_list.getSurface(name); }
324 
326  void checkUniverseLinking() const;
327 
334  void getLinkedUniverses(const CSGUniverse & univ,
335  std::vector<std::string> & linked_universe_names) const;
336 
343 
350 
357 
363  void joinSurfaceList(CSGSurfaceList & surf_list);
364 
370  void joinCellList(CSGCellList & cell_list);
371 
378  void joinUniverseList(CSGUniverseList & univ_list);
379 
389  void joinUniverseList(CSGUniverseList & univ_list, const std::string & new_root_name_incoming);
390 
402  void joinUniverseList(CSGUniverseList & univ_list,
403  const std::string & new_root_name_base,
404  const std::string & new_root_name_incoming);
405 
406  // check that surfaces used in this region are a part of this CSGBase instance
407  void checkRegionSurfaces(const CSGRegion & region) const;
408 
409  // check that cell being accessed is a part of this CSGBase instance
410  bool checkCellInBase(const CSGCell & cell) const;
411 
412  // check that universe being accessed is a part of this CSGBase instance
413  bool checkUniverseInBase(const CSGUniverse & universe) const;
414 
417 
420 
423 
424 #ifdef MOOSE_UNIT_TEST
425  FRIEND_TEST(CSGBaseTest, testCheckRegionSurfaces);
428  FRIEND_TEST(CSGBaseTest, testAddGetSurface);
429  FRIEND_TEST(CSGBaseTest, testUniverseLinking);
431 #endif
432 };
433 } // namespace CSG
std::string name(const ElemQuality q)
void joinCellList(CSGCellList &cell_list)
join a separate CSGCellList object to this one
Definition: CSGBase.C:179
void renameUniverse(const CSGUniverse &universe, const std::string &name)
rename the specified universe
Definition: CSGBase.h:189
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:254
CSGUniverseList _universe_list
List of universes associated with CSG object.
Definition: CSGBase.h:422
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
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:23
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:187
void joinOtherBase(std::unique_ptr< CSGBase > base)
Join another CSGBase object to this one.
Definition: CSGBase.C:142
const CSGSurface & getSurfaceByName(const std::string &name) const
Get a Surface object by name.
Definition: CSGBase.h:70
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
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:416
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:308
nlohmann::json generateOutput() const
generate the JSON representation output for the CSG object
Definition: CSGBase.C:319
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:109
const CSGUniverse & getRootUniverse() const
Get the Root Universe object.
Definition: CSGBase.h:171
void updateCellRegion(const CSGCell &cell, const CSGRegion &region)
change the region of the specified cell
Definition: CSGBase.C:71
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:153
const CSGUniverse & getRoot() const
Get the root universe.
void renameRootUniverse(const std::string &name)
rename the root universe for this instance (default is ROOT_UNIVERSE)
Definition: CSGBase.h:178
void joinSurfaceList(CSGSurfaceList &surf_list)
join a separate CSGSurfaceList object to this one
Definition: CSGBase.C:168
const CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a unique surface pointer to this base instance
Definition: CSGBase.h:49
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:134
CSGSurface & getSurface(const std::string &name)
Get a Surface object by name.
Definition: CSGBase.h:323
CSGUniverse & addUniverse(const std::string &name)
create an empty universe
bool checkUniverseInBase(const CSGUniverse &universe) const
Definition: CSGBase.C:282
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell...
Definition: CSGCell.h:27
void checkRegionSurfaces(const CSGRegion &region) const
Definition: CSGBase.C:255
CSGCellList _cell_list
List of cells associated with CSG object.
Definition: CSGBase.h:419
CSGCellList & getCellList()
Get the CSGCellList object.
Definition: CSGBase.h:349
const CSGCell & getCellByName(const std::string &name) const
Get a Cell object by name.
Definition: CSGBase.h:145
void renameUniverse(const CSGUniverse &universe, const std::string &name)
rename the specified universe
CSGUniverseList & getUniverseList()
Get the CSGUniverseList 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:272
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 CSGUniverse & createUniverse(const std::string &name)
Create an empty Universe object.
Definition: CSGBase.h:200
void addCellToUniverse(const CSGUniverse &universe, const CSGCell &cell)
Add a cell to an existing universe.
Definition: CSGBase.C:92
CSGSurfaceList & getSurfaceList()
Get the CSGSurfaceList object.
Definition: CSGBase.h:342
void checkUniverseLinking() const
Check universes linked to root universe match universes defined in _universe_list.
Definition: CSGBase.C:292
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all cell objects.
Definition: CSGBase.h:134
~CSGBase()
Destructor.
Definition: CSGBase.C:20
void renameSurface(const CSGSurface &surface, const std::string &name)
rename the specified surface
Definition: CSGBase.h:81
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model...
Definition: CSGBase.h:29
const CSGUniverse & getUniverseByName(const std::string &name)
Get a universe object by name.
Definition: CSGBase.h:265
void removeCellFromUniverse(const CSGUniverse &universe, const CSGCell &cell)
Remove a cell from an existing universe.
Definition: CSGBase.C:117
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get all surface objects.
Definition: CSGBase.h:59