From f984f34977ec52f1c6276563bbf9742be69a5755 Mon Sep 17 00:00:00 2001 From: Ludovic Raess Date: Tue, 5 Mar 2024 13:44:19 +0100 Subject: [PATCH 1/6] Add uniform spacing support --- src/Grids/structured_grid.jl | 18 ++++++++++++++++++ test/test_grids.jl | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Grids/structured_grid.jl b/src/Grids/structured_grid.jl index f21f778e..2d132be3 100644 --- a/src/Grids/structured_grid.jl +++ b/src/Grids/structured_grid.jl @@ -153,6 +153,22 @@ for (sp, desc) in ((:spacing, "grid spacings"), (:inv_spacing, "inverse grid spa end end +""" + spacing(grid::UniformGrid) + +Return a tuple of grid spacing for a uniform grid `grid`. +""" +spacing(grid::UniformGrid) = getfield.(grid.axes, :spacing) +spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = getfield.(grid.axes, :spacing)[dim] + +""" + inv_spacing(grid::UniformGrid) + +Return a tuple of inverse grid spacing for a uniform grid `grid`. +""" +inv_spacing(grid::UniformGrid) = getfield.(grid.axes, :inv_spacing) +inv_spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = getfield.(grid.axes, :inv_spacing)[dim] + # coordinate lists coords(grid::SG{N}, loc::LocOrLocs{N}) where {N} = coords.(grid.axes, loc) @@ -181,6 +197,8 @@ for (dim, c) in enumerate((:x, :y, :z)) @eval begin export $_Δ, $_coord, $_coords, $_vertex, $_center, $_vertices, $_centers + @propagate_inbounds $_Δ(grid::UniformGrid) = spacing(grid, Dim($dim)) + @propagate_inbounds $_Δ(grid::SG{N}, loc, I::Vararg{Integer,N}) where {N} = spacing(grid, loc, Dim($dim), I...) @propagate_inbounds $_Δ(grid::SG, loc, I) = spacing(grid, loc, Dim($dim), I) diff --git a/test/test_grids.jl b/test/test_grids.jl index 768f951e..bc8bdd72 100644 --- a/test/test_grids.jl +++ b/test/test_grids.jl @@ -109,6 +109,16 @@ using Chmy.Architectures @test inv_spacing(grid, Center(), 1, 1) == inv_spacing(grid, (Center(), Center()), 1, 1) end + @testset "uniform spacing" begin + # spacing + @test all(spacing(grid) .≈ (0.4, 0.2)) + # inverse + @test all(inv_spacing(grid) .≈ (2.5, 5.0)) + # cartesian + @test Δx(grid) ≈ 0.4 + @test Δy(grid) ≈ 0.2 + end + @testset "coords" begin # one index @test coord(grid, Vertex(), Dim(1), 1) ≈ -1.0 From 4db21197dcd1f0c30151de57e7fa07ce18a422fd Mon Sep 17 00:00:00 2001 From: Ludovic Raess Date: Tue, 5 Mar 2024 13:45:37 +0100 Subject: [PATCH 2/6] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ec828075..52b17ca0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Chmy" uuid = "33a72cf0-4690-46d7-b987-06506c2248b9" authors = ["Ivan Utkin , Ludovic Raess , and contributors"] -version = "0.1.0" +version = "0.2.0" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From bd219d7804998adec5f5373a996523bf83bdddda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20R=C3=A4ss?= <61313342+luraess@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:35:43 +0100 Subject: [PATCH 3/6] Update src/Grids/structured_grid.jl Co-authored-by: Ivan Utkin --- src/Grids/structured_grid.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grids/structured_grid.jl b/src/Grids/structured_grid.jl index 2d132be3..c1c45302 100644 --- a/src/Grids/structured_grid.jl +++ b/src/Grids/structured_grid.jl @@ -159,7 +159,7 @@ end Return a tuple of grid spacing for a uniform grid `grid`. """ spacing(grid::UniformGrid) = getfield.(grid.axes, :spacing) -spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = getfield.(grid.axes, :spacing)[dim] +spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = grid.axes[dim].spacing """ inv_spacing(grid::UniformGrid) From 3f0ae9bd73665618c042732a34181afa6897cfdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20R=C3=A4ss?= <61313342+luraess@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:35:56 +0100 Subject: [PATCH 4/6] Update src/Grids/structured_grid.jl Co-authored-by: Ivan Utkin --- src/Grids/structured_grid.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grids/structured_grid.jl b/src/Grids/structured_grid.jl index c1c45302..f720888b 100644 --- a/src/Grids/structured_grid.jl +++ b/src/Grids/structured_grid.jl @@ -167,7 +167,7 @@ spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = grid.axes[dim].spacing Return a tuple of inverse grid spacing for a uniform grid `grid`. """ inv_spacing(grid::UniformGrid) = getfield.(grid.axes, :inv_spacing) -inv_spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = getfield.(grid.axes, :inv_spacing)[dim] +inv_spacing(grid::UniformGrid, ::Dim{dim}) where {dim} = grid.axes[dim].inv_spacing # coordinate lists From bca4cf77ef51c1351f36b8543fde0dc309e5f66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20R=C3=A4ss?= <61313342+luraess@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:37:48 +0100 Subject: [PATCH 5/6] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 52b17ca0..afadd2dc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Chmy" uuid = "33a72cf0-4690-46d7-b987-06506c2248b9" authors = ["Ivan Utkin , Ludovic Raess , and contributors"] -version = "0.2.0" +version = "0.1.1" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From c2453498789460336a7a66353df5b89f2ee4e471 Mon Sep 17 00:00:00 2001 From: Ludovic Raess Date: Tue, 5 Mar 2024 16:39:42 +0100 Subject: [PATCH 6/6] Rename cartesian coords from topology --- src/Distributed/Distributed.jl | 2 +- src/Distributed/distributed_grid.jl | 2 +- src/Distributed/topology.jl | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Distributed/Distributed.jl b/src/Distributed/Distributed.jl index 7ade2e76..e317e7a2 100644 --- a/src/Distributed/Distributed.jl +++ b/src/Distributed/Distributed.jl @@ -9,7 +9,7 @@ Enables hiding MPI communication behind computations. module Distributed export CartesianTopology, global_rank, shared_rank, node_name, cart_comm, shared_comm -export dims, coords, neighbors, neighbor, has_neighbor, global_size, node_size +export dims, cart_coords, neighbors, neighbor, has_neighbor, global_size, node_size export DistributedArchitecture, topology export exchange_halo!, gather! diff --git a/src/Distributed/distributed_grid.jl b/src/Distributed/distributed_grid.jl index ce83bbf0..ad2cbc9c 100644 --- a/src/Distributed/distributed_grid.jl +++ b/src/Distributed/distributed_grid.jl @@ -23,7 +23,7 @@ function Grids.StructuredGrid{C}(arch::DistributedArchitecture, axes::Vararg{Abs end local_dims = cld.(global_dims, dims(arch.topology)) - offsets = coords(arch.topology) .* local_dims + offsets = cart_coords(arch.topology) .* local_dims local_axes = ntuple(Val(N)) do D Base.@_inline_meta diff --git a/src/Distributed/topology.jl b/src/Distributed/topology.jl index ab724b7c..6ebae90e 100644 --- a/src/Distributed/topology.jl +++ b/src/Distributed/topology.jl @@ -83,11 +83,11 @@ Dimensions of the topology as NTuple. dims(t::CartesianTopology) = t.dims """ - coords(topo) + cart_coords(topo) Coordinates of a current process within a Cartesian topology. """ -coords(t::CartesianTopology) = t.cart_coords +cart_coords(t::CartesianTopology) = t.cart_coords """ neighbors(topo)