Retrieving particle data

Retrieving Distribution Data in Interpreter

It is easy to retrieving information about the particle distribution(s) in the interpreter for use in diagnostics, to save in external files, etc. Say you defined a species via:

selectrons = Species(type=Electron,name='e-')

then information on macroparticles defining the species selectrons can be obtained by running

n = selectrons.getn() # selectron macro-particle number

x = selectrons.getx() # selectron macro-particle x-coordinates

y = selectrons.gety() # selectron macro-particle y-coordinates

z = selectrons.getz() # selectron macro-particle x-coordinates

pid = selectrons.getpid() # selectron macro-particle id's used in Warp arrays

Additional "get" scripts available that are applied analogously include:

    • position: getx(), gety(), getz()

    • velocites: getvx(), getvy(), getvz()

    • momentum/mass: getux(), getuv(), getuz()

    • tranverse angles (x-velocity/z-velocity etc): getxp(), getyp()

    • gamma inverse: getgaminv()

    • particle identification number: getpid()

    • x-x' and y-y' statistical slopes of the distribution: getxxpslope(), getyypslop()

Saving to an External File

Data can be saved to external files using methods described in the How To Saving/Retrieving Data. Here we cover further examples in the context of particle distribution data. To save data to external file the following model can be used

myfile = open("tmp.tmp","w")

for i in range(n):

value = i,x[i],y[i],z[i],pid[i]

myfile.write(str(value))

myfile.write("\n")

myfile.close()

Or if you want to order the data by PID:

all = sorted(zip(pid,x,y,z))

and then in the for loop something like:

myfile.write(' '.join(map(str, all[i]))

Saving data at a fixed z-position

Warp has a way tp collecting particles at a given z location. You can use the ZCrossingParticles class. For example,

from extpart import ZCrossingParticles

targetz_particles = ZCrossingParticles(zz=targetz,laccumulate=1)

During the run, this will save all particles as they cross targetz. Then after the simulation, you can do

x = targetz_particles.getx()

And write out x etc. to a file.