-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify calculation of coefficients in moment-kinetic equation #320
base: master
Are you sure you want to change the base?
Simplify calculation of coefficients in moment-kinetic equation #320
Conversation
This will allow the time derivatives of moments to be used directly in the kinetic equation.
Simplifies code, making fewer places that need to be updated if new terms are added (now only RHS of kinetic equation and moment equations, not zdot, wpadot, Fdot coefficients). Updates expected values in some tests: discretization errors are changed by the rearrangement of the moment kinetic advection coefficients, and the tests are generally poorly resolved (in order to be fast), so are sensitive to this.
I am in favour of anything which simplifies the upgrading of the model. Thanks for looking at the possibility that this might work! Looking in the code it seems that you have Is there a way to make things even more general, so that the function which computes EDIT: I suppose here the challenge is that |
We don't currently use a time advance scheme where the electron density (equal to the ion density) is updated during the same step as the electron pressure (because explicit and implicit steps are separate even if the electrons are updated directly on the ion timestep), but if we did, and also used the temperature equation option for the electrons (instead of the default pressure equation), then the implementation would be wrong because it did not distinguish the density at the beginning and the end of the timestep (compare the implementation of the parallel velocity update using a momentum equation in force_balance.jl). This commit fixes this potential error, by passing in separate electron_density_out and electron_density in to electron_energy_equation!().
@mrhardman ah, my comment was not correct (I'll edit to try and clarify). I was only thinking of adding new terms to the RHS of the kinetic equation, not potentially adding drift terms or other modifications to the free-streaming or acceleration. Potentially we could do something along the lines you're suggesting for drift terms - I think it's something to come back to when we're implementing the 2D version of moment-kinetics. Yes, using arrays with dn/dt, etc. instead of substituting by hand using the moment equations, then evaluating the resulting expressions is what this PR does. |
This will allow the time derivatives of moments to be used directly in the electron kinetic equation.
Allows using more functions from the main simulation code during post-processing.
8d9688a
to
4afa758
Compare
Yes, in the best case scenario when modifying the advection velocities and accelerations we would have to modify both |
…n-coefficients' into simplify-moment-kinetic-advection-coefficients
…imes, rather than recursively updating each element in the time derivative calculator in get_variable().
By fixing _get_fake_moments_fields_scratch(), we can apply the fix in a single place, instead of everwhere _get_fake_moments_fields_scratch() is called.
…ie_post_processing for now
…etic-advection-coefficients' into simplify-moment-kinetic-advection-coefficients
Saving the time derivatives of the moments as they are calculated for the time-advance of the moments, and then using those time derivatives for the coefficients in the moment-kinetic equation, simplifies the code, making fewer places that need to be updated if new$\dot z$ , $\dot w_\parallel$ , $\dot F$ coefficients).
terms are added (e.g. if new terms are added to the RHS of the drift-kinetic equation, only the moment equations and the RHS of the moment-kinetic equation change, not the
Updates expected values in some tests: discretization errors are changed slightly by the rearrangement of the moment kinetic advection coefficients, and the tests are generally poorly resolved (in order to be fast), so are sensitive to this.
There is a question whether making this change is a good idea, with the concern that there may be some desirable cancellations between terms that would take place analytically but might not happen exactly numerically. Possibly the most concerning is the cancellation of the parallel electric field, but I think that one should be exact up to machine precision, as
So that we end up evaluating numerically
0.5 * Ez - 0.5 * Ez * n / n
- there will be some rounding error, but no discretization error (for other terms there might be a discretization error due to something liked(n*upar)/dz - n*dupar/dz - upar*dn/dz
). For the corresponding lines of code, see:moment_kinetics/moment_kinetics/src/velocity_moments.jl
Line 962 in e8d95c5
moment_kinetics/moment_kinetics/src/force_balance.jl
Line 31 in e8d95c5
moment_kinetics/moment_kinetics/src/vpa_advection.jl
Lines 410 to 413 in e8d95c5