Exemple #1
0
def duplicate(fin, nx=1, ny=1, rot_angle=None):
    para0 = get_para(fin)
    x0, y0, theta0 = read_snap(fin)
    if rot_angle is not None:
        x0, y0, theta0 = rotate(x0, y0, theta0, rot_angle, para0["Lx"],
                                para0["Ly"])
    para_new = {key: para0[key] for key in para0}
    if rot_angle is None:
        para_new["Lx"] *= nx
        para_new["Ly"] *= ny
        dx = para0["Lx"]
        dy = para0["Ly"]
    elif rot_angle == 90 or rot_angle == -90:
        para_new["Lx"] = para0["Ly"] * nx
        para_new["Ly"] = para0["Lx"] * ny
        dx = para0["Ly"]
        dy = para0["Lx"]
    para_new["seed"] = int("2%d%d%d" % (nx, ny, para0["seed"]))
    para_new["t"] = 0
    N0 = x0.size

    x, y, theta = np.zeros((3, x0.size * nx * ny), np.float32)
    for row in range(ny):
        for col in range(nx):
            k = col + row * nx
            beg = k * N0
            end = beg + N0
            x[beg:end] = x0 + col * dx
            y[beg:end] = y0 + row * dy
            theta[beg:end] = theta0

    plot_snap(x0, y0, theta0, para0, frac=2e4 / x0.size)
    plot_snap(x, y, theta, para_new, frac=2e4 / x.size)
    save_to_file(x, y, theta, para_new)
Exemple #2
0
def piece_together(f1, f2, rot_ang1=None, rot_ang2=None, save=True):
    para1 = get_para(f1)
    x, y, theta = read_snap(f1)
    x1, y1, theta1 = rotate(x, y, theta, rot_ang1, para1["Lx"], para1["Ly"])

    para2 = get_para(f2)
    x, y, theta = read_snap(f2)
    x2, y2, theta2 = rotate(x, y, theta, rot_ang2, para2["Lx"], para2["Ly"])

    x2 += para2["Ly"]
    x = np.hstack((x1, x2))
    y = np.hstack((y1, y2))
    theta = np.hstack((theta1, theta2))

    para = para1
    para["Lx"] = para1["Lx"] * 2
    para["seed"] = int(f"2{para1['seed']}{para2['seed']}")
    para["t"] = 0
    plot_snap(x, y, theta, para, show_relative_angle=False, frac=0.05)
    if save:
        save_to_file(x, y, theta, para)
Exemple #3
0
def make_lane(fin, save=True):
    para0 = get_para(fin)
    x0, y0, theta0 = read_snap(fin)
    x1, y1, theta1 = rotate(x0.copy(), y0.copy(), theta0.copy(), 180,
                            para0["Lx"], para0["Ly"])
    x1 += para0["Lx"]
    x = np.hstack((x0, x1))
    y = np.hstack((y0, y1))
    theta = np.hstack((theta0, theta1))
    para = para0
    para["Lx"] = para0["Lx"] * 2
    para["t"] = 0
    plot_snap(x, y, theta, para, show_relative_angle=False, frac=0.01)
    if save:
        save_to_file(x, y, theta, para)
Exemple #4
0
def add_particles(fin, rho_add, save=True):
    para0 = get_para(fin)
    x0, y0, theta0 = read_snap(fin)
    rho_new = para0["rho0"] + rho_add
    n_old = x0.size
    n_new = int(para0["Lx"] * para0["Ly"] * rho_new)
    x1, y1, theta1 = np.zeros((3, n_new), np.float32)
    x1[:n_old] = x0
    y1[:n_old] = y0
    theta1[:n_old] = theta0
    x1[n_old:n_new] = np.random.rand(n_new-n_old) * para0["Lx"]
    y1[n_old:n_new] = np.random.rand(n_new-n_old) * para0["Ly"]
    theta1[n_old:n_new] = np.random.rand(n_new-n_old) * np.pi * 2
    para = para0
    para["rho0"] = rho_new
    para["t"] = 0
    plot_snap(x1, y1, theta1, show_relative_angle=False, frac=0.01)
    if save:
        save_to_file(x1, y1, theta1, para)
Exemple #5
0
def create_band_lane_snap():
    # fin = "snap/s2400_0.290_1.000_0.5_133_47200000.bin"
    fin = "snap/s2400_0.350_1.000_0.5_411_26160000.bin"
    para = get_para(fin)
    if para["seed"] == 133:
        direction = "y"
        length = para["Lx"]
        # width, ymin, ymax = 400, 1500, 1900
        width, ymin, ymax = 600, 0, 600
        rect = [0, para["Lx"], ymin, ymax]
    else:
        direction = "x"
        length = para["Ly"]
        width, xmin, xmax = 400, 1500, 1900
        rect = [xmin, xmax, 0, para["Ly"]]
    x, y, theta = read_snap(fin)
    x, y, theta = slice(x, y, theta, rect, shift=True)
    n_lane = 6
    para["Ly"] = n_lane * width
    para["t"] = 0
    para["seed"] = int("%d%d%d" % (2, n_lane, para["seed"]))
    x, y, theta = make_band_lane(x, y, theta, n_lane, width, length, direction)
    save_to_file(x, y, theta, para, adjust_rho0=True)