Skip to content

Commit

Permalink
Merge pull request #246 from FourierFlows/ncc/proper-dealias
Browse files Browse the repository at this point in the history
Dealias `sol` before computing nonlinear terms
  • Loading branch information
navidcy authored Jun 4, 2021
2 parents c30c5a3 + 6e44b4d commit bf62e73
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "GeophysicalFlows"
uuid = "44ee3b1c-bc02-53fa-8355-8e347616e15e"
license = "MIT"
authors = ["Navid C. Constantinou <navidcy@gmail.com>", "Gregory L. Wagner <wagner.greg@gmail.com>", "and co-contributors"]
version = "0.12.3"
version = "0.13.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand All @@ -21,7 +21,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
CUDA = "^1, ^2.4.2, ^3.0"
DocStringExtensions = "^0.8"
FFTW = "^1"
FourierFlows = "^0.6.19"
FourierFlows = "^0.7.1"
JLD2 = "^0.1, ^0.2, ^0.3, ^0.4"
Reexport = "^0.2, ^1"
SpecialFunctions = "^0.10, ^1"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
FourierFlows = "≥ 0.6.17"
FourierFlows = "≥ 0.7.1"
Plots = "≥ 1.10.1"
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ sitename = "GeophysicalFlows.jl",
pages = Any[
"Home" => "index.md",
"Installation instructions" => "installation_instructions.md",
"Aliasing" => "aliasing.md",
"GPU" => "gpu.md",
"Examples" => [
"TwoDNavierStokes" => Any[
Expand Down
33 changes: 33 additions & 0 deletions docs/src/aliasing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Aliasing


In pseudospectral methods, computing nonlinear terms results in aliasing errors. (Read more about
aliasing errors in the [FourierFlows.jl Documentation](https://fourierflows.github.io/FourierFlowsDocumentation/stable/aliasing/).) To avoid aliasing errors, we need to apply some dealiasing to our fields
in Fourier space before transforming to physical space to compute nonlinear terms.

!!! info "De-aliasing scheme"
FourierFlows.jl curently implements dealiasing by zeroing out the highest-`aliased_fraction`
wavenumber components on a `grid`. By default in FourierFlows.jl, `aliased_fraction=1/3`.
Users can construct a grid with different `aliased_fraction`, e.g.,

```julia
julia> grid = OneDGrid(64, 2π, aliased_fraction=1/2)

julia> OneDimensionalGrid
├─────────── Device: CPU
├──────── FloatType: Float64
├────────── size Lx: 6.283185307179586
├──── resolution nx: 64
├── grid spacing dx: 0.09817477042468103
├─────────── domain: x ∈ [-3.141592653589793, 3.0434178831651124]
└─ aliased fraction: 0.5
```

Currently, all nonlinearities in all modules included in GeophysicalFlows.jl modules are quadratic
nonlinearities. Therefore, the default `aliased_fraction` of 1/3 is appropriate.

All modules apply de-aliasing by calling, e.g., `dealias!(prob.sol, prob.grid)` both before
computing any nonlinear terms and also during updating all variable, i.e., within `updatevars!`.

To disable de-aliasing you need to create a problem with a grid that has been constructed with
the keyword `aliased_fraction=0`.
3 changes: 1 addition & 2 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
FourierFlows = "2aec4490-903f-5c70-9b11-9bed06a700e1"
GeophysicalFlows = "44ee3b1c-bc02-53fa-8355-8e347616e15e"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand All @@ -10,5 +9,5 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
FourierFlows = "≥ 0.6.17"
FourierFlows = "≥ 0.7.1"
Plots = "≥ 1.10.1"
5 changes: 5 additions & 0 deletions src/barotropicqgql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ N = - \\widehat{𝖩(ψ, q+η)} + F̂ .
```
"""
function calcN!(N, sol, t, clock, vars, params, grid)
dealias!(sol, grid)

calcN_advection!(N, sol, t, clock, vars, params, grid)

addforcing!(N, sol, t, clock, vars, params, grid)

return nothing
Expand Down Expand Up @@ -373,6 +376,8 @@ end
Update the `vars` of a problem `prob` that has `grid` and `params` with the solution in `sol`.
"""
function updatevars!(sol, vars, params, grid)
dealias!(sol, grid)

CUDA.@allowscalar sol[1, 1] = 0
@. vars.zetah = sol
CUDA.@allowscalar @. vars.zetah[1, :] = 0
Expand Down
6 changes: 6 additions & 0 deletions src/multilayerqg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,12 @@ N_j = - \\widehat{𝖩(ψ_j, q_j)} - \\widehat{U_j ∂_x Q_j} - \\widehat{U_j
function calcN!(N, sol, t, clock, vars, params, grid)
nlayers = numberoflayers(params)

dealias!(sol, grid)

calcN_advection!(N, sol, vars, params, grid)

@views @. N[:, :, nlayers] += params.μ * grid.Krsq * vars.ψh[:, :, nlayers] # bottom linear drag

addforcing!(N, sol, t, clock, vars, params, grid)

return nothing
Expand Down Expand Up @@ -688,6 +692,8 @@ end
Update all problem variables using `sol`.
"""
function updatevars!(vars, params, grid, sol)
dealias!(sol, grid)

@. vars.qh = sol
streamfunctionfrompv!(vars.ψh, vars.qh, params, grid)
@. vars.uh = -im * grid.l * vars.ψh
Expand Down
5 changes: 5 additions & 0 deletions src/singlelayerqg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ N = - \\widehat{𝖩(ψ, q+η)} + F̂ .
```
"""
function calcN!(N, sol, t, clock, vars, params, grid)
dealias!(sol, grid)

calcN_advection!(N, sol, t, clock, vars, params, grid)

addforcing!(N, sol, t, clock, vars, params, grid)

return nothing
Expand Down Expand Up @@ -389,6 +392,8 @@ end
Update the variables in `vars` with the solution in `sol`.
"""
function updatevars!(sol, vars, params, grid)
dealias!(sol, grid)

@. vars.qh = sol
streamfunctionfrompv!(vars.ψh, vars.qh, params, grid)
@. vars.uh = -im * grid.l * vars.ψh
Expand Down
5 changes: 5 additions & 0 deletions src/surfaceqg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ N = - \\widehat{𝖩(ψ, b)} + F̂ .
```
"""
function calcN!(N, sol, t, clock, vars, params, grid)
dealias!(sol, grid)

calcN_advection!(N, sol, t, clock, vars, params, grid)

addforcing!(N, sol, t, clock, vars, params, grid)

return nothing
Expand Down Expand Up @@ -301,6 +304,8 @@ Update variables in `vars` with solution in `sol`.
function updatevars!(prob)
vars, grid, sol = prob.vars, prob.grid, prob.sol

dealias!(sol, grid)

@. vars.bh = sol
@. vars.uh = im * grid.l * sqrt(grid.invKrsq) * sol
@. vars.vh = - im * grid.kr * sqrt(grid.invKrsq) * sol
Expand Down
4 changes: 4 additions & 0 deletions src/twodnavierstokes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ N = - \\widehat{𝖩(ψ, ζ)} + F̂ .
```
"""
function calcN!(N, sol, t, clock, vars, params, grid)
dealias!(sol, grid)

calcN_advection!(N, sol, t, clock, vars, params, grid)

addforcing!(N, sol, t, clock, vars, params, grid)
Expand Down Expand Up @@ -319,6 +321,8 @@ Update variables in `vars` with solution in `sol`.
function updatevars!(prob)
vars, grid, sol = prob.vars, prob.grid, prob.sol

dealias!(sol, grid)

@. vars.ζh = sol
@. vars.uh = im * grid.l * grid.invKrsq * sol
@. vars.vh = - im * grid.kr * grid.invKrsq * sol
Expand Down

2 comments on commit bf62e73

@navidcy
Copy link
Member Author

@navidcy navidcy commented on bf62e73 Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38135

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.0 -m "<description of version>" bf62e730c16b7566852ef15e8c77f4c867f8c70f
git push origin v0.13.0

Please sign in to comment.