-
Notifications
You must be signed in to change notification settings - Fork 4
Bunch Simulator
Sajid Ali edited this page Oct 19, 2022
·
1 revision
In order to propagate the generated bunch through a lattice, we need to do a little
extra work -- creating a Bunch_simulator
object. A Bunch_simulator
is the container
for holding one or multiple bunches that will be sent to the lattice for propagation.
It is also the object for registering diagnostics actions with the bunches.
A Bunch_simulator
can be created from an existing bunch. It is however more
convenient and optimal to create a Bunch_simulator
with bunches in it. For the reason
that when running simulations with multiple bunches on multiple MPI processes the
built-in construct()
method will do the decomposition and distribute bunches across
all processes in an optimal way.
# reference particle, number of macro particles, and number of real particles
reference_particle = synergia.foundation.Reference_particle(charge, mass, energy)
macroparticles = 1024
realparticles = 1e13
# create the Bunch_simulator
simulator = synergia.simulation.Bunch_simulator.create_single_bunch_simulator(
reference_particle, macroparticles, realparticles)
# the bunch object can be access from the simulator for further operations
bunch = simulator.get_bunch()
# or to create a Bunch_simulator with a bunch train
simulator = synergia.simulation.Bunch_simulator.create_bunch_train_simulator(
reference_particle, macroparticles, realparticles,
num_bunches, spacing)
# access the bunch object from the simulator
bunch = simulator.get_bunch(train=0, bunch=1)
# not all bunches are present on the local MPI rank, so you should check
# if the bunch is available before accessing it
simulator.has_local_bunch(train=0, bunch=1)