From f8f607a6f8635817c1321bb0599bdce1eaa9331f Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Tue, 1 Jun 2021 07:09:57 +1000 Subject: [PATCH 01/10] dealias before computing nonlinear terms --- src/twodnavierstokes.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/twodnavierstokes.jl b/src/twodnavierstokes.jl index 926b2512..2ec071ee 100644 --- a/src/twodnavierstokes.jl +++ b/src/twodnavierstokes.jl @@ -244,6 +244,8 @@ N = - \\widehat{𝖩(ψ, ΞΆ)} + FΜ‚ . ``` """ function calcN!(N, sol, t, clock, vars, params, grid) + dealias!(sol, g) + calcN_advection!(N, sol, t, clock, vars, params, grid) addforcing!(N, sol, t, clock, vars, params, grid) From 6e2d22d80fed3dbf4e1d16aaf188de2cd715c555 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Tue, 1 Jun 2021 07:14:29 +1000 Subject: [PATCH 02/10] proper dealias before computing nonlinear terms --- src/barotropicqgql.jl | 3 +++ src/multilayerqg.jl | 4 ++++ src/singlelayerqg.jl | 3 +++ src/surfaceqg.jl | 3 +++ src/twodnavierstokes.jl | 2 +- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/barotropicqgql.jl b/src/barotropicqgql.jl index 1e0aa513..6131f6ea 100644 --- a/src/barotropicqgql.jl +++ b/src/barotropicqgql.jl @@ -297,7 +297,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 diff --git a/src/multilayerqg.jl b/src/multilayerqg.jl index 4a6e50db..57f1a195 100644 --- a/src/multilayerqg.jl +++ b/src/multilayerqg.jl @@ -496,8 +496,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 diff --git a/src/singlelayerqg.jl b/src/singlelayerqg.jl index 0b9b4e13..d0e3c7ff 100644 --- a/src/singlelayerqg.jl +++ b/src/singlelayerqg.jl @@ -299,7 +299,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 diff --git a/src/surfaceqg.jl b/src/surfaceqg.jl index 39e13898..2618d132 100644 --- a/src/surfaceqg.jl +++ b/src/surfaceqg.jl @@ -230,7 +230,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 diff --git a/src/twodnavierstokes.jl b/src/twodnavierstokes.jl index 2ec071ee..4c6b2360 100644 --- a/src/twodnavierstokes.jl +++ b/src/twodnavierstokes.jl @@ -244,7 +244,7 @@ N = - \\widehat{𝖩(ψ, ΞΆ)} + FΜ‚ . ``` """ function calcN!(N, sol, t, clock, vars, params, grid) - dealias!(sol, g) + dealias!(sol, grid) calcN_advection!(N, sol, t, clock, vars, params, grid) From afad8059f9cc10bf1214c512192b16bc439288bc Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Tue, 1 Jun 2021 07:21:03 +1000 Subject: [PATCH 03/10] bumps version to 0.12.4 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 2c162e1d..1c09e0f3 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "GeophysicalFlows" uuid = "44ee3b1c-bc02-53fa-8355-8e347616e15e" license = "MIT" authors = ["Navid C. Constantinou ", "Gregory L. Wagner ", "and co-contributors"] -version = "0.12.3" +version = "0.12.4" [deps] CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" From cf3b8c94df8d6e87a1fb1b341a39c9ecbae2943e Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Tue, 1 Jun 2021 07:24:53 +1000 Subject: [PATCH 04/10] dealias in updatevars --- src/barotropicqgql.jl | 2 ++ src/multilayerqg.jl | 2 ++ src/singlelayerqg.jl | 2 ++ src/surfaceqg.jl | 2 ++ src/twodnavierstokes.jl | 2 ++ 5 files changed, 10 insertions(+) diff --git a/src/barotropicqgql.jl b/src/barotropicqgql.jl index 6131f6ea..6e1c9752 100644 --- a/src/barotropicqgql.jl +++ b/src/barotropicqgql.jl @@ -343,6 +343,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 diff --git a/src/multilayerqg.jl b/src/multilayerqg.jl index 57f1a195..63ceb999 100644 --- a/src/multilayerqg.jl +++ b/src/multilayerqg.jl @@ -647,6 +647,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 diff --git a/src/singlelayerqg.jl b/src/singlelayerqg.jl index d0e3c7ff..e4e3a690 100644 --- a/src/singlelayerqg.jl +++ b/src/singlelayerqg.jl @@ -358,6 +358,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 diff --git a/src/surfaceqg.jl b/src/surfaceqg.jl index 2618d132..1abc7921 100644 --- a/src/surfaceqg.jl +++ b/src/surfaceqg.jl @@ -278,6 +278,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 diff --git a/src/twodnavierstokes.jl b/src/twodnavierstokes.jl index 4c6b2360..8f408400 100644 --- a/src/twodnavierstokes.jl +++ b/src/twodnavierstokes.jl @@ -291,6 +291,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 From 577b2d258fea143bfddd72f820fc43c6745f3e80 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 4 Jun 2021 14:01:03 +1000 Subject: [PATCH 05/10] bumps FourierFlows.jl compat to ^0.7 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1c09e0f3..55bde3d7 100644 --- a/Project.toml +++ b/Project.toml @@ -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" JLD2 = "^0.1, ^0.2, ^0.3, ^0.4" Reexport = "^0.2, ^1" SpecialFunctions = "^0.10, ^1" From b1c8ca9db7f63cc13bc404070084edc34bcbb11c Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 4 Jun 2021 15:34:32 +1000 Subject: [PATCH 06/10] adds Docs/Aliasing --- docs/make.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/make.jl b/docs/make.jl index 98eaed09..5381ccd6 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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[ From 7f51f2dc5d0d12ac77125b85a4d7fa41de9e7433 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 4 Jun 2021 15:39:56 +1000 Subject: [PATCH 07/10] top-1/n -> highest-1/n --- docs/src/aliasing.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docs/src/aliasing.md diff --git a/docs/src/aliasing.md b/docs/src/aliasing.md new file mode 100644 index 00000000..bb011727 --- /dev/null +++ b/docs/src/aliasing.md @@ -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`. From f0b77a0a834b144147b59ce7c3012cedd718856e Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 4 Jun 2021 15:47:04 +1000 Subject: [PATCH 08/10] bumps FourierFlows.jl compat to ^0.7.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 55bde3d7..cbe3be91 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" CUDA = "^1, ^2.4.2, ^3.0" DocStringExtensions = "^0.8" FFTW = "^1" -FourierFlows = "^0.7" +FourierFlows = "^0.7.1" JLD2 = "^0.1, ^0.2, ^0.3, ^0.4" Reexport = "^0.2, ^1" SpecialFunctions = "^0.10, ^1" From 0e360651435973c6a693758905abe9e28b8bb9e2 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 4 Jun 2021 15:57:14 +1000 Subject: [PATCH 09/10] bumps version to 0.13.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index cbe3be91..aebfe298 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "GeophysicalFlows" uuid = "44ee3b1c-bc02-53fa-8355-8e347616e15e" license = "MIT" authors = ["Navid C. Constantinou ", "Gregory L. Wagner ", "and co-contributors"] -version = "0.12.4" +version = "0.13.0" [deps] CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" From 6e44b4d63f3f174cb0149b086899587ccc2e3b85 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 4 Jun 2021 16:03:48 +1000 Subject: [PATCH 10/10] bumps FourierFlows.jl compat to ^0.7.1 --- docs/Project.toml | 2 +- examples/Project.toml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index b9b3ef43..4867e3e2 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -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" diff --git a/examples/Project.toml b/examples/Project.toml index 4a247dff..619d5905 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -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" @@ -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"