Skip to content

Commit 0efb00a

Browse files
committed
Simplify topology code a tiny bit
1 parent 76cf3ca commit 0efb00a

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OceanTransportMatrixBuilder"
22
uuid = "c2b4a04e-6049-4fc4-aa6a-5508a29a1e1c"
33
authors = ["Benoit Pasquier <briochemc@gmail.com> and contributors"]
4-
version = "0.2.3"
4+
version = "0.2.4"
55

66
[deps]
77
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"

src/topology.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ end
3535

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

47-
# Special behavior for tripolar grids
48-
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])
47+
# Special behavior for tripolar grids where the seam connects the top and "folds" it around
48+
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])
4949

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

0 commit comments

Comments
 (0)