예제 #1
0
def data(request):

    print("\n create data")
    # initial condition and simulation parameters
    domain = ([-2, 12], [0, 3])
    dt = 0.5
    t_max = 6
    loc_0 = np.array([[0, 1.5], [10, 1.5]])
    vel_0 = np.array([[1, 0], [-1, 0]])
    radius = 1
    mass = [1, 1]

    loc, vel = sim2d.simulation(t_max, dt, mass, radius, loc_0, vel_0, domain)

    my_data = {}
    my_data["loc_0"] = loc_0
    my_data["vel_0"] = vel_0
    my_data["loc"] = loc
    my_data["vel"] = vel
    my_data["mass"] = mass

    def data_cleanup():
        print("\n removing data")
        my_data.clear()

    request.addfinalizer(data_cleanup)
    return my_data
예제 #2
0
def test_simulation_1d(dt):
    # initial condition and simulation parameters
    domain = ([-2, 12], [0, 3])
    dt = dt
    t_max = 6
    loc_0 = np.array([[0, 1.5], [10, 1.5]])
    vel_0 = np.array([[1, 0], [-1, 0]])
    radius = 1
    mass = [1, 1]

    loc, vel = sim2d.simulation(t_max, dt, mass, radius, loc_0, vel_0, domain)

    # create movie
    movie = Movie_2d(sim2d.simulation_step, dt, t_max - dt, loc, vel, domain,
                     mass, radius)
    movie.animate("pytest_movie_1d_dt_" + str(dt))

    # test location and velocities after colision
    assert loc[0][0] < 5
    assert loc[1][0] > 5
    assert (loc[0][1], loc[1][1]) == (loc_0[0][1], loc_0[1][1])

    assert vel[0][0] == -1
    assert vel[1][0] == 1
    assert (vel[0][1], vel[1][1]) == (vel_0[0][1], vel_0[1][1])
예제 #3
0
def test_simulation_1d_fail():
    # initial condition and simulation parameters
    domain = ([-2, 12], [0, 3])
    dt = 1.
    t_max = 12
    loc_0 = np.array([[0, 1.5], [10, 1.5]])
    vel_0 = np.array([[1, 0], [-1, 0]])
    radius = 1
    mass = [1, 1]

    with pytest.raises(Exception) as excinfo:
        loc, vel = sim2d.simulation(t_max, dt, mass, radius, loc_0, vel_0,
                                    domain)
    assert "two balls are exactly in the same place" in str(excinfo.value)
def test_energy_hypothesis(mass1, mass2):

    # initial condition and simulation parameters
    domain = ([0, 20], [0, 20])
    dt = 0.5
    t_max = 6
    loc_0 = np.array([[3, 4], [15, 2]])
    vel_0 = np.array([[1, 0.5], [-1, -.25]])
    radius = 1

    # mass randomly chosen by hypothesis
    mass = [mass1, mass2]

    # run the simulation
    loc, vel = sim2d.simulation(t_max, dt, mass, radius, loc_0, vel_0, domain)

    E_ini = E_kin(vel_0, mass)
    E_end = E_kin(vel, mass)

    print("testing for mass = {}. E_end = {}".format(mass, E_end))

    assert E_ini == E_end