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

FEL simulation in the boosted frame #4861

Open rl3418 opened 5 months ago

rl3418 commented 5 months ago

I'm trying to do a 1D simulation of an gamma=200 beam travelling through an undulator. I transformed everything to a frame with gamma_f=50 an performed a simulation in that frame. The results I obtained from WarpX is very different compared to OSIRIS. I have attached to input file I used and a comparison of the density evolution in the boosted frame.

density_boost_frame_200_short 200_50.txt

jlvay commented 4 months ago

Hi. You seem to be doing the Lorentz Transform of the undulator field by hand, which is not needed I think with WarpX. Let me check tomorrow with the team.

RemiLehe commented 4 months ago

@rl3418 Thanks for raising this issue. Do you understand what is causing the sharp modulations in the Osiris simulations (which are not seen in WarpX)? Are these physical? One might think that these modulations correspond to FEL microbunching, but their shape (sharp spikes instead of a sinusoidal modulation, at early times) do not seem consistent with what is usually observed for micro-bunching. Or is there something I am missing?

Also: I tried to quickly estimate the expected microbunching wavelength. My understanding is that the undulator B field has a 1 T oscillation amplitude. From this, I found that, for your particular parameters, the K parameter is 0.93, and the corresponding expected radiation wavelength in the lab-frame ( $\lambda_u/(2\gamma_0^2)(1+K^2/2)$ ) is 0.18 microns. The corresponding radiation wavelength in the boosted-frame is 1.8e-5 m. Does this calculation seem correct?

This seems roughly consistent with the wavelength of the small-amplitude density modulation seen in the orange curve. So my impression is that that the WarpX simulation starts to show (sinusoidal) microbunching. But again, I am not sure what the sharper, shorter-wavelength modulations in the Osiris simulations correspond to, physically. Does this make sense?

jlvay commented 4 months ago

Hi. I see that you are actually doing the Lorentz Transform of all quantities by hand rather than relying on WarpX doing this automatically for you, which is the preferred way. This can be done by setting: warpx.gamma_boost = my_constants.gamma_f warpx.boost_direction = 'z'

and setting every quantity, e.g., beam density, length and velocity, and the undulator field, in the lab frame, then use back-transformed diagnostics (see https://warpx.readthedocs.io/en/latest/usage/parameters.html#backtransformed-diagnostics) to get the data back-transformed automatically from the boosted frame of simulation to the lab frame.

You can also read more about how boosted frame simulations work under the hood from the theory section: https://warpx.readthedocs.io/en/latest/theory/boosted_frame.html#

Let us know if you have questions about that.

rl3418 commented 4 months ago

Thanks for the reply, I'll try the warpx.gamma_boost parameter then.

I think your calculation is correct. The radiation wavelength is about 1.8e-5 m. I'm just trying to do a scan to see if the FEL gain length from the boosted frame simulations agree with the theoretical prediction.

The modulation in the Osiris simulations does seem a bit unphysical, which is why I moved to the WarpX in the first place. I originally thought that the beam is just reaching the saturation level very fast.

rl3418 commented 4 months ago

Does dt and dx transform to dt'=dt*gamma*(1+beta) and dz'=dz*gamma*(1+beta) when the warpx.gamma_boost parameter is specified? Also, does warpx transform the .zinject_plane automatically as well?

rl3418 commented 4 months ago

Seems like the time step is taken to be warpx.const_dt. Is this supposed to specified in the boosted frame?

ax3l commented 4 months ago

Does dt and dx transform to dt'=dtgamma(1+beta) and dz'=dzgamma(1+beta) when the warpx.gamma_boost parameter is specified? Also, does warpx transform the .zinject_plane automatically as well?

Yes, correct. We transform all input parameters from lab to boosted frame automatically, to make WarpX easy to use in the boosted frame.

Seems like the time step is taken to be warpx.const_dt. Is this supposed to specified in the boosted frame?

I would suggest to use the CFL option warpx.cfl and the resolution amr.n_cell to set the time step automatically from the spatial resolution. (Note that for FDTD stencils and standard PSATD, you want to use a CFL close to, but smaller than, 1, e.g., the default we set is 0.999 and 0.9999 is a good choice, too.)