Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bf27a11
now using center point instead of z_pos and added edge filleting
billingsley-john Feb 4, 2021
5ec94e5
added type hinting
billingsley-john Feb 4, 2021
854fb54
added port cutter tests
billingsley-john Feb 4, 2021
31b726c
moved point at which filleting is performed
billingsley-john Feb 4, 2021
6880229
Automated autopep8 fixes
Feb 4, 2021
7e3f4ee
using solid instead of self.solid
billingsley-john Feb 4, 2021
52f6d32
using solid instead of self.solid
billingsley-john Feb 4, 2021
1dc42ec
resolved conflicts
billingsley-john Feb 4, 2021
efcb411
Automated autopep8 fixes
Feb 4, 2021
dd4f6e7
updated port arguments
billingsley-john Feb 4, 2021
69641d0
Merge branch 'fix_port_cutting_z_position' of https://github.com/ukae…
billingsley-john Feb 4, 2021
db55b43
updated port center points
billingsley-john Feb 4, 2021
4a79d93
changed to pascal style
billingsley-john Feb 5, 2021
edd5df2
updated import and docstring orders
billingsley-john Feb 5, 2021
c0e804f
added missing docstrings
billingsley-john Feb 5, 2021
057a417
Automated autopep8 fixes
Feb 5, 2021
faf577c
now accounting for workplane correctly
billingsley-john Feb 5, 2021
28b1046
Merge branch 'fix_port_cutting_z_position' of https://github.com/ukae…
billingsley-john Feb 5, 2021
3efe6e7
Automated autopep8 fixes
Feb 5, 2021
79df4ee
updated test class name
billingsley-john Feb 5, 2021
40fdb4d
Merge branch 'fix_port_cutting_z_position' of https://github.com/ukae…
billingsley-john Feb 5, 2021
071f9dd
now using center_point instead of z_pos
billingsley-john Feb 5, 2021
aed1daf
Automated autopep8 fixes
Feb 5, 2021
8628034
added workplane geometry test
billingsley-john Feb 15, 2021
6c80984
Automated autopep8 fixes
Feb 15, 2021
bd95376
fixed assertion
billingsley-john Feb 15, 2021
f2bbc21
Merge branch 'fix_port_cutting_z_position' of https://github.com/ukae…
billingsley-john Feb 15, 2021
0d2497e
added filleting test
billingsley-john Feb 15, 2021
e4c9819
added more filleting tests
billingsley-john Feb 15, 2021
ee51bb5
added assertion
billingsley-john Feb 15, 2021
ce3bdf7
Automated autopep8 fixes
Feb 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def main():

