ascot4fusion / ascot5

ASCOT5 is a high-performance orbit-following code for fusion plasma physics and engineering
https://ascot4fusion.github.io/ascot5/
GNU Lesser General Public License v3.0
31 stars 9 forks source link

Recording GO results as GCs (RECORD_MODE=1) results in 1e4 times more particles in the fast ion distribution #119

Closed Ian-Dolby closed 1 month ago

Ian-Dolby commented 2 months ago

When I record gyro-orbit runs as GCs (RECORD_MODE = 1), the FI distribution contains orders of magnitude (1e4) more particles. I get this result even with the ASCOT5 distributions tutorial setup. I have not changed any distribution values between the two settings, and all of the GO particles are always within the distribution boundaries, so I am not accidentally reducing the number of particles by them going outside. The total number of particles is obtained by using dist.integrate(r=np.s_[:], phi=np.s_[:], z=np.s_[:], ppar=np.s_[:], pperp=np.s_[:],charge=np.s_[:], time=np.s_[:], copy=True).distribution().v

The results for the tutorial are below: FI total: 0.09996 (GC), 0.10007 (GO), 939.321, (GO as GC). Figure_5 Figure_1 Figure_3

Figure_6 Figure_2 Figure_4

I found equivalent issues when recording the COM distribution in previous simulations.

Ian-Dolby commented 2 months ago

The phase space volume elements obtained using dist.phasespacevolume() are identical, and the difference is coming from the histograms.

miekkasarki commented 1 month ago

Interesting... What RECORD_MODE=1 does, is that it makes a guiding center transformation and then updates the distributions as usual (i.e. as they are updated in pure GC simulation). Maybe the weight is not copied? I'll have a look.

Nice catch!

miekkasarki commented 1 month ago

This should be now fixed in branch feature/119-recording-go-as-gc-brokes-distributions.

Can you confirm @Ian-Dolby ?

Ian-Dolby commented 1 month ago

The discrepancy is now only ~5e3 instead of 1e4, but it is still there. I have done git switch and git fetch, and done make clean and then make ascot5_main -j MPI=0 VERBOSE=1 FLAGS="-g" CC=gcc and make libascot -j MPI=0 VERBOSE=1 FLAGS="-g" CC=gcc, so I'm fairly confident that I am testing the new version.

The new plots are quite similar to the old ones.

Ian-Dolby commented 1 month ago

The simulations from that tutorial are set up with a time limit of 10 ms, but the difference remains even with a longer time limit.

Ian-Dolby commented 1 month ago

Update: I made a mistake in rerunning the simulations and I was accidentally still using a previous version.

The agreement is now extremely good, within 0.1% for even quick simulations with 1e-4 s sim times.

miekkasarki commented 1 month ago

Great! This fix will be in the next release.