示例#1
0
def test_GIVEN_length_of_arrow_position_WHEN_adding_top_dead_centre_arrow_THEN_expected_arrow_is_created(
    geometry_creator,
):
    length_of_arrow_position = 5

    expected_centre_point = Point(length_of_arrow_position, 0, EXPECTED_Z)
    expected_left_point = Point(
        length_of_arrow_position - geometry_creator.arrow_size,
        0,
        EXPECTED_Z + geometry_creator.arrow_size,
    )
    expected_right_point = Point(
        length_of_arrow_position + geometry_creator.arrow_size,
        0,
        EXPECTED_Z + geometry_creator.arrow_size,
    )

    geometry_creator._add_point_to_list(expected_centre_point)

    geometry_creator.add_top_dead_centre_arrow(length_of_arrow_position)

    assert geometry_creator.points[-3] == expected_centre_point
    assert geometry_creator.points[-2] == expected_right_point
    assert geometry_creator.points[-1] == expected_left_point

    expected_face = create_list_of_ids(
        *[geometry_creator.points[i] for i in range(-3, 0)]
    )
    assert expected_face in geometry_creator.faces
示例#2
0
def test_GIVEN_polar_coordinates_WHEN_creating_mirrored_points_THEN_expected_points_are_returned(
    geometry_creator, chopper_details
):
    expected_first_point = Point(1.0, 1.0, EXPECTED_Z)
    expected_second_point = Point(1.0, 1.0, -EXPECTED_Z)

    actual_first_point, actual_second_point = geometry_creator._create_mirrored_points(
        R, THETA
    )
    assert actual_first_point == expected_first_point
    assert actual_second_point == expected_second_point
示例#3
0
def test_GIVEN_point_WHEN_adding_point_to_list_THEN_point_is_added_and_assigned_an_id(
    geometry_creator,
):
    point = Point(1, 2, 3)
    geometry_creator._add_point_to_list(point)

    assert point in geometry_creator.points
    assert point.id == len(geometry_creator.points) - 1
示例#4
0
def create_two_points():
    """
    Create two points for testing the face connected to front/back centre methods.
    """
    first_point = Point(3, 4, 5)
    first_point.set_id(10)
    second_point = Point(6, 7, 8)
    second_point.set_id(11)

    return first_point, second_point
示例#5
0
def test_GIVEN_chopper_details_WHEN_initialising_geometry_creator_THEN_geometry_creator_is_initialised_with_expected_values(
    geometry_creator, chopper_details
):
    assert geometry_creator.faces == []
    assert geometry_creator.z == pytest.approx(EXPECTED_Z)
    assert geometry_creator.arrow_size == pytest.approx(EXPECTED_Z)
    assert geometry_creator.resolution == RESOLUTION

    assert geometry_creator._radius == pytest.approx(chopper_details.radius)
    assert np.array_equal(geometry_creator._slit_edges, chopper_details.slit_edges)
    assert geometry_creator._slit_height == pytest.approx(chopper_details.slit_height)

    assert len(geometry_creator.points) == 2

    expected_points = [Point(0, 0, EXPECTED_Z), Point(0, 0, -EXPECTED_Z)]

    for i in range(2):
        assert geometry_creator.points[i] == expected_points[i]
示例#6
0
def test_GIVEN_r_and_theta_WHEN_creating_and_adding_mirrored_points_THEN_expected_points_are_created_and_added_to_list(
    geometry_creator, chopper_details
):
    r = 20
    theta = 0

    expected_front_point = Point(r, 0, EXPECTED_Z)
    expected_back_point = Point(r, 0, -EXPECTED_Z)

    (
        actual_front_point,
        actual_back_point,
    ) = geometry_creator.create_and_add_mirrored_points(r, theta)

    assert expected_front_point == actual_front_point
    assert expected_back_point == actual_back_point

    assert actual_front_point in geometry_creator.points
    assert actual_back_point in geometry_creator.points
