def brownTest(): """Testing for brownian motion plot""" global mySys, fig, ax reload(objects) reload(system) reload(core) Writer = animation.writers['ffmpeg'] writer = Writer(fps=core.FRAMERATE, bitrate=1800) balls = objects.distributeBalls(60, 5, ballsize=0.1, v=20.) big_ball = objects.BigBall(pos=[7, 0, 0], radius=1., mass=5) balls.append(big_ball) cont = objects.Container(9) mySys = system.System(balls, cont) fig = plt.figure() ax = plt.axes(xlim=(-20, 20), ylim=(-20, 20)) ax.axes.set_aspect('equal') mySys.init_system(ax) anim = animation.FuncAnimation(fig, mySys.next_frame, frames=200, interval=20, blit=True, repeat=False) anim.save("mov.mp4", writer=writer) fig2 = plt.figure(2) ax2 = plt.axes(xlim=(-20, 20), ylim=(-20, 20)) ax2.add_artist(plt.Circle((0, 0), 9, fill=False)) nodes = big_ball.get_nodes() plt.plot(nodes[0], nodes[1]) plt.savefig("brown.png")
def conservationTest(step=5): """Run the system for *step* seconds to check physics works""" global mySys sys.setrecursionlimit(10000) reload(objects) reload(system) reload(core) balls = objects.distributeBalls(20, 12, ballsize=0.1) cont = objects.Container(12) mySys = system.System(balls, cont) mySys.init_system(None) E0 = mySys.total_KE() p0 = mySys.get_total_momentum() mySys.check_collide(step) E1 = mySys.total_KE() p1 = mySys.get_total_momentum() if core.close(p0, p1): core.logging.log(20, "Momentum conserved") else: core.logging.log(50, "Momentum not conserved") core.logging.log(50, p0) core.logging.log(50, p1) if np.abs(E0 - E1) < 1E-30: core.logging.log(20, "Energy conserved") else: core.logging.log(50, "Energy not conserved") core.logging.log(50, E0) core.logging.log(50, E1)
def genMaxwellBData(v=15.): # params rad = 12. ballsize = 0.2 num_balls = 400 # INITIALIZE SYSTEM balls = objects.distributeBalls(num_balls, rad, ballsize, v, 3) cont = objects.Container(rad) mySys = system.System(balls, cont) mySys.init_system(None) vels = [] for ball in balls: v = ball.get_vel() vels.append(np.dot(v, v)) v_bar = np.mean(vels) # 5 times charictersitic collision time t = 5. * ((4. / 3.) * np.pi * rad**3) / ( np.sqrt(v_bar) * 4. * np.pi * ballsize**2 * num_balls) mySys.advance(t) vels = [] for ball in balls: v = ball.get_vel() vels.append(np.sqrt(np.dot(v, v))) temp = mySys.temperature() return vels, temp
def genTest(n=6): """To be used interactively. Generate system of *n* balls as mySys""" global mySys reload(objects) reload(system) reload(core) balls = objects.distributeBalls(n, 12) cont = objects.Container(12.) mySys = system.System(balls, cont)
def pressure(num_balls, ballsize, v, dim): balls = objects.distributeBalls( n=num_balls, radius=12, ballsize=ballsize, v=v, dim=dim) cont = objects.Container(12) mySys = system.System(balls, cont) mySys.init_system(None) mySys.check_collide(2) P = mySys.pressure(5) T = mySys.temperature() return [P, T]
def pressure(num_balls, ballsize, v, dim): balls = objects.distributeBalls(n=int(np.ceil(num_balls)), radius=12, ballsize=ballsize, v=v, dim=dim) for ball in balls[int(np.ceil(num_balls / 2.)):]: # Bad and wrong, but I don't want to write another method just # for a test. ball._radius = ballsize / 2. cont = objects.Container(12) mySys = system.System(balls, cont) mySys.init_system(None) mySys.check_collide(2) P = mySys.pressure(5) T = mySys.temperature() return [P, T]
def animGenTest(n=6, r=12., ballsize=1.): """ Create animation with *n* balls, size *ballsize* in container radius *r* """ global mySys, fig, ax reload(objects) reload(system) reload(core) balls = objects.distributeBalls(n, r, ballsize=ballsize) cont = objects.Container(r) mySys = system.System(balls, cont) fig = plt.figure() ax = plt.axes(xlim=(-20, 20), ylim=(-20, 20)) ax.axes.set_aspect('equal') mySys.init_system(ax) anim = animation.FuncAnimation(fig, mySys.next_frame, interval=20, blit=True) plt.show()
def physicsTest(num_balls=200, ballsize=0.01): global mySys, pressure sys.setrecursionlimit(10000) reload(objects) reload(system) reload(core) balls = objects.distributeBalls(n=num_balls, radius=12, ballsize=ballsize) cont = objects.Container(12) mySys = system.System(balls, cont) mySys.init_system(None) mySys.check_collide(5) P = mySys.pressure(20) print "pressure", P print "temp", mySys.temperature() core.logging.log(50, "temp is {}".format(mySys.temperature())) a = P * (4. / 3.) * np.pi * 12.**3 b = num_balls * core.Kb * mySys.temperature() c = P * (((4. / 3.) * np.pi * 12.**3) - ((16. / 3.) * np.pi * ballsize**3 * num_balls)) print "Pv", a print "nkT", b print "frac", a / b print "P(V-bn)", c print "frac", c / b