Exemple #1
0
    def test_invalid_parameters_errors(self):
        """Checks that the correct errors are raised when invalid arguments are input as
        shape parameters."""

        shape = paramak.ExtrudeStraightShape(distance=1,
                                             points=[(0, 0), (0, 1), (1, 1)],
                                             rotation_angle=180)

        cutter = paramak.CuttingWedgeFS(
            shape=shape,
            azimuth_placement_angle=0,
        )

        def incorrect_rotation_angle():
            shape.rotation_angle = 360
            cutter.solid

        def incorrect_shape_points():
            shape.rotation_angle = 180
            cutter.shape.points = [(0, 0, 'straight')]
            cutter.solid

        def incorrect_shape_rotation_angle():
            cutter.shape.points = [(0, 0), (0, 1), (1, 1)]
            shape.rotation_angle = 360
            cutter.shape = shape

        self.assertRaises(ValueError, incorrect_rotation_angle)
        self.assertRaises(ValueError, incorrect_shape_points)
        self.assertRaises(ValueError, incorrect_shape_rotation_angle)
Exemple #2
0
        def test_stl_filename_duplication_Extrude_straight():
            """Checks ValueError is raised when ExtrudeStraightShapes with
            duplicate stl filenames are added."""

            test_shape = paramak.ExtrudeStraightShape(
                points=[(0, 0), (0, 20), (20, 20)],
                distance=10,
                stl_filename="filename.stl",
            )
            test_shape2 = paramak.ExtrudeStraightShape(
                points=[(0, 0), (0, 20), (20, 20)],
                distance=10,
                stl_filename="filename.stl",
            )
            test_shape.rotation_angle = 360
            test_shape.create_solid()
            my_reactor = paramak.Reactor([test_shape, test_shape2])
            my_reactor.export_stl()
    def test_creation_with_inner_leg(self):
        """Creates a tf coil with inner leg using the ToroidalFieldCoilPrincetonD
        parametric component and checks that a cadquery solid is created."""

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

        test_inner_leg = paramak.ExtrudeStraightShape(
            points=self.test_shape.inner_leg_connection_points, distance=30)
        assert test_inner_leg.solid is not None
Exemple #4
0
    def test_FaceAreaSelector_with_fillet_areas(self):
        """tests the filleting of a ExtrudeStraightShape"""

        test_shape = paramak.ExtrudeStraightShape(distance=5,
                                                  points=[(1, 1), (2, 1),
                                                          (2, 2)])

        assert len(test_shape.areas) == 5

        test_shape.solid = test_shape.solid.faces(
            FaceAreaSelector(0.5)).fillet(0.1)

        assert len(test_shape.areas) == 11
Exemple #5
0
    def test_creation_no_inner_leg(self):
        """Creates a tf coil with no inner leg using the ToroidalFieldCoilRectangle
        parametric component and checks that a cadquery solid is created."""

        test_volume = self.test_shape.volume

        test_inner_leg = paramak.ExtrudeStraightShape(
            points=self.test_shape.inner_leg_connection_points, distance=30)
        inner_leg_volume = test_inner_leg.volume

        self.test_shape.with_inner_leg = False
        assert self.test_shape.solid is not None
        assert self.test_shape.volume == pytest.approx(test_volume -
                                                       inner_leg_volume)
Exemple #6
0
    def test_ToroidalFieldCoilPrincetonD_with_leg(self):
        """creates a ToroidalFieldCoilPrincetonD object and checks a leg can
        be created"""

        my_magnet = paramak.ToroidalFieldCoilPrincetonD(R1=0.29,
                                                        R2=0.91,
                                                        thickness=0.05,
                                                        distance=0.05,
                                                        number_of_coils=1)
        my_magnet.export_stp('princeton.stp')

        my_leg = paramak.ExtrudeStraightShape(
            points=my_magnet.inner_leg_connection_points, distance=0.05)

        assert my_leg.solid is not None
Exemple #7
0
 def test_different_workplanes(self):
     """Test that checks the cutting wedge can be correctly applied to a
     shape with non-default workplane and rotation_axis
     """
     rectangle = paramak.ExtrudeStraightShape(2,
                                              points=[(-0.5, -0.5),
                                                      (0.5, -0.5),
                                                      (0.5, 0.5),
                                                      (-0.5, 0.5)],
                                              workplane="XY",
                                              rotation_axis="Z")
     rectangle.rotation_angle = 360
     volume_full = rectangle.volume
     assert np.isclose(volume_full, 2)
     rectangle.rotation_angle = 90
     volume_quarter = rectangle.volume
     assert np.isclose(volume_quarter, 0.5)
