ECP-WarpX / WarpX

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

Possible bug. An issue produced by WarpX compiled with `WarpX_EB=ON`. #3468

Open jcyu96 opened 1 year ago

jcyu96 commented 1 year ago

Hi developers, When I add the external fields to a simulation (like below), everything works fine.

warpx.B_ext_grid_init_style = parse_B_ext_grid_function
warpx.Bx_external_grid_function(x,y,z) = if(sqrt((x-r0)**2+z**2)<200.e-6,
                 -1*(10.)*z*(r0/(r0+sqrt((x-r0)**2+z**2)))/sqrt((x-r0)**2+z**2), 0)
warpx.By_external_grid_function(x,y,z) = 0
warpx.Bz_external_grid_function(x,y,z) = if(sqrt((x-r0)**2+z**2)<200.e-6,
                 (10.)*(x-r0)*(r0/(r0+sqrt((x-r0)**2+z**2)))/sqrt((x-r0)**2+z**2), 0)

image image

But when I insert embedded boundary like the following:

warpx.eb_implicit_function = "-((x-250.e-6)**2+z**2-(50.e-6)**2)"

After that I re-compiled WarpX by switching on WarpX_EB=ON and ran the simulation again, the magnetic fields Bx and Bz stayed unchanged throughout the entire process and could not propagate properly like above. This is not physically correct, but I don't know where the problem is in the code? Can anyone help me to solve this issue? Thank you very much!

RemiLehe commented 1 year ago

Thanks for reporting this issue! Would you be willing to post your full input script (or a modified version thereof), so that we can try to reproduce this problem locally? Thanks!

jcyu96 commented 1 year ago

Hi @RemiLehe, here is my input file. inputs_2d.txt

WeiqunZhang commented 1 year ago

I am not sure I understand the issue. EB means embedded boundary that has nothing to do the electric or magnetic fields. The eb_implicit_function specifies the surface of a solid object, not electric/magnetic fields.

WeiqunZhang commented 1 year ago

More information on EB. https://amrex-codes.github.io/amrex/docs_html/EB_Chapter.html

jcyu96 commented 1 year ago

I am not sure I understand the issue. EB means embedded boundary that has nothing to do the electric or magnetic fields. The eb_implicit_function specifies the surface of a solid object, not electric/magnetic fields.

As you said, embedded boundary should not have anything to do with EM field. Actually, if I run a simulation using WarpX compiled with WarpX_EB=ON, the EM field will stay unchanged (obviously not right). If I run a simulation with WarpX compiled with WarpX_EB=OFF, the EM field will perform normally, so I guess the embedded boundary code makes the EM solver unable to work properly.

RemiLehe commented 1 year ago

@jcyu96 I just had a closer look at your script ; I think there is indeed a bug in WarpX, in how we treat embedded boundaries in 2D Cartesian geometry. This PR should in principle fix it: https://github.com/ECP-WarpX/WarpX/pull/2942. We'll try to merge this soon.

RemiLehe commented 1 year ago

@jcyu96

2942 was just merged in the code. Could you try to download the latest version of the source code (e.g. git pull) and recompile, and check that this fixes the issue that you were observing?

Thanks again for reporting this issue.

jcyu96 commented 1 year ago

Thank you so much @RemiLehe, I tested it with the latest version and embedded boundary still has an effect on the magnetic field evolution, as shown in the below:

with WarpX_EB=OFF image

with WarpX_EB=ON image

The two cases above should be the same in theory. The latest version of WarpX fixed the issue that the magnetic field could not evolve. But from my test results, there is still the issue that the magnetic field of two cases (whether to add embedded boundary) evolve differently. Here's my input. inputs_2d.txt

RemiLehe commented 1 year ago

OK, yes, thanks for pointing this out. It seems that, for some reason, the embedded boundary is interfering with the PML... We'll take a closer look at this.