예제 #1
0
def inelastic_wall(wall: Wall, particle: Particle, dt: float):
    """
    TODO extending for moveable walls
    Determines the resulting velocity of a particle bouncing off a wall, with mid-frame position correction
    :param wall: the wall object that may intersect the particle
    :param particle: the particle in the vicinity of the wall
    :param dt: length of the timestep
    :return: Boolean value of true if a collision occured
    """
    x0 = particle.x
    u0 = particle.u
    x1 = wall.vert[0, :]
    p = x0 - x1
    r = particle.mole.radius

    unit = wall.unit
    norm = wall.norm
    dis = np.dot(p, norm)

    # Determine if a collision actually occured
    if dis > r:
        return False


    #if norm_dir > 0:
    #    return False

    # Decompose particles velocity normal and tangential to wall
    norm_dir = np.dot(u0, norm)
    nu = np.multiply(norm_dir, norm)
    uu = np.multiply(np.dot(u0, unit), unit)

    # Update velocity and position
    x0 -= u0 * dt
    dt0 = (np.abs(np.dot(x0 - x1, norm)) - r) / np.linalg.norm(nu)
    x0 += u0 * dt0
    particle.u = uu - nu
    particle.x = x0 + particle.u*(dt - dt0)

    return True