Using a callback to modify particle properties #4402
-
Hi, I'm trying to learn about the capabilities of the Python callbacks. I'm trying to use a callback to modify particle properties. As a simple example, say I wanted to set the electron z-momentum to zero each iteration. What I would do is: # Initialize simulation
sim.initialize_inputs()
sim.initialize_warpx()
elec_wrapper = particle_containers.ParticleContainerWrapper('electrons')
def adjust_velocity():
nps = elec_wrapper.nps
uz = elec_wrapper.get_particle_uz()
uz[:] = np.zeros(len(uz))
callbacks.installbeforestep(adjust_velocity)
# Run simulation for one step
sim.step(1) However, this doesn't seem to work. Is there a correct way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In WarpX, the particles are divided up into the same blocks that the fields are divided up into. Because of this, there is not a single array holding that particle quantities, but many arrays. The thing that is returned by
|
Beta Was this translation helpful? Give feedback.
In WarpX, the particles are divided up into the same blocks that the fields are divided up into. Because of this, there is not a single array holding that particle quantities, but many arrays. The thing that is returned by
elec_wrapper.get_particle_uz()
is a list of those arrays. To set the z velocity, you would need a loop like this, looping over the list of arrays