Note
Go to the end to download the full example code.
Shamrock 3D Gaussian generator#
This example shows how to use the mock gaussian function
10 import matplotlib.pyplot as plt # plots
11 import numpy as np # sqrt & arctan2
12
13 import shamrock
Pseudo random number generator seed
18 eng = shamrock.algs.gen_seed(111)
Generate positions
23 list_pos = []
24 for i in range(1000000):
25 list_pos.append(shamrock.algs.mock_gaussian_f64_3(eng))
Compute r and theta
Radial distribution
45 hist_r, bins_r = np.histogram(r_val, bins=1000, density=True)
46 r = np.linspace(bins_r[0], bins_r[-1], 1000)
47
48 maxwell_b = (4 * np.pi * r * r) * np.exp(-(r**2) / 2) / (np.sqrt(2 * np.pi)) ** 3
49
50 plt.figure()
51 plt.plot(r, maxwell_b, "r--", lw=2)
52 plt.bar(bins_r[:-1], hist_r, np.diff(bins_r), alpha=0.5)
53 plt.xlabel("$r$")
54 plt.ylabel("$f(r)$")
55 plt.show()

Angular distribution
60 hist_theta, bins_theta = np.histogram(theta_val, bins=1000, density=True)
61 theta = np.linspace(bins_theta[0], bins_theta[-1], 1000)
62
63 plt.figure()
64 plt.plot(theta, [1 / (2 * np.pi) for _ in theta], "r--", lw=2)
65 plt.bar(bins_theta[:-1], hist_theta, np.diff(bins_theta), alpha=0.5)
66 plt.xlabel(r"$\theta$")
67 plt.ylabel(r"$f(\theta)$")
68
69 plt.show()

Total running time of the script: (0 minutes 5.148 seconds)
Estimated memory usage: 315 MB