Skip to content

Commit a26ed3a

Browse files
authored
Merge pull request #356 from FourierFlows/ncc/docs-visit
Adds comparison of filter for different `order` parameter
2 parents 270c41d + 2bb7ffd commit a26ed3a

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using
99
##### Generate examples
1010
#####
1111

12-
@show bib_filepath = joinpath(@__DIR__, "src/references.bib")
12+
bib_filepath = joinpath(@__DIR__, "src/references.bib")
1313
bib = CitationBibliography(bib_filepath)
1414

1515
const EXAMPLES_DIR = joinpath(@__DIR__, "..", "examples")

docs/src/timestepping.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,46 @@ For example, `"RK4"` for the Runge-Kutta 4th-order time stepper.
1616
Most of the time steppers also come with their `Filtered` equivalents: [`FilteredForwardEulerTimeStepper`](@ref), [`FilteredAB3TimeStepper`](@ref), [`FilteredRK4TimeStepper`](@ref), [`FilteredLSRK54TimeStepper`](@ref), and [`FilteredETDRK4TimeStepper`](@ref).
1717

1818
The filtered time steppers apply a high-wavenumber filter to the solution at the end of each step.
19-
The motivation behind filtering is to remove enstrophy accumulating at high wavenumbers and creating
20-
noise at grid-scale level.
19+
The motivation behind filtering is to preclude enstrophy from accumulating at high wavenumbers and
20+
creating noise at grid-scale level.
2121

22-
The high-wavenumber filter used in the filtered timesteppers is:
22+
The high-wavenumber filter used in the filtered time steppers is:
2323

2424
```math
2525
\mathrm{filter}(\boldsymbol{k}) =
26-
\begin{cases}
27-
1 & \quad |\boldsymbol{k}| ≤ k_{\textrm{cutoff}} \, ,\\
28-
\exp{ \left [- \alpha (|\boldsymbol{k}| - k_{\textrm{cutoff}})^p \right]} & \quad |\boldsymbol{k}| > k_{\textrm{cutoff}} \, .
29-
\end{cases}
26+
\begin{cases}
27+
1 & \quad |\boldsymbol{k}| ≤ k_{\textrm{cutoff}} \, ,\\
28+
\exp{ \left [- \alpha (|\boldsymbol{k}| - k_{\textrm{cutoff}})^p \right]} & \quad |\boldsymbol{k}| > k_{\textrm{cutoff}} \, .
29+
\end{cases}
3030
```
3131

32-
For fluid equations with quadratic non-linearities it makes sense to choose a cutoff wavenumber
33-
at 2/3 of the highest wavenumber resolved in our domain, ``k_{\textrm{cutoff}} = \tfrac{2}{3} k_{\textrm{max}}`` (see discussion in [Aliasing section](@ref aliasing)).
32+
For fluid equations with quadratic non-linearities it makes sense to choose a cut-off wavenumber
33+
at 2/3 of the highest wavenumber that is resolved in our domain,
34+
``k_{\textrm{cutoff}} = \tfrac{2}{3} k_{\textrm{max}}`` (see discussion in [Aliasing section](@ref aliasing)).
3435

35-
Given the order ``p``, we calculate the coefficient ``\alpha`` so that the the filter value
36-
that corresponds to the highest allowed wavenumber in our domain is a small value, ``\delta``,
37-
taken to be close to machine precision.
38-
39-
That is:
36+
Given the order ``p``, we choose coefficient ``\alpha`` so that the filter value that corresponds
37+
to the highest allowed wavenumber in our domain is a small number ``\delta``, usually taken to be
38+
close to machine precision. That is:
4039

4140
```math
4241
\alpha = \frac{- \log\delta}{(k_{\textrm{max}} - k_{\textrm{cutoff}})^p} \ .
4342
```
4443

45-
The above filter originates from the book by [Canuto-etal-1987](@cite). In geophysical turbulence
46-
applications it was used by [LaCasce-1996](@cite) and later by [Arbic-Flierl-2004](@cite).
44+
The above-mentioned filter form originates from the book by [Canuto-etal-1987](@cite).
45+
In geophysical turbulence applications it was used by [LaCasce-1996](@cite) and later
46+
by [Arbic-Flierl-2004](@cite).
47+
48+
!!! warning "Not too steep, not too shallow"
49+
Care should be taken if one decides to fiddle with the filter parameters. Changing
50+
the order ``p`` affects how steeply the filter falls off. Lower order values imply
51+
that the filter might fall off too quickly and may lead to Gibbs artifacts; higher
52+
order value implies that the filter might fall off too slow and won't suffice to
53+
remove enstrophy accumulating at the grid scale.
4754

48-
Using the default parameters provided by the filtered time steppers (see
49-
[`FourierFlows.makefilter`](@ref)), the filter has the following form:
55+
The filter using the default parameters provided by the filtered time steppers (see
56+
[`FourierFlows.makefilter`](@ref)) is depicted below. The same plot also compares how
57+
the filter changes when we vary the order parameter ``p`` while keeping everything
58+
else the same.
5059

5160
```@setup 1
5261
using CairoMakie
@@ -55,16 +64,21 @@ set_theme!(Theme(linewidth = 3, fontsize = 20))
5564
```
5665

5766
```@example 1
58-
using FourierFlows, CairoMakie
59-
60-
K = 0:0.01:1 # non-dimensional wavenumber k * dx / π
67+
using CairoMakie
68+
using FourierFlows: makefilter
6169
62-
filter = FourierFlows.makefilter(K)
70+
K = 0:0.001:1 # non-dimensional wavenumber k * dx / π
6371
6472
fig = Figure()
65-
ax = Axis(fig[1, 1], xlabel = "k dx / π", ylabel = "filter", aspect=2.5, xticks=0:0.2:1)
73+
ax = Axis(fig[1, 1], xlabel = "|𝐤| dx / π", ylabel = "filter", aspect=2.5, xticks=0:0.2:1)
74+
75+
vlines!(ax, 2/3, color = (:gray, 0.4), linewidth = 6, label = "cutoff wavenumber |𝐤| dx / π = 2/3 (default)")
76+
77+
lines!(ax, K, makefilter(K), linewidth = 4, label = "order 4 (default)")
78+
lines!(ax, K, makefilter(K, order = 1), linestyle = :dash, label = "order 1")
79+
lines!(ax, K, makefilter(K, order = 10), linestyle = :dot, label = "order 10")
6680
67-
lines!(ax, K, filter)
81+
axislegend(position = :lb)
6882
6983
current_figure() # hide
7084
```

src/domains.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ one-dimensional grid, the non-dimensional wavenumber `K` is
485485
K = k * dx / π
486486
```
487487
488-
and thus it takes values `K` ``[-1, 1]``.
488+
and thus take values in ``[-1, 1]``.
489489
490490
For `K ≤ innerK` the filter is inactive, i.e., equal to 1. For `K > innerK`,
491491
the filter decays exponentially to remove high-wavenumber content from
@@ -495,8 +495,9 @@ the solution, i.e.,
495495
filter(K) = exp(- decay * (K - innerK)^order)
496496
```
497497
498-
For a given `order` and , the `decay` rate is determined so that the filter value at the
499-
outer wavenumber `outerK` is `tol`, where `tol` is a small number, close to machine precision.
498+
For a given `order`, the `decay` rate is determined so that the filter value at the
499+
outer wavenumber `outerK` is `tol`, where `tol` is a small number, close to machine
500+
precision.
500501
501502
```julia
502503
decay = - log(tol) / (outerK - innerK)^order

0 commit comments

Comments
 (0)