Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
vdf_params.py
Go to the documentation of this file.
1import matplotlib.pyplot as plt
2import numpy as np
3import math
4
5# constants
6mp = 1.672622e-27 # kg
7kB = 1.380649e-23 # J/K
8q = 1.602177e-19 # C
9
10# enter parameters in SI!!!
11particle_mass = 1*mp # kg
12density = 1e6 # m^-3
13temperature = 5e5 # K
14vmean = 5e5 # m/s
15vmin = -1.2e6 # m/s
16vmax = 1.2e6 # m/s
17n_blocks = 15
18block_width = 4
19sparsity_threshold = 1e-15 # s^3/m^6
20
21v_th = math.sqrt(3. * kB * temperature / particle_mass)
22
23fig = plt.figure()
24ax = fig.gca()
25
26dv = (vmax-vmin)/(n_blocks * block_width)
27v = np.arange(vmin, vmax, dv)
28
29vdf = np.ma.array(density * (particle_mass / (2.*math.pi*kB*temperature))**(3./2.) * np.exp(-particle_mass*(v-vmean)**2 / (2.*kB*temperature)))
30vdf = np.ma.masked_where(vdf < 0.005*sparsity_threshold, vdf)
31
32print("Parameters:")
33print(f"mass: {particle_mass:.3e} kg or {particle_mass/mp:.1f} proton masses")
34print(f"temperature: {temperature:.3e} K or {temperature * kB / q:.3e} eV")
35print(f"density: {density:.3e} m^-3")
36print(f"thermal speed: {v_th:.3e} m/s")
37print(f"dv: {dv:.3e} m/s")
38print(f"VDF max, sparsity threshold {np.max(vdf):.2e}, {sparsity_threshold:.1e}")
39
40
41ax.scatter(v, vdf, s=10, label=f"v-space cell resolution dv = {dv:.3e} m/s")
42#ax.step(v, vdf)
43ax.scatter(v[::block_width], vdf[::block_width], marker="|", s=300, label="v-space blocks WID = "+str(block_width)+" cells")
44#ax.step(v[::block_width], vdf[::block_width], where="post")
45ax.axvline(vmean, label=f"mean velocity {vmean:.1e} m/s")
46ax.set_yscale("log")
47ax.hlines(sparsity_threshold, vmin, vmax, label=f"sparsity threshold {sparsity_threshold:.1e} s^3/m^6", color="C3", lw=3, alpha=0.5)
48ax.axvspan(vmean - v_th, vmean + v_th, alpha=0.3, label=f"thermal velocity = {v_th:.3e} m/s")
49ax.axhspan(np.ma.min(vdf)*0.1, sparsity_threshold, xmin=vmin, xmax=vmax, color="C3", hatch="/", alpha=0.5)
50ax.set_xlim((vmin, vmax))
51
52ax.set_xlabel("Velocity space extent (m/s)")
53ax.set_ylabel("Phase-space density of VDF (s^3/m^6)")
54ax.set_title(f"VDF parameters for mass {particle_mass:.3e} kg or {particle_mass/mp:.1f} proton masses, n = {density:.3e} m^-3 and T = {temperature:.3e} K or {temperature * kB / q:.3e} eV")
55
56ax.legend()
57
58plt.draw()
59plt.show()