示例#7
0
def expected_slit_boundary_face_points(center_to_slit_start: float, radius: float):
    """
    Creates for points that match the expected points for the face for the slit boundary. Assumes the slit edge has an
    angle of zero.
    :param center_to_slit_start: Distance from disk chopper center to the beginning of the slit.
    :param radius: The radius of the disk chopper.
    :return: Four points that should be roughly equal to the points for slit boundary face.
    """

    expected_upper_front = Point(radius, 0, EXPECTED_Z)
    expected_lower_front = Point(center_to_slit_start, 0, EXPECTED_Z)
    expected_upper_back = Point(radius, 0, -EXPECTED_Z)
    expected_lower_back = Point(center_to_slit_start, 0, -EXPECTED_Z)

    return (
        expected_lower_back,
        expected_lower_front,
        expected_upper_back,
        expected_upper_front,
    )
示例#8
0
def test_GIVEN_set_of_points_WHEN_adding_face_to_list_THEN_list_of_ids_is_added_to_list_of_faces(
    geometry_creator,
):
    num_points = 3
    points = []
    ids = []

    for i in range(num_points):
        ids.append(i + 2)
        points.append(Point(i, i, i))
        points[-1].set_id(ids[-1])

    geometry_creator.add_face_to_list(points)
    assert ids in geometry_creator.faces
示例#9
0
def test_GIVEN_angle_distance_to_centre_and_two_points_WHEN_creating_wedge_shape_THEN_expected_faces_and_points_are_created(
    geometry_creator,
):
    theta = np.pi
    r = 10
    prev_back, prev_front = geometry_creator.create_and_add_mirrored_points(r, theta)
    current_back, current_front = geometry_creator.create_cake_slice(
        theta, prev_back, prev_front, r
    )

    assert current_front == Point(-r, 0, geometry_creator.z)
    assert current_back == Point(-r, 0, -geometry_creator.z)

    assert geometry_creator.faces[-3] == create_list_of_ids(
        prev_front, prev_back, current_back, current_front
    )

    assert geometry_creator.faces[-2] == create_list_of_ids(
        geometry_creator.front_centre, prev_front, current_front
    )

    assert geometry_creator.faces[-1] == create_list_of_ids(
        geometry_creator.back_centre, current_back, prev_back
    )
示例#10
0
def test_GIVEN_simple_chopper_details_WHEN_creating_disk_chopper_THEN_chopper_mesh_has_expected_shape():
    radius = 1
    slit_height = 0.5
    resolution = 5
    chopper_details = ChopperDetails(
        slits=1,
        slit_edges=np.array([0.0, np.deg2rad(90)]),
        radius=radius,
        slit_height=slit_height,
        angle_units="rad",
        slit_height_units="m",
        radius_units="m",
    )
    geometry_creator = DiskChopperGeometryCreator(chopper_details)
    geometry_creator.resolution = resolution
    z = geometry_creator.z

    angles = np.linspace(0, np.pi * 2, resolution + 1)[:-1]

    def find_x(r, theta):
        return r * np.cos(theta)

    def find_y(r, theta):
        return r * np.sin(theta)

    def check_cake_slice_faces(indices):
        assert indices in geometry_creator.faces
        assert [0, indices[0], indices[-1]] in geometry_creator.faces
        assert [1, indices[-2], indices[1]] in geometry_creator.faces

    geometry_creator.convert_chopper_details_to_off()

    # Check the centre points
    assert geometry_creator.points[0] == Point(0, 0, z)
    assert geometry_creator.points[1] == Point(0, 0, -z)

    # Check the next four points that make form the "right" slit boundary
    assert geometry_creator.points[2] == Point(radius, 0, z)
    assert geometry_creator.points[3] == Point(radius, 0, -z)
    assert geometry_creator.points[4] == Point(slit_height, 0, z)
    assert geometry_creator.points[5] == Point(slit_height, 0, -z)

    assert [4, 2, 3, 5] in geometry_creator.faces

    # Check the next four points that make form the "left" slit boundary
    assert geometry_creator.points[6] == Point(0, radius, z)
    assert geometry_creator.points[7] == Point(0, radius, -z)
    assert geometry_creator.points[8] == Point(0, slit_height, z)
    assert geometry_creator.points[9] == Point(0, slit_height, -z)

    assert [9, 7, 6, 8] in geometry_creator.faces

    # Test the intermediate points in the slit
    x, y = find_x(slit_height, angles[1]), find_y(slit_height, angles[1])
    assert geometry_creator.points[10] == Point(x, y, z)
    assert geometry_creator.points[11] == Point(x, y, -z)

    # Test for the faces connected to the points 10 and 11
    check_cake_slice_faces([4, 5, 11, 10])
    check_cake_slice_faces([10, 11, 9, 8])

    # Test for the next pair of points
    x, y = find_x(radius, angles[2]), find_y(radius, angles[2])
    assert geometry_creator.points[12] == Point(x, y, z)
    assert geometry_creator.points[13] == Point(x, y, -z)

    # Test for the faces connected to points 12 and 13
    check_cake_slice_faces([6, 7, 13, 12])

    # Test for the next pair of points
    x, y = find_x(radius, angles[3]), find_y(radius, angles[3])
    assert geometry_creator.points[14] == Point(x, y, z)
    assert geometry_creator.points[15] == Point(x, y, -z)

    # Test for the faces connected to points 14 and 15
    check_cake_slice_faces([12, 13, 15, 14])

    # Test for the next pair of points
    x, y = find_x(radius, angles[4]), find_y(radius, angles[4])
    assert geometry_creator.points[16] == Point(x, y, z)
    assert geometry_creator.points[17] == Point(x, y, -z)

    # Test for the faces connected to points 14 and 15
    check_cake_slice_faces([14, 15, 17, 16])

    # Test for the remaining connection in the chopper
    check_cake_slice_faces([16, 17, 3, 2])

    # Test for the points in the top dead centre arrow
    assert geometry_creator.points[18] == Point(radius, 0, z)
    assert geometry_creator.points[19] == Point(
        radius + geometry_creator.arrow_size, 0, z + geometry_creator.arrow_size
    )
    assert geometry_creator.points[20] == Point(
        radius - geometry_creator.arrow_size, 0, z + geometry_creator.arrow_size
    )

    # Test for the top dead centre arrow face
    assert [18, 19, 20] in geometry_creator.faces
