def test_laser_pusher(): """Tests ExB drift for particles.""" S = initial("test_current", 0, 1378, 0, 0, 0) p = Particle(S.grid, 9.45 * S.grid.dx, 0, 0, q=-electric_charge, m=electron_rest_mass, scaling=npic) S.grid.list_species = [p] Ev, Bv = (np.array([[0, 1.228e12, 0]]), np.array([[0, 0, 4.027e3]])) E = lambda x: (Ev, Bv) p.velocity_push(E) p.position_push() print(p.v) expected_u = np.array([[5.089e4, -5.5698e6, 0]]) # this is u! expected_v = expected_u #* gamma_from_u(expected_u, S.grid.c) print(expected_v) print((p.v - expected_v)[0, :2] / p.v[0, :2] * 100, "%") # print(f"vx:{a:.9e}\n" # f"vy:{b:.9e}\n" # f"vz:{c:.9e}\n" # f"KE:{e:.9e}\n") assert np.allclose(expected_v, p.v, atol=1e-1, rtol=1e-2)
def test_laser_pusher(): """Tests ExB drift for particles.""" S = initial("test_current", 0, 1378, 0, 0, 0) p = Particle(S.grid, 9.45*S.grid.dx, 0, 0, q=-electric_charge, m=electron_rest_mass, scaling=npic) S.grid.list_species = [p] Ev, Bv = (np.array([[0, 1.228e12, 0]]), np.array([[0,0,4.027e3]])) E = lambda x: (Ev, Bv) p.velocity_push(E) p.position_push() print(p.v) expected_u = np.array([[5.089e4, -5.5698e6, 0]]) # this is u! expected_v = expected_u #* gamma_from_u(expected_u, S.grid.c) print(expected_v) print((p.v - expected_v)[0,:2] / p.v[0,:2] * 100, "%") # print(f"vx:{a:.9e}\n" # f"vy:{b:.9e}\n" # f"vz:{c:.9e}\n" # f"KE:{e:.9e}\n") assert np.allclose(expected_v, p.v, atol=1e-1, rtol=1e-2)
def test_transversal_current(init_pos, init_vx, expected): S = initial("test_current", 0, number_cells, 0, 0, 0) print(f"dx: {S.grid.dx}, dt: {S.grid.dt}, Neuler: {S.grid.NG}") init_vy = 0.01 p = Particle(S.grid, init_pos*S.grid.dx, init_vx*lightspeed, init_vy*lightspeed, q=-electric_charge, m=electron_rest_mass, scaling=npic) S.grid.list_species = [p] S.grid.gather_current([p]) investigated_density = S.grid.current_density_yz[9:14, 0] / p.eff_q / init_vy / lightspeed error = error_table(investigated_density, expected) print(pd.DataFrame({"indices": np.arange(9, 14)-2, "found density":investigated_density, "target density":expected, "error %":error})) assert np.allclose(investigated_density, expected, rtol=1e-2, atol=1e-3)
def test_longitudinal_current(init_pos, init_vx, target_density): S = initial("test_current", 0, number_cells, 0, 0, 0) print(f"dx: {S.grid.dx}, dt: {S.grid.dt}, Neuler: {S.grid.NG}") p = Particle(S.grid, init_pos*S.grid.dx, init_vx*lightspeed, q=-electric_charge, m=electron_rest_mass, scaling=npic) S.grid.list_species = [p] S.grid.gather_current([p]) investigated_density = S.grid.current_density_x[9:13] /(p.eff_q * lightspeed) if init_vx: investigated_density /= init_vx error = error_table(investigated_density, target_density) print(pd.DataFrame({"indices": np.arange(9, 13)-1, "found density":investigated_density, "target density":target_density, "error %":error})) assert np.allclose(target_density, investigated_density, rtol=1e-2, atol = 1e-3)
def test_longitudinal_current_multiples_as_species(paramset): expected_density = np.zeros(4) S = initial("test_current", 0, number_cells, 0, 0, 0) init_pos = np.array([params[0] for params in paramset]) * S.grid.dx init_vx = np.array([params[1] for params in paramset]) * S.grid.c for expected, v in zip([params[2] for params in paramset], init_vx): expected_density += expected * v # TODO figure this out spec = Species(-electric_charge, electron_rest_mass, 2, S.grid, scaling=npic) spec.x = init_pos spec.v[:,0] = init_vx S.grid.list_species = [spec] S.grid.gather_current([spec]) investigated_density = S.grid.current_density_x[9:13] / spec.eff_q error = error_table(investigated_density, expected_density) print("FINISHED. PARTICLE DATA") print(pd.DataFrame({'x/dx': spec.x/S.grid.dx, 'v/c': spec.v[:,0]/spec.c})) print("FINISHED. GRID DATA") print(pd.DataFrame({"indices": np.arange(9, 13)-1, "found density":investigated_density, "target density":expected_density, "error %":error})) assert np.allclose(expected_density, investigated_density, rtol=1e-2, atol = 1e-3)
# coding=utf-8 from pythonpic import plotting_parser from pythonpic.configs.run_laser import initial, impulse_duration, n_macroparticles, number_cells args = plotting_parser("Hydrogen shield") perturbation_amplitude = 0 powers = [21, 22, 23] polarizations = ["Ey", "Circular"] for power, number_particles, n_cells, polarization in [ [21, 75000, int(number_cells), "Ey"], [21, 75000, int(number_cells), "Circular"], [23, 75000, int(number_cells), "Ey"], [23, 75000, int(number_cells), "Circular"], ]: intensity = 10**power s = initial(f"{number_particles}_{n_cells}_run_{power}_{polarization}", number_particles, n_cells, impulse_duration, intensity, perturbation_amplitude, laser_polarization=polarization).lazy_run().plots_3d(*args) del s
save_data=False, T=T, scaling=scaling, c=c).lazy_run() static_plots.publication_plots(S, str(plot_folder / "ESE_energy_plot.pdf"), [static_plots.electrostatic_energy_time_plots]) del S S = run_coldplasma.initial(f"energy_plot_2", qmratio=qmratio, plasma_frequency=plasma_frequency, NG=NG, N_electrons=N_electrons, epsilon_zero=epsilon_zero, push_mode=push_mode, save_data=False, T=T * 10, scaling=scaling, c=c).lazy_run() static_plots.publication_plots(S, str(plot_folder / "ESE_energy_plot_long.pdf"), [static_plots.electrostatic_energy_time_plots]) del S S = run_laser.initial(f"75000_1378_run_21_Circular", n_macroparticles, number_cells, impulse_duration, 1e21, "Circular").lazy_run() static_plots.publication_plots( S, str(plot_folder / "preplazma.pdf"), [time_snapshots.SpatialDistributionPlot]) # TODO fix
# coding=utf-8 """Laser field propagation only""" from pythonpic import plotting_parser from pythonpic.configs.run_laser import initial, impulse_duration, n_macroparticles, plots, number_cells args = plotting_parser("Hydrogen shield") perturbation_amplitude = 0 number_particles = 10000 powers = range(23, 20, -1) power = 23 intensity = 10**power for number_particles, n_cells in [ [0, int(number_cells)], # ]: s = initial(f"{number_particles}_{n_cells}_run_{power}_{perturbation_amplitude}", number_particles, n_cells, impulse_duration, intensity, perturbation_amplitude).test_run() plots(s, *args, frames="few") del s
# coding=utf-8 from pythonpic import plotting_parser from pythonpic.configs.run_laser import initial, impulse_duration, n_macroparticles args = plotting_parser("Hydrogen shield") perturbation_amplitude = 0 intensity = 1e22 ncells = [500, 1000, 1378, 1500, 1800, 2000] scaling = 1 for n_cells in ncells: s = initial(f"timing_run_ncells_{n_cells}", n_macroparticles, n_cells, impulse_duration, intensity, perturbation_amplitude).lazy_run().plots_3d(*args) del s ncells = 1378 nparticles = [0, 1000, 5000, 10000, 20000, 40000, 60000, 70000, 80000] for n_particles in nparticles: s = initial(f"timing_run_nparticles_{n_particles}", n_particles, ncells, impulse_duration, intensity, perturbation_amplitude).lazy_run().plots_3d(*args) del s
# coding=utf-8 from pythonpic import plotting_parser from pythonpic.configs.run_laser import (initial, impulse_duration, n_macroparticles) args = plotting_parser("Hydrogen shield") perturbation_amplitude = 0 intensities = [5e20, 1e21, 5e21, 1e21, 5e21, 1e22, 5e22, 1e23] scalings = [0.5, 0.9, 1, 1.1, 1.5] for intensity in intensities: for scaling in scalings: s = initial(f"production_run_{intensity}_{scaling}", n_macroparticles, impulse_duration, intensity, perturbation_amplitude, scaling).lazy_run().plots_3d(*args)
from pythonpic import plotting_parser from pythonpic.configs import run_coldplasma, run_laser from pythonpic.visualization import static_plots, time_snapshots from pythonpic.configs.run_laser import initial, impulse_duration, n_macroparticles, number_cells import pathlib args = plotting_parser("Cold plasma oscillations") plasma_frequency = 1 push_mode = 2 N_electrons = 1024 NG = 64 qmratio = -1 T = 10 scaling = 1 c = 10 epsilon_zero = 1 plot_folder = pathlib.Path("/home/dominik/Inzynierka/ThesisText/Images/") S = run_coldplasma.initial(f"energy_plot", qmratio=qmratio, plasma_frequency=plasma_frequency, NG=NG, N_electrons=N_electrons, epsilon_zero=epsilon_zero, push_mode=push_mode, save_data=False, T = T, scaling=scaling, c=c).lazy_run() static_plots.publication_plots(S, str(plot_folder/"ESE_energy_plot.pdf"), [static_plots.electrostatic_energy_time_plots]) del S S = run_coldplasma.initial(f"energy_plot_2", qmratio=qmratio, plasma_frequency=plasma_frequency, NG=NG, N_electrons=N_electrons, epsilon_zero=epsilon_zero, push_mode=push_mode, save_data=False, T = T*10, scaling=scaling, c=c).lazy_run() static_plots.publication_plots(S, str(plot_folder/"ESE_energy_plot_long.pdf"), [static_plots.electrostatic_energy_time_plots]) del S S = run_laser.initial(f"75000_1378_run_21_Circular", n_macroparticles, number_cells, impulse_duration, 1e21, "Circular").lazy_run() static_plots.publication_plots(S, str(plot_folder/"preplazma.pdf"), [time_snapshots.SpatialDistributionPlot]) # TODO fix