From 9b052593e773a8d101ae1195d5208325dc2cd525 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 24 Mar 2020 21:34:53 +0100 Subject: Update plot-only program to use module --- gasplot.py | 60 ------------------------------------------------------------ plot.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 60 deletions(-) delete mode 100644 gasplot.py create mode 100644 plot.py diff --git a/gasplot.py b/gasplot.py deleted file mode 100644 index 44b0a53..0000000 --- a/gasplot.py +++ /dev/null @@ -1,60 +0,0 @@ -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 - -position, velocity = grid_of_random_velocity_particles(grid_width, radius, char_u) -velocity[:,:] = 0 -velocity[0,0] = 10.75*char_u -velocity[0,1] = -.25*char_u -config = HardSphereSetup(radius, char_u, position, velocity) -#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(100000, 1000) diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..422db21 --- /dev/null +++ b/plot.py @@ -0,0 +1,60 @@ +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 boltzgas import HardSphereSetup, HardSphereSimulation +from boltzgas.initial_condition import grid_of_random_velocity_particles + +grid_width = 30 +radius = 0.002 +char_u = 1120 + +position, velocity = grid_of_random_velocity_particles(grid_width, radius, char_u) +velocity[:,:] = 0 +velocity[0,0] = 10.75*char_u +velocity[0,1] = -.25*char_u +config = HardSphereSetup(radius, char_u, position, velocity) +gas = HardSphereSimulation(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(100000, 1000) -- cgit v1.2.3