Exemplo n.º 1
0
def curved_surface2(detector_r=2.0,
                    diameter=2.5,
                    nsteps=8,
                    base_pxl=4,
                    ret_arr=False):
    '''Builds a curved surface based on the specified radius. Origin is center of surface.'''
    if (detector_r < diameter / 2.0):
        raise Exception(
            'The Radius of the curved surface must be larger than diameter/2.0'
        )
    shift1 = np.sqrt(detector_r**2 - (diameter / 2.0)**2)
    theta1 = np.arctan(shift1 / (diameter / 2.0))
    angles1 = np.linspace(theta1, np.pi / 2, nsteps)
    # print('Parameters: %f %f %s' % (shift1, theta1, str(angles1)))
    x_value = abs(detector_r * np.cos(angles1))
    y_value = detector_r - detector_r * np.sin(angles1)
    surf = None
    x_coord, y_coord, n_step = calc_steps(x_value,
                                          y_value,
                                          detector_r,
                                          base_pixel=base_pxl)
    for i, (x, y, n_stp) in enumerate(zip(x_coord, y_coord, n_step)):
        if i == 0:
            surf = make.rotate_extrude(x, y, n_stp)
        else:
            surf += make.rotate_extrude(x, y, n_stp)
    if ret_arr: return surf, n_step
    else: return surf
Exemplo n.º 2
0
def cylindrical_shell(inner_radius, outer_radius, thickness, nsteps=inputn):
    #make sure that nsteps is the same as that of rotate extrude in lens
    #inner_radius must be less than outer_radius
    return make.rotate_extrude(
        [inner_radius, outer_radius, outer_radius, inner_radius],
        [-thickness / 2.0, -thickness / 2.0, thickness / 2.0, thickness / 2.0],
        nsteps)
Exemplo n.º 3
0
def build_pmt(filename,
              glass_thickness,
              outer_material,
              glass,
              vacuum,
              photocathode_surface,
              back_surface,
              nsteps=16):
    profile = read_csv(filename)

    # slice profile in half
    profile = profile[profile[:, 0] < 0]
    profile[:, 0] = -profile[:, 0]
    # order profile from base to face
    profile = profile[np.argsort(profile[:, 1])]
    # set x coordinate to 0.0 for first and last profile along the profile
    # so that the mesh is closed
    profile[0, 0] = 0.0
    profile[-1, 0] = 0.0

    offset_profile = offset(profile, -glass_thickness)

    outer_envelope_mesh = rotate_extrude(profile[:, 0], profile[:, 1], nsteps)
    inner_envelope_mesh = rotate_extrude(offset_profile[:, 0],
                                         offset_profile[:, 1], nsteps)

    outer_envelope = Solid(outer_envelope_mesh, glass, outer_material)

    photocathode = np.mean(inner_envelope_mesh.assemble(), axis=1)[:, 1] > 0

    inner_envelope = Solid(inner_envelope_mesh,
                           vacuum,
                           glass,
                           surface=np.where(photocathode, photocathode_surface,
                                            back_surface),
                           color=np.where(photocathode, 0xff00, 0xff0000))

    pmt = outer_envelope + inner_envelope

    # profile points, outer_material, and theta are used to construct the
    # light collector
    pmt.profile = profile
    pmt.outer_material = outer_material
    pmt.nsteps = nsteps

    return pmt
Exemplo n.º 4
0
def build_light_collector_from_file(filename,
                                    outer_material,
                                    surface,
                                    nsteps=48):
    profile = read_csv(filename)

    mesh = rotate_extrude(profile[:, 0], profile[:, 1], nsteps)
    solid = Solid(mesh, outer_material, outer_material, surface=surface)
    return solid
Exemplo n.º 5
0
def lens(diameter, thickness, nsteps=inputn):
    #constructs a parabolic lens
    a = np.linspace(0, diameter / 2, nsteps / 2, endpoint=False)
    b = np.linspace(diameter / 2, 0, nsteps / 2)
    return make.rotate_extrude(
        np.concatenate((a, b)),
        np.concatenate(
            (2 * thickness / diameter**2 * (a)**2 - 0.5 * thickness,
             -2.0 * thickness / diameter**2 * (b)**2 + 0.5 * thickness)),
        nsteps=inputn)
Exemplo n.º 6
0
def BuildBlocker(radius, height):
    nsteps = 50
    x_value = np.linspace(radius, radius + 200, nsteps)
    y_value = [1] * nsteps

    blocker = make.rotate_extrude(x_value, y_value, nsteps)

    blocker = mh.rotate(blocker, make_rotation_matrix(+np.pi / 2, (1, 0, 0)))
    blocker = mh.shift(blocker, (0, 0, height))

    return blocker
Exemplo n.º 7
0
def build_pmt_shell(filename, outer_material, glass, nsteps=16):
    profile = read_csv(filename)

    # slice profile in half
    profile = profile[profile[:, 0] < 0]
    profile[:, 0] = -profile[:, 0]
    # order profile from base to face
    profile = profile[np.argsort(profile[:, 1])]
    # set x coordinate to 0.0 for first and last profile along the profile
    # so that the mesh is closed
    profile[0, 0] = 0.0
    profile[-1, 0] = 0.0

    return Solid(rotate_extrude(profile[:, 0], profile[:, 1], nsteps),
                 glass,
                 outer_material,
                 color=0xeeffffff)
Exemplo n.º 8
0
def build_light_collector(pmt, a, b, d, rmin, rmax, surface, npoints=10):
    if not isinstance(pmt, Solid):
        raise Exception('`pmt` must be an instance of %s' % Solid)

    lc_radii = np.linspace(rmin, rmax, npoints)
    lc_profile = get_lc_profile(lc_radii, a, b, d, rmin, rmax)

    pmt_face_profile = pmt.profile[pmt.profile[:, 1] > -1e-3]

    lc_offset = np.interp(lc_radii[0], list(reversed(pmt_face_profile[:, 0])),
                          list(reversed(pmt_face_profile[:, 1])))

    lc_mesh = rotate_extrude(lc_radii, lc_profile + lc_offset, pmt.nsteps)

    return Solid(lc_mesh,
                 pmt.outer_material,
                 pmt.outer_material,
                 surface=surface)
Exemplo n.º 9
0
def PlotBlocker(radius, height):
    nsteps = 30
    x_value = np.linspace(radius, radius + 200, nsteps)
    y_value = [0] * nsteps

    blocker = make.rotate_extrude(x_value, y_value, nsteps)
    blocker = mh.rotate(blocker, make_rotation_matrix(+np.pi / 2, (1, 0, 0)))
    blocker = mh.shift(blocker, (0, 0, height))

    blocker_triangles = blocker.get_triangle_centers()
    blocker_vertices = blocker.assemble()

    X = blocker_vertices[:, :, 0].flatten()
    Y = blocker_vertices[:, :, 1].flatten()
    Z = blocker_vertices[:, :, 2].flatten()

    trianglesblocker = [[3 * ii, 3 * ii + 1, 3 * ii + 2]
                        for ii in range(len(X) / 3)]
    triang = Triangulation(X, Y, trianglesblocker)

    return triang, Z