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

(0.91.14) Extend Lagrangian advection to immersed grids and add tests #3765

Merged
merged 24 commits into from
Sep 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4b72263
extend lagrangian advection to all AbstractGrids
tomchor Sep 6, 2024
2334603
cleaner syntax
tomchor Sep 6, 2024
25d02a6
bugfix for immersed grids with flat dimensions
tomchor Sep 6, 2024
c37be12
add tests with immersed boundary grid
tomchor Sep 6, 2024
5e28d4b
oops, wrong topology
tomchor Sep 6, 2024
9634e51
convert immersed function to boolean output
tomchor Sep 6, 2024
abff491
simplify
tomchor Sep 9, 2024
e858e54
Merge branch 'main' into tc/ibg-tracking
tomchor Sep 9, 2024
97b197f
clean up logic
tomchor Sep 9, 2024
54b1dcf
Merge branch 'tc/ibg-tracking' of github.com:CliMA/Oceananigans.jl in…
tomchor Sep 9, 2024
8bcdef1
bump patch version
tomchor Sep 9, 2024
81ff38f
added docstring
tomchor Sep 9, 2024
6ac566a
Merge branch 'main' into tc/ibg-tracking
tomchor Sep 10, 2024
c786eaa
Merge branch 'main' into tc/ibg-tracking
tomchor Sep 11, 2024
31bec4e
correct indices
tomchor Sep 16, 2024
28171f6
Merge branch 'tc/ibg-tracking' of github.com:CliMA/Oceananigans.jl in…
tomchor Sep 16, 2024
1fd6833
add LatLonGrid to tests
tomchor Sep 18, 2024
17a5f89
Merge branch 'main' into tc/ibg-tracking
tomchor Sep 18, 2024
9635d03
write speed differently to try and avoid using too much parameter space
tomchor Sep 18, 2024
a06faf1
use only horizontal speed
tomchor Sep 18, 2024
f590acb
fix docs and convert code to doctest
tomchor Sep 18, 2024
65e76c0
add output to doctest
tomchor Sep 19, 2024
0cfe076
add filtering
tomchor Sep 19, 2024
2c53428
Merge branch 'main' into tc/ibg-tracking
tomchor Sep 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,26 @@ bouncing the particle off the immersed boundary with a coefficient or `restituti
X = flattened_node((x, y, z), ibg)

# Determine current particle cell
fi, fj, fk = fractional_indices(X, ibg.underlying_grid, (c, c, c))
fi, fj, fk = fractional_indices(X, ibg.underlying_grid, c, c, c)
i, j, k = truncate_fractional_indices(fi, fj, fk)

if immersed_cell(i, j, k, ibg)
# Determine whether particle was _previously_ in a non-immersed cell
i⁻, j⁻, k⁻ = previous_particle_indices

if !immersed_cell(i⁻, j⁻, k⁻, ibg)
# Left-right bounds of the previous, non-immersed cell
xᴿ, yᴿ, zᴿ = node(i⁻+1, j⁻+1, k⁻+1, ibg, f, f, f)
xᴸ, yᴸ, zᴸ = node(i⁻, j⁻, k⁻, ibg, f, f, f)
# Left-right bounds of the previous, non-immersed cell
xᴿ, yᴿ, zᴿ = node(i⁻ + 1, j⁻ + 1, k⁻ + 1, ibg, f, f, f)
xᴸ, yᴸ, zᴸ = node(i⁻, j⁻, k⁻, ibg, f, f, f)

Cʳ = restitution
x⁺ = enforce_boundary_conditions(Bounded(), x, xᴸ, xᴿ, Cʳ)
y⁺ = enforce_boundary_conditions(Bounded(), y, yᴸ, yᴿ, Cʳ)
z⁺ = enforce_boundary_conditions(Bounded(), z, zᴸ, zᴿ, Cʳ)

end
Cʳ = restitution
x⁺ = enforce_boundary_conditions(Bounded(), x, xᴸ, xᴿ, Cʳ)
y⁺ = enforce_boundary_conditions(Bounded(), y, yᴸ, yᴿ, Cʳ)
z⁺ = enforce_boundary_conditions(Bounded(), z, zᴸ, zᴿ, Cʳ)
else
x⁺, y⁺, z⁺ = x, y, z
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This part of the algorithm was failing so I had to change it. However, I'm not familiar with the lagrangian advection algorithm so I'm sure if this is the right way to do things. Can someone double-check this part? From what I can tell, @Jamie-Hilditch and @jagoosw were the main authors of this algorithm, so maybe we should hear from them also.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be cleaner todo

if immersed_cell
    ...
    return ...
else
    return x, y, z
end

But otherwise I agree this looks like it is needed.

Copy link
Collaborator

@simone-silvestri simone-silvestri Sep 6, 2024

Choose a reason for hiding this comment

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

you can also use an ifelse syntax to avoid branching:

xb⁺ = enforce_boundary_conditions(Bounded(), x, xᴸ, xᴿ, Cʳ)
yb⁺ = enforce_boundary_conditions(Bounded(), y, yᴸ, yᴿ, Cʳ)
zb⁺ = enforce_boundary_conditions(Bounded(), z, zᴸ, zᴿ, Cʳ)

immersed = immersed_cell(i, j, k, ibg)  

x⁺ = ifelse(immersed, xb⁺, x)
y⁺ = ifelse(immersed, yb⁺, y)
z⁺ = ifelse(immersed, zb⁺, z)

Copy link
Contributor

Choose a reason for hiding this comment

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

This part of the algorithm was failing so I had to change it. However, I'm not familiar with the lagrangian advection algorithm so I'm sure if this is the right way to do things. Can someone double-check this part? From what I can tell, @Jamie-Hilditch and @jagoosw were the main authors of this algorithm, so maybe we should hear from them also.

You've not really touched the couple of things I contributed so it looks good from my end.

end

return x⁺, y⁺, z⁺
return (x⁺, y⁺, z⁺)
end

"""
Expand Down Expand Up @@ -134,7 +133,7 @@ given `velocities`, time-step `Δt, and coefficient of `restitution`.
z⁺ = enforce_boundary_conditions(tz, z⁺, zᴸ, zᴿ, Cʳ)
if grid isa ImmersedBoundaryGrid
previous_particle_indices = current_particle_indices # particle has been advected
x⁺, y⁺, z⁺ = bounce_immersed_particle((x⁺, y⁺, z⁺), grid, Cʳ, previous_particle_indices)
(x⁺, y⁺, z⁺) = bounce_immersed_particle((x⁺, y⁺, z⁺), grid, Cʳ, previous_particle_indices)
end

return (x⁺, y⁺, z⁺)
Expand All @@ -145,11 +144,13 @@ end
# * Sphere metric for `LatitudeLongitudeGrid` and geographic coordinates
@inline x_metric(i, j, grid::RectilinearGrid) = 1
@inline x_metric(i, j, grid::LatitudeLongitudeGrid{FT}) where FT = @inbounds 1 / (grid.radius * hack_cosd(grid.φᵃᶜᵃ[j])) * FT(360 / 2π)
@inline x_metric(i, j, grid::ImmersedBoundaryGrid) = x_metric(i, j, grid.underlying_grid)

@inline y_metric(i, j, grid::RectilinearGrid) = 1
@inline y_metric(i, j, grid::LatitudeLongitudeGrid{FT}) where FT = 1 / grid.radius * FT(360 / 2π)
@inline y_metric(i, j, grid::ImmersedBoundaryGrid) = y_metric(i, j, grid.underlying_grid)

@kernel function _advect_particles!(particles, restitution, grid::AbstractUnderlyingGrid, Δt, velocities)
@kernel function _advect_particles!(particles, restitution, grid::AbstractGrid, Δt, velocities)
p = @index(Global)

@inbounds begin
Expand Down