Skip to content

Commit

Permalink
Merge pull request #6 from simone-silvestri/ss/another-bugfix
Browse files Browse the repository at this point in the history
Last bugfix
  • Loading branch information
simone-silvestri authored Jul 15, 2024
2 parents 2cadff0 + 6986a38 commit 6e81143
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OrthogonalSphericalShellGrids"
uuid = "c2be9673-fb75-4747-82dc-aa2bb9f4aed0"
authors = ["Simone Silvestri"]
version = "0.1.1"
version = "0.1.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const OUTPUT_DIR = joinpath(@__DIR__, "src/literated")

example_scripts = [
"generate_grid.jl",
"bickley_jet.jl"
]

for example in example_scripts
Expand All @@ -34,7 +33,7 @@ pages = [
"Home" => "index.md",
"API" => "grids.md",
"Generate Grid" => "literated/generate_grid.md"
"Bickley jet" => "literated/bickley_jet.md"
# "Bickley jet" => "literated/bickley_jet.md"
]

#####
Expand Down
45 changes: 40 additions & 5 deletions examples/generate_grid.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
# # Generate a Tripolar Grid
#
# This Examples shows how to generate and visualize a Tripolar grid using the `OrthogonalSphericalShellGrids`
# and CairoMakie packages. The script is structured into several key sections, each performing a specific task in the process
# of creating and displaying the grid.
#
# The script begins by importing the required Julia packages.
# OrthogonalSphericalShellGrids is used for generating the Tripolar grid, a type of grid used in geophysical and oceanographic modeling
# due to its ability to handle polar singularities effectively.
# CairoMakie is used for visualization purposes, allowing the creation of figures and plots to display the grid.
#

using OrthogonalSphericalShellGrids
using OrthogonalSphericalShellGrids: Face, Center
using OrthogonalSphericalShellGrids: get_cartesian_nodes_and_vertices
using CairoMakie

# Generate a Tripolar grid with a 2 degree resolution and ``north'' singularities at 20 degrees latitude
# ## Grid generation
#
# The grid is generated with a call to OrthogonalSphericalShellGrids.TripolarGrid,
# specifying the grid size and the latitude of the "north" singularities. In this case, the grid has a resolution of 2 degrees
# (180x90 grid points) and north singularities at 35 degrees latitude. This setup creates a grid that covers the globe with a
# specific focus on handling the complexities near the poles.

grid = OrthogonalSphericalShellGrids.TripolarGrid(size = (180, 90, 1), north_poles_latitude = 35)

# retrieve the Face-Face nodes in a Cartesian coordinate system
# ## Retriveing the nodes
#
# The lines retrieve Cartesian coordinates for two types of grid nodes: `Face`-`Face` nodes
# and `Center`-`Center`` nodes. This is done using the `get_cartesian_nodes_and_vertices` function,
# which converts the grid's spherical coordinates into Cartesian coordinates for easier manipulation and visualization.
# The coordinates are stored in variables xF, yF, zF for Face-Face nodes, and xC, yC, zC for Center-Center nodes.

cartesian_nodes, _ = get_cartesian_nodes_and_vertices(grid, Face(), Face(), Center())
xF, yF, zF = cartesian_nodes

# retrieve the Center-Center nodes in a Cartesian coordinate system
cartesian_nodes, _ = get_cartesian_nodes_and_vertices(grid, Center(), Center(), Center())
xC, yC, zC = cartesian_nodes

# Plot a nice visualization of the grid structure
# ## Visualization
#
# Finally, we can visualize the grid using two types of visual elements: surfaces and wireframes.
# Surfaces are plotted slightly smaller (0.9999 scale) than the wireframes to create a layered effect,
# enhancing the visual distinction between the grid's structure and its outline.
# The Face-Face nodes are visualized with blue surfaces and black wireframes,
# while the Center-Center nodes are visualized with blue surfaces and wireframes.

fig = Figure()
ax = LScene(fig[1, 1]; show_axis = false)

Expand All @@ -24,4 +54,9 @@ wireframe!(ax, xF, yF, zF, color = :black)
surface!(ax, xC.*0.9999, yC.*0.9999, zC.*0.9999, color = :blue)
wireframe!(ax, xC, yC, zC, color = :blue)

fig
save("tripolar_grid_nodes.png", fig)
nothing #hide

# ![](tripolar_grid_nodes.png)


2 changes: 1 addition & 1 deletion src/OrthogonalSphericalShellGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ include("zipper_boundary_condition.jl")
include("generate_tripolar_coordinates.jl")
include("tripolar_grid.jl")
include("grid_extensions.jl")
include("with_halo.jl")
include("distributed_tripolar_grid.jl")
include("with_halo.jl")
include("split_explicit_free_surface.jl")

end
22 changes: 0 additions & 22 deletions src/distributed_tripolar_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,3 @@ function reconstruct_global_grid(grid::DistributedTripolarGrid)
southermost_latitude,
z)
end

function with_halo(new_halo, grid::DistributedTripolarGrid)

arch = grid.architecture

n = size(grid)
N = map(sum, concatenate_local_sizes(n, arch))
z = cpu_face_constructor_z(grid)
FT = eltype(grid)

north_poles_latitude = grid.conformal_mapping.north_poles_latitude
first_pole_longitude = grid.conformal_mapping.first_pole_longitude
southermost_latitude = grid.conformal_mapping.southermost_latitude

return TripolarGrid(arch, FT;
halo = new_halo,
size = N,
north_poles_latitude,
first_pole_longitude,
southermost_latitude,
z)
end
4 changes: 2 additions & 2 deletions src/grid_extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Oceananigans.Fields: Field
import Oceananigans.Fields: tupled_fill_halo_regions!

# A tripolar grid is always between 0 and 360 in longitude!
x_domain(grid::TRG) = @allowscalar 0, 360
y_domain(grid::TRG) = @allowscalar minimum(grid.φᶠᶠᵃ), 90
x_domain(grid::TRG) = 0, 360
y_domain(grid::TRG) = minimum(grid.φᶠᶠᵃ), 90

# a `TripolarGrid` needs a `ZipperBoundaryCondition` for the north boundary
# The `sign` 1 for regular tracers and -1 for velocities and signed vectors
Expand Down
23 changes: 22 additions & 1 deletion src/with_halo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,25 @@ function with_halo(new_halo, old_grid::TripolarGrid)
southermost_latitude)

return new_grid
end
end

function with_halo(new_halo, old_grid::DistributedTripolarGrid)

arch = old_grid.architecture

n = size(old_grid)
N = map(sum, concatenate_local_sizes(n, arch))
z = cpu_face_constructor_z(old_grid)

north_poles_latitude = old_grid.conformal_mapping.north_poles_latitude
first_pole_longitude = old_grid.conformal_mapping.first_pole_longitude
southermost_latitude = old_grid.conformal_mapping.southermost_latitude

return TripolarGrid(arch, eltype(old_grid);
halo = new_halo,
size = N,
north_poles_latitude,
first_pole_longitude,
southermost_latitude,
z)
end

2 comments on commit 6e81143

@simone-silvestri
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/111113

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 6e8114342fe56a0088c0414672dbe3eec5b2e0b4
git push origin v0.1.2

Also, note the warning: Version 0.1.2 skips over 0.1.1
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.