diff --git a/Project.toml b/Project.toml index cb7d8c7..4179f19 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/docs/make.jl b/docs/make.jl index 008c947..5d921aa 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -15,7 +15,6 @@ const OUTPUT_DIR = joinpath(@__DIR__, "src/literated") example_scripts = [ "generate_grid.jl", - "bickley_jet.jl" ] for example in example_scripts @@ -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" ] ##### diff --git a/examples/generate_grid.jl b/examples/generate_grid.jl index 91f8a30..63d88bb 100644 --- a/examples/generate_grid.jl +++ b/examples/generate_grid.jl @@ -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) @@ -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) + + diff --git a/src/OrthogonalSphericalShellGrids.jl b/src/OrthogonalSphericalShellGrids.jl index a1324a4..ffe57cb 100644 --- a/src/OrthogonalSphericalShellGrids.jl +++ b/src/OrthogonalSphericalShellGrids.jl @@ -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 diff --git a/src/distributed_tripolar_grid.jl b/src/distributed_tripolar_grid.jl index 5b03f2b..96ad19c 100644 --- a/src/distributed_tripolar_grid.jl +++ b/src/distributed_tripolar_grid.jl @@ -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 diff --git a/src/grid_extensions.jl b/src/grid_extensions.jl index 7843c45..15a8597 100644 --- a/src/grid_extensions.jl +++ b/src/grid_extensions.jl @@ -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 diff --git a/src/with_halo.jl b/src/with_halo.jl index e13ad7e..c5ce92b 100644 --- a/src/with_halo.jl +++ b/src/with_halo.jl @@ -20,4 +20,25 @@ function with_halo(new_halo, old_grid::TripolarGrid) southermost_latitude) return new_grid -end \ No newline at end of file +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