Skip to content

Commit

Permalink
Allow divergent Lagrangian-mean velocity by subtracting Stokes drift …
Browse files Browse the repository at this point in the history
…before pressure correction
  • Loading branch information
glwagner committed Dec 18, 2024
1 parent ac86c3a commit 0fc5708
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
42 changes: 39 additions & 3 deletions src/Models/NonhydrostaticModels/pressure_correction.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
import Oceananigans.TimeSteppers: calculate_pressure_correction!, pressure_correct_velocities!

const c = Center()
const f = Face()

using Oceananigans.Grids: node
using Oceananigans.StokesDrifts: StokesDrift, parameters_tuple

function modulate_by_stokes_drift!(model, sgn, t=time(model))
stokes_drift = model.stokes_drift
if stokes_drift isa StokesDrift
grid = model.grid
arch = architecture(grid)
u, v, w = model.velocities
launch!(arch, grid, :xyz, _modulate_by_stokes_drift, u, v, w, sgn, grid, t, stokes_drift)
end
return nothing
end

@kernel function _modulate_by_stokes_drift(u, v, w, sgn, grid, time, sd)
i, j, k = @index(Global, NTuple)

pt = parameters_tuple(sd)
Xu = node(i, j, k, grid, f, c, c)
Xv = node(i, j, k, grid, c, f, c)
Xw = node(i, j, k, grid, c, c, f)

@inbounds begin
u[i, j, k] = u[i, j, k] + sgn * sd.(Xu..., time, pt...)
v[i, j, k] = v[i, j, k] + sgn * sd.(Xv..., time, pt...)
w[i, j, k] = w[i, j, k] + sgn * sd.(Xw..., time, pt...)
end
end

subtract_stokes_drift!(model, t=time(model)) = modulate_by_stokes_drift!(model, -1, t)
add_stokes_drift!(model, t=time(model)) = modulate_by_stokes_drift!(model, +1, t)

"""
calculate_pressure_correction!(model::NonhydrostaticModel, Δt)
Calculate the (nonhydrostatic) pressure correction associated `tendencies`, `velocities`, and step size `Δt`.
"""
function calculate_pressure_correction!(model::NonhydrostaticModel, Δt)

subtract_stokes_drift!(model)

# Mask immersed velocities
foreach(mask_immersed_field!, model.velocities)

fill_halo_regions!(model.velocities, model.clock, fields(model))

solve_for_pressure!(model.pressures.pNHS, model.pressure_solver, Δt, model.velocities)

fill_halo_regions!(model.pressures.pNHS)

add_stokes_drift!(model, time(model) + Δt)

return nothing
end

Expand Down
20 changes: 15 additions & 5 deletions src/StokesDrifts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ using Oceananigans.Operators
using Oceananigans.Grids: AbstractGrid, node
using Oceananigans.Utils: prettysummary

using KernelAbstractions: @kernel, @index

import Adapt: adapt_structure

#####
Expand Down Expand Up @@ -148,7 +150,10 @@ const c = Center()
@inline z_curl_Uˢ_cross_U(i, j, k, grid, sw::USDnoP, U, time) = (- ℑxzᶜᵃᶠ(i, j, k, grid, U.u) * sw.∂z_uˢ(znode(k, grid, f), time)
- ℑyzᵃᶜᶠ(i, j, k, grid, U.v) * sw.∂z_vˢ(znode(k, grid, f), time))

struct StokesDrift{P, VX, WX, UY, WY, UZ, VZ, UT, VT, WT}
struct StokesDrift{P, US, VS, WS, VX, WX, UY, WY, UZ, VZ, UT, VT, WT}
:: US
:: VS
:: WS
∂x_vˢ :: VX
∂x_wˢ :: WX
∂y_uˢ :: UY
Expand All @@ -161,7 +166,10 @@ struct StokesDrift{P, VX, WX, UY, WY, UZ, VZ, UT, VT, WT}
parameters :: P
end

adapt_structure(to, sd::StokesDrift) = StokesDrift(adapt(to, sd.∂x_vˢ),
adapt_structure(to, sd::StokesDrift) = StokesDrift(adapt(to, sd.uˢ),
adapt(to, sd.vˢ),
adapt(to, sd.wˢ),
adapt(to, sd.∂x_wˢ),
adapt(to, sd.∂x_wˢ),
adapt(to, sd.∂y_uˢ),
adapt(to, sd.∂y_wˢ),
Expand Down Expand Up @@ -283,7 +291,10 @@ StokesDrift{Nothing}:
└── ∂t_wˢ: ∂t_wˢ
```
"""
function StokesDrift(; ∂x_vˢ = zerofunction,
function StokesDrift(; uˢ = zerofunction,
= zerofunction,
= zerofunction,
∂x_vˢ = zerofunction,
∂x_wˢ = zerofunction,
∂y_uˢ = zerofunction,
∂y_wˢ = zerofunction,
Expand All @@ -294,7 +305,7 @@ function StokesDrift(; ∂x_vˢ = zerofunction,
∂t_wˢ = zerofunction,
parameters = nothing)

return StokesDrift(∂x_vˢ, ∂x_wˢ, ∂y_uˢ, ∂y_wˢ, ∂z_uˢ, ∂z_vˢ, ∂t_uˢ, ∂t_vˢ, ∂t_wˢ, parameters)
return StokesDrift(uˢ, vˢ, wˢ, ∂x_vˢ, ∂x_wˢ, ∂y_uˢ, ∂y_wˢ, ∂z_uˢ, ∂z_vˢ, ∂t_uˢ, ∂t_vˢ, ∂t_wˢ, parameters)
end

const SD = StokesDrift
Expand Down Expand Up @@ -325,7 +336,6 @@ const SDnoP = StokesDrift{<:Nothing}
return wᶠᶜᶜ * (∂z_uˢ - ∂x_wˢ) - vᶠᶜᶜ * (∂x_vˢ - ∂y_uˢ)
end


@inline function y_curl_Uˢ_cross_U(i, j, k, grid, sw::SD, U, time)
wᶜᶠᶜ = ℑyzᵃᶠᶜ(i, j, k, grid, U.w)
uᶜᶠᶜ = ℑxyᶜᶠᵃ(i, j, k, grid, U.u)
Expand Down

0 comments on commit 0fc5708

Please sign in to comment.