Skip to content
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

Adding bpar to stella, explicit and implicit algorithms #129

Merged
merged 103 commits into from
Jul 16, 2024

Conversation

mrhardman
Copy link
Collaborator

@mrhardman mrhardman commented Dec 31, 2023

This pull request is intended to deliver a fully functional implementation of the explicit and implicit algorithms using all three fields, phi, apar, and bpar. Starting from the development/apar2 branch where apar is included by introducing the distribution function gbar = g + 2 (Zs/Ts) vths vpa J0 apar, and g = h - Zs J0 phi / Ts, we include bpar. Bpar is included by modifying g to g = h - (Zs/Ts)(J0 phi + 4 (J1/bs) mu (Ts/Zs) bpar).

For the explicit algorithm standard flux tube features are supported (tested linear, collisionless simulations).

For the implicit algorithm collisionless features are supported (tested linear, and nonlinear collisionless simulations).

Initial low-resolution nonlinear simulations have been performed with promising results (no blow-up!).

Linear, collisionless, benchmarks have been carried out against GS2 for an ITG and a KBM example.

Not supported

  • perpendicular flow shear for simulations with A|| (The implicit implementation of perpendicular flow shear acts on g, not gbar, meaning that there are (potentially, probably) missing flow-shear terms involving A||). B|| terms are included in the evolved g in the implicit algorithm so there are no missing flow shear terms for B||

  • radial variation

  • full flux surface

  • implicit collisions

  • driftkinetic_implicit

  • neoclassical terms

  • in-code comments: many places refer to g as g = < f >, which is no longer true.

  • Support the implicit algorithm for flow shear and A||

  • Support the implicit algorithm for collisions.

  • Provide electromagnetic fluxes in the diagnostics (are separate variables preferred, or should the existing flux be upgraded to the total one? @mabarnes @GeorgiaActon)

  • Provide in-code documentation.

  • Provide benchmarks and report documentation.

  • (Optional extra) Support neoclassical terms for apar and bpar (@mabarnes where are the equations written down?).

  • (Optional extra) Support radial variation.

  • (Optional extra) Support full flux surface (@GeorgiaActon I see you have another open PR, so perhaps this is a non-trivial job).

mabarnes and others added 30 commits May 4, 2023 20:08
…he code would function properly even if they are specified. ultimately, we should remove these variables.
…p to make it easier to see what is happening and to make targeted changes.
…. further changes need to be made to implicit_solve to calculate the apar source terms associated with unit impulse in apar.
…ar. still need to add apar code to implicit_solve and test everything.
…es. currently produces unphysical behaviour so need to debug.
…so added apar treatment of explicit mirror advance, but not tested.
…d use of include_apar = T for explicit solve, with the exception of wstar term.
…steps rather than gbar;

this required removal of a gbar_to_g call in implicit_solve.f90
@mrhardman
Copy link
Collaborator Author

@mabarnes @GeorgiaActon The last commits add the bpar contribution to the particle and heat fluxes, but the contribution to the perpendicular part of the momentum flux is not included. To support this stella would need to have the Bessel function d J'_1(x) /d x = (1/2) (J0(x) - J2(x)).

@GeorgiaActon
Copy link
Collaborator

Notes on numerical instability:

  • Including parallel streaming in isolation seems stable, including mirror in isolation seems stable, but including them both without the presence of drifts can be unstable.

  • This numerical instability is worse with increasing dt, decreasing k_y, or decreasing qinp.

  • It seems that these parameters are all knobs for the relative amplitudes of the streaming and mirror terms compared to the time derivative.

  • Turning off the phi contribution in the streaming removes the instability. However, keeping the phi contribution and reducing the amplitude of the g contribution from streaming kills the instability. The reverse is also true; increasing the amplitude of the g contribution to the streaming equation worsens the instability.

@mrhardman
Copy link
Collaborator Author

Notes on numerical instability:

A further note that all of these experiments were done with zed_upwind = 1.0, demonstrating that even maximum first-order upwinding does not guarantee a stable simulation.

@mrhardman
Copy link
Collaborator Author

An additional note:

Examining the collisionless_mtm_implicit.zip example above, using drifts_implicit = .true. makes the example numerically unstable. This might be consistent with the fact that the implicit algorithm cannot accept a timestep size too large. However, this instability is not repaired by setting include_mirror = .false.. This may suggest that the electromagnetic implementation has addition bugs compared to the electrostatic implementation @GeorgiaActon @mabarnes.

Another check for the instability: turning off the drifts with

&time_advance_knobs
xdriftknob = 0.0
ydriftknob = 0.0
wstarknob = 0.0

removes the time step restraint from the automatic CFL condition and appears to give a stable simulation for the nominal time step (the automatic CFL otherwise reduces the timestep size to 1.0e-3 from 1.0e-2 in the input file).

mrhardman added 4 commits May 15, 2024 16:42
…t throughout the netcdf file. Note that some variables still do not have units.
… flx_vs_kxky -> and the sum (weighted by mode_fac) of flx_vs_kxky is equal to the corresponding flx. This gives flx_vs_kxkyz a clear physical meaning as the contribution to the flux from the volume around the point in z. This improves testability of the diagnostics.
@mrhardman mrhardman requested a review from Scottyujia May 17, 2024 10:00
@mrhardman
Copy link
Collaborator Author

@Scottyujia @mabarnes I have just noticed that the perpendicular flow shear terms connected to apar are likely missing, so perpendicular flow shear is likely not implemented properly in the electromagnetic case. I have updated the tracker at the top of this PR.

…ort simulation if fapar > -1 or fbpar > -1 are set in the input. May fix #130.
… numpy error. "AttributeError: `np.unicode_` was removed in the NumPy 2.0 release. Use `np.str_` instead".
@GeorgiaActon GeorgiaActon merged commit 52df87b into master Jul 16, 2024
8 of 9 checks passed
@HanneThienpondt HanneThienpondt added stella review 07/2024 Georgia and Hanne are cleaning up stella Physics feature Add new physics capabilities and removed enhancement New feature or request labels Jul 24, 2024
@mrhardman
Copy link
Collaborator Author

mrhardman commented Jul 28, 2024

example_nonlinear_phiaparbpar_2.zip
Example of a very low resolution nonlinear electromagnetic simulation in cyclone base case geometry. This case is definitely under-resolved but shows successful execution of the code. Made with

commit ee47b7ce6c0dacfe00cb165cf7582de1df4b9855 (HEAD -> development/apar2plusbpar, origin/development/apar2plusbpar)

and taking ~1.5 CPU hrs to execute on 16 cores (5.60 mins). Perhaps suitable for "long" automatic tests.

Plots are made with

python3  xarray_post_processing/plot_stella.py example_nonlinear_phiaparbpar_2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Physics feature Add new physics capabilities stella review 07/2024 Georgia and Hanne are cleaning up stella
Projects
None yet
6 participants