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

Invoke mask_immersed_field! when converting args for Makie #3725

Merged
merged 11 commits into from
Aug 25, 2024

Conversation

glwagner
Copy link
Member

@navidcy I think you can use this in the internal tide example?

@navidcy navidcy self-requested a review August 24, 2024 22:10
Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

lgtm!

only minor thing is that we need to call mask_immersed_field!(f, NaN) in three different places... bit trickier to modify if needed.

we could be calling it within flattened_cpu_interior but the method name doesn't suggest that... if you think of a way to improve do it!

@navidcy
Copy link
Collaborator

navidcy commented Aug 24, 2024

@navidcy navidcy changed the title Invoke mask_immersed_field! when converting args for Makie Invoke mask_immersed_field! when converting args for Makie Aug 24, 2024
@glwagner
Copy link
Member Author

we could be calling it within flattened_cpu_interior but the method name doesn't suggest that... if you think of a way to improve do it!

Good idea. Find a new name for the function! What it does:

  1. Drops singleton dimensions
  2. Converts from CPU to GPU
  3. masks immersed regions with NaN

Perhaps simple convert_field, because in the context of the extension "convert" means to change an argument from the input into something plottable. Or perhaps make_plottable_field(f)

@navidcy
Copy link
Collaborator

navidcy commented Aug 25, 2024

I'm tempted to merge this. But I don't understand why the code snippet below is not working:

Look:

using Oceananigans, CairoMakie

underlying_grid = RectilinearGrid(size = (250, 125),
                                  x = (-1000e3, 1000e3),
                                  z = (-2e3, 0),
                                  halo = (4, 4),
                                  topology = (Periodic, Flat, Bounded))

bottom(x) = - underlying_grid.Lz + 500 * exp(-x^2 / (2*(20e3)^2))

grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))

lines(grid.immersed_boundary.bottom_height)

gives:

fig1

which is all good! But:

x, y, z = nodes(grid.immersed_boundary.bottom_height)

lines(x, grid.immersed_boundary.bottom_height)

fig2

Perhaps this is a bit informative

lines(x/1e3, grid.immersed_boundary.bottom_height)

fig3

@navidcy
Copy link
Collaborator

navidcy commented Aug 25, 2024

Hm...

julia> using Oceananigans, CairoMakie

julia> underlying_grid = RectilinearGrid(size = (250, 125),
                                         x = (-1000e3, 1000e3),
                                         z = (-2e3, 0),
                                         halo = (4, 4),
                                         topology = (Periodic, Flat, Bounded));

julia> bottom(x) = - underlying_grid.Lz + 500 * exp(-x^2 / (2*(20e3)^2));

julia> grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom));

julia> c = Field{Center, Nothing, Nothing}(grid)
250×1×1 Field{Center, Nothing, Nothing} reduced over dims = (2, 3) on ImmersedBoundaryGrid on CPU
├── grid: 250×1×125 ImmersedBoundaryGrid{Float64, Periodic, Flat, Bounded} on CPU with 4×0×4 halo
├── boundary conditions: FieldBoundaryConditions
│   └── west: Periodic, east: Periodic, south: Nothing, north: Nothing, bottom: Nothing, top: Nothing, immersed: ZeroFlux
└── data: 258×1×1 OffsetArray(::Array{Float64, 3}, -3:254, 1:1, 1:1) with eltype Float64 with indices -3:254×1:1×1:1
    └── max=0.0, min=0.0, mean=0.0

julia> set!(c, rand())
250×1×1 Field{Center, Nothing, Nothing} reduced over dims = (2, 3) on ImmersedBoundaryGrid on CPU
├── grid: 250×1×125 ImmersedBoundaryGrid{Float64, Periodic, Flat, Bounded} on CPU with 4×0×4 halo
├── boundary conditions: FieldBoundaryConditions
│   └── west: Periodic, east: Periodic, south: Nothing, north: Nothing, bottom: Nothing, top: Nothing, immersed: ZeroFlux
└── data: 258×1×1 OffsetArray(::Array{Float64, 3}, -3:254, 1:1, 1:1) with eltype Float64 with indices -3:254×1:1×1:1
    └── max=0.952381, min=0.952381, mean=0.952381

julia> lines(c)

