Skip to content

Commit

Permalink
Merge pull request #56 from ColwynGulliford/fix_write_gpt_species_ass…
Browse files Browse the repository at this point in the history
…ertion

Fixed writing particle data to gpt format, tested with tracking
  • Loading branch information
ChristopherMayes committed Mar 26, 2024
2 parents 571f7e3 + 6e31ee5 commit 670f9ac
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pmd_beamphysics/interfaces/gpt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pmd_beamphysics.units import e_charge
from pmd_beamphysics.units import e_charge, c_light
from pmd_beamphysics.interfaces.superfish import fish_complex_to_real_fields

import numpy as np
Expand All @@ -16,19 +16,16 @@ def write_gpt(particle_group,
asci2gdf -o particles.gdf particles.txt
This routine makes ASCII particles, with column labels:
'x', 'y', 'z', 'GBx', 'GBy', 'GBz', 't', 'q', 'nmacro'
'x', 'y', 'z', 'GBx', 'GBy', 'GBz', 't', 'q', 'm', 'nmacro'
in SI units.
For now, only electrons are supported.
"""

assert particle_group.species == 'electron' # TODO: add more species

assert np.all(particle_group.weight >= 0), 'ParticleGroup.weight must be >= 0'

q = -e_charge

q = particle_group.species_charge
mc2 = particle_group.mass # returns pmd_beamphysics.species.mass_of(particle_group.species) [eV]
m = mc2 * (e_charge / c_light**2)
n = particle_group.n_particle
gamma = particle_group.gamma

Expand All @@ -41,14 +38,14 @@ def write_gpt(particle_group,
'GBz': gamma*particle_group.beta_z,
't': particle_group.t,
'q': np.full(n, q),
'nmacro': particle_group.weight/e_charge}
'm': np.full(n, m),
'nmacro': np.abs(particle_group.weight/q)}

if hasattr(particle_group, 'id'):
dat['ID'] = particle_group.id
else:
dat['ID'] = np.arange(1, particle_group['n_particle']+1)


header = ' '.join(list(dat))

outdat = np.array([dat[k] for k in dat]).T
Expand Down

0 comments on commit 670f9ac

Please sign in to comment.