GK passive advection & twistshift fixes - #1084
Merged
Merged
Conversation
… given in the input file. Add sample regression test (gkylcas 16cfe76398a327fa8617ed162509585f0c6c6f47).
…up. We should make it so that omega_H is only computed if the field evolves. Passive eqn object is clearly not ready as the result is not as expected.
…x2v passive advection reg test. Tried using TS BCs in passive advection but I think there's a memory bug, need to switch to cluster with valgrind.
…oken its use in bc_twistshift. Also, I think there was a bug in find_cell all along, though I don't know if it was ever triggered. Fix this bug, and adjust a tolerance in twistshift to make it work with the recently added epsilon in rect_grid_find_cell. Unit tests pass. There's still an issue with passive advection using TS BCs because the solution quickly becomes NaNs.
… show that the shift at the lower boundary is OK, but the shift at the upper boundary (which -1 times the lower shift) produces NaNs.
… integrals of bc_twistshift, it was causing NaNs in the fig14 scenario. Fix boundary kernel selection in gk_collisionless_passive_flux. Now the passive advection test with TS BCs looks as expected.
…uadratic q has issues near the upper radial boundary. We'll examine this in a unit test setting, and try it with TCV geo.
… delete or simplify this in the future, but it already reproduces the checkerboard pattern seen in the simulation.
…in the shift across a single cell is equal or greater to the length of the domain along y. I tried to add support for this sort of scenario but didn't succeed. I'll try again in the future. For now we must increase resolution along y, reduce shear or increase Ly so this doesn't happen. Add accepted results to CBC unit test.
…n TS BC updater. The previous approach looked in periodic copies of the domain independently for each point, but this could give different periodic copies for 2-4 points that are meant to define a subcell integral, leading to error. So now we look for the correct periodic copy only once (for a given donor-target pair) and pass that to be used for looking for intersections. This fixes some checkerboarding seen in the CBC geo with Nx cells. All other unit tests continue to pass (I had to generate new cbc accepted results, but I confirmed visually that for Nx=32 the difference was machine precision.
…eger. This explains a mysterious shift we were seeing when structures crossed the IMP.
…ew, so we can call it from python.
…nto gk_passive
…ddress, this makes it easier to call it from python. Rename num_cell_ variables in tcv reg tests so that they use Nx like all other reg tests (makes it easier to automate changes to them).
Antoinehoff
self-requested a review
July 11, 2026 17:51
Collaborator
|
Great addition and fixes. Can you share your results of production-like simulation with that branch? Once this is done I think we can merge. |
Collaborator
Author
I checked a production TCV and D3D setup, and for those resolutions and shifts/q-profiles, nothing seemed to change. The TS fixes here appears to have afflicted other scenarios, but not those two. I'll valgrind check when Perlmutter comes back online. |
Merged
…n't run at too low a res because of constraints on TS BCs. Increase tolerance in unit test to 1e-8 so it passes on Perlmutter.
…compilers/libraries being used/linked.
Collaborator
Author
|
Antoinehoff
added a commit
that referenced
this pull request
Sep 2, 2026
Reapply GK passive advection work (PR #1084)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This goes with:
Changes
We add a new passive advection collisionless equation type,
GKYL_GK_COLLISIONLESS_PASSIVE. This can be invoked from the input file along with user-specified advection speeds. Seert_gk_passive_3x2v_p1.c, for example, where we useand
passive_velocity_elcis a function that returns 3 values for the x,y,z components of the advection velocity.This object has been quite useful for debugging some twist-shift BC issues. For example, we can now reproduce the test in figure 14 of M.Francisquez, et al. CPC 298 (2024) 109109:
and now there's a unit test with this set up.
These kinds of tests allowed us to make 3 improvements in twistshift:
However, because of 3 now the d3d and tcv IWL reg tests don't run (because they are too coarse in x). Maybe we should increase the resolution of those.
Other small but consequential changes:
gkyl_rect_grid_find_cell. Parts of it assumed the indexing of cells went from 1 to N, but in one place it placed the lower cell at 0.Additional changes:
gkyl_bc_twistshift_newtogkyl_bc_twistshift_inew, and implemented a newgkyl_bc_twistshift_newwhich takes the arguments in the function signature, not in an input struct.These changes make it easier to call bc_twistshift from python/postgkyl.
Results
In addition to reproducing the passive advection test in the twistshift paper, we were also able to check advection across the twistshift boundary in the CBC geometry (see rt_gk_cbc_passive_3x2v_p1.c). Here's a movie made with the gk-rz command in PR 214 of postgkyl:
rt_gk_cbc_passive_3x2v_p1-elc_M0.1.mp4
Moreover, with the changes made to the bc_twistshift API, we created a Marimo notebook that can plot the effect of the shift for a specific input file (see postgkyl PR 224). It allows us to visualize the shifted lower-y cell, e.g.
and a specified quantity, twistshifted by the bc_twistshift operator:
Lastly, the pre-existent bc_twistshift unit tests continue to pass.