Warwick-Plasma/epoch

Retrieving particle data information

dmargarone opened this issue · 2 comments

Dear @Status-Mirror,
I have one more question. Suppose I have an electron beam launched in the simulation as shown in the tutorial (https://epochpic.github.io/quickstart/basic_examples/injectors.html#particle-bunch-injection).

Now, assuming that I am using Matlab for data plotting and the simulation is in 3D, how I can access the momentum of the electron beam, position of the electron beam and its weight ?

Do you think that the below method is correct:
q = GetDataSDF(filename);
Px = q.Particles.Px.electron_beam.data;
Py = q.Particles.Py.electron_beam.data;
Pz = q.Particles.Pz.electron_beam.data;
Wb = q.Particles.Weight.electron_beam.data;

How to retrieve beam particle position ?
and can I get the total beam charge by summing the weight and multiplying it by "e (electronic charge = 1.6e-19)"

Thank you.
DM

Hey DM,

Provided the name of your species is electron_beam, then this should be okay. You can get all your requested variables using:

q = GetDataSDF(filename);
Px = q.Particles.Px.electron_beam.data;
Py = q.Particles.Py.electron_beam.data;
Pz = q.Particles.Pz.electron_beam.data;
x = q.Grid.Particles.electron_beam.x;
y = q.Grid.Particles.electron_beam.y;
z = q.Grid.Particles.electron_beam.z;
Wb = q.Particles.Weight.electron.data;
beam_charge = -1.6e-19 * sum(Wb);

Since your simulation is in 3D, the beam_charge variable is the true beam charge. If you were running a 1D or 2D code, you need to remember that EPOCH assumes the length of a cell in a missing dimension is 1m, and you would need to scale your values down accordingly.

If you output a particle variable, I think the positions are output automatically. For example, I can get all these variables (except $z$) using an adapted form of the 2D basic target demo deck.

begin:control
    nx = 500
    ny = 500
    t_end = 1.0e-15
    x_min = 0
    x_max = 25e-6
    y_min = 0
    y_max = 25e-6
    stdout_frequency = 100
    npart = 50 * (5.0e-6/(x_max-x_min)) * nx * ny
end:control

begin:boundaries
    bc_x_min = open
    bc_x_max = open
    bc_y_min = open
    bc_y_max = open
end:boundaries

begin:species
    name = Electron
    mass = 1.0
    charge = -1.0
    frac = 0.8
    density = if (x gt 15.0e-6, 1.0e24, density(Electron))
    density = if (x gt 20.0e-6, 0, density(Electron))
    temp_ev = 1000
end:species

begin:species
    name = Carbon
    mass = 22033.0
    charge = 6.0
    frac = 0.2
    density = density(Electron) / 6
    temp_ev = 1000
end:species

begin:output
    dt_snapshot = t_end
    px = always
    py = always
    pz = always
    weight = always
end:output

Hope this helps,
Stuart

Dear @Status-Mirror thanks for your great help.

DM