Closed Otsooni closed 4 months ago
In principle it should support all distributions. Maybe a good idea to check bbnbi.c is there a bug somewhere.
I confirmed that (obviously) the direct marker data from the bbnbi has theta variation, by creating a rho5d distribution on the python side from the markers. These are the integrated plots as rho- theta images:
Curiously, the total particle has is clearly not preserved. I wonder if that means the distribution is losing markers somewhere.
I did not find any obvious faults on the c code from either bbnbi.c or diag_rho5D, but I might just use the rest of the afternoon searching for them.
My guess is that there is a conversion (between radians and degrees) error somewhere. You could try to increase the poloidal grid bin number to 120. If all the markers are still at the first bin, then we can rule this out.
Are the units same in both plots? The top plot shows "markers in bin / bin volume" and the bin volume in this case is 0.1 rho x 10 deg.
Put a print in diag/dist_rho5d.c in the correct update function and check if theta=0 for all markers.
I increased the grid size to 180, and the problem persisted. Moreover, I assigned PHIMAX as 7, so we can safely rule it out.
Yes the units are same for both plots. Both should be particle per bin (and the bins are identical for both)
Put a print in diag/dist_rho5d.c in the correct update function and check if theta=0 for all markers.
Correct! Theta and consequently i_theta are zero.
Exactly zero or close to zero?
Here theta is missing: https://github.com/ascot4fusion/ascot5/blob/a7bff59eacc587d617e9314ab4c492ee106e5eca/src/bbnbi5.c#L278 See here what fields should be initialized: https://github.com/ascot4fusion/ascot5/blob/a7bff59eacc587d617e9314ab4c492ee106e5eca/src/particle.h#L40
You can check from particle.c how theta is computed.
Well, I only printed the first decimal, so everything said 0.0.
Exactly zero or close to zero?
Here theta is missing:
See here what fields should be initialized: https://github.com/ascot4fusion/ascot5/blob/a7bff59eacc587d617e9314ab4c492ee106e5eca/src/particle.h#L40
Neither is rho initialized there. I'll put the theta calculation on the same place as rho
Never mind that, rho is needed during the simulation of course but not theta, I'll initialize it for collecting the distribution.
One mystery still remains. That fixes the initial theta, but when the markers are pushed the integrator calculates Delta theta. Why that is not included? I mean if it were, then the printed theta would be small but not constantly zero.
Could you put a print here as well https://github.com/ascot4fusion/ascot5/blob/a7bff59eacc587d617e9314ab4c492ee106e5eca/src/simulate/step/step_fo_vpa.c#L185
This is where theta is incremented when the marker is neutral.
Is RHS zero or does the code even reach this block?
Could you put a print here as well
This is where theta is incremented when the marker is neutral.
Is RHS zero or does the code even reach this block?
I don't see that function even getting called directly in bbnbi
True, I was wrong. It doesn't use that. This is where theta incrementation should be https://github.com/ascot4fusion/ascot5/blob/a7bff59eacc587d617e9314ab4c492ee106e5eca/src/bbnbi5.c#L387
I got it to work. I didn't feel the need to update the theta for every simulation step (as it's not used for anything, at least currently), so I just put it at the end. I'll create a branch or something and push it through.
If it's not too much trouble, I'd suggest updating theta at every step. Right now it doesn't matter but it becomes relevant when someone wants to have the neutral density from beams.
Well, I decided to be nice and to implement it as you suggested. I just didn't initially like it due to lowering the performance. Preferably the theta would only be updated when it would be used for each time step.
rho5d
distribution from bbnbi5 only populates the first theta bin, even though the bbnbi resulting markers would suggest other theta bins should also be populated.Does the current bbnbi not support rho5d? If so, it would be nice to be implemented.