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

run error when using the clara2 code to compute the radiation spectrum #105

Open QJohn2017 opened 6 years ago

QJohn2017 commented 6 years ago

Hi @PrometheusPi , when I use the clara2 code to calculate the radiation spectrum from some electron trajectories which tracked by Vorpal code. I have 141 number particles, when I calculate the spectrum by clara2 code, some errors were raised at some electron trajectories, but the other trajectories had no errors. The errors are recorded by the file "my_error.txt-...". the error is as follows:

error 01: interpolation inverted (ned_fft.hpp) 1648 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1650 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1652 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1654 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1656 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1658 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1660 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1662 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1664 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1666 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1668 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1670 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1672 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1675 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1677 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1679 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1681 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1683 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1685 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1688 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1690 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1692 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1694 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1697 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1699 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1701 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1704 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1706 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1709 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1711 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1714 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1716 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1719 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1721 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1724 --> -2.88261e-12 <=! -2.88261e-12
error 01: interpolation inverted (ned_fft.hpp) 1726 --> -2.88261e-12 <=! -2.88261e-12
 ........

So, I don't know how to avoid this error, could you help me? Thank you very much!

PrometheusPi commented 6 years ago

Hi @QJohn2017, this error warns you that the retarded time of one of your particles with regard to a specific observation direction does not increase between two iteration-/time-steps. This can have two reasons:

While the first case is a real error in the initial simulation code creating the trajectory data, the second is a common warning that you reached the limit of numerical precision of either your input data or of Clara2 (double precision floats). Since you are using the well tested Vorpal code and since the warning states no decrease in time, this looks like the second case to me and can be safely ignored. Clara2 just does not perform an interpolation between these two iterations because numerically they appear to be equal.

@QJohn2017 Please excuse that I had no time to further investigate the factor~2 discrepancy between expected radiation frequency and output. Could you find a reason for this discrepancy?

QJohn2017 commented 6 years ago

Hi @PrometheusPi , You said that the errors occurred in my spectrum calculation are look like the second case above and can be ignored. But I have tried many times and the errors always existed and the output file "my_spectrum_data000*.dat" related to the "wrong" trajectories can not be created. The attachments are two sample trajectories of mine. The "data_1.txt" is a "wrong" trajectory that had errors when running, the other trajectory "data_66.txt" is normal for running and can create the output file "my_spectrum_data00066.dat". So, can you help me to check it ? The propagation is x direction.** data_1.txt data_66.txt

@PrometheusPi , sorry, i could not find the reason for this ~2 discrepancy.

QJohn2017 commented 6 years ago

Hi @PrometheusPi , Recently, I have tested the clara2 code again and I founded that this code is right and there is no ~2 times discrepancy. I tested a head-on inverse Compton scatter, in which the a0 = 1.0, wavelength= 0.8um, and the gamma = 600. Therefore, the undulator_wavelength=0.4um , and K = a0 = 1.0. the scatter frequency= 2.26e21 Hz. When I calculated this spectrum by clara2 code, the result is right and there is no ~2 times discrepancy. So, I think your code is right and the ~2 times discrepancy before may came from my own claculation fault. Thank you for focusing this question.

PrometheusPi commented 5 years ago

@QJohn2017 Great you found the time to validate the code with a test case. I am very sorry - I could not find the time to further test clara2 - I was occupied with other projects.

Would you be willing to upload your test case (the code that generated your test trajectories) as a pull request to this repository so that other users have can generate an example to start from?

PrometheusPi commented 5 years ago

Were you able to determine the cause of the factor 2 error in your trajectories? (I hope so.)

QJohn2017 commented 5 years ago

@PrometheusPi , Sorry that I was busy in recent days. The attachment file is the code that generated my trajectory, you can check it and test it, if there are any errors or problem, you can contact me at any time.

The namelist.example is my input file, you can set the laser intensity and the undulator intensity. The *.txt is my initial particles' distribution, you can modify the output format in interaction.cpp file, the element.cpp file is the electromagnetic field and undulator field. modu_trajectory.zip

PrometheusPi commented 5 years ago

@QJohn2017 Thank you for providing your code for computing the trajectories. I already had a brief look at the source code. It looks very sophisticated and advanced. I have seen you include some header files that I also found online. Which license does your source code (including the Bessel functions) have and will this conflict with the GNU3 license we use for Clara2?

PrometheusPi commented 5 years ago

@QJohn2017 No reason to apologize - you always react very quickly. I am the one who needs weeks to answer questions and find a solution. Thanks again for your feedback and support.

QJohn2017 commented 5 years ago

@PrometheusPi , I don't know whether the GNU3 license conflict with the Clara2, but i think it is ok ! Actually, the codes I provided are downloaded from the Github, I just made some modifications and improvements. I am anxious for your advice and improvement. Thank you !

PrometheusPi commented 5 years ago

@QJohn2017 Please excuse my imprecise question: Clara2 is under the GNU3 license. Under which license are your code and the code you found on GitHub?

QJohn2017 commented 5 years ago

@PrometheusPi , sorry, i don't have any license for my code, but the license of the code i found on GitHub is located at https://github.com/archman/felscripts/tree/master/felsim/scripts/src

PrometheusPi commented 5 years ago

@QJohn2017 Thank you for the link. The code seems to be under GNU2 license, so that should be fine. Would you agree, if I add your code changes to this public Clara2 repository?

@steindev are you by accident familiar with the FEL code the trajectory generator is based on?

PrometheusPi commented 5 years ago

@ax3l are there any license issues when using GNU2 code in a GNU3 project?

steindev commented 5 years ago

I don't know it. And it is not an FEL Code.

QJohn2017 commented 5 years ago

@PrometheusPi , I am very glad that you can add the code I provided to Clara2.

ax3l commented 5 years ago

are there any license issues when using GNU2 code in a GNU3 project?

As long as it's GPLv2+ and not GPLv2-only there should be no problem. The repo you link is a bit wildly structured, but looks like overall using the usual GPLv2+ license text.

PrometheusPi commented 5 years ago

@ax3l Thanks for your expertise :+1: