Decapole - Comparing to Bmad¶
In [1]:
Copied!
import numpy as np
from pmd_beamphysics import single_particle
from pmd_beamphysics.units import mec2
from pytao import Tao
import impact.z as IZ
from impact.tests.z.conftest import bmad_files
from impact.z.interfaces.bmad import plot_impactz_and_tao_stats, track_tao
import numpy as np
from pmd_beamphysics import single_particle
from pmd_beamphysics.units import mec2
from pytao import Tao
import impact.z as IZ
from impact.tests.z.conftest import bmad_files
from impact.z.interfaces.bmad import plot_impactz_and_tao_stats, track_tao
Initial Particles¶
In [2]:
Copied!
reference_particle_mass = mec2
energy = 10e6
pz = np.sqrt(energy**2 - mec2**2)
P0 = single_particle(x=1e-3, pz=pz)
reference_particle_mass = mec2
energy = 10e6
pz = np.sqrt(energy**2 - mec2**2)
P0 = single_particle(x=1e-3, pz=pz)
In [3]:
Copied!
!cat $bmad_files/decapole.bmad
!cat $bmad_files/decapole.bmad
! Lattice file adapted from simple.bmad no_digested beginning[beta_a] = 10. ! m a-mode beta function beginning[beta_b] = 10. ! m b-mode beta function beginning[e_tot] = 10e6 ! eV Or can set beginning[p0c] parameter[geometry] = open ! Or closed parameter[particle] = electron ! Reference particle. dec1: thick_multipole, L = .1, scale_multipoles = F, b4= 1e9, num_steps = 10 lat: line = (dec1) use, lat
Tao¶
In [4]:
Copied!
tao = Tao(lattice_file=bmad_files / "decapole.bmad", plot="mpl")
tao.plot("beta")
tao = Tao(lattice_file=bmad_files / "decapole.bmad", plot="mpl")
tao.plot("beta")
In [5]:
Copied!
Ptao = track_tao(tao, P0)
Ptao = track_tao(tao, P0)
In [6]:
Copied!
## Impact-Z
## Impact-Z
In [7]:
Copied!
I = IZ.ImpactZ.from_tao(tao, initial_particles=P0)
I = IZ.ImpactZ.from_tao(tao, initial_particles=P0)
In [8]:
Copied!
I.input
I.input
Out[8]:
ImpactZInput(
    initial_particles=<ParticleGroup with 1 particles at 0x7f3ea546a900>,
    seed=-1,
    n_particle=1,
    nx=64,
    ny=64,
    nz=64,
    distribution=IZ.DistributionType.read,
    particle_list=[1],
    charge_over_mass_list=[-1.956951180916719e-06],
    twiss_beta_x=10.0,
    twiss_beta_y=10.0,
    average_current=0.0,
    reference_kinetic_energy=9489001.04931,
    reference_particle_mass=510998.95069,
    reference_particle_charge=-1.0,
    reference_frequency=1300000000.0,
    lattice=[
        ToggleSpaceCharge(),
        WriteFull(name='initial_particles', file_id=100),
        IntegratorTypeSwitch(metadata={'bmad_id': 1}, integrator_type=IZ.IntegratorType.runge_kutta),
        Multipole(
            name='DEC1',
            metadata={'bmad_csr': False, 'bmad_sc': False, 'bmad_id': 1},
            length=0.1,
            steps=10,
            map_steps=10,
            multipole_type=IZ.MultipoleType.decapole,
            field_strength=-7995079424.864135,
            file_id=-1.0,
            radius=0.03
        ),
        IntegratorTypeSwitch(metadata={'bmad_id': 1}),
        WriteFull(name='WRITE_END', metadata={'bmad_id': 2}, file_id=200),
        WriteFull(name='final_particles', file_id=101)
    ]
)
Including defaults
ImpactZInput(
    initial_particles=<ParticleGroup with 1 particles at 0x7f3ea546a900>,
    ncpu_y=1,
    ncpu_z=1,
    gpu=IZ.GPUFlag.disabled,
    seed=-1,
    n_particle=1,
    integrator_type=IZ.IntegratorType.linear_map,
    err=1,
    diagnostic_type=IZ.DiagnosticType.extended,
    nx=64,
    ny=64,
    nz=64,
    boundary_type=IZ.BoundaryType.trans_open_longi_open,
    radius_x=0.0,
    radius_y=0.0,
    z_period_size=0.0,
    distribution=IZ.DistributionType.read,
    restart=0,
    subcycle=0,
    nbunch=1,
    particle_list=[1],
    current_list=[0.0],
    charge_over_mass_list=[-1.956951180916719e-06],
    twiss_alpha_x=0.0,
    twiss_beta_x=10.0,
    twiss_norm_emit_x=1e-06,
    twiss_mismatch_x=1.0,
    twiss_mismatch_px=1.0,
    twiss_offset_x=0.0,
    twiss_offset_px=0.0,
    twiss_alpha_y=0.0,
    twiss_beta_y=10.0,
    twiss_norm_emit_y=1e-06,
    twiss_mismatch_y=1.0,
    twiss_mismatch_py=1.0,
    twiss_offset_y=0.0,
    twiss_offset_py=0.0,
    twiss_alpha_z=1e-09,
    twiss_beta_z=1.0,
    twiss_norm_emit_z=1e-06,
    twiss_mismatch_z=1.0,
    twiss_mismatch_e_z=1.0,
    twiss_offset_phase_z=0.0,
    twiss_offset_energy_z=0.0,
    average_current=0.0,
    reference_kinetic_energy=9489001.04931,
    reference_particle_mass=510998.95069,
    reference_particle_charge=-1.0,
    reference_frequency=1300000000.0,
    initial_phase_ref=0.0,
    lattice=[
        ToggleSpaceCharge(
            name='',
            metadata={},
            length=0.0,
            steps=0,
            map_steps=0,
            type_id=-14,
            unused=0.0,
            enable=False
        ),
        WriteFull(
            name='initial_particles',
            metadata={},
            length=0.0,
            steps=0,
            file_id=100,
            type_id=-2,
            unused_2=0.0,
            sample_frequency=0
        ),
        IntegratorTypeSwitch(
            name='',
            metadata={'bmad_id': 1},
            length=0.0,
            steps=0,
            integrator_type=IZ.IntegratorType.runge_kutta,
            type_id=-25,
            unused=0.0
        ),
        Multipole(
            name='DEC1',
            metadata={'bmad_csr': False, 'bmad_sc': False, 'bmad_id': 1},
            length=0.1,
            steps=10,
            map_steps=10,
            type_id=5,
            multipole_type=IZ.MultipoleType.decapole,
            field_strength=-7995079424.864135,
            file_id=-1.0,
            radius=0.03,
            misalignment_error_x=0.0,
            misalignment_error_y=0.0,
            rotation_error_x=0.0,
            rotation_error_y=0.0,
            rotation_error_z=-0.0
        ),
        IntegratorTypeSwitch(
            name='',
            metadata={'bmad_id': 1},
            length=0.0,
            steps=0,
            integrator_type=IZ.IntegratorType.linear_map,
            type_id=-25,
            unused=0.0
        ),
        WriteFull(
            name='WRITE_END',
            metadata={'bmad_id': 2},
            length=0.0,
            steps=0,
            file_id=200,
            type_id=-2,
            unused_2=0.0,
            sample_frequency=0
        ),
        WriteFull(
            name='final_particles',
            metadata={},
            length=0.0,
            steps=0,
            file_id=101,
            type_id=-2,
            unused_2=0.0,
            sample_frequency=0
        )
    ],
    filename=None,
    verbose=False
)
In [9]:
Copied!
I.input.multipoles
I.input.multipoles
Out[9]:
[Multipole(
     name='DEC1',
     metadata={'bmad_csr': False, 'bmad_sc': False, 'bmad_id': 1},
     length=0.1,
     steps=10,
     map_steps=10,
     type_id=5,
     multipole_type=IZ.MultipoleType.decapole,
     field_strength=-7995079424.864135,
     file_id=-1.0,
     radius=0.03,
     misalignment_error_x=0.0,
     misalignment_error_y=0.0,
     rotation_error_x=0.0,
     rotation_error_y=0.0,
     rotation_error_z=-0.0
 )]
In [10]:
Copied!
output = I.run()
output = I.run()
In [11]:
Copied!
P = I.output.particles["final_particles"]
P = I.output.particles["final_particles"]
Compare¶
In [12]:
Copied!
plot_impactz_and_tao_stats(I, tao)
plot_impactz_and_tao_stats(I, tao)
In [13]:
Copied!
Ptao.data
Ptao.data
Out[13]:
{'x': array([0.0009516]),
 'px': array([-9361.99994092]),
 'y': array([0.]),
 'py': array([0.]),
 'z': array([0]),
 'pz': array([9986931.08143592]),
 't': array([3.34000503e-10]),
 'status': array([1], dtype=int32),
 'weight': array([1.]),
 'species': np.str_('electron')}
In [14]:
Copied!
P.data
P.data
Out[14]:
{'x': array([0.00095158]),
 'px': array([-9367.62396914]),
 'y': array([0.]),
 'py': array([0.]),
 'z': array([0.]),
 'pz': array([9986931.07616223]),
 't': array([3.34000503e-10]),
 'status': array([1.]),
 'weight': array([1.e-20]),
 'id': array([1]),
 'species': np.str_('electron')}