from config import * import numpy as np #--------Paramenters---------- N_collisions = 10 repeats = 10 Number_of_Balls = 100 #--------VDW: a,b----------- a = [] b = [] P = [] for i in range(repeats): sim = Simulation(Number_of_Balls) sim.run(N_collisions) V = sim.Ball_Volume() Nb = Number_of_Balls * V #2d ball constants = (Number_of_Balls * kb * sim.Temperature()) / (2 * np.pi * con_radius - Nb) a.append((V * V / Number_of_Balls**2) * (constants - sim.Pressure())) b.append(2 * np.pi * Max_Radius) P.append(sim.Pressure()) print("\nNumber of Repeats = ", repeats) print("\nPressure =", np.mean(P), "+/-", np.std(P), "Pa") print("Volume of Balls =", V, "m^3") print("a = ", np.mean(a), "+/-", np.std(a)) print("b = ", np.mean(b), "+/-", np.std(b))
# Thermodynamic Graphs #----------Parameters------------- Number_of_Balls = 10 #For P-N plot N_Collisions = 10 N_Plots = 10 #For P-T plot and P-V plot Container_Radius = 10 #----------P against N------------- n_i = np.linspace(1, Number_of_Balls, Number_of_Balls) pressure = [] pressure_error = [] for i in range(1, Number_of_Balls + 1): s = Simulation(i) s.run(N_Collisions) pressure.append(s.Pressure()) pressure_error.append(s.std_dev()) plt.figure(figsize=(8, 5)) plt.title("Pressure against Number of Balls") plt.xlabel("Number of Balls") plt.ylabel("Pressure/ Pa") plt.plot(n_i, pressure, 'x', color='C1') plt.plot(np.unique(n_i), np.poly1d(np.polyfit(n_i, pressure, 1))(np.unique(n_i)), color='C0') plt.errorbar(n_i, pressure, yerr=pressure_error, fmt='x', mew=1,
plt.xlabel("Velocity /$ms^-1$") plt.ylabel("Density") n, bins, patches = plt.hist(data, bins=50, normed=True) y = mlab.normpdf(bins, mu, sigma) l = plt.plot(bins, y, label='Experimental') print("\nuncertainty", sigma, "variance", sigma * sigma, "mean", mu) #---------Theoretical Maxwell Boltzmann Curve---------- def Maxwell_Boltzmann(x): #2D # print(sim.Temperature()) A = (ball_mass / (kb * sim.Temperature())) exponent = (-x * x * ball_mass) / (2 * kb * sim.Temperature()) y = A * (x) * np.exp(exponent) return y x_value = bins y_value = Maxwell_Boltzmann(x_value) plt.plot(x_value, y_value, 'r--', linewidth=2, label='Theoretical') plt.savefig("FIG_Maxwell_Boltzmann") plt.legend() plt.show() print("Real Temperature:", sim.Temperature()) print("Real Pressure:", sim.Pressure(), "\nIdeal Pressure:", sim.Pressure_Ideal(), "\n as Particle Size decreases, Real Pressure tend to Ideal Pressure")