Skip to content

Commit

Permalink
Simplify topology code a tiny bit
Browse files Browse the repository at this point in the history
  • Loading branch information
briochemc committed Oct 10, 2024
1 parent 76cf3ca commit 0efb00a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OceanTransportMatrixBuilder"
uuid = "c2b4a04e-6049-4fc4-aa6a-5508a29a1e1c"
authors = ["Benoit Pasquier <[email protected]> and contributors"]
version = "0.2.3"
version = "0.2.4"

[deps]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand Down
16 changes: 8 additions & 8 deletions src/topology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ end

# Default behavior for grids (assumed bipolar)
# wrap around in the i direction (longitude)
i₊₁(C, g::AbstractGrid) = C.I[1] < g.nx ? C .+ CartesianIndex(1, 0, 0) : CartesianIndex(1, C.I[2], C.I[3])
i₋₁(C, g::AbstractGrid) = C.I[1] > 1 ? C .- CartesianIndex(1, 0, 0) : CartesianIndex(g.nx, C.I[2], C.I[3])
i₊₁(C, g::AbstractGrid) = C.I[1] < g.nx ? C + CartesianIndex(1, 0, 0) : CartesianIndex(1, C.I[2], C.I[3])
i₋₁(C, g::AbstractGrid) = C.I[1] > 1 ? C + CartesianIndex(-1, 0, 0) : CartesianIndex(g.nx, C.I[2], C.I[3])
# No connection by default in the j direction (latitude)
j₊₁(C, g::AbstractGrid) = C.I[2] < g.ny ? C .+ CartesianIndex(0, 1, 0) : nothing
j₋₁(C, ::AbstractGrid) = C.I[2] > 1 ? C .- CartesianIndex(0, 1, 0) : nothing
j₊₁(C, g::AbstractGrid) = C.I[2] < g.ny ? C + CartesianIndex(0, 1, 0) : nothing
j₋₁(C, ::AbstractGrid) = C.I[2] > 1 ? C + CartesianIndex(0, -1, 0) : nothing
# No connection by default in the k direction (depth)
k₊₁(C, g::AbstractGrid) = C.I[3] < g.nz ? C .+ CartesianIndex(0, 0, 1) : nothing
k₋₁(C, ::AbstractGrid) = C.I[3] > 1 ? C .- CartesianIndex(0, 0, 1) : nothing
k₊₁(C, g::AbstractGrid) = C.I[3] < g.nz ? C + CartesianIndex(0, 0, 1) : nothing
k₋₁(C, ::AbstractGrid) = C.I[3] > 1 ? C + CartesianIndex(0, 0, -1) : nothing

# Special behavior for tripolar grids
j₊₁(C, g::TripolarGrid) = C.I[2] < g.ny ? C .+ CartesianIndex(0, 1, 0) : CartesianIndex(mod1(g.nx - C.I[1] + 1, g.nx), g.ny, C.I[3])
# Special behavior for tripolar grids where the seam connects the top and "folds" it around
j₊₁(C, g::TripolarGrid) = C.I[2] < g.ny ? C + CartesianIndex(0, 1, 0) : CartesianIndex(mod1(g.nx - C.I[1] + 1, g.nx), g.ny, C.I[3])

# error for unknown grids
i₊₁(C, ::UnknownGrid) = error("Unknown grid type")
Expand Down

2 comments on commit 0efb00a

@briochemc
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

  • simplify topology code a tiny bit

@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/116982

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.2.4 -m "<description of version>" 0efb00aee9aec9143c048e7d7046a201103ac43c
git push origin v0.2.4

Please sign in to comment.