Initializing PICMI real component #4416
-
Hi, I'd like to add a real component to a particle species. However, trying to access this component causes WarpX to segfault. Here's an example: # Define my particle container and the component
elec_wrapper = particle_containers.ParticleContainerWrapper('electrons')
elec_wrapper.add_real_comp('my_comp')
# Trying to initialize this component to zero at the first timestep
def initialize_comp():
x = elec_wrapper.get_particle_arrays('my_comp')
for xi in x:
xi[:] = 0.0
# Install callback
callbacks.installafterinit(initialize_comp) What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi Thomas. The reason you are encountering a segfault is because the particle containers are not initialized yet when you query WarpX for it via Please let us know if you have further questions. |
Beta Was this translation helpful? Give feedback.
-
Yep, that was it. Thank you! |
Beta Was this translation helpful? Give feedback.
Hi Thomas. The reason you are encountering a segfault is because the particle containers are not initialized yet when you query WarpX for it via
elec_wrapper = particle_containers.ParticleContainerWrapper('electrons')
. This call needs to happen after WarpX has been initialized throughsimulation.initialize_warpx()
.Take a look at the example at https://github.com/ECP-WarpX/WarpX/blob/development/Examples/Tests/particle_data_python/PICMI_inputs_2d.py for how this can be achieved.
Please let us know if you have further questions.