ECP-WarpX / WarpX

WarpX is an advanced electromagnetic & electrostatic Particle-In-Cell code.
https://ecp-warpx.github.io
Other
291 stars 185 forks source link

User-defined runtime attributes are not initialized in multi-physics modules #4483

Open RemiLehe opened 9 months ago

RemiLehe commented 9 months ago

In WarpX, the user can define runtime attribute on the particles, that are then tracked during the simulation. (See addRealAttributes in the WarpX documentation ; a typical example is tracking the x/y/z position at which a particle was created.)

However, these runtime attribute are only correctly set when particles are created via the functions AddNParticles, AddPlasma or AddPlasmaFlux (see https://github.com/ECP-WarpX/WarpX/pull/3272). This happens when we initialize particles through our various initialization/injection methods, but not when creating particles via multi-physics modules. In particular:

RemiLehe commented 9 months ago

Here is an input script that demonstrates the issue: the quantity origZ is (incorrectly) 0 for all electrons: inputs_2d.txt

ax3l commented 9 months ago

Thanks for the report, analysis and reproducer! attn @atmyers @RevathiJambunathan @hklion - can you help? :)

RemiLehe commented 9 months ago

I think that the solution would be to call the function DefaultInitializeRuntimeAttributes in the different multi-physics modules (and in particular inside filterCopyTransformParticles and filterCreateTransformFromFAB). However, in order to do so, the function DefaultInitializeRuntimeAttributes would need to be generalized. In particular:

Note that, if DefaultInitializeRuntimeAttributes is generalized in this way, we can then also use it to simplify the code in AddPlasma and AddPlasmaFlux.