ECP-WarpX / WarpX

WarpX is an advanced, time-based electromagnetic & electrostatic Particle-In-Cell code.
https://ecp-warpx.github.io
Other
276 stars 176 forks source link

plot applied field #4950

Open rl3418 opened 1 month ago

rl3418 commented 1 month ago

According to the manual, the external fields applied to the grid can be seen in the diagnostics that output the fields on the grid. I performed a boosted frame simulation with sinusoidal B fields in the lab frame.

I tried to plot the B fields in the boosted frame using diag1.diag_type = Full diag1.fields_to_plot = Bx By Bz

The boost was along z, so I was expecting the field to be proportional to cos(gamma_f*k_u*(z+beta_f*t*clight)). This doesn't seem to be consistent. What diagnostic should I use to plot the applied field.

Here is a lineout of the field and the input I used

By lineout

test_3d.txt

rl3418 commented 1 month ago

I am do a 3d boosted frame simulation of an electron beam travelling through a 3d undulator field. The boost is along the z direction and this is the field I used

#boost along z
warpx.gamma_boost = gamma_f
warpx.boost_direction = z
#field in lab frame
warpx.B_ext_grid_init_style = parse_B_ext_grid_function
warpx.Bx_external_grid_function(x,y,z) = if((z>(0.0)),if(z<2.15,-(k_x/k_y)\*sin(k_x\*x)*sinh(k_y\*y)*cos(k_u\*z),0.0),0.0)
warpx.By_external_grid_function(x,y,z) = if((z>(0.0)),if(z<2.15,B_0*cos(k_x\*x)\*cosh(k_y\*y)\*cos(k_u\*z),0.0),0.0)
warpx.Bz_external_grid_function(x,y,z) = if((z>(0.0)),if(z<2.15,-(k_u/k_y)\*B_0\*cos(k_x\*x)*sinh(k_y\*y)*sin(k_u\*z),0.0),0.0)
warpx.E_ext_grid_init_style = parse_E_ext_grid_function
warpx.Ex_external_grid_function(x,y,z) = 0
warpx.Ey_external_grid_function(x,y,z) = 0
warpx.Ez_external_grid_function(x,y,z) = 0

Below is a comparision between the z phase space predicted by the osiris simulation and the Warpx simulation

osiris osiris z pz warpx warpx z pz

The external field should sinusoidally modulate the z phase space. This is seen in the osiris code. Seems that the field is not applied properly in the WarpX code. Is there additional parameter that I need to specify?

rl3418 commented 1 month ago

external_particle_function seems to work. I guess external_grid_function doesn't include any time dependence. It doesn't know how to handle the time dependence after Lorentz transformation.

rl3418 commented 1 month ago
.zinject_plane only have spatial dependence as well. Does it transform properly when warpx.gamma_boost is set?
RemiLehe commented 1 month ago

@rl3418 Thanks for your questions, and sorry for the late reply!

You had a number of different questions, so here are a few corresponding answers:

Please let us know if anything is unclear. Also, feel free to post an updated version of your script that takes into account the above points, if you would like us to take another look.

rl3418 commented 1 month ago

Thanks for the clarification. I was doing the transformation manually just to diagnose the problems. The BackTransformation diagnostics was not working properly, so I tried to do the transformation myself. I need to run more simulations to figure out what is the underlying problem.

I found a typo in my script. The preliminary simulation showed some agreement with the osiris results. This was performed without the injection plane, since it is not possibility to have the zinject_plane change with time. I will run more simulations with the zinject_plane using the WarpX transformation then.

rl3418 commented 1 month ago

I performed 3d simulations of an electron beam travelling through an undulator in the boosted frame. The warpx simulation and the osiris simulation showed similar behaviour. The beam evolution in the zpz phase space seems to match, but warpx results showed splitting which seems numerical. z is the beam propagation and the boost direction.

The plots here show the phase space distribution in the boosted frame just before the beam fully enters the undulator. The red vertical line marks the boundary of the undulator field in the boosted frame. pz shows sinusoidal modulation as expected due to the z dependence of the undulator field. However, warpx results showed splitting which seems numerical.

warpx

warpx

osiris osiris

comparision

overlayed

rl3418 commented 1 month ago

0 40ps This is the z pz plot at a later time in the boosted frame

rl3418 commented 1 month ago

One could argue that this is due to microbunching. But it forms very rapidly and this is not observed in osiris.

warpx possible_bunching

osiris osiris boost