hightower8083 / synchrad

Synchrotron Radiation calculator via openCL
GNU General Public License v3.0
17 stars 11 forks source link

coherent synchrotron radiation #23

Open berceanu opened 1 year ago

berceanu commented 1 year ago

Hi, We're looking to check the code corectness for the coherent part of the synchrotron emission spectrum by comparing with the PIConGPU radiation plugin output for a simple LWFA setup.

Coh

While we get relatively good agreement for the incoherent part of the spectrum, the coherent part seems to be a global upward shift of the whole spectrum in the case of synchrad, while for PIConGPU, the coherent low-energy part actually has a different shape, as can be seen in the attached figure.

We used this code in the case of synchrad:

def main():
    """Main entry point."""
    args = cmdline_args()

    calc_input = {
        "grid": [
            (args.params["omega_min"], args.params["omega_max"]),
            (args.params["theta_min"], args.params["theta_max"]),
            (PHI_MIN, PHI_MAX),
            (N_OMEGA, N_THETA, N_PHI),
        ],
        "dtype": "double",
        "native": False,
        "ctx": "mpi",  # set your context to avoid being asked
    }

    calc = SynchRad(calc_input)
    calc.calculate_spectrum(
        file_tracks=args.infile,
        comp='cartesian_complex',
        file_spectrum=args.outfile,
    )

if __name__ == "__main__":
    main()

adapted from the Betatron_Example.ipynb.

hightower8083 commented 1 year ago

Thanx for these interesting tests @berceanu -- we should definitely look into this, PoG is doing things a bit differently and handles particles shapes (you can fix macroparticle size with sigma_particle argument in synchrad) Could you post details (inputs) of how exactly the particle tracks are obtained?

berceanu commented 1 year ago

Hi @hightower8083 indeed, the radiation plugin implementation from PoG is described in some detail here.

Would you also require the PoG input files, or just the synchrad input and trajectory data?

hightower8083 commented 1 year ago

inputs would already be helpful, and I suspect tracks data should be rather large. right now I'd like to understand why all spectrum in synchrad case is coherent -- in general that shouldn't be the case for a finite-size beam.

berceanu commented 1 year ago

Hi @hightower8083 , in the interest of completeness and reproducibility, I am going to link here to the complete data set, including the PIConGPU input files and trajectories.

The total archive size is ~60 GB, so it should be download-able over a standard connection in about 20 minutes (tested on Chrome).

To extract, simply run:

tar -xf betatron.tar

PIConGPU particle data is under /simOutput/h5.

berceanu commented 1 year ago

This might also be of interest for @PrometheusPi by the way, as he is the main person behind PIConGPU's radiation plugin.

hightower8083 commented 1 year ago

Hi @hightower8083 , in the interest of completeness and reproducibility, I am going to link here to the complete data set, including the PoG input files and trajectories.

The total archive size is ~60 GB, so it should be download-able over a standard connection in about 20 minutes (tested on Chrome).

To extract, simply run:

tar -xf betatron.tar

Than you for the data @berceanu , though its a bit fat for a quick check. As I do not have much doubt on the PIC simulation itself, and I suspect something is happening as the data is passed to synchrad. Do you by chance have the tracks data extracted for the openpmd dataset which was used for synchrad ?

berceanu commented 1 year ago

Of course @hightower8083 , here is a link to the extracted tracks. The y and z axes are already switched in this file, compared to the PoG convention.

Thanks again for taking the time to look at this!

hightower8083 commented 1 year ago

hi @berceanu

I did some tests and found a couple problems: 1) originally each track in the integral had its own time axis, that completely spoiled the coherency of particles contributions for the cases when tracks have difference starting time. This was indeed a bug which practically only appears for coherent calculation with PIC input, which is your case and its great that we have found it. Its fixed now 2) strictly speaking, coherent summation of LW potentials is valid only for the physical particles, i.e. single electrons, and is much less for the case of macro-particles that present point-like ensembles of many particles. In PoG field sums are calculated over samples for each time-step and as far as i understand apply some particle shaping. In synchrad we treat track by track and I guess this makes on-flight smoothing of particles phase shapes more difficult.

While first issue is fixed, I'm still not sure which would be the best solution for the second problem. For an ideal case of all macro-particles emitting coherently the same field $A$ and each presenting some $N{e/mp}$ electrons we obtain a correct scaling for the full energy $W\propto (N{mp} N_{e/mp})^2 = Ne^2$, while for a fully incoherent situation we have $W\propto N{mp} N_{e/mp}^2 = Ne N{e/mp}\ggg N_e$, which is definitely incorrect (see left central panels in fig below).

I've tried several cases and these solutions seems to give cleaner results though do not show much difference between them (see right panel in fig below). syncrad_coh

I'm still puzzled why in the case of unity weights there is still an important difference in the incoherent region between coherent and incoherent mappers. In the simple betatron example case below (with unity weights) I see that mappers converge well in the incoherent region and the coherent peak corresponds to the one expected. image

To conclude, for now I've implemented the correction $N{e/mp}$ with $\sqrt{N{e/mp}}$ in the mappers for complex fields, and also added in the calculate_spectrum method an option weights_normalize which can be ones to set all weights to 1, and either mean or max for corresponding re-normalizations. This is done in #25 which I'm going to merge soon, so let me know if you have any thoughts or comments.

PrometheusPi commented 1 year ago

The time issue that @hightower8083 found would definitely cause a significant issue.

I would not trust the coherent to incoherent transition from the ensemble average PIConGPU simulation, since this depends heavily on the assumed macro particle shape. (See https://doi.org/10.1016/j.nima.2018.02.020 for details.) But this does not explain why PIConGPU predicts such a high intensity at 1e-3 keV.

Without knowing many details of syncrad, I agree with @hightower8083 that the higher result of the coherent calculation compared to the incoherent calculation in the high frequency/incoherent region of the spectrum is strange. @hightower8083 Do you apply some filters on the coherently calculated spectra to avoid coherent cancelation? I would have expected very strong oscillation between values above the incoherent spectrum and zero in the incoherent region. But the overall spectrum looks smooth.