particle module

Define Particle, created by reading CST ParticleMonitor files.

class Particle(raw_line)[source]

Bases: object

Holds evolution of position and adim momentum with time.

Position in \(\mathrm{mm}\), time in \(\mathrm{ns}\).

position

Position of the particle during the simulation.

momentum

Momentum of the particle during the simulation.

_masses

Mass of particle at each time step. An error is raised if it changes between two files.

mass

Mass of the particle in \(\mathrm{kg}\).

mass_eV

Mass of the particle in \(\mathrm{eV}\).

_charges

Charge of particle at each time step. An error is raised if it changes between two files.

charge

Charge of the particle.

time

Holds the time steps in \(\mathrm{ns}\) corresponding to every value of pos, mom, etc.

particle_id

Unique id for the particle.

source_id

Gives information on how the particle was created.

extrapolated_times

Times at which position and momentum are extrapolated.

Parameters:

raw_line (tuple[str, str, str, str, str, str, str, str, str, str, str, str])

__init__(raw_line)[source]

Init from a line of a position_monitor file.

Parameters:

raw_line (tuple[str, str, str, str, str, str, str, str, str, str, str, str])

add_a_file(raw_line)[source]

Add a time-step/a file to the current Particle.

Parameters:

raw_line (tuple[str, str, str, str, str, str, str, str, str, str, str, str])

Return type:

None

finalize()[source]

Post treat object for consistency checks, better data types.

Return type:

None

_check_constanteness_of_some_attributes()[source]

Ensure that mass and charge did not evolve during simulation.

Return type:

None

property macro_charge: ndarray[tuple[int, ...], dtype[float64]]

Return macro charge as an array.

_switch_to_mm_ns_units()[source]

Change the system units to limit rounding errors. :rtype: None

Warning

In CST Particle Monitor files, the time is given in seconds * 1e-18 (aka nano-nanoseconds). Tested with CST units for time in nanoseconds.

_sort_by_increasing_time_values()[source]

Sort arrays by increasing time values.

Return type:

None

property emission_energy: float

Compute emission energy in \(\mathrm{eV}\).

property collision_energy: float

Determine the impact energy in \(\mathrm{eV}\).

Returns:

energy – The last known energy in \(\mathrm{eV}\).

Return type:

float

extrapolate_pos_and_mom_one_time_step_further()[source]

Extrapolate position and momentum by one time step.

CST PIC solves the motion with a leapfrog solver (source: Mohamad Houssini from Keonys, private communication). Several possibilities: - pos corresponds to time and mom shifted by half time-steps (most probable). - mom corresponds to time and pos shifted by half time-steps (also possible). - pos or mom is interpolated so that both are expressed at full time steps (what I will consider for now).

Return type:

None

determine_if_alive_at_end(max_time, tol=1e-06)[source]

Determine if the particle collisioned before end of simulation.

This method sets alive_at_end flag.

Parameters:
  • max_time (float) – Simulation end time in \(\mathrm{ns}\).

  • tol (float, default: 1e-06) – Tolerance in \(\mathrm{ns}\).

Return type:

None

find_collision(mesh, warn_no_collision=True, warn_multiple_collisions=False, **kwargs)[source]

Find where the trajectory impacts the structure.

If the particle is alive at the end of the simulation, we do not even try. If it has only one known time step, neither do we.

We first try to detect a collision between the last known position of the particle and the last extrapolated position. If no collision is found, we try to find it between the last known position and the know position just before that.

Note

If the last extrapolated position is too far from the last known position, several collisions may be detected.

Todo

Take only nearest cell instead of the one with the lowest ID as for now.

Parameters:
  • mesh (Mesh) – vedo mesh object describing the structure of the rf system.

  • warn_no_collision (bool, default: True) – If True, a warning is raised when the electron was not alive at the end of the simulation, but no collision was detected. The default is True.

  • warn_multiple_collisions (bool, default: False) – To warn if several collisions were detected for the same particle. Also remove all collisions but the first one. The default is True.

  • kwargs – kwargs

Return type:

None

compute_emission_angle(mesh)[source]

Compute the angle of emission.

Parameters:

mesh (Mesh)

Return type:

None

compute_collision_angle(mesh)[source]

Compute the angle of impact.

Parameters:

mesh (Mesh)

Return type:

None

plot_trajectory(plotter, emission_color=None, collision_color=None, lw=7, r=8, **kwargs)[source]

Plot the trajectory of the particle in 3D.

Parameters:
  • plotter (Plotter) – Objet realizing the plots.

  • emission_color (str | None, default: None) – If provided, the first known position is colored with this color.

  • collision_color (str | None, default: None) – If provided, the last known position is colored with this color.

  • collision_point – If provided and collision_color is not None, we plot this point instead of the last of points. This is useful when the extrapolated time is large, and actuel collision point may differ significantly from last position points.

  • lw (int, default: 7) – Trajectory line width.

  • r (int, default: 8) – Size of the emission/collision points.

Return type:

Any

_str_to_correct_types(line)[source]

Convert the input line of strings to proper data types.

Parameters:

line (tuple[str, str, str, str, str, str, str, str, str, str, str, str])

Return type:

tuple[float, float, float, float, float, float, float, float, float, float, int, int]

_get_constant(variables)[source]

Check that the list of floats is a constant, return constant.

Parameters:

variables (list[float])

Return type:

float

_is_sorted(array)[source]

Check that given array is ordered (increasing values).

Parameters:

array (ndarray)

Return type:

bool