Exemple #8
0
    def test_extract_points_from_edges(self):
        """Extracts points from edges and checks the list returned is the
        correct len and contains the correct types"""

        test_points = [(1, 1), (3, 1), (4, 2)]
        test_shape = paramak.ExtrudeStraightShape(points=test_points,
                                                  distance=6,
                                                  workplane='YZ')

        edges = facet_wire(wire=test_shape.wire)

        points = extract_points_from_edges(edges=edges, view_plane='YZ')

        assert len(points) == 6

        for point in points:
            assert len(point) == 2
            assert isinstance(point[0], float)
            assert isinstance(point[1], float)

        points_single_edge = extract_points_from_edges(edges=edges[0],
                                                       view_plane='YZ')

        assert len(points) > len(points_single_edge)
        for point in points_single_edge:
            assert len(point) == 2
            assert isinstance(point[0], float)
            assert isinstance(point[1], float)

        points_single_edge = extract_points_from_edges(edges=edges[0],
                                                       view_plane='XYZ')

        assert len(points) > len(points_single_edge)
        for point in points_single_edge:
            assert len(point) == 3
            assert isinstance(point[0], float)
            assert isinstance(point[1], float)
            assert isinstance(point[2], float)
def main():

    # rotate examples

    # this makes a rectangle and rotates it to make a solid
    rotated_straights = paramak.RotateStraightShape(rotation_angle=180,
                                                    points=[(400, 100),
                                                            (400, 200),
                                                            (600, 200),
                                                            (600, 100)])
    rotated_straights.export_stp("rotated_straights.stp")
    rotated_straights.export_html("rotated_straights.html")

    # this makes a banana shape and rotates it to make a solid
    rotated_spline = paramak.RotateSplineShape(rotation_angle=180,
                                               points=[
                                                   (500, 0),
                                                   (500, -20),
                                                   (400, -300),
                                                   (300, -300),
                                                   (400, 0),
                                                   (300, 300),
                                                   (400, 300),
                                                   (500, 20),
                                               ])
    rotated_spline.export_stp("rotated_spline.stp")
    rotated_spline.export_html("rotated_spline.html")

    # this makes a shape with straight, spline and circular edges and rotates
    # it to make a solid
    rotated_mixed = paramak.RotateMixedShape(rotation_angle=180,
                                             points=[
                                                 (100, 0, "straight"),
                                                 (200, 0, "circle"),
                                                 (250, 50, "circle"),
                                                 (200, 100, "straight"),
                                                 (150, 100, "spline"),
                                                 (140, 75, "spline"),
                                                 (110, 45, "spline"),
                                             ])
    rotated_mixed.export_stp("rotated_mixed.stp")
    rotated_mixed.export_html("rotated_mixed.html")

    # this makes a circular shape and rotates it to make a solid
    rotated_circle = paramak.RotateCircleShape(rotation_angle=180,
                                               points=[(50, 0)],
                                               radius=5,
                                               workplane="XZ")
    rotated_circle.export_stp("rotated_circle.stp")
    rotated_circle.export_html("rotated_circle.html")

    # extrude examples

    # this makes a banana shape with straight edges and rotates it to make a
    # solid
    extruded_straight = paramak.ExtrudeStraightShape(distance=200,
                                                     points=[
                                                         (300, -300),
                                                         (400, 0),
                                                         (300, 300),
                                                         (400, 300),
                                                         (500, 0),
                                                         (400, -300),
                                                     ])
    extruded_straight.export_stp("extruded_straight.stp")
    extruded_straight.export_html("extruded_straight.html")

    # this makes a banana shape and rotates it to make a solid
    extruded_spline = paramak.ExtrudeSplineShape(distance=200,
                                                 points=[
                                                     (500, 0),
                                                     (500, -20),
                                                     (400, -300),
                                                     (300, -300),
                                                     (400, 0),
                                                     (300, 300),
                                                     (400, 300),
                                                     (500, 20),
                                                 ])
    extruded_spline.export_stp("extruded_spline.stp")
    extruded_spline.export_html("extruded_spline.html")

    # this makes a banana shape straight top and bottom edges and extrudes it
    # to make a solid
    extruded_mixed = paramak.ExtrudeMixedShape(
        distance=100,
        points=[
            (100, 0, "straight"),
            (200, 0, "circle"),
            (250, 50, "circle"),
            (200, 100, "straight"),
            (150, 100, "spline"),
            (140, 75, "spline"),
            (110, 45, "spline"),
        ],
    )
    extruded_mixed.export_stp("extruded_mixed.stp")
    extruded_mixed.export_html("extruded_mixed.html")

    # this makes a circular shape and extrudes it to make a solid
    extruded_circle = paramak.ExtrudeCircleShape(points=[(20, 0)],
                                                 radius=20,
                                                 distance=200)
    extruded_circle.export_stp("extruded_circle.stp")
    extruded_circle.export_html("extruded_circle.html")

    # sweep examples

    # this makes a banana shape with straight edges and sweeps it along a
    # spline to make a solid
    sweep_straight = paramak.SweepStraightShape(points=[(-150, 300),
                                                        (-50, 300), (50, 0),
                                                        (-50, -300),
                                                        (-150, -300),
                                                        (-50, 0)],
                                                path_points=[(50, 0),
                                                             (150, 400),
                                                             (400, 500),
                                                             (650, 600),
                                                             (750, 1000)],
                                                workplane="XY",
                                                path_workplane="XZ")
    sweep_straight.export_stp("sweep_straight.stp")
    sweep_straight.export_html("sweep_straight.html")

    # this makes a banana shape with spline edges and sweeps it along a spline
    # to make a solid
    sweep_spline = paramak.SweepSplineShape(points=[(50, 0), (50, -20),
                                                    (-50, -300), (-150, -300),
                                                    (-50, 0), (-150, 300),
                                                    (-50, 300), (50, 20)],
                                            path_points=[(50, 0), (150, 400),
                                                         (400, 500),
                                                         (650, 600),
                                                         (750, 1000)],
                                            workplane="XY",
                                            path_workplane="XZ")
    sweep_spline.export_stp("sweep_spline.stp")
    sweep_spline.export_html("sweep_spline.html")

    # this makes a shape with straight, spline and circular edges and sweeps
    # it along a spline to make a solid
    sweep_mixed = paramak.SweepMixedShape(points=[(-80, -50, "straight"),
                                                  (20, -50, "circle"),
                                                  (70, 0, "circle"),
                                                  (20, 50, "straight"),
                                                  (-30, 50, "spline"),
                                                  (-40, 25, "spline"),
                                                  (-70, -5, "spline")],
                                          path_points=[(50, 0), (150, 400),
                                                       (400, 500), (650, 600),
                                                       (750, 1000)],
                                          workplane="XY",
                                          path_workplane="XZ")
    sweep_mixed.export_stp("sweep_mixed.stp")
    sweep_mixed.export_html("sweep_mixed.html")

    # this makes a circular shape and sweeps it to make a solid
    sweep_circle = paramak.SweepCircleShape(radius=40,
                                            path_points=[(50, 0), (150, 400),
                                                         (400, 500),
                                                         (650, 600),
                                                         (750, 1000)],
                                            workplane="XY",
                                            path_workplane="XZ")
    sweep_circle.export_stp("sweep_circle.stp")
    sweep_circle.export_html("sweep_circle.html")
