bmad-sim / bmad-ecosystem

Bmad simulation ecosystem for simulating high energy storage rings.
https://www.classe.cornell.edu/bmad/
10 stars 13 forks source link

Projected Emittance Not Calculated Correctly in Solenoid and Segmentation Fault #305

Open ColwynGulliford opened 1 year ago

ColwynGulliford commented 1 year ago

I created a simple example of a uniform pancake beam (all particles z=0) and send it through a solenoid in GPT and Tao. I plot the transverse beam size:

Screenshot 2022-12-08 at 2 50 53 PM

and see good agreement. However it appears the projected emittance is not being computed, and perhaps calling the x.norm_emit from the bunch_comb is really just returning a.norm_emit:

Screenshot 2022-12-08 at 2 51 53 PM

Here GPT shows the projected emittance increase as particles enter the solenoid, whereas there is no increase in Tao.

Also, I noticed if I don't put "call::" in front of the field map file name in the lattice file, Tao segmentation faults.

The complete working example is attached. sol.zip

DavidSagan commented 1 year ago

@ColwynGulliford "call::" is always needed. If there is some documentation that indicates otherwise please tell me where and I will fix it.

DavidSagan commented 1 year ago

@ColwynGulliford beam_init parameters not set in example. Please correct.

ColwynGulliford commented 1 year ago

Re: "call::", it's ok if it's always needed, but shouldn't a seg fault be avoided? When that happens it will kill a python kernel, say if someone is running pytao.

To run the example requires the following commands:

set global lattice_calc_on = False set beam_init position_file = initial_tao_particles.h5 set ele beginning e_tot = 1122995.9603226997 set beam_init n_particle = 1000 set beam_init bunch_charge = 1.0000000000000002e-12 set bmad_com csr_and_space_charge_on = False set ele * csr_method = off set global lattice_calc_on = True set global track_type = beam set global track_type = single

I've put these into the file "commands.tao" and reattached the example. Thanks!

sol.zip

DavidSagan commented 1 year ago

Sorry I was misinterpreting. The bomb has been fixed and I am working on the emit problem.

ColwynGulliford commented 1 year ago

Hi Dave,

I've updated the example files to have non-zero initial emittances / energy spread. This avoids the issues with the dispersion. I also have computed the emittance from GPT using the formula from Bmad (orange curve):

Screenshot 2022-12-09 at 10 47 07 AM

Note that in the solenoid there isn't any dispersion to first order:

Screenshot 2022-12-09 at 10 43 30 AM

This is why the gpt and gpt disp. removed curves are the same. So the way the projected emittance is computed is not described correctly by the formula:

Screenshot 2022-12-09 at 10 35 36 AM

I've attached an updated example with the non-zero emittance beam below:

sol.zip

ColwynGulliford commented 1 year ago

Attached are particle x, px, y, py coordinates dumped at 3 z locations (in file name) from GPT: gpt_particles_at_0.0.txt gpt_particles_at_1.0.txt gpt_particles_at_0.5.txt

DavidSagan commented 1 year ago

I traced down the problem to be that effectively Bmad is correcting for the vector potential in the solenoid when it reports the phase space position even though it is using the mechanical momentum when tracking tracking. This is an old convention which has outlived its usefulness. I will work on a fix...

ColwynGulliford commented 1 year ago

I was able to confirm that, the momenta Tao reports is really:

Screenshot 2022-12-11 at 5 00 28 PM

In a solenoid Lz ~ Bsol, so this is the canonical momentum. I can make GPT agree with Tao if I use that variable:

Screenshot 2022-12-11 at 5 02 18 PM