示例#11
0
def test_GIVEN_slit_boundaries_WHEN_creating_intermediate_points_and_faces_THEN_expected_points_and_faces_are_created(
    geometry_creator,
):
    # Choose angles for the boundaries of the slit edge
    first_angle = np.deg2rad(80)
    second_angle = np.deg2rad(100)

    # Set a middle angle
    middle_angle = np.deg2rad(90)

    # Set the length of the vertices
    r = 10

    # Create the points for the boundaries of the slit edges
    first_front, first_back = geometry_creator.create_and_add_mirrored_points(
        r, first_angle
    )
    second_front, second_back = geometry_creator.create_and_add_mirrored_points(
        r, second_angle
    )

    # Create a fake set of resolution angles with zero between the first and second angle
    geometry_creator.resolution_angles = np.array(
        [first_angle, middle_angle, second_angle]
    )

    # Call the method for creating the intermediate points and faces
    geometry_creator.create_intermediate_points_and_faces(
        first_angle, second_angle, first_front, first_back, second_front, second_back, r
    )

    # The expected intermediate points should have a distance from the centres of r, an angle of 90 degrees and be
    # separated by 2 * z
    expected_intermediate_front = Point(0, r, geometry_creator.z)
    expected_intermediate_back = Point(0, r, -geometry_creator.z)

    # Check that the last two points that were created in the geometry creator match what was expected
    actual_intermediate_front = geometry_creator.points[-2]
    actual_intermediate_back = geometry_creator.points[-1]

    assert actual_intermediate_front == expected_intermediate_front
    assert actual_intermediate_back == expected_intermediate_back

    # Check that the expected faces were created
    assert geometry_creator.faces[-6] == create_list_of_ids(
        first_front, first_back, actual_intermediate_back, actual_intermediate_front
    )

    assert geometry_creator.faces[-5] == create_list_of_ids(
        geometry_creator.front_centre, first_front, actual_intermediate_front
    )

    assert geometry_creator.faces[-4] == create_list_of_ids(
        geometry_creator.back_centre, actual_intermediate_back, first_back
    )

    assert geometry_creator.faces[-3] == create_list_of_ids(
        actual_intermediate_front, actual_intermediate_back, second_back, second_front
    )

    assert geometry_creator.faces[-2] == create_list_of_ids(
        geometry_creator.front_centre, actual_intermediate_front, second_front
    )

    assert geometry_creator.faces[-1] == create_list_of_ids(
        geometry_creator.back_centre, second_back, actual_intermediate_back
    )
示例#12
0
def point():
    return Point(POINT_X, POINT_Y, POINT_Z)