ECP-WarpX / WarpX

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

Make `add initial fields on grid` work for RZ #3904

Open Yin-YinjianZhao opened 1 year ago

Yin-YinjianZhao commented 1 year ago

Recently, I need to give an initial B field, but just noticed it has not been implemented yet for RZ. See https://github.com/ECP-WarpX/WarpX/blob/development/Source/Initialization/WarpXInitData.cpp#L773 "E and B parser for external fields does not work with RZ -- TO DO"

@RemiLehe Said this can be added relatively easy, so I opened this PR for tracking.

BTW, I'm using PICMI with:

Bfield = picmi.AnalyticInitialField(
    Bx_expression = "-y/sqrt(x*x+y*y) * (-2.5407392385349525e-4*sqrt(x*x+y*y)/0.00021277183540403992)", 
    By_expression =  "x/sqrt(x*x+y*y) * (-2.5407392385349525e-4*sqrt(x*x+y*y)/0.00021277183540403992)",
    Bz_expression = "0")
sim.add_applied_field(Bfield)
ax3l commented 1 year ago

@RemiLehe and I discussed a potential first quick implementation.

Assumption: start with purely cylindrical (RZ) fields.

Naming: Er, Etheta, Ez all only depending on r,z (not yet theta).

Implementation: write into mode zero.

RemiLehe commented 1 year ago

@Yin-YinjianZhao I quickly looked at the code, and it seems that you could essentially remove the assert and run the code as is. The only trick is that, in this case, WarpX will interpret your Bx_expression/By_expression as Br/Bt and it will interpret x in the expression as r (y will be taken to be 0 by default).

So, for the azimuthal B field that you wanted to use, you should enter:

Bfield = picmi.AnalyticInitialField(
    Bx_expression = "0", 
    By_expression =  "(-2.5407392385349525e-4*x/0.00021277183540403992)",
    Bz_expression = "0")
sim.add_applied_field(Bfield)

However, this can be quite confusing for a general user. Which is why @ax3l was suggesting to modify the WarpX code so that the user needs to pass a function of r, z in the case where is compiled in RZ mode.