ComputationalRadiationPhysics / clara2

Clara2 - a parallel classical radiation calculator based on Liénard-Wiechert potentials
GNU General Public License v3.0
13 stars 9 forks source link

Strange result in radiation calculation #109

Closed shouyr closed 5 years ago

shouyr commented 5 years ago

I am attempting to calculate radiation spectrum from electron trajectory. The electron trajectory was obtained from a PIC simulation by EPOCH. However, the result seems to be strange. As shown in the following picture, the spectrum is discrete, especially in the theta axis. I also plot the electron trajectory, which is similar to the trajectory in an undulator. One difference of the trajectory from PIC is that the electron does not have a nearly constant velocity, its gamma factor could vary in a large range. Is this the reason resulting in the strange spectrum? And would you know how to obtained the right results? Thank you! Betatron trace_0000.txt

PrometheusPi commented 5 years ago

Hi @shouyr great to hear from you again.

Your inital guess is correct. In order to speed up the computation clara2 relies on using an FFT algorithm. FFTs however reqire equidustanly spaced data points, which is not given for retarded time of a wiggling electrons. Therefore, ther code performs an interpolation of the retared time step onto a equidistant grid. Then it is given to the FFT. By default the code uses the same number of equidistant grid points in retarded time as sample points in the trajectory. This is a good ratio for undulator like radiation sources. For anything with high gamma and pointing changing more than 1/gamma (e.g. wiggler radiation, LWFA), this does however under-samples the retarded time. In order to increase this ratio, please increase the param::fft_length_factor in clara2/src/settings.hpp.

Did increasing the sampling solve your issue?

shouyr commented 5 years ago

Hi @PrometheusPi thanks for your response.

I have tried a larger param::fft_length_factor, however, it does not work. Actually I plot 1/(1-\beta_x) of the electron as shown in the following picture. The value of 1/(1-\beta_x) just varies in a too large range. If I only calculate the trajectory in the blue cycle, the result then seems reasonable. I notice that there is another solution named Time domain code in your thesis. Do you think the Time domain code can be applied for radiation calculation of such wiggler-like electron trajectory? Thank you! beta

PrometheusPi commented 5 years ago

@shouyr The time domain code from my thesis computes the electric (and magnetic) fields created in a position- and time-space. Thus it only provides information on the spectrum only indirectly if you Fourier Transform these fields afterwards. (It was built to study the influence of self-fields of a bunch in synchrotrons.) Therefore, I would consider it unsuited for your regime. I would propose a non-FFT approach instead, similar to the radiation code in the particle-in-cell code PIConGPU (my main task). Such an algorithm is already implemented in Clara2, but not (yet) exposed in a user-friendly manner (see #72). It is the so-called DFT (discrete Fourier Transform) part in Clara2.

In order to use it, you will need to switch from FFT to the DFT mode (here) and define your frequency domain manually (this is going to be the tricky part - see here). Furthermore, the DFT algorithm scales with the product of the number of frequencies (N_omega) times the number of time steps (N_t) compared to the FFT which scales as N_t * log(N_t) but forces N_omega=N_t. Thus in most cases, the FFT will be significantly faster while the DFT will be "dead" slow. Additionally, the differing Nyquist frequency (due to the strongly varying retared time step) needs to be taken care of as well (Nyquist limiter in my thesis). This is not yet implemented in Clara2 - I will open an issue on that #110.

I am not sure whether I will find time to quickly expose the DFT in a more user-friendly manner soon and additionally add a Nyquist-limiter (which is only relevant for the DFT). What are your time constraints regarding these simulations? Are you by any chance interested in implementing these features and submitting them as pull request to the Clara2 repo your-self?

shouyr commented 5 years ago

Hi @PrometheusPi thanks for your response. I have written a time domain code according to your thesis and compute the spectrum using FFT of the electric field. Then I found this spectrum is similar to the result of Clara2 if param::fft_length_factor = 256. So now I think setting an enough large param::fft_length_factor is a feasible solution. The DFT mode seems to be a more universal method and I will attempt it. However, honestly speaking I am not familiar with C++ and it will take some time.

PrometheusPi commented 5 years ago

@shouyr Great to hear that setting param::fft_length_factor to 256 solved your issue.

Don't worry about my request. I just wanted to let you know that most likely I won't have time to do this quickly and that you might have to do it if you need such a feature urgently. Anyway, you are always welcome to participate in Clara2 if you like.

Just out of curiosity: might I ask what the topping of your work/research is? (It looks a bit like betatron radiation to me.)

I will close this issue for now. All feature requests have been extracted to separate issues.

shouyr commented 5 years ago

Hi @PrometheusPi thanks for your help. My study now is focusing on radiations from laser driven near-critical density plasmas. Electrons can oscillate in the laser-induced magnetic field, which is similar to betatron in LWFA. We can discuss this further if you are interested.