julia> c
250×1×1 Field{Center, Nothing, Nothing} reduced over dims = (2, 3) on ImmersedBoundaryGrid on CPU
├── grid: 250×1×125 ImmersedBoundaryGrid{Float64, Periodic, Flat, Bounded} on CPU with 4×0×4 halo
├── boundary conditions: FieldBoundaryConditions
│   └── west: Periodic, east: Periodic, south: Nothing, north: Nothing, bottom: Nothing, top: Nothing, immersed: ZeroFlux
└── data: 258×1×1 OffsetArray(::Array{Float64, 3}, -3:254, 1:1, 1:1) with eltype Float64 with indices -3:254×1:1×1:1
    └── max=NaN, min=NaN, mean=NaN

After plotting a field then it has NaNs. Is this OK?
Of course, we expect that because we masked it in immersed regions. Is the issue here the show method? Should it be ignoring immersed regions?

ext/OceananigansMakieExt.jl Outdated Show resolved Hide resolved
ext/OceananigansMakieExt.jl Outdated Show resolved Hide resolved
ext/OceananigansMakieExt.jl Outdated Show resolved Hide resolved
@glwagner
Copy link
Member Author

glwagner commented Aug 25, 2024

Is the issue here the show method? Should it be ignoring immersed regions?

Yes, that's a bug. Hopefully @simone-silvestri can help who designed the conditional reductions

@glwagner
Copy link
Member Author

I'm tempted to merge this. But I don't understand why the code snippet below is not working:

Look:

using Oceananigans, CairoMakie

underlying_grid = RectilinearGrid(size = (250, 125),
                                  x = (-1000e3, 1000e3),
                                  z = (-2e3, 0),
                                  halo = (4, 4),
                                  topology = (Periodic, Flat, Bounded))

bottom(x) = - underlying_grid.Lz + 500 * exp(-x^2 / (2*(20e3)^2))

grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))

lines(grid.immersed_boundary.bottom_height)

gives:

fig1

which is all good! But:

x, y, z = nodes(grid.immersed_boundary.bottom_height)

lines(x, grid.immersed_boundary.bottom_height)

fig2

Perhaps this is a bit informative

lines(x/1e3, grid.immersed_boundary.bottom_height)

fig3

Can you check whether this behavior is actually changed by this PR? It seems like maybe this would have happened before this PR anyways.

navidcy and others added 4 commits August 26, 2024 06:48
Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>
Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>
Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>
@navidcy
Copy link
Collaborator

navidcy commented Aug 25, 2024

I'm tempted to merge this. But I don't understand why the code snippet below is not working:
Look:

using Oceananigans, CairoMakie

underlying_grid = RectilinearGrid(size = (250, 125),
                                  x = (-1000e3, 1000e3),
                                  z = (-2e3, 0),
                                  halo = (4, 4),
                                  topology = (Periodic, Flat, Bounded))

bottom(x) = - underlying_grid.Lz + 500 * exp(-x^2 / (2*(20e3)^2))

grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))

lines(grid.immersed_boundary.bottom_height)

gives:
fig1
which is all good! But:

x, y, z = nodes(grid.immersed_boundary.bottom_height)

lines(x, grid.immersed_boundary.bottom_height)

fig2
Perhaps this is a bit informative

lines(x/1e3, grid.immersed_boundary.bottom_height)

fig3

Can you check whether this behavior is actually changed by this PR? It seems like maybe this would have happened before this PR anyways.

Right!. Indeed it's not a result of this PR.
So we'll merge and deal with this bug in a different PR.

@navidcy navidcy merged commit d73d78f into main Aug 25, 2024
46 checks passed
@navidcy navidcy deleted the glw/immersed-makie branch August 25, 2024 22:09
navidcy added a commit that referenced this pull request Aug 26, 2024
Captures the masking of immersed cells for visualization in #3725.
@navidcy navidcy mentioned this pull request Aug 26, 2024
navidcy added a commit that referenced this pull request Aug 26, 2024
* Bump patch release

Captures the masking of immersed cells for visualization in #3725.

* enable doc previews

Now there is a [GitHub action](https://github.com/CliMA/OceananigansDocumentation/blob/master/.github/workflows/DocPreviewsCleanup.yml) that automatically clears up the previews directory once a week!

* update comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants