Skip to content

Add a filter and upsampler to gk twist-shift bc - #1088

Draft
Antoinehoff wants to merge 41 commits into
mainfrom
gk_tsbc_filter_fix
Draft

Add a filter and upsampler to gk twist-shift bc#1088
Antoinehoff wants to merge 41 commits into
mainfrom
gk_tsbc_filter_fix

Conversation

@Antoinehoff

@Antoinehoff Antoinehoff commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

This PR is related to DR #1083 and gkylcas PR gkeyllorg/gkylcas#106

Modal filter application

For simplicity we apply the filter on each DG modal coefficient separately. This holds as long as the filter width is a multiple of the cell width. Since the basis elements follow the property

$$\psi_i^{(p)}(x)=\psi^{(p)}(x-x_j),$$

i.e. they are all the same except for a shift that center them in the middle of their respective cell $i$, the introduction of a shift[+] $k\Delta x$ yields[/+][-] which consist in a multiple of the cell width $k\Delta x$ yields[/-]

$$\psi_i^{(p)}(x - k \Delta x) = \psi^{(p)}(x-x_i - k\Delta x) = \psi^{(p)}(x-x_{k+i}) = \psi_{i+k}^{(p)}(x).$$

Consequently we can write

$$\phi(x - k\Delta x) = \sum_{i=1}^N \sum_{p=0}^{P} \phi_i^{(p)} \psi_{i+k}^{(p)}(x),$$

where we do not care about the $i+k>N$ limit for now (this can be resolved by a reflection at the boundary which preserves M0).
Now we see that the coefficient of order $q$ of the filtered DG rerpresentation in a cell $j$ is

$$\hat{\phi}_{j}^{(q)} = \int dx \hat{\phi}(x) \psi_j^{(q)}(x) = \sum_{k=-M}^{M} \hat{h}[k] \sum_{i=1}^N \sum_{p=0}^{P} \phi_i^{(p)} \int dx \psi_{i+k}^{(p)}(x)\psi_j^{(q)} = \sum_{k=-M}^{M} \hat{h}[k] \phi_{j-k}^{(q)}.$$

Caveat

The filter is done on the DG modal coefficients directly and cannot prevent oscillations smaller than the cell width. This is not a problem for our main application, twist-shift anti-aliasing, because we filter a field that is previously upscaled to a resolution expected to be large enough so that the twist-shift does not introduce grid scale mode.

Single mode example

We show here the example of a single two period $k_y$ mode as a "donor", the data that need to be twisted. Below, you see from left to right: i) the donor on the original resolution, ii) the shifted version of the donor on a 4x resolution (the truth), iii) the shifted version using the original Gkeyll TSBC, iv) the new Gkeyll TSBC that includes supersampling and filter.

image

In the original TSBC we see a reversed kx>0 wave appearing in the 2.4<x<3.0 region. This is the aliasing we want to get rid of. A finite perturbation remains at the border of the domain. This is part of the limit of a discrete filter capability. At the boundary, the filter cannot be applied entirely as it is applied to neighbors cells. Here we reflect the data to apply the filter but this causes a reduction of the damping capability.

The Fourier spectral analysis shows that the new TSBC is indeed removing that branch and mimics better the spectrum of the truth. The higher modes, rising from the shift, that cannot be resolved are simply dissipated similarly to some local GK codes (GS2, GENE, stella, Gyacomo).

image

Two mode example

We consider here a higher resolution and a two-mode input. The first mode is sheared outside of the resolution that can be resolved by the original grid. We see that the TSBC without anti-aliasing filter is presenting a checkerboard pattern while the anti-aliased version presents a much smoother wave, though boundary effects remain.

image image

manauref and others added 12 commits May 9, 2026 10:33
…there, then coarsen back to the original grid as an attempt to deal with aliasing. There are many inefficiencies right now, like interpolatig in the whole volume and declaring whole-volume buffers, rather than ones just 1-cell-in-z wide, but it's just a proof of principle right now. Reg test runs on CPU, not yet tested on GPU.
…, and down sampling in the twist and shift updater.
…wistshift is a boundary condition operator that runs now the whole process of the boundary condition, i.e. periodic -> upsample -> twist shift -> filter -> downsample. A new updater twistshift_dg is created to contain the "pure" twist-shift operations. It compiles but some program flow errors may remain in this commit and the GPU path is not ready yet.
…m per_sync in species. Remove related structure attributes.
…e sum(h_k) = 1 which conserves the first moment. No need to renormalize the stencil anymore.

We also add a new unit test for the twistshift bc updater where we verify that the filter filters, the upsampler upsamples and the trivial case returns trivially.
… at the boundary is not cropped but act on a reflexion of the data and this includes a change of sign of odd basis element coefficient that was missing.
… test in the ctest_bc_twistshift run. It seems that there was a possibility of an infinite while loop here but I am not 100% sure of what was happening. The original twistshift unit test is still passing.
…ssing on stellar CPU. We just verify the absolute error if the numbers are too small.
…h CPU and GPU. We remove the allocation of Bmag since it is unused and fix the evaluation of bmag at the end of the gk tests.
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.

2 participants