Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background zonal flow U or U(y) in the SingleLayerQG module #360

Merged
merged 39 commits into from
Jul 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
16bd801
Update singlelayerqg.jl to include background flow
mncrowe Jun 17, 2024
30178e1
Fixed typo in previous change
mncrowe Jun 17, 2024
4362a87
added background flow test
mncrowe Jun 27, 2024
76f1643
corrected typo
mncrowe Jun 27, 2024
4781b8d
Added some spaces to cheer up Greg
mncrowe Jun 27, 2024
eada586
more spaces
mncrowe Jun 27, 2024
cc1b78a
added variable U functionality
mncrowe Jul 22, 2024
e756aa1
Merge branch 'main' into main
mncrowe Jul 22, 2024
3ce3abd
reduced memory of Uy assignment and updated function descriptions
mncrowe Jul 22, 2024
8641abe
Merge branch 'main' of https://github.com/mncrowe/GeophysicalFlows.jl
mncrowe Jul 22, 2024
9bd7576
update function descriptions
mncrowe Jul 22, 2024
f0baf3f
T(U) -> convert(T, U)
mncrowe Jul 22, 2024
deea626
clarify U array formulation
mncrowe Jul 22, 2024
f351da2
fix bug with previous push
mncrowe Jul 22, 2024
8c1859f
add additional test function for U as an Array and include tests in
mncrowe Jul 23, 2024
dd93d22
simplify background U and use Rossby wave test for U that does not va…
navidcy Jul 27, 2024
122b713
homogenize notation/docs
navidcy Jul 27, 2024
ab0fe02
bump patch release
navidcy Jul 27, 2024
dd3c1ad
Merge remote-tracking branch 'upstream/main'
navidcy Jul 27, 2024
85d4393
fix test for gpu
navidcy Jul 27, 2024
619f398
== -> ===
navidcy Jul 27, 2024
ace06eb
use different calcN_advection! methods for U const and y-varying
navidcy Jul 27, 2024
2fcccc7
minor tweaks
navidcy Jul 27, 2024
20a361b
update singlelayergq module in docs
navidcy Jul 27, 2024
346f914
homogenize notation/wording
navidcy Jul 27, 2024
e6e7707
add empty line
navidcy Jul 28, 2024
73399f0
code alignment
navidcy Jul 28, 2024
99eb5ff
add Qx and Qy in params; refactor calcN_advection
navidcy Jul 28, 2024
6604120
clarify when U=const
navidcy Jul 28, 2024
f387333
some fixes + cleanup
navidcy Jul 28, 2024
40cc4db
add nonlinear advection test for finite deformation + topo
navidcy Jul 28, 2024
63a7a8c
fixes nonlinear advection w U(y) + add tests
navidcy Jul 28, 2024
6430e59
add comment for β term
navidcy Jul 28, 2024
48f2f1b
remove debug statements + fix test for julia 1.6
navidcy Jul 28, 2024
42d9003
more tests for the nonlinear terms
navidcy Jul 28, 2024
22e3bde
fix test_1layerqg_nonlinearadvection on gpu
navidcy Jul 28, 2024
c6cf36a
fix test_1layerqg_nonlinearadvection on gpu
navidcy Jul 28, 2024
5c9eb93
improve docs
navidcy Jul 28, 2024
1d2509f
drop GeophysicalFlows from docs/Project.toml
navidcy Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions src/singlelayerqg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ function Problem(dev::Device=CPU();
# topographic PV
eta === nothing && (eta = zeros(dev, T, (nx, ny)))

params = deformation_radius == Inf ? BarotropicQGParams(grid, T(β), T(U), eta, T(μ), T(ν), nν, calcF) : EquivalentBarotropicQGParams(grid, T(β), T(deformation_radius), T(U), eta, T(μ), T(ν), nν, calcF)
if U isa Number
U = T(U)
mncrowe marked this conversation as resolved.
Show resolved Hide resolved
else
U = device_array(dev)(reshape(U,(1, grid.ny)))
navidcy marked this conversation as resolved.
Show resolved Hide resolved
end

params = deformation_radius == Inf ? BarotropicQGParams(grid, T(β), U, eta, T(μ), T(ν), nν, calcF) : EquivalentBarotropicQGParams(grid, T(β), T(deformation_radius), U, eta, T(μ), T(ν), nν, calcF)

vars = calcF == nothingfunction ? DecayingVars(grid) : (stochastic ? StochasticForcedVars(grid) : ForcedVars(grid))

Expand Down Expand Up @@ -135,7 +141,7 @@ struct Params{T, Aphys, Atrans, ℓ} <: SingleLayerQGParams
"Rossby radius of deformation"
deformation_radius :: ℓ
"Background flow in x direction"
U :: T
U :: Union{T, Aphys}
"topographic potential vorticity"
eta :: Aphys
"Fourier transform of topographic potential vorticity"
Expand Down Expand Up @@ -172,7 +178,7 @@ Return the parameters for a Barotropic QG problem (i.e., with infinite Rossby ra
"""
BarotropicQGParams(grid::AbstractGrid, β, U, eta, μ, ν, nν::Int, calcF) =
EquivalentBarotropicQGParams(grid, β, nothing, U, eta, μ, ν, nν, calcF)


# ---------
# Equations
Expand All @@ -192,7 +198,14 @@ L = - μ - ν |𝐤|^{2 n_ν} + i β k_x / |𝐤|² - i U k_x .
The nonlinear term is computed via `calcN!` function.
"""
function Equation(params::BarotropicQGParams, grid::AbstractGrid)
L = @. - params.μ - params.ν * grid.Krsq^params.nν + im * params.β * grid.kr * grid.invKrsq - im * params.U * grid.kr

if params.U isa Number
U₀ = params.U
else
U₀ = 0.0
end

L = @. - params.μ - params.ν * grid.Krsq^params.nν + im * params.β * grid.kr * grid.invKrsq - im * U₀ * grid.kr
CUDA.@allowscalar L[1, 1] = 0

return FourierFlows.Equation(L, calcN!, grid)
Expand All @@ -212,7 +225,14 @@ L = -μ - ν |𝐤|^{2 n_ν} + i β k_x / (|𝐤|² + 1/ℓ²) - i U k_x .
The nonlinear term is computed via `calcN!` function.
"""
function Equation(params::EquivalentBarotropicQGParams, grid::AbstractGrid)
L = @. - params.μ - params.ν * grid.Krsq^params.nν + im * params.β * grid.kr / (grid.Krsq + 1 / params.deformation_radius^2) - im * params.U * grid.kr

if params.U isa Number
U₀ = params.U
else
U₀ = 0.0
end

L = @. - params.μ - params.ν * grid.Krsq^params.nν + im * params.β * grid.kr / (grid.Krsq + 1 / params.deformation_radius^2) - im * U₀ * grid.kr
CUDA.@allowscalar L[1, 1] = 0

return FourierFlows.Equation(L, calcN!, grid)
Expand Down Expand Up @@ -319,6 +339,7 @@ N = - \\widehat{𝖩(ψ, q + η)} = - i k_x \\widehat{u (q + η)} - i k_y \\wide
```
"""
function calcN_advection!(N, sol, t, clock, vars, params, grid)

@. vars.qh = sol
streamfunctionfrompv!(vars.ψh, vars.qh, params, grid)
@. vars.uh = -im * grid.l * vars.ψh
Expand All @@ -328,17 +349,30 @@ function calcN_advection!(N, sol, t, clock, vars, params, grid)
ldiv!(vars.u, grid.rfftplan, vars.uh)
ldiv!(vars.v, grid.rfftplan, vars.vh)

uq_plus_η = vars.u # use vars.u as scratch variable
@. uq_plus_η *= vars.q + params.eta # u * (q + η)
vq_plus_η = vars.v # use vars.v as scratch variable
@. vq_plus_η *= vars.q + params.eta # v * (q + η)
if params.U isa Number

uq_plus_η = vars.u # use vars.u as scratch variable
@. uq_plus_η *= vars.q + params.eta # u * (q + η)
vq_plus_η = vars.v # use vars.v as scratch variable
@. vq_plus_η *= vars.q + params.eta # v * (q + η)

else

Q = params.eta .- real.(ifft(im * grid.l .* fft(U))) # PV background (η - ∂U/∂y)

uq_plus_η = vars.u .+ U # use vars.u as scratch variable
@. uq_plus_η *= vars.q + Q # (u + U) * (q + η - ∂U/∂y)
vq_plus_η = vars.v # use vars.v as scratch variable
@. vq_plus_η *= vars.q + Q # v * (q + η - ∂U/∂y)

end

uq_plus_ηh = vars.uh # use vars.uh as scratch variable
mul!(uq_plus_ηh, grid.rfftplan, uq_plus_η) # \hat{u * (q + η)}
vq_plus_ηh = vars.vh # use vars.vh as scratch variable
mul!(vq_plus_ηh, grid.rfftplan, vq_plus_η) # \hat{v * (q + η)}
uq_plus_ηh = vars.uh # use vars.uh as scratch variable
mul!(uq_plus_ηh, grid.rfftplan, uq_plus_η) # \hat{(u + U) * (q + η - ∂U/∂y)}
vq_plus_ηh = vars.vh # use vars.vh as scratch variable
mul!(vq_plus_ηh, grid.rfftplan, vq_plus_η) # \hat{v * (q + η - ∂U/∂y)}

@. N = -im * grid.kr * uq_plus_ηh - im * grid.l * vq_plus_ηh # - ∂[u*(q+η)]/∂x - ∂[v*(q+η)]/∂y
@. N = -im * grid.kr * uq_plus_ηh - im * grid.l * vq_plus_ηh # - ∂[(u+U)*(q+η-∂U/∂y)]/∂x - ∂[v*(q+η-∂U/∂y)]/∂y

return nothing
end
Expand Down