Skip to content

Add a low pass time filter to GK - #990

Draft
Maxwell-Rosen wants to merge 28 commits into
mainfrom
low-pass-filter
Draft

Add a low pass time filter to GK#990
Maxwell-Rosen wants to merge 28 commits into
mainfrom
low-pass-filter

Conversation

@Maxwell-Rosen

@Maxwell-Rosen Maxwell-Rosen commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

Feature

Summary

The coding for this PR was almost entirely done with GitHub Copilot, with @Maxwell-Rosen providing direction. I certify the results and take responsibility for any mistakes that may have been made.

Purpose: A low-pass filter is added to the gk_species_damping modules to damp high-frequency oscillations in $f$.

$$ \frac{d f_s}{d t} = -\nu_{\rm LP} \left(f_s-\bar f_s\right), $$

$$ \frac{d \bar f_s}{d t} = \nu_{\rm LP} \left(f_s-\bar f_s\right). $$

Issue link: fixes #985

Implementation Details

Key changes:
This PR features pretty big changes, extending from gk_species_damping.c, all the way to the SSPRK3 time stepper. This is necessary because the low-pass filter adds an entirely new equation, RHS, and a new variable to step in time. I did my best to preserve the current architecture while simply adding new arguments to existing functions and mirroring how the distribution function is updated.

The new variable fbar is constructed as P0 so that this feature doesn't take up too much memory. I am pretty sure that fbar and f having different bases will not cause discritization errors, but I wouldn’t be surprised if it did.

I had to refactor gk_species_damping quite a lot because there were tons of if statements in the advance functions and the write function.

There are severe merge conflicts with #934, so I ultimately deprecated the loss cone damping term. I'm not using this, and no one else is running mirror simulations. If it's important in the future, we can always bring it back. This was implemented as one of the first ideas regarding pseudo-orbit averaging, which did not work as we intended.

Although this function does look like a BGK operator, we should keep the BGK collisions app seperate, while this term is used to damp oscillations. The damping properties of the low pass filter are why I put this in damping, not the bgk app.

Automated testing: rt_gk_wham_1x2v has included this as a term in its input file

Example Use

  struct gkyl_gyrokinetic_species elc = {
    ...
    .damping = {
      .type = GKYL_GK_DAMPING_LOW_PASS_FILTER,
      .rate_const = 1/1e-6, # Damps on a time scale of 1e-6 seconds
      .write_rate = true,
      .write_fbar = true,
    },
    ....
  },

Community Standards

  • Documentation has been updated.
  • My code follows the project's coding guidelines.
  • Changes to layer/zero should have a unit test, e.g., core/zero.

Testing:

  • I added a regression test to test this feature.
  • I added this feature to an existing regression test.
  • I added a unit test to test this feature.
  • Ran make check and unit tests all pass.
  • I ran the code with make valcheck, and it is clean.
  • I ran the code through computer-sanitizer on GPU, and it is clean.
  • I ran a few regression tests to ensure no apparent errors.
  • Tested and works on CPU.
  • Tested and works on multi-CPU.
  • Tested and works on GPU.
  • Tested and works on multi-GPU.

Additional Notes

gyrokinetic/creg/rt_gk_mirror_boltz_elc_poa_1x2v_p1.c and gyrokinetic/creg/rt_gk_mirror_boltz_elc_damping_1x2v_p1.c are valgrind clean, even with the resets and restoring fbar during different cycles.

Here is a simulation that used the low-pass filter using R=50 for the mirror ratio. I do notice that the time evolution is much slower in the density; however, in the temperatures, it can be quite rapid. Although rapid oscillations are strongly damped, they still occur. This simulation uses rate_const = 1/5e-6.
image

- Add low-pass filter damping type to gkyl_gyrokinetic_damping enum.
- Initialize filtered distribution function in gk_species_apply_ic.
- Implement damping initialization and calculation functions for low-pass filter.
- Update SSP RK3 integration to advance filtered distributions.
…e a ton of memory and computation on the updates
…me from someone using Vim in the gyrokinetic_multib_update_ssp_rk3. I fixed the spacing issues. I also found an issue with the implementation where the fbar was not being passed appropriately from ssprk3 down to the damping modules. Syntax is updated
…e conflicts with another PR and nobody is using this feature, as far as I know
…ving fbar having gkhyb basis will help with rapid oscillations in gradients of f, driving negativity
…cross resets and add configuration options

This was pretty difficult to figure out and make sure it's valgrind clean. The damping_release method needed to be circumvented, posing memory sanitization issues. This is valgrind clean with and without the flag. rt_gk_sheath_1x2v is also valgrind clean
@Maxwell-Rosen
Maxwell-Rosen marked this pull request as ready for review April 21, 2026 16:54
@Maxwell-Rosen
Maxwell-Rosen marked this pull request as draft April 21, 2026 19:11
@Maxwell-Rosen

Copy link
Copy Markdown
Collaborator Author

This will merge after the sundials branch. It heavily interacts with #996

@Antoinehoff Antoinehoff changed the title Add a low pass filter to GK Add a low pass time filter to GK Jul 24, 2026
…restarted as well from the file. Implement this

• Implemented fbar restart support.

  - Reads the matching damping_fbar frame file.
  - Synchronizes CPU/GPU state and SSP-RK stage arrays.
  - Supports single- and multi-block restarts.
  - Properly propagates missing/corrupt restart-file errors.
  - Falls back to restarted f when fbar output is disabled.

  Verified with reduced WHAM restart and Valgrind: 0 errors, 0 leaks. Build compiled and linked; only the sandbox-blocked external ADAS install copy failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DR] Low pass time filter in gyrokinetics

1 participant