APEX Gun, IMPACT-T¶
In [1]:
Copied!
from impact import Impact
from distgen import Generator
import os
# Nicer plotting
import matplotlib.pyplot as plt
import matplotlib
%config InlineBackend.figure_format = 'retina'
matplotlib.rcParams['figure.figsize'] = (8,4)
from impact import Impact
from distgen import Generator
import os
# Nicer plotting
import matplotlib.pyplot as plt
import matplotlib
%config InlineBackend.figure_format = 'retina'
matplotlib.rcParams['figure.figsize'] = (8,4)
In [2]:
Copied!
IMPACT_IN = '../templates/apex_gun/ImpactT.in'
DISTGEN_IN = '../templates/apex_gun/distgen.yaml'
NUMPROCS=4
os.path.exists(IMPACT_IN)
IMPACT_IN = '../templates/apex_gun/ImpactT.in'
DISTGEN_IN = '../templates/apex_gun/distgen.yaml'
NUMPROCS=4
os.path.exists(IMPACT_IN)
Out[2]:
True
In [3]:
Copied!
G = Generator(DISTGEN_IN)
G['n_particle'] = 10000
G.run()
P0 = G.particles
factor = 1.01
P0.x *= factor
P0.y *= 1/factor
P0.plot('x', 'y')
G = Generator(DISTGEN_IN)
G['n_particle'] = 10000
G.run()
P0 = G.particles
factor = 1.01
P0.x *= factor
P0.y *= 1/factor
P0.plot('x', 'y')
In [4]:
Copied!
P0['charge']
P0['charge']
Out[4]:
1.0000000000000004e-10
In [5]:
Copied!
# Make Impact object
I = Impact(IMPACT_IN)
# Make Impact object
I = Impact(IMPACT_IN)
In [6]:
Copied!
I.track1()
I.plot('mean_kinetic_energy')
I.track1()
I.plot('mean_kinetic_energy')
In [7]:
Copied!
I.initial_particles = P0
# Change some things
I.header['Nx'] = 32
I.header['Ny'] = 32
I.header['Nz'] = 32
I.header['Dt'] = 1e-13
#I.total_charge = P0['charge']
I.total_charge = 0 # Turn off space charge
# Other switches
I.timeout = 1000
# Change stop location
I.stop = 0.15
# Switches for MPI
I.numprocs=NUMPROCS
I.initial_particles = P0
# Change some things
I.header['Nx'] = 32
I.header['Ny'] = 32
I.header['Nz'] = 32
I.header['Dt'] = 1e-13
#I.total_charge = P0['charge']
I.total_charge = 0 # Turn off space charge
# Other switches
I.timeout = 1000
# Change stop location
I.stop = 0.15
# Switches for MPI
I.numprocs=NUMPROCS
In [8]:
Copied!
%%time
I.run()
print(I)
%%time
I.run()
print(I)
================ Impact-T Summary ================ 10000 particles 1 bunch of electrons total charge: 0.0 pC Distribution type: read Cathode start at z = 0 m emission time: 5.0643085710098247e-11 s image charges neglected after z = 0.02 m Processor domain: 2 x 2 = 4 CPUs Space charge grid: 32 x 32 x 32 Maximum time steps: 1000000 Reference Frequency: 1300000000.0 Hz Initial reference time: -2.5403549006681168e-11 s Simulation starting from the beginning ================================================= Impact-T finished in /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp34kdqbjo CPU times: user 108 ms, sys: 63.4 ms, total: 171 ms Wall time: 12.7 s
Particles¶
In [9]:
Copied!
# Particles are automatically parsed in to openpmd-beamphysics ParticleGroup objects
I.output['particles']
# Particles are automatically parsed in to openpmd-beamphysics ParticleGroup objects
I.output['particles']
Out[9]:
{'initial_particles': <ParticleGroup with 10000 particles at 0x123d435f0>, 'final_particles': <ParticleGroup with 10000 particles at 0x1229c4050>}
In [10]:
Copied!
# Get the final particles, calculate some statistic
P = I.output['particles']['final_particles']
P['mean_energy']
# Get the final particles, calculate some statistic
P = I.output['particles']['final_particles']
P['mean_energy']
Out[10]:
1269508.2687502399
In [11]:
Copied!
# Show the units
P.units('mean_energy')
# Show the units
P.units('mean_energy')
Out[11]:
pmd_unit('eV', 1.602176634e-19, (2, 1, -2, 0, 0, 0, 0))
In [12]:
Copied!
P.plot('z', 'pz')
P.plot('z', 'pz')
Stats¶
In [13]:
Copied!
# Impact's own calculated statistics can be retieved
len(I.stat('norm_emit_x')), I.stat('norm_emit_x')[-1]
# Impact's own calculated statistics can be retieved
len(I.stat('norm_emit_x')), I.stat('norm_emit_x')[-1]
Out[13]:
(1239, 9.6541591e-07)
In [14]:
Copied!
# Stats can also be computed from the particles. For example:
I.particles['final_particles']['norm_emit_x']
# Stats can also be computed from the particles. For example:
I.particles['final_particles']['norm_emit_x']
Out[14]:
9.655238949707681e-07
In [15]:
Copied!
# Compare these.
key1 = 'mean_z'
key2 = 'sigma_x'
units1 = str(I.units(key1))
units2 = str(I.units(key2))
plt.xlabel(key1+f' ({units1})')
plt.ylabel(key2+f' ({units2})')
plt.plot(I.stat(key1), I.stat(key2))
plt.scatter(
[I.particles[name][key1] for name in I.particles],
[I.particles[name][key2] for name in I.particles], color='red')
# Compare these.
key1 = 'mean_z'
key2 = 'sigma_x'
units1 = str(I.units(key1))
units2 = str(I.units(key2))
plt.xlabel(key1+f' ({units1})')
plt.ylabel(key2+f' ({units2})')
plt.plot(I.stat(key1), I.stat(key2))
plt.scatter(
[I.particles[name][key1] for name in I.particles],
[I.particles[name][key2] for name in I.particles], color='red')
Out[15]:
<matplotlib.collections.PathCollection at 0x123ac27b0>