component = paramak.PortCutterRectangular(
distance=3,
z_pos=0,
center_point=(0, 0),
height=0.2,
width=0.4,
fillet_radius=0.02,
Expand All @@ -344,7 +344,7 @@ def main():

component = paramak.PortCutterCircular(
distance=3,
z_pos=0.25,
center_point=(0.25, 0),
radius=0.1,
# azimuth_placement_angle=[0, 45, 90, 180], # TODO: fix issue #548
azimuth_placement_angle=[0, 45, 90],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def main():
# makes the middle row of ports
circular_ports = paramak.PortCutterCircular(
distance=5,
z_pos=0,
center_point=(0, 0),
radius=0.2,
azimuth_placement_angle=angles_for_ports
)

# makes the lower row of ports
rectangular_ports = paramak.PortCutterRectangular(
distance=5,
z_pos=-1,
center_point=(-1, 0),
height=0.3,
width=0.4,
fillet_radius=0.08,
Expand Down
49 changes: 27 additions & 22 deletions paramak/parametric_components/port_cutters_circular.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from typing import Optional

from paramak import ExtrudeCircleShape


Expand All @@ -7,30 +9,33 @@ class PortCutterCircular(ExtrudeCircleShape):
other components (eg. blanket, vessel,..) in order to create ports.

Args:
z_pos (float): Z position (cm) of the port
height (float): height (cm) of the port
width (float): width (cm) of the port
distance (float): extruded distance (cm) of the cutter
stp_filename (str, optional): defaults to "PortCutterCircular.stp".
stl_filename (str, optional): defaults to "PortCutterCircular.stl".
name (str, optional): defaults to "circular_port_cutter".
material_tag (str, optional): defaults to "circular_port_cutter_mat".
extrusion_start_offset (float, optional): the distance between 0 and
the start of the extrusion. Defaults to 1..
radius: radius (cm) of port cutter.
distance: extruded distance (cm) of the port cutter.
center_point: center point of the port cutter. Defaults to (0, 0).
workplane: workplane in which the port cutters are created. Defaults
to "ZY".
rotation_axis: axis around which the port cutters are rotated and
placed. Defaults to "Z".
extrusion_start_offset: the distance between 0 and the start of the
extrusion. Defaults to 1..
stp_filename: defaults to "PortCutterCircular.stp".
stl_filename: defaults to "PortCutterCircular.stl".
name: defaults to "circular_port_cutter".
material_tag: defaults to "circular_port_cutter_mat".
"""

def __init__(
self,
z_pos,
radius,
distance,
workplane="ZY",
rotation_axis="Z",
extrusion_start_offset=1.,
stp_filename="PortCutterCircular.stp",
stl_filename="PortCutterCircular.stl",
name="circular_port_cutter",
material_tag="circular_port_cutter_mat",
radius: float,
distance: float,
center_point: Optional[tuple] = (0, 0),
workplane: Optional[str] = "ZY",
rotation_axis: Optional[str] = "Z",
extrusion_start_offset: Optional[float] = 1.,
stp_filename: Optional[str] = "PortCutterCircular.stp",
stl_filename: Optional[str] = "PortCutterCircular.stl",
name: Optional[str] = "circular_port_cutter",
material_tag: Optional[str] = "circular_port_cutter_mat",
**kwargs
):
super().__init__(
Expand All @@ -47,8 +52,8 @@ def __init__(
**kwargs
)

self.z_pos = z_pos
self.radius = radius
self.center_point = center_point

def find_points(self):
self.points = [(0, self.z_pos)]
self.points = [self.center_point]
77 changes: 50 additions & 27 deletions paramak/parametric_components/port_cutters_rectangular.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from typing import Optional

from paramak import ExtrudeStraightShape


Expand All @@ -7,35 +9,39 @@ class PortCutterRectangular(ExtrudeStraightShape):
other components (eg. blanket, vessel,..) in order to create ports.

Args:
z_pos (float): Z position (cm) of the port
height (float): height (cm) of the port
width (float): width (cm) of the port
distance (float): extruded distance (cm) of the cutter
height: height (cm) of the port cutter.
width: width (cm) of the port cutter.
distance: extruded distance (cm) of the port cutter.
center_point: Center point of the port cutter. Defaults to (0, 0).
workplane: workplane in which the port cutters are created. Defaults
to "ZY".
rotation_axis: axis around which the port cutters are rotated and
placed. Defaults to "Z".
extrusion_start_offset (float, optional): the distance between 0 and
the start of the extrusion. Defaults to 1..
fillet_radius (float, optional): If not None, radius (cm) of fillets
added to edges orthogonal to the Z direction. Defaults to None.
stp_filename (str, optional): defaults to "PortCutterRectangular.stp".
stl_filename (str, optional): defaults to "PortCutterRectangular.stl".
name (str, optional): defaults to "rectangular_port_cutter".
material_tag (str, optional): defaults to
"rectangular_port_cutter_mat".
extrusion_start_offset (float, optional): the distance between 0 and
the start of the extrusion. Defaults to 1..
"""

def __init__(
self,
z_pos,
height,
width,
distance,
workplane="ZY",
rotation_axis="Z",
extrusion_start_offset=1.,
fillet_radius=None,
stp_filename="PortCutterRectangular.stp",
stl_filename="PortCutterRectangular.stl",
name="rectangular_port_cutter",
material_tag="rectangular_port_cutter_mat",
height: float,
width: float,
distance: float,
center_point: Optional[tuple] = (0, 0),
workplane: Optional[str] = "ZY",
rotation_axis: Optional[str] = "Z",
extrusion_start_offset: Optional[float] = 1.,
fillet_radius: Optional[float] = None,
stp_filename: Optional[str] = "PortCutterRectangular.stp",
stl_filename: Optional[str] = "PortCutterRectangular.stl",
name: Optional[str] = "rectangular_port_cutter",
material_tag: Optional[str] = "rectangular_port_cutter_mat",
**kwargs
):

Expand All @@ -52,22 +58,39 @@ def __init__(
**kwargs
)

self.z_pos = z_pos
self.height = height
self.width = width
self.center_point = center_point
self.fillet_radius = fillet_radius
self.add_fillet()

def find_points(self):
if self.workplane[0] < self.workplane[1]:
parameter_1 = self.width
parameter_2 = self.height
else:
parameter_1 = self.height
parameter_2 = self.width

points = [
(-self.width / 2, -self.height / 2),
(self.width / 2, -self.height / 2),
(self.width / 2, self.height / 2),
(-self.width / 2, self.height / 2),
(-parameter_1 / 2, parameter_2 / 2),
(parameter_1 / 2, parameter_2 / 2),
(parameter_1 / 2, -parameter_2 / 2),
(-parameter_1 / 2, -parameter_2 / 2),
]
points = [(e[0], e[1] + self.z_pos) for e in points]
points = [(e[0] + self.center_point[0], e[1] +
self.center_point[1]) for e in points]

self.points = points

def add_fillet(self):
def add_fillet(self, solid):
if "X" not in self.workplane:
filleting_edge = "|X"
if "Y" not in self.workplane:
filleting_edge = "|Y"
if "Z" not in self.workplane:
filleting_edge = "|Z"

if self.fillet_radius is not None and self.fillet_radius != 0:
self.solid = self.solid.edges('#Z').fillet(self.fillet_radius)
solid = solid.edges(filleting_edge).fillet(self.fillet_radius)

return solid
5 changes: 5 additions & 0 deletions paramak/parametric_shapes/extruded_mixed_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def create_solid(self):
distance=extrusion_distance,
both=self.extrude_both)

# filleting rectangular port cutter edges
# must be done before azimuthal placement
if hasattr(self, "add_fillet"):
solid = self.add_fillet(solid)

solid = self.rotate_solid(solid)
cutting_wedge = calculate_wedge_cut(self)
solid = self.perform_boolean_operations(solid, wedge_cut=cutting_wedge)
Expand Down
61 changes: 49 additions & 12 deletions tests/test_parametric_components/test_PortCutterCircular.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@

import math
import unittest

import paramak

import pytest


class TestPortCutterCircular(unittest.TestCase):

def setUp(self):
self.test_shape = paramak.PortCutterCircular(
distance=300, radius=20
)

def test_default_parameters(self):
"""Checks that the default parameters of a PortCutterCircular are correct."""

assert self.test_shape.center_point == (0, 0)
assert self.test_shape.workplane == "ZY"
assert self.test_shape.rotation_axis == "Z"
assert self.test_shape.extrusion_start_offset == 1
assert self.test_shape.stp_filename == "PortCutterCircular.stp"
assert self.test_shape.stl_filename == "PortCutterCircular.stl"
assert self.test_shape.name == "circular_port_cutter"
assert self.test_shape.material_tag == "circular_port_cutter_mat"

def test_creation(self):
"""Creates a circular port cutter using the PortCutterCircular parametric
component and checks that a cadquery solid is created."""

assert self.test_shape.solid is not None
assert self.test_shape.volume > 1000

def test_relative_volume(self):
"""Creates PortCutterCircular shapes and checks that their relative volumes
are correct."""

test_volume = self.test_shape.volume

self.test_shape.extrusion_start_offset = 20
self.test_shape.azimuth_placement_angle = [0, 90, 180, 270]

assert self.test_shape.volume == pytest.approx(test_volume * 4)

def test_absolute_volume(self):
"""Creates a PortCutterCircular shape and checks that its volume is correct."""

# class test_component(unittest.TestCase):
# TODO: fix issue 548
# def test_creation(self):
# """Checks a PortCutterCircular creation."""
assert self.test_shape.volume == pytest.approx(math.pi * (20**2) * 300)

# test_component = paramak.PortCutterCircular(
# distance=3,
# z_pos=0.25,
# radius=0.1,
# azimuth_placement_angle=[0, 45, 90, 180]
# )
self.test_shape.extrusion_start_offset = 20
self.test_shape.azimuth_placement_angle = [0, 90, 180, 270]
self.test_shape.radius = 10

# assert test_component.solid is not None
assert self.test_shape.volume == pytest.approx(
math.pi * (10**2) * 300 * 4)
86 changes: 76 additions & 10 deletions tests/test_parametric_components/test_PortCutterRectangular.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,85 @@

import paramak

import pytest


class TestPortCutterRectangular(unittest.TestCase):

def setUp(self):
self.test_shape = paramak.PortCutterRectangular(
width=20, height=40, distance=300
)

def test_default_parameters(self):
"""Checks that the default parameters of a PortCutterRectangular are correct."""

assert self.test_shape.center_point == (0, 0)
assert self.test_shape.workplane == "ZY"
assert self.test_shape.rotation_axis == "Z"
assert self.test_shape.extrusion_start_offset == 1
assert self.test_shape.fillet_radius is None
assert self.test_shape.stp_filename == "PortCutterRectangular.stp"
assert self.test_shape.stl_filename == "PortCutterRectangular.stl"
assert self.test_shape.name == "rectangular_port_cutter"
assert self.test_shape.material_tag == "rectangular_port_cutter_mat"

def test_creation(self):
"""Checks a PortCutterRectangular creation."""

test_component = paramak.PortCutterRectangular(
distance=3,
z_pos=0,
height=0.2,
width=0.4,
fillet_radius=0.02,
azimuth_placement_angle=[0, 45, 90, 180]
"""Creates a rectangular port cutter using the PortCutterRectangular parametric
component and checks that a cadquery solid is created."""

assert self.test_shape.solid is not None
assert self.test_shape.volume > 1000

def test_relative_volume(self):
"""Creates PortCutterRectangular shapes and checks that their relative volumes
are correct."""

test_volume = self.test_shape.volume

self.test_shape.extrusion_start_offset = 20
self.test_shape.azimuth_placement_angle = [0, 90, 180, 270]

assert self.test_shape.volume == pytest.approx(test_volume * 4)

def test_absolute_volume(self):
"""Creates a PortCutterRectangular shape and checks that its volume is correct."""

assert self.test_shape.volume == pytest.approx(20 * 40 * 300)

self.test_shape.extrusion_start_offset = 20
self.test_shape.azimuth_placement_angle = [0, 90, 180, 270]
self.test_shape.width = 20
self.test_shape.height = 20

assert self.test_shape.volume == pytest.approx(20 * 20 * 300 * 4)

def test_workplane(self):
"""Creates PortCutterRectangular shapes in different workplanes and checks that
the geometries are correct."""

cutting_shape = paramak.RotateStraightShape(
points=[(0, 0), (0, 50), (500, 50), (500, 0)],
workplane="YZ",
)
self.test_shape.cut = cutting_shape

assert self.test_shape.volume == pytest.approx(20 * 40 * 300 * 0.5)

self.test_shape.workplane = "XZ"
cutting_shape.workplane = "YZ"

assert self.test_shape.volume == pytest.approx(20 * 40 * 300 * 0.5)

def test_filleting(self):
"""Creates a PortCutterRectangular shape with filleted edges and checks
that its volume is correct."""

test_volume = self.test_shape.volume
self.test_shape.fillet_radius = 5

assert test_component.solid is not None
assert self.test_shape.volume < test_volume
self.test_shape.workplane = "ZX"
assert self.test_shape.volume < test_volume
self.test_shape.workplane = "YX"
assert self.test_shape.volume < test_volume
Loading