def main():

    # rotate examples

    # this makes a rectangle and rotates it to make a solid
    rotated_straights = paramak.RotateStraightShape(
        points=[(400, 100), (400, 200), (600, 200), (600, 100)])
    rotated_straights.rotation_angle = 180
    rotated_straights.export_stp("rotated_straights.stp")
    rotated_straights.export_html("rotated_straights.html")

    # this makes a banana shape and rotates it to make a solid
    rotated_spline = paramak.RotateSplineShape(points=[
        (500, 0),
        (500, -20),
        (400, -300),
        (300, -300),
        (400, 0),
        (300, 300),
        (400, 300),
        (500, 20),
    ])
    rotated_spline.rotation_angle = 180
    rotated_spline.export_stp("rotated_spline.stp")
    rotated_spline.export_html("rotated_spline.html")

    # this makes a shape with straight, spline and circular edges and rotates it to make a solid
    rotated_mixed = paramak.RotateMixedShape(points=[
        (100, 0, 'straight'),
        (200, 0, 'circle'),
        (250, 50, 'circle'),
        (200, 100, 'straight'),
        (150, 100, 'spline'),
        (140, 75, 'spline'),
        (110, 45, 'spline'),
    ])
    rotated_mixed.rotation_angle = 180
    rotated_mixed.export_stp("rotated_mixed.stp")
    rotated_mixed.export_html("rotated_mixed.html")

    # this makes a circular shape and rotates it to make a solid
    rotated_circle = paramak.RotateCircleShape(points=[(50, 0)],
                                               radius=5,
                                               workplane="XZ")
    rotated_circle.rotation_angle = 180
    rotated_circle.export_stp("rotated_circle.stp")
    rotated_circle.export_html("rotated_circle.html")

    # extrude examples

    # this makes a banana shape with straight edges and rotates it to make a solid
    extruded_straight = paramak.ExtrudeStraightShape(
        points=[
            (300, -300),
            (400, 0),
            (300, 300),
            (400, 300),
            (500, 0),
            (400, -300),
        ],
        distance=200,
    )
    extruded_straight.export_stp("extruded_straight.stp")
    extruded_straight.export_html("extruded_straight.html")

    # this makes a banana shape and rotates it to make a solid
    extruded_spline = paramak.ExtrudeSplineShape(
        points=[
            (500, 0),
            (500, -20),
            (400, -300),
            (300, -300),
            (400, 0),
            (300, 300),
            (400, 300),
            (500, 20),
        ],
        distance=200,
    )
    extruded_spline.export_stp("extruded_spline.stp")
    extruded_spline.export_html("extruded_spline.html")

    # this makes a banana shape straight top and bottom edges and extrudes it to make a solid
    extruded_mixed = paramak.ExtrudeMixedShape(
        points=[
            (100, 0, 'straight'),
            (200, 0, 'circle'),
            (250, 50, 'circle'),
            (200, 100, 'straight'),
            (150, 100, 'spline'),
            (140, 75, 'spline'),
            (110, 45, 'spline'),
        ],
        distance=100,
    )
    extruded_mixed.export_stp("extruded_mixed.stp")
    extruded_mixed.export_html("extruded_mixed.html")

    # this makes a circular shape and extrudes it to make a solid
    extruded_circle = paramak.ExtrudeCircleShape(points=[(20, 0)],
                                                 radius=20,
                                                 distance=200)
    extruded_circle.export_stp("extruded_circle.stp")
    extruded_circle.export_html("extruded_circle.html")
