Add a filter and upsampler to gk twist-shift bc - #1088
Draft
Antoinehoff wants to merge 41 commits into
Draft
Conversation
…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.
…s 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.
… grid, not the supersampled one
… 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.
…o gk_tsbc_filter_fix
…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.
… weight=1 conserves the 0 mode but this is not equivalent to conserving the density number if we are not considering a periodic field. In IWL sim, x is not periodic, so this filter breaks particle conservation :( I need to see how to fix this.
…ve the conservation test for the bump when the stencil is truncated because it cannot conserve in this scenario.
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 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
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[/-]
Consequently we can write
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).$q$ of the filtered DG rerpresentation in a cell $j$ is
Now we see that the coefficient of order
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.
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).
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.