-
Notifications
You must be signed in to change notification settings - Fork 241
Small improvements to PerturbationAdvectionOpenBoundaryCondition
interface
#4394
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
Changes from 7 commits
93aea21
f454ce6
44a1544
29ac05a
a9a9b38
e438a01
5567f28
71d0c4a
40560f1
dc35ff0
b3234b9
3951467
3776a48
06f1dce
16c3e89
ae598c6
9daa752
004f420
b1519c4
a814987
5b45568
2ecdb37
dd4b0f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,15 +37,25 @@ struct PerturbationAdvection{VT, FT} | |
outflow_timescale :: FT | ||
end | ||
|
||
Adapt.adapt_structure(to, pe::PerturbationAdvection) = | ||
Adapt.adapt_structure(to, pe::PerturbationAdvection) = | ||
PerturbationAdvection(adapt(to, pe.backward_step), | ||
adapt(to, pe.inflow_timescale), | ||
adapt(to, pe.outflow_timescale)) | ||
|
||
function PerturbationAdvectionOpenBoundaryCondition(val, FT = Float64; | ||
""" | ||
PerturbationAdvectionOpenBoundaryCondition(val, FT = Float64; | ||
backward_step = true, | ||
outflow_timescale = Inf, | ||
inflow_timescale = 0.0, kwargs...) | ||
|
||
Creates a `PerturbationAdvectionOpenBoundaryCondition` with a given `outflow_timescale` and | ||
`inflow_timescale`. `backward_step` determines whether we assume a backward and forward time | ||
discretization. For details about this method, refer to the docstring for `PerturbationAdvection`. | ||
""" | ||
function PerturbationAdvectionOpenBoundaryCondition(val, FT = Float64; | ||
tomchor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
backward_step = true, | ||
outflow_timescale = Inf, | ||
inflow_timescale = 300.0, kwargs...) | ||
outflow_timescale = Inf, | ||
inflow_timescale = 0, kwargs...) | ||
tomchor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
classification = Open(PerturbationAdvection(Val(backward_step), inflow_timescale, outflow_timescale)) | ||
|
||
|
@@ -62,23 +72,18 @@ const FPAOBC = BoundaryCondition{<:Open{<:PerturbationAdvection{Val{false}}}} | |
@inline function step_right_boundary!(bc::BPAOBC, l, m, boundary_indices, boundary_adjacent_indices, | ||
grid, u, clock, model_fields, ΔX) | ||
Δt = clock.last_stage_Δt | ||
|
||
Δt = ifelse(isinf(Δt), 0, Δt) | ||
|
||
ūⁿ⁺¹ = getbc(bc, l, m, grid, clock, model_fields) | ||
|
||
uᵢⁿ = @inbounds getindex(u, boundary_indices...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jagoosw this isn't critical but I'd appreciate some clarity here. In your derivation you arrive at the equation
and from it, I understand that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we get the previous value of the boundary point since it hasn't been stepped yet so its still at the previous time step, and then put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, thanks for the clarification. Just to clarify even further, the way time-stepping works is that the interior of the flow is time-stepped first, then we do the boundaries? |
||
uᵢ₋₁ⁿ⁺¹ = @inbounds getindex(u, boundary_adjacent_indices...) | ||
|
||
U = max(0, min(1, Δt / ΔX * ūⁿ⁺¹)) | ||
|
||
pa = bc.classification.matching_scheme | ||
|
||
τ = ifelse(ūⁿ⁺¹ >= 0, pa.outflow_timescale, pa.inflow_timescale) | ||
|
||
τ̃ = Δt / τ | ||
|
||
uᵢⁿ⁺¹ = (uᵢⁿ + U * uᵢ₋₁ⁿ⁺¹ + ūⁿ⁺¹ * τ̃) / (1 + τ̃ + U) | ||
uᵢⁿ⁺¹ = isinf(τ̃) ? ūⁿ⁺¹ : (uᵢⁿ + U * uᵢ₋₁ⁿ⁺¹ + ūⁿ⁺¹ * τ̃) / (1 + τ̃ + U) | ||
tomchor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@inbounds setindex!(u, uᵢⁿ⁺¹, boundary_indices...) | ||
|
||
|
@@ -88,23 +93,18 @@ end | |
@inline function step_left_boundary!(bc::BPAOBC, l, m, boundary_indices, boundary_adjacent_indices, boundary_secret_storage_indices, | ||
grid, u, clock, model_fields, ΔX) | ||
Δt = clock.last_stage_Δt | ||
|
||
Δt = ifelse(isinf(Δt), 0, Δt) | ||
|
||
ūⁿ⁺¹ = getbc(bc, l, m, grid, clock, model_fields) | ||
|
||
uᵢⁿ = @inbounds getindex(u, boundary_secret_storage_indices...) | ||
uᵢ₋₁ⁿ⁺¹ = @inbounds getindex(u, boundary_adjacent_indices...) | ||
|
||
U = min(0, max(-1, Δt / ΔX * ūⁿ⁺¹)) | ||
|
||
pa = bc.classification.matching_scheme | ||
|
||
τ = ifelse(ūⁿ⁺¹ <= 0, pa.outflow_timescale, pa.inflow_timescale) | ||
|
||
τ̃ = Δt / τ | ||
|
||
tomchor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
u₁ⁿ⁺¹ = (uᵢⁿ - U * uᵢ₋₁ⁿ⁺¹ + ūⁿ⁺¹ * τ̃) / (1 + τ̃ - U) | ||
u₁ⁿ⁺¹ = isinf(τ̃) ? ūⁿ⁺¹ : (uᵢⁿ - U * uᵢ₋₁ⁿ⁺¹ + ūⁿ⁺¹ * τ̃) / (1 + τ̃ - U) | ||
tomchor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@inbounds setindex!(u, u₁ⁿ⁺¹, boundary_indices...) | ||
@inbounds setindex!(u, u₁ⁿ⁺¹, boundary_secret_storage_indices...) | ||
|
@@ -116,20 +116,15 @@ end | |
@inline function step_right_boundary!(bc::FPAOBC, l, m, boundary_indices, boundary_adjacent_indices, | ||
grid, u, clock, model_fields, ΔX) | ||
Δt = clock.last_stage_Δt | ||
|
||
Δt = ifelse(isinf(Δt), 0, Δt) | ||
|
||
ūⁿ⁺¹ = getbc(bc, l, m, grid, clock, model_fields) | ||
|
||
uᵢⁿ = @inbounds getindex(u, boundary_indices...) | ||
uᵢ₋₁ⁿ⁺¹ = @inbounds getindex(u, boundary_adjacent_indices...) | ||
|
||
U = max(0, min(1, Δt / ΔX * ūⁿ⁺¹)) | ||
|
||
pa = bc.classification.matching_scheme | ||
|
||
τ = ifelse(ūⁿ⁺¹ >= 0, pa.outflow_timescale, pa.inflow_timescale) | ||
|
||
τ̃ = Δt / τ | ||
|
||
uᵢⁿ⁺¹ = uᵢⁿ + U * (uᵢ₋₁ⁿ⁺¹ - ūⁿ⁺¹) + (ūⁿ⁺¹ - uᵢⁿ) * τ̃ | ||
|
@@ -142,20 +137,15 @@ end | |
@inline function step_left_boundary!(bc::FPAOBC, l, m, boundary_indices, boundary_adjacent_indices, boundary_secret_storage_indices, | ||
grid, u, clock, model_fields, ΔX) | ||
Δt = clock.last_stage_Δt | ||
|
||
Δt = ifelse(isinf(Δt), 0, Δt) | ||
|
||
ūⁿ⁺¹ = getbc(bc, l, m, grid, clock, model_fields) | ||
|
||
uᵢⁿ = @inbounds getindex(u, boundary_secret_storage_indices...) | ||
uᵢ₋₁ⁿ⁺¹ = @inbounds getindex(u, boundary_adjacent_indices...) | ||
|
||
U = min(0, max(-1, Δt / ΔX * ūⁿ⁺¹)) | ||
|
||
pa = bc.classification.matching_scheme | ||
|
||
τ = ifelse(ūⁿ⁺¹ <= 0, pa.outflow_timescale, pa.inflow_timescale) | ||
|
||
τ̃ = Δt / τ | ||
|
||
u₁ⁿ⁺¹ = uᵢⁿ - U * (uᵢ₋₁ⁿ⁺¹ - ūⁿ⁺¹) + (ūⁿ⁺¹ - uᵢⁿ) * τ̃ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the docstring doesn't describe what
val
is. I'm also confused, would a better name thanval
help?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val
is the exterior value of the normal valocity. The one we're relaxing the flow to (withinflow_timescale
during inflow and withoutflow_timescale
with during outflow). I agree it isn't a very intuitive name. Maybe justexterior_value
?