Пример #1
0
    def __init__(self, f_image, abc_name, sound_speed, density, dt, dx):
        img = Image.open(f_image)
        self.width, self.height = img.size

        if abc_name == "Mur1":
            self.abc_field = ABC.Mur1(
                0, self.width, 0, self.height, sound_speed["air"], dt, dx)
        elif abc_name == "Mur2":
            u_list = np.zeros([self.width-2, self.height-2])
            self.abc_field = ABC.Mur2(
                0, self.width, 0, self.height, sound_speed["air"], dt, dx, density, u_list)

        self.ref_points = []
        field_arr = np.array(img, dtype=np.int32).T
        # (self.wall_area,
        # self.ref_points_w,
        # self.ref_points_h) = self.__read_field(field_arr)
        (self.wall_area,
         self.ref_points_w_p,
         self.ref_points_w_m,
         self.ref_points_h_p,
         self.ref_points_h_m) = self.__read_field(field_arr)
        self.velocity_arr, self.density_arr = self.__make_velocity_density_field(
            self.wall_area, sound_speed, density)

        R = 1
        self.coef_obs = ((1+R)*(sound_speed["air"]*dt/dx) - (1-R)) / \
            ((1 + R) * (sound_speed["air"] * dt / dx) + (1 - R))
Пример #2
0
def main(field_image, txt_data):
    print("field setting....")
    if gpu_flag:
        field_data = field.Field_GPU(field_image, abc_name,
                                     sound_speed_list, density_list, dt, dx)
    else:
        field_data = field.Field(field_image, abc_name,
                                 sound_speed_list, density_list, dt, dx)
    width = field_data.width
    height = field_data.height

    if abc_name == "Mur1":
        import ABC
        abc_field = ABC.Mur1(0, width, 0, height,
                             sound_speed_list["air"], dt, dx)
    print("done")
    print("pulse information reading....")
    pulse_info_list = read_pulse_info(txt_data)
    print("done")

    if gpu_flag:
        print("calc with GPU start....")
        cp.cuda.set_allocator(cp.cuda.MemoryPool().malloc)
        P1 = cp.zeros((width, height), dtype=cp.float32)
        P2 = cp.zeros((width, height), dtype=cp.float32)
        if debug_flag:
            fig = plt.figure()
        image_list = Calc(field_data, P1, P2, pulse_info_list)
    else:
        print("calc without GPU start....")
        P1 = np.zeros((width, height), dtype=np.float32)
        P2 = np.zeros((width, height), dtype=np.float32)
        if debug_flag:
            fig = plt.figure()
        image_list = Calc(field_data, P1, P2, pulse_info_list)
    if debug_flag:
        print("make animation....")
        ani = animation.ArtistAnimation(
            fig, image_list[0], interval=100, blit=True)
        ani.save(f'ani.gif', writer="imagemagick")