Exemple #11
0
def make_demo_blanket(number_of_sections=8,
                      gap_size=15,
                      central_block_width=200):

    number_of_segments = 8
    gap_size = 15.
    central_block_width = 200

    large_dimention = 10000  # used to make large cutting slices
    offset = (360 / number_of_segments) / 2

    # a plasma shape is made and used by the BlanketFP, which builds around
    # the plasma
    plasma = paramak.Plasma(elongation=1.59,
                            triangularity=0.33,
                            major_radius=910,
                            minor_radius=290)
    plasma.solid

    # makes a block which is used later to make the to parallel gaps segments
    parallel_outboard_gaps_inner = paramak.ExtrudeStraightShape(
        points=[
            (large_dimention, large_dimention),
            (large_dimention, -large_dimention),
            (0, -large_dimention),
            (0, large_dimention),
        ],
        distance=central_block_width,
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments,
                                            endpoint=False))

    # makes a larger block which has the smaller block cut away and the result
    # is two parallel gaps segments
    parallel_outboard_gaps_outer = paramak.ExtrudeStraightShape(
        points=[
            (large_dimention, large_dimention),
            (large_dimention, -large_dimention),
            (0, -large_dimention),
            (0, large_dimention),
        ],
        distance=central_block_width + (gap_size * 2),
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments,
                                            endpoint=False),
        cut=parallel_outboard_gaps_inner)

    # this makes a gap that seperates the inboard and outboard blanket
    inboard_to_outboard_gaps = paramak.ExtrudeStraightShape(
        points=[
            (plasma.high_point[0] - (0.5 * gap_size), plasma.high_point[1]),
            (plasma.high_point[0] - (0.5 * gap_size),
             plasma.high_point[1] + 1000),
            (plasma.high_point[0] + (0.5 * gap_size),
             plasma.high_point[1] + 1000),
            (plasma.high_point[0] + (0.5 * gap_size), plasma.high_point[1]),
        ],
        distance=math.tan(math.radians(360 / (2 * number_of_segments))) *
        plasma.high_point[0] * 2,
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments,
                                            endpoint=False))

    # this makes the regular gaps (non parallel) gaps on the outboard blanket
    outboard_gaps = paramak.ExtrudeStraightShape(
        points=[
            (large_dimention, large_dimention),
            (large_dimention, -large_dimention),
            (0, -large_dimention),
            (0, large_dimention),
        ],
        distance=gap_size,
        azimuth_placement_angle=np.linspace(0 + offset,
                                            360 + offset,
                                            number_of_segments,
                                            endpoint=False))

    # makes the outboard blanket with cuts for all the segmentation
    outboard_blanket = paramak.BlanketFP(plasma=plasma,
                                         thickness=100,
                                         stop_angle=90,
                                         start_angle=-60,
                                         offset_from_plasma=30,
                                         rotation_angle=360,
                                         cut=[
                                             outboard_gaps,
                                             parallel_outboard_gaps_outer,
                                             inboard_to_outboard_gaps
                                         ])

    # this makes the regular gaps on the outboard blanket
    inboard_gaps = paramak.ExtrudeStraightShape(
        points=[
            (large_dimention, large_dimention),
            (large_dimention, -large_dimention),
            (0, -large_dimention),
            (0, large_dimention),
        ],
        distance=gap_size,
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments * 2,
                                            endpoint=False))

    # makes the inboard blanket with cuts for all the segmentation
    inboard_blanket = paramak.BlanketFP(
        plasma=plasma,
        thickness=100,
        stop_angle=90,
        start_angle=260,
        offset_from_plasma=30,
        rotation_angle=360,
        cut=[inboard_gaps, inboard_to_outboard_gaps],
        union=outboard_blanket)

    # saves the blanket as an stp file
    inboard_blanket.export_stp('blanket.stp')
