An open source method of characteristics neutron transport code.
Universe.h
Go to the documentation of this file.
1 
8 #ifndef UNIVERSE_H_
9 #define UNIVERSE_H_
10 
11 #ifdef __cplusplus
12 #ifdef SWIG
13 #include "Python.h"
14 #endif
15 #include "constants.h"
16 #include "LocalCoords.h"
17 #include "boundary_type.h"
18 #include <limits>
19 #include <map>
20 #include <vector>
21 #endif
22 
23 
24 /* Forward declarations to resolve circular dependencies */
25 class LocalCoords;
26 class Cell;
27 class Surface;
28 class Material;
29 
30 
31 int universe_id();
32 void reset_universe_id();
34 
35 
41 
44 
47 };
48 
49 
58 class Universe {
59 
60 protected:
61 
63  static int _n;
64 
66  int _uid;
67 
69  int _id;
70 
72  char* _name;
73 
76 
78  std::map<int, Cell*> _cells;
79 
83 
85  double _min_x;
86  double _max_x;
87  double _min_y;
88  double _max_y;
89  double _min_z;
90  double _max_z;
91 
94 
97  boundaryType _max_x_bound;
98  boundaryType _min_y_bound;
99  boundaryType _max_y_bound;
100  boundaryType _min_z_bound;
101  boundaryType _max_z_bound;
102 
103 public:
104 
105  Universe(const int id=-1, const char* name="");
106  virtual ~Universe();
107  int getUid() const;
108  int getId() const;
109  char* getName() const;
111  int getNumCells() const;
112  double getMinX();
113  double getMaxX();
114  double getMinY();
115  double getMaxY();
116  double getMinZ();
117  double getMaxZ();
124 
125  Cell* getCell(int cell_id);
126  std::map<int, Cell*> getCells() const;
127  std::map<int, Cell*> getAllCells();
128  std::map<int, Material*> getAllMaterials();
129  std::map<int, Universe*> getAllUniverses();
130  bool isFissionable();
131 
132  void resetBoundaries();
133  void calculateBoundaries();
134  void setName(const char* name);
135  void setType(universeType type);
136  void addCell(Cell* cell);
137  void removeCell(Cell* cell);
138 
139  bool containsPoint(Point* point);
140  Cell* findCell(LocalCoords* coords);
141  void setFissionability(bool fissionable);
142  void subdivideCells(double max_radius=INFINITY);
143  void buildNeighbors();
144 
145  virtual std::string toString();
146  void printString();
147 
148  Universe* clone();
149 };
150 
151 
156 class Lattice: public Universe {
157 
158 private:
159 
161  int _num_x;
162 
164  int _num_y;
165 
167  int _num_z;
168 
170  bool _non_uniform;
171 
174  double _width_x;
175 
177  std::vector<double> _widths_x;
178  std::vector<double> _accumulate_x;
179 
182  double _width_y;
183 
185  std::vector<double> _widths_y;
186  std::vector<double> _accumulate_y;
187 
190  double _width_z;
191 
193  std::vector<double> _widths_z;
194  std::vector<double> _accumulate_z;
195 
197  Point _offset;
198 
200  std::vector< std::vector< std::vector< std::pair<int, Universe*> > > >
201  _universes;
202 
203 public:
204 
205  Lattice(const int id=-1, const char* name="");
206  virtual ~Lattice();
207 
208  void setOffset(double x, double y, double z=0.0);
209  Point* getOffset();
210  int getNumX() const;
211  int getNumY() const;
212  int getNumZ() const;
213  double getWidthX() const;
214  double getWidthY() const;
215  double getWidthZ() const;
216  bool getNonUniform() const;
217  const std::vector<double>& getWidthsX() const;
218  const std::vector<double>& getWidthsY() const;
219  const std::vector<double>& getWidthsZ() const;
220  const std::vector<double>& getAccumulateX() const;
221  const std::vector<double>& getAccumulateY() const;
222  const std::vector<double>& getAccumulateZ() const;
223  double getMinX();
224  double getMaxX();
225  double getMinY();
226  double getMaxY();
227  double getMinZ();
228  double getMaxZ();
229 
230  Universe* getUniverse(int lat_x, int lat_y, int lat_z=0) const;
231  std::vector< std::vector< std::vector< std::pair<int, Universe*> > > >*
232  getUniverses();
233  std::map<int, Universe*> getUniqueUniverses();
234  std::map<int, double> getUniqueRadius(std::map<int, Universe*> unique_universes);
235  std::map<int, Cell*> getAllCells();
236  std::map<int, Universe*> getAllUniverses();
237 
238  void setNumX(int num_x);
239  void setNumY(int num_y);
240  void setNumZ(int num_z);
241  void setWidth(double width_x, double width_y,
242  double width_z=std::numeric_limits<double>::infinity());
243  void setNonUniform(bool non_uniform);
244  void setWidthsX(std::vector<double> widthsx);
245  void setWidthsY(std::vector<double> widthsy);
246  void setWidthsZ(std::vector<double> widthsz);
247  void setAccumulateX(std::vector<double> accumulatex);
248  void setAccumulateY(std::vector<double> accumulatey);
249  void setAccumulateZ(std::vector<double> accumulatez);
250  void setUniverses(int num_z, int num_y, int num_x, Universe** universes);
251  void updateUniverse(int lat_x, int lat_y, int lat_z, Universe* universe);
252  void removeUniverse(Universe* universe);
253  void subdivideCells(double max_radius=INFINITY);
254  void buildNeighbors();
255 
256  bool containsPoint(Point* point);
257  Cell* findCell(LocalCoords* coords);
258  double minSurfaceDist(Point* point, double azim, double polar=M_PI/2.0);
259 
260  int getLatX(Point* point);
261  int getLatY(Point* point);
262  int getLatZ(Point* point);
263 
264  int getLatticeCell(Point* point);
265  int getLatticeSurface(int cell, Point* point);
266  int getLatticeSurfaceOTF(int cell, double z, int surface_2D);
267 
268  std::string toString();
269  void printString();
270 
271  /* Set XYZ widths of non-uniform meshes */
272  void setWidths(std::vector<double> widths_x, std::vector<double> widths_y,
273  std::vector<double> widths_z);
274  void computeSizes();
275 
276  /* For debug use */
277  void printLatticeSizes();
278 
279 };
280 
287 template<typename tPair>
288 struct second_t {
289  typename tPair::second_type operator()(const tPair& p) const {
290  return p.second;
291  }
292 };
293 
294 
303 template<typename tMap>
306 }
307 
308 #endif /* UNIVERSE_H_ */
double getMaxX()
Returns the maximum reachable x-coordinate in the Lattice.
Definition: Universe.cpp:1250
int getLatticeCell(Point *point)
Finds the Lattice cell index that a point lies in.
Definition: Universe.cpp:2068
int universe_id()
Returns an auto-generated unique Universe ID.
Definition: Universe.cpp:19
Universe * getUniverse(int lat_x, int lat_y, int lat_z=0) const
Returns a pointer to the Universe within a specific Lattice cell.
Definition: Universe.cpp:1298
Represents a Cell inside of a Universe.
Definition: Cell.h:56
int _id
Definition: Universe.h:69
The LocalCoords represents a set of local coordinates on some level of nested Universes making up the...
Definition: LocalCoords.h:46
double getMaxZ()
Returns the maximum reachable z-coordinate in the Universe.
Definition: Universe.cpp:214
int getUid() const
Returns the Universe&#39;s unique ID.
Definition: Universe.cpp:104
int cell_id()
Returns an auto-generated unique Cell ID.
Definition: Cell.cpp:20
void setWidthsX(std::vector< double > widthsx)
Set the widths of non-uniform Lattice in x direction.
Definition: Universe.cpp:1489
void setWidthsY(std::vector< double > widthsy)
Set the widths of non-uniform Lattice in y direction.
Definition: Universe.cpp:1498
void setNumX(int num_x)
Set the number of Lattice cells along the x-axis.
Definition: Universe.cpp:1434
Universe * clone()
Clones this Universe and copy cells map.
Definition: Universe.cpp:699
Represents a general Surface in 3D.
Definition: Surface.h:70
boundaryType getMinYBoundaryType()
Returns the boundary conditions (VACUUM or REFLECTIVE) at the minimum reachable y-coordinate in the U...
Definition: Universe.cpp:270
double getMinZ()
Returns the minimum reachable z-coordinate in the Universe.
Definition: Universe.cpp:201
void printLatticeSizes()
For debug use.
Definition: Universe.cpp:2369
double getWidthY() const
Return the width of the Lattice along the y-axis.
Definition: Universe.cpp:1160
boundaryType
The types of boundary conditions supported by OpenMOC for Surfaces.
Definition: boundary_type.h:15
Math constants and comparision tolerances.
const std::vector< double > & getAccumulateX() const
Return the accumulate widths of non-uniform Lattice in x direction.
Definition: Universe.cpp:1214
A Universe represents an unbounded space in 3D.
Definition: Universe.h:58
int getNumCells() const
Return the number of Cells in this Universe.
Definition: Universe.cpp:140
boundaryType getMinZBoundaryType()
Returns the boundary conditions (VACUUM or REFLECTIVE) at the minimum reachable z-coordinate in the U...
Definition: Universe.cpp:312
void setAccumulateY(std::vector< double > accumulatey)
Set the accumulate widths of non-uniform Lattice in y direction.
Definition: Universe.cpp:1527
double getWidthX() const
Return the width of the Lattice along the x-axis.
Definition: Universe.cpp:1151
std::map< int, Cell * > _cells
Definition: Universe.h:78
const std::vector< double > & getWidthsZ() const
Return the widths of non-uniform Lattice in z direction.
Definition: Universe.cpp:1205
void setNonUniform(bool non_uniform)
Set the non-uniform boolean of Lattice.
Definition: Universe.cpp:1480
void printString()
Prints a string representation of all of the Lattice&#39;s attributes to the console. ...
Definition: Universe.cpp:2051
void reset_universe_id()
Resets the auto-generated unique Universe ID counter to 1,000,000.
Definition: Universe.cpp:33
char * getName() const
Return the user-defined name of the Universe.
Definition: Universe.cpp:122
int getId() const
Return the user-specified ID for this Universe.
Definition: Universe.cpp:113
int getLatZ(Point *point)
Finds the Lattice cell z index that a point lies in.
Definition: Universe.cpp:1968
const std::vector< double > & getAccumulateZ() const
Return the accumulate widths of non-uniform Lattice in z direction.
Definition: Universe.cpp:1232
bool getNonUniform() const
Return the non-uniform boolean of Lattice.
Definition: Universe.cpp:1178
Class to represent a 2D/3D point in space.
Definition: Point.h:24
void removeCell(Cell *cell)
Removes a Cell from this Universe&#39;s container of Cells.
Definition: Universe.cpp:528
void setFissionability(bool fissionable)
Sets whether or not this Universe contains a fissionable Material with a non-zero fission cross-secti...
Definition: Universe.cpp:497
void computeSizes()
Set _widths_x, _widths_y, _widths_z for uniform case, compute accumulate variables.
Definition: Universe.cpp:2337
void setName(const char *name)
Sets the name of the Universe.
Definition: Universe.cpp:465
int getLatticeSurface(int cell, Point *point)
Finds the Lattice cell surface that a point lies on. If the point is not on a surface, -1 is returned.
Definition: Universe.cpp:2085
universeType _type
Definition: Universe.h:75
void setWidthsZ(std::vector< double > widthsz)
Set the widths of non-uniform Lattice in z direction.
Definition: Universe.cpp:1507
Cell * findCell(LocalCoords *coords)
Finds the Cell within this Lattice that a LocalCoords is in.
Definition: Universe.cpp:1778
double getMaxY()
Returns the maximum reachable y-coordinate in the Lattice.
Definition: Universe.cpp:1268
double getMaxX()
Returns the maximum reachable x-coordinate in the Universe.
Definition: Universe.cpp:162
void setUniverses(int num_z, int num_y, int num_x, Universe **universes)
Sets the array of Universe pointers filling each Lattice cell.
Definition: Universe.cpp:1563
double getMinZ()
Returns the minimum reachable z-coordinate in the Lattice.
Definition: Universe.cpp:1277
int getLatX(Point *point)
Finds the Lattice cell x index that a point lies in.
Definition: Universe.cpp:1897
void setAccumulateZ(std::vector< double > accumulatez)
Set the accumulate widths of non-uniform Lattice in z direction.
Definition: Universe.cpp:1537
boundaryType getMaxYBoundaryType()
Returns the boundary conditions (VACUUM or REFLECTIVE) at the maximum reachable y-coordinate in the U...
Definition: Universe.cpp:291
boundaryType getMaxXBoundaryType()
Returns the boundary conditions (VACUUM or REFLECTIVE) at the maximum reachable x-coordinate in the U...
Definition: Universe.cpp:249
const std::vector< double > & getWidthsY() const
Return the widths of non-uniform Lattice in y direction.
Definition: Universe.cpp:1196
Point * getOffset()
Return a pointer to the offset for this Cell (in global coordinates).
Definition: Universe.cpp:1115
double getMinX()
Returns the minimum reachable x-coordinate in the Lattice.
Definition: Universe.cpp:1241
void printString()
Prints a string representation of the Universe&#39;s attributes to the console.
Definition: Universe.cpp:690
void setNumY(int num_y)
Set the number of Lattice cells along the y-axis.
Definition: Universe.cpp:1443
void setAccumulateX(std::vector< double > accumulatex)
Set the accumulate widths of non-uniform Lattice in x direction.
Definition: Universe.cpp:1517
void buildNeighbors()
Builds collections of neighboring Cells for all Cells in this Universe for optimized ray tracing...
Definition: Universe.cpp:650
double getMaxZ()
Returns the maximum reachable z-coordinate in the Lattice.
Definition: Universe.cpp:1286
second_t< typename tMap::value_type > pair_second(const tMap &map)
A helper routine for the Universe::findCell() method.
Definition: Universe.h:304
virtual ~Universe()
Destructor clears the Cell pointers container.
Definition: Universe.cpp:89
double getMinX()
Returns the minimum reachable x-coordinate in the Universe.
Definition: Universe.cpp:149
double getMaxY()
Returns the maximum reachable y-coordinate in the Universe.
Definition: Universe.cpp:188
Cell * getCell(int cell_id)
Returns a Cell in this universe.
Definition: Universe.cpp:354
int _uid
Definition: Universe.h:66
double minSurfaceDist(Point *point, double azim, double polar=M_PI/2.0)
Finds the distance to the nearest surface.
Definition: Universe.cpp:1835
void calculateBoundaries()
Calculates the boundary locations and conditions (VACUUM or REFLECTIVE) at the maximum and minimum re...
Definition: Universe.cpp:736
int getNumY() const
Return the number of Lattice cells along the y-axis.
Definition: Universe.cpp:1133
std::map< int, Universe * > getUniqueUniverses()
Aggregates a list (vector) of the IDs of all Universes within the FILL type Cells filling this Univer...
Definition: Universe.cpp:1328
std::map< int, Cell * > getCells() const
Return the container of Cell IDs and Cell pointers in this Universe.
Definition: Universe.cpp:368
A helper struct for the Universe::findCell() method.
Definition: Universe.h:288
std::map< int, Material * > getAllMaterials()
Returns the std::map of all IDs and Material pointers filling this Universe.
Definition: Universe.cpp:401
std::string toString()
Converts a Lattice&#39;s attributes to a character array representation.
Definition: Universe.cpp:2007
bool _fissionable
Definition: Universe.h:82
void removeUniverse(Universe *universe)
Removes all references to a Universe from the Lattice.
Definition: Universe.cpp:1650
std::map< int, Cell * > getAllCells()
Returns the std::map of Cell IDs and Cell pointers in this Universe at all nested Universe levels...
Definition: Universe.cpp:378
int getLatticeSurfaceOTF(int cell, double z, int surface_2D)
Finds the Lattice cell surface that a point lies on. If the point is not on a surface, -1 is returned.
Definition: Universe.cpp:2225
void subdivideCells(double max_radius=INFINITY)
Subdivides all of the Material-filled Cells within this Lattice into rings and angular sectors aligne...
Definition: Universe.cpp:1671
void setWidth(double width_x, double width_y, double width_z=std::numeric_limits< double >::infinity())
Set the width of each Lattice cell.
Definition: Universe.cpp:1463
The Material class represents a unique material and its relevant nuclear data (i.e., multigroup cross-sections) for neutron transport.
Definition: Material.h:51
Cell * findCell(LocalCoords *coords)
Finds the Cell for which a LocalCoords object resides.
Definition: Universe.cpp:544
const std::vector< double > & getAccumulateY() const
Return the accumulate widths of non-uniform Lattice in y direction.
Definition: Universe.cpp:1223
bool containsPoint(Point *point)
Determines whether a Point is contained inside a Universe.
Definition: Universe.cpp:1719
void buildNeighbors()
Builds collections of neighboring Cells for all Cells in each Universe in the Lattice for optimized r...
Definition: Universe.cpp:1699
virtual std::string toString()
Convert the member attributes of this Universe to a character array.
Definition: Universe.cpp:663
std::map< int, Cell * > getAllCells()
Returns the std::map of Cell IDs and Cell pointers in this Lattice at all nested Universe levels...
Definition: Universe.cpp:1383
bool containsPoint(Point *point)
Checks if a Point is within the bounds of a Lattice.
Definition: Universe.cpp:1737
double getMinY()
Returns the minimum reachable y-coordinate in the Universe.
Definition: Universe.cpp:175
void updateUniverse(int lat_x, int lat_y, int lat_z, Universe *universe)
Update the Universe in a particular Lattice cell.
Definition: Universe.cpp:1620
double getMinY()
Returns the minimum reachable y-coordinate in the Lattice.
Definition: Universe.cpp:1259
const std::vector< double > & getWidthsX() const
Return the widths of non-uniform Lattice in x direction.
Definition: Universe.cpp:1187
void setType(universeType type)
Sets the Universe type to SIMPLE or LATTICE.
Definition: Universe.cpp:484
int getNumX() const
Return the number of Lattice cells along the x-axis.
Definition: Universe.cpp:1124
Universe(const int id=-1, const char *name="")
Constructor assigns a unique and user-specified ID for the Universe.
Definition: Universe.cpp:58
void addCell(Cell *cell)
Adds a Cell to this Universe.
Definition: Universe.cpp:508
void setOffset(double x, double y, double z=0.0)
Set the offset in global coordinates for this Lattice.
Definition: Universe.cpp:1104
double getWidthZ() const
Return the width of the Lattice along the z-axis.
Definition: Universe.cpp:1169
int getNumZ() const
Return the number of Lattice cells along the z-axis.
Definition: Universe.cpp:1142
Lattice(const int id=-1, const char *name="")
Constructor sets the user-specified and unique IDs for this Lattice.
Definition: Universe.cpp:1059
boundaryType getMinXBoundaryType()
Returns the boundary conditions (VACUUM or REFLECTIVE) at the minimum reachable x-coordinate in the U...
Definition: Universe.cpp:228
bool _boundaries_inspected
Definition: Universe.h:93
Represents a repeating 3D Lattice of Universes.
Definition: Universe.h:156
universeType getType()
Return the Universe type (SIMPLE or LATTICE).
Definition: Universe.cpp:131
void setWidths(std::vector< double > widths_x, std::vector< double > widths_y, std::vector< double > widths_z)
Set widths of non-uniform meshes in x y z directions.
Definition: Universe.cpp:2324
virtual ~Lattice()
Destructor clears memory for all of Universes pointers.
Definition: Universe.cpp:1079
boundaryType getMaxZBoundaryType()
Returns the boundary conditions (VACUUM or REFLECTIVE) at the maximum reachable z-coordinate in the U...
Definition: Universe.cpp:333
static int _n
Definition: Universe.h:63
Definition: Universe.h:43
std::map< int, Universe * > getAllUniverses()
Returns the std::map of all nested Universe IDs and Universe pointers filling this Universe...
Definition: Universe.cpp:428
void subdivideCells(double max_radius=INFINITY)
Subdivides all of the Material-filled Cells within this Universe into rings and angular sectors align...
Definition: Universe.cpp:617
void setNumZ(int num_z)
Set the number of Lattice cells along the z-axis.
Definition: Universe.cpp:1452
The LocalCoords class.
universeType
The type of universe.
Definition: Universe.h:40
char * _name
Definition: Universe.h:72
void resetBoundaries()
Sets _boundaries_not_updated to true so boundaries will be recalculated if needed.
Definition: Universe.cpp:1049
std::map< int, double > getUniqueRadius(std::map< int, Universe *> unique_universes)
Get the maximum equivalent radius of each unique universes. Equivalent radius are computed as the dia...
Definition: Universe.cpp:1353
int getLatY(Point *point)
Finds the Lattice cell y index that a point lies in.
Definition: Universe.cpp:1932
std::vector< std::vector< std::vector< std::pair< int, Universe * > > > > * getUniverses()
Return a 3D vector of the Universes in the Lattice.
Definition: Universe.cpp:1316
void maximize_universe_id(int universe_id)
Maximize the auto-generated unique Universe ID counter.
Definition: Universe.cpp:47
Definition: Universe.h:46
double _min_x
Definition: Universe.h:85
bool isFissionable()
Returns true if the Universe contains a Cell filled by a fissionable Material and false otherwise...
Definition: Universe.cpp:456
std::map< int, Universe * > getAllUniverses()
Returns the std::map of all nested Universe IDs and Universe pointers filling this Lattice...
Definition: Universe.cpp:1405
boundaryType _min_x_bound
Definition: Universe.h:96