diff options
author | Adrian Kummerlaender | 2020-03-22 21:08:29 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2020-03-22 21:08:29 +0100 |
commit | 58678cfc3956ac5a1dbec91392b41b1b73a31463 (patch) | |
tree | 69957d6e6bc8a7977ead8bdcd3a8d82d98ee9e57 /gasplot.py | |
download | boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.tar boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.tar.gz boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.tar.bz2 boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.tar.lz boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.tar.xz boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.tar.zst boltzgas-58678cfc3956ac5a1dbec91392b41b1b73a31463.zip |
Extract hard sphere gas from particle playground
Diffstat (limited to 'gasplot.py')
-rw-r--r-- | gasplot.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gasplot.py b/gasplot.py new file mode 100644 index 0000000..8adfe4d --- /dev/null +++ b/gasplot.py @@ -0,0 +1,55 @@ +import numpy as np +import scipy.stats as stats +import scipy.constants as const +from scipy.optimize import minimize + +import matplotlib +import matplotlib.pyplot as plt + +from particles import GasFlow, HardSphereSetup, grid_of_random_velocity_particles + +grid_width = 30 +radius = 0.002 +char_u = 1120 + +config = HardSphereSetup(radius, char_u, *grid_of_random_velocity_particles(grid_width, radius, char_u)) +gas = GasFlow(config) + +m_nitrogen = 0.028 / const.N_A + +def plot(step, velocities): + velocities = np.array([np.linalg.norm(v) for v in velocities]) + maxwellian = stats.maxwell.fit(velocities) + + print("T = %.0f K; u_mean = %.0f [m/s]; energy = %.05f" % ((maxwellian[1]**2 / const.k * m_nitrogen, stats.maxwell.mean(*maxwellian), np.sum([x*2 for x in velocities])))) + + plt.figure() + + plt.ylim(0, 0.003) + plt.ylabel('Probability') + + plt.xlim(0, 1.2*char_u) + plt.xlabel('Velocity magnitude [m/s]') + + plt.hist(velocities, bins=50, density=True, alpha=0.5, label='Simulated velocities') + + xs = np.linspace(0, 1.2*char_u, 100) + plt.plot(xs, stats.maxwell.pdf(xs, *maxwellian), label='Maxwell-Boltzmann distribution') + + plt.legend(loc='upper right') + + plt.savefig("result/%04d.png" % step) + plt.close() + +def simulate(n_steps, section): + for i in range(0, int(n_steps / section)): + print("Plot step %d." % (i * section)) + + velocities = gas.get_velocities() + + for j in range(0,section): + gas.evolve() + + plot(i, velocities) + +simulate(10000, 500) |