Exemple #12
0
def main(number_of_sections=8, gap_size=15, central_block_width=200):

    number_of_segments = 8
    gap_size = 15.
    central_block_width = 200

    offset = (360 / number_of_segments) / 2

    # a plasma shape is made and used by the BlanketFP, which builds around
    # the plasma
    plasma = paramak.Plasma(elongation=1.59,
                            triangularity=0.33,
                            major_radius=910,
                            minor_radius=290)
    plasma.solid

    # this makes a cutter shape that is used to make the blanket bananna
    # segment that has parallel sides
    parallel_outboard_gaps_outer = paramak.BlanketCutterParallels(
        thickness=gap_size,
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments,
                                            endpoint=False),
        gap_size=central_block_width)

    # this makes a gap that seperates the inboard and outboard blanket
    inboard_to_outboard_gaps = paramak.ExtrudeStraightShape(
        points=[
            (plasma.high_point[0] - (0.5 * gap_size), plasma.high_point[1]),
            (plasma.high_point[0] - (0.5 * gap_size),
             plasma.high_point[1] + 1000),
            (plasma.high_point[0] + (0.5 * gap_size),
             plasma.high_point[1] + 1000),
            (plasma.high_point[0] + (0.5 * gap_size), plasma.high_point[1]),
        ],
        distance=math.tan(math.radians(360 / (2 * number_of_segments))) *
        plasma.high_point[0] * 2,
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments,
                                            endpoint=False))

    # this makes the regular gaps (non parallel) gaps on the outboard blanket
    outboard_gaps = paramak.BlanketCutterStar(
        distance=gap_size,
        azimuth_placement_angle=np.linspace(0 + offset,
                                            360 + offset,
                                            number_of_segments,
                                            endpoint=False))

    # makes the outboard blanket with cuts for all the segmentation
    outboard_blanket = paramak.BlanketFP(plasma=plasma,
                                         thickness=100,
                                         stop_angle=90,
                                         start_angle=-60,
                                         offset_from_plasma=30,
                                         rotation_angle=360,
                                         cut=[
                                             outboard_gaps,
                                             parallel_outboard_gaps_outer,
                                             inboard_to_outboard_gaps
                                         ])

    # this makes the regular gaps on the outboard blanket
    inboard_gaps = paramak.BlanketCutterStar(
        distance=gap_size,
        azimuth_placement_angle=np.linspace(0,
                                            360,
                                            number_of_segments * 2,
                                            endpoint=False))

    # makes the inboard blanket with cuts for all the segmentation
    inboard_blanket = paramak.BlanketFP(
        plasma=plasma,
        thickness=100,
        stop_angle=90,
        start_angle=260,
        offset_from_plasma=30,
        rotation_angle=360,
        cut=[inboard_gaps, inboard_to_outboard_gaps],
        union=outboard_blanket)

    # saves the blanket as an stp file
    inboard_blanket.export_stp('blanket.stp')