Shape() class¶
The Shape class is the container class for all Shapes and Components.
Shape()¶
- class Shape(points=None, connection_type='mixed', name=None, color=(0.5, 0.5, 0.5), azimuth_placement_angle=0.0, workplane='XZ', rotation_axis=None, cut=None, intersect=None, union=None, graveyard_size=20000, graveyard_offset=None)¶
Bases:
object
A shape object that represents a 3d volume and can have materials and neutronics tallies assigned. Shape objects are not intended to be used directly by the user but provide basic functionality for user-facing classes that inherit from Shape. Provides a .show attribute for rendering in Jupyter Lab
- Parameters
points (tuple of (float, float, float), optional) – the x, y, z coordinates of points that make up the shape. Defaults to None.
connection_type (str, optional) – The type of connection between points. Possible values are “straight”, “circle”, “spline”, “mixed”. Defaults to “mixed”.
name (str, optional) – the name of the shape, used in the graph legend by export_html. Defaults to None.
color ((float, float, float [, float]), optional) – The color to use when exporting as html graphs or png images. Can be in RGB or RGBA format with floats between 0 and 1. Defaults to (0.5, 0.5, 0.5).
azimuth_placement_angle (iterable of floats or float, optional) – the azimuth angle(s) used when positioning the shape. If a list of angles is provided, the shape is duplicated at all angles. Defaults to 0.0.
workplane – the orientation of the Cadquery workplane. Options include strings “XY”, “YZ”, “XZ” or a Cadquery.Plane(). Defaults to “XZ”.
rotation_axis (str or list, optional) – rotation axis around which the solid is rotated. If None, the rotation axis will depend on the workplane or path_workplane if applicable. Can be set to “X”, “-Y”, “Z”, etc. A custom axis can be set by setting a list of two XYZ floats. Defaults to None.
cut (paramak.shape or list, optional) – If set, the current solid will be cut with the provided solid or iterable in cut. Defaults to None.
intersect (paramak.shape or list, optional) – If set, the current solid will be interested with the provided solid or iterable of solids. Defaults to None.
union (paramak.shape or list, optional) – If set, the current solid will be united with the provided solid or iterable of solids. Defaults to None.
graveyard_size – The dimension of cube shaped the graveyard region used by DAGMC. This attribute is used preferentially over graveyard_offset.
graveyard_offset – The distance between the graveyard and the largest shape. If graveyard_size is set the this is ignored.
- property area¶
Get the total surface area of the Shape. Returns a float
- property areas¶
Get the surface areas of the Shape. Compound shapes provide a separate area value for each entry. Returns a list of floats
- convert_all_circle_connections_to_splines(tolerance=0.1)¶
Replaces circle edges in Shape.processed_points points with spline edges. The spline control coordinates are obtained by faceting the circle edge with the provided tolerance. The Shape.processed_points will be updated to exclude the circle points and include the new spline points. This method works best when the connection before and after the circle is a straight connection type. This method is useful when converting the stp file into other formats due to errors in the conversion of circle edges.
- Parameters
tolerance – the precision of the faceting.
- Returns
The new points with spline connections
- Return type
List
[Tuple
[float
,float
,str
]]
- create_limits()¶
Finds the x,y,z limits (min and max) of the points that make up the face of the shape. Note the Shape may extend beyond this boundary if splines are used to connect points.
- Raises
ValueError – if no points are defined
- Returns
x_minimum, x_maximum, y_minimum, y_maximum, z_minimum, z_maximum
- Return type
float, float, float, float, float, float
- Return type
Tuple
[float
,float
,float
,float
]
- export_2d_image(filename='shape.png', xmin=0.0, xmax=900.0, ymin=- 600.0, ymax=600.0)¶
Exports a 2d image (png) of the reactor. Components are colored by their Shape.color property. If filename provided doesn’t end with .png then .png will be added.
- Parameters
filename – the filename of the saved png image.
xmin – the minimum x value of the x axis. Defaults to 0..
xmax – the maximum x value of the x axis. Defaults to 900..
ymin – the minimum y value of the y axis. Defaults to -600..
ymax – the maximum y value of the y axis. Defaults to 600..
- Returns
a plt object
- Return type
matplotlib.plt()
- export_brep(filename)¶
Exports a brep file for the Shape.solid.
- Parameters
filename – the filename of exported the brep file.
- export_dagmc_h5m(filename='dagmc.h5m', min_mesh_size=10, max_mesh_size=20)¶
Export a DAGMC compatible h5m file for use in neutronics simulations. This method makes use of Gmsh to create a surface mesh of the geometry. MOAB is used to convert the meshed geometry into a h5m with parts tagged by using the reactor.shape_and_components.name properties. You will need Gmsh installed and MOAB installed to use this function.
- Parameters
filename – the filename of the DAGMC h5m file to write
min_mesh_size – the minimum mesh element size to use in Gmsh. Passed into gmsh.option.setNumber(“Mesh.MeshSizeMin”, min_mesh_size)
max_mesh_size – the maximum mesh element size to use in Gmsh. Passed into gmsh.option.setNumber(“Mesh.MeshSizeMax”, max_mesh_size)
- Return type
str
- export_graveyard(filename='graveyard.stp', graveyard_offset=100)¶
Writes an stp file (CAD geometry) for the reactor graveyard. This is needed for DAGMC simulations. This method also calls Reactor.make_graveyard with the offset.
- Parameters
filename (str) – the filename for saving the stp file
graveyard_offset (float) – the offset between the largest edge of the geometry and inner bounding shell created. Defaults to Reactor.graveyard_offset
- Returns
the stp filename created
- Return type
str
- Return type
str
- export_html(filename='shape.html', facet_splines=True, facet_circles=True, tolerance=0.001, view_plane=None)¶
Creates a html graph representation of the points and connections for the Shape object. Shapes are colored by their .color property. Shapes are also labelled by their .name. If filename provided doesn’t end with .html then .html will be added.
- Parameters
filename – the filename used to save the html graph. Defaults to shape.html
facet_splines – If True then spline edges will be faceted. Defaults to True.
facet_circles – If True then circle edges will be faceted. Defaults to True.
tolerance – faceting toleranceto use when faceting cirles and splines. Defaults to 1e-3.
view_plane – The plane to project. Options are ‘XZ’, ‘XY’, ‘YZ’, ‘YX’, ‘ZY’, ‘ZX’, ‘RZ’ and ‘XYZ’. Defaults to ‘RZ’. Defaults to the workplane of the paramak.Shape.
- Returns
figure object
- Return type
plotly.Figure()
- export_html_3d(filename='shape_3d.html', **kwargs)¶
Saves an interactive 3d html view of the Shape to a html file.
- Parameters
filename – the filename used to save the html graph. Defaults to shape_3d.html
kwargs – keyword arguments passed to jupyter-cadquery show() function. See https://github.com/bernhard-42/jupyter-cadquery#usage for more details on acceptable keywords
- Returns
filename of the created html file
- Return type
str
- export_stl(filename, tolerance=0.001, angular_tolerance=0.1, verbose=True)¶
Exports an stl file for the Shape.solid.
- Parameters
filename – the filename of exported the stl file. Defaults to None which will attempt to use the Shape.stl_filename. If both are None then a valueError will be raised.
tolerance – the deflection tolerance of the faceting
angular_tolerance – the angular tolerance, in radians
verbose – Enables (True) or disables (False) the printing of the file produced.
- Return type
str
- export_stp(filename, units='mm', mode='solid', verbose=True)¶
Exports an stp file for the Shape.solid.
- Parameters
filename – the filename of exported the stp file.
units – the units of the stp file, options are ‘cm’ or ‘mm’. Default is mm.
mode – the object to export can be either ‘solid’ which exports 3D solid shapes or the ‘wire’ which exports the wire edges of the shape. Defaults to ‘solid’.
verbose – Enables (True) or disables (False) the printing of the file produced.
- Return type
str
- export_svg(filename='shape.svg', projectionDir=(- 1.75, 1.1, 5), width=800, height=800, marginLeft=100, marginTop=100, strokeWidth=None, strokeColor=(0, 0, 0), hiddenColor=(100, 100, 100), showHidden=True, showAxes=False)¶
Exports an svg file for the Reactor.solid. If the filename provided doesn’t end with .svg it will be added.
- Parameters
filename – the filename of the svg file to be exported. Defaults to “reactor.svg”.
projectionDir – The direction vector to view the geometry from (x, y, z). Defaults to (-1.75, 1.1, 5)
width – the width of the svg image produced in pixels. Defaults to 1000
height – the height of the svg image produced in pixels. Defaults to 800
marginLeft – the number of pixels between the left edge of the image and the start of the geometry.
marginTop – the number of pixels between the top edge of the image and the start of the geometry.
strokeWidth – the width of the lines used to draw the geometry. Defaults to None which automatically selects an suitable width.
strokeColor – the color of the lines used to draw the geometry in RGB format with each value between 0 and 255. Defaults to (0, 0, 0) which is black.
hiddenColor – the color of the lines used to draw the geometry in RGB format with each value between 0 and 255. Defaults to (100, 100, 100) which is light grey.
showHidden – If the edges obscured by geometry should be included in the diagram. Defaults to True.
showAxes – If the x, y, z axis should be included in the image. Defaults to False.
- Returns
the svg filename created
- Return type
str
- Return type
str
- find_points()¶
Calculates the shape points. Empty method which some components overright when inheritting.
- from_stp_file(filename)¶
Loads the filename using CadQuery and populates the Shape.solid with the contents
- Parameters
filename – the file name of the stp / step file to be loaded
- get_rotation_axis()¶
Returns the rotation axis for a given shape. If self.rotation_axis is None, the rotation axis will be computed from self.workplane (or from self.path_workplane if applicable). If self.rotation_axis is an acceptable string (eg. “X”, “+Y”, “-Z”…) then this axis will be used. If self.rotation_axis is a list of two points, then these two points will be used to form an axis.
- Returns
- list of two XYZ points and the string of the axis (eg.
”X”, “Y”..)
- Return type
list, str
- property largest_dimension¶
Calculates a bounding box for the Shape and returns the largest absolute value of the largest dimension of the bounding box
- make_graveyard(graveyard_size=None, graveyard_offset=None)¶
Creates a graveyard volume (bounding box) that encapsulates all volumes. This is required by DAGMC when performing neutronics simulations. The graveyard size can be ascertained in two ways. Either the size can be set directly using the graveyard_size which is the quickest method. Alternativley the graveyard can be automatically sized to the geometry by setting a graveyard_offset value. If both options are set then the method will default to using the graveyard_size preferentially.
- Parameters
graveyard_size – directly sets the size of the graveyard. Defaults to None which then uses the Reactor.graveyard_size attribute.
graveyard_offset – the offset between the largest edge of the geometry and inner bounding shell created. Defaults to None which then uses Reactor.graveyard_offset attribute.
- Returns
- a shell volume that bounds the geometry,
referred to as a graveyard in DAGMC.
- Return type
paramak.HollowCube
- property name¶
The name of the Shape, used to identify Shapes when exporting_html
- perform_boolean_operations(solid, **kwargs)¶
Performs boolean cut, intersect and union operations if shapes are provided
- property points¶
Sets the Shape.point attributes.
- Parameters
points (a tuple of tuples) – tuple of points that create the shape
- Raises
incorrect type – only list of lists or tuples are accepted
- property processed_points¶
Shape.processed_points attributes is set internally from the Shape.points
- show(**kwargs)¶
Shows / renders the CadQuery the 3d object in Jupyter Lab. Imports show from jupyter_cadquery and returns show(Shape.solid, kwargs)
- Parameters
kwargs – keyword arguments passed to jupyter-cadquery show() function. See https://github.com/bernhard-42/jupyter-cadquery#usage for more details on acceptable keywords
- Returns
jupyter_cadquery show object
- property solid¶
The CadQuery solid of the 3d object. Returns a CadQuery workplane or CadQuery Compound
- volume(split_compounds=False)¶
Get the total volume of the Shape.
- Parameters
split_compounds – If the Shape is a compound of Shapes and therefore contains multiple volumes. This option allows access to the separate volumes of each component within a Shape (True) or the volumes of compounds can be summed (False).
- Returns
The the volume(s) of the Shape
- Return type
Union
[float
,List
[float
]]
- property wire¶
The CadQuery wire of the 3d object. Returns a CadQuery workplane or CadQuery Compound