Skip to content

Commit 8d82187

Browse files
committed
Use space filling curve for CommonGrids
1 parent 3ce37ea commit 8d82187

File tree

9 files changed

+120
-5
lines changed

9 files changed

+120
-5
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ ClimaCore.jl Release Notes
44
main
55
-------
66

7+
v0.14.46
8+
-------
9+
- Use space-filling curve for CommonGrids.CubedSphereGrid and ExtrudedCubedSphereGrid [2429](https://github.com/CliMA/ClimaCore.jl/pull/2429)
10+
711
v0.14.45
812
-------
913
- Add split divergence operator [2409](https://github.com/CliMA/ClimaCore.jl/pull/2409)

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClimaCore"
22
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
33
authors = ["CliMA Contributors <clima-software@caltech.edu>"]
4-
version = "0.14.45"
4+
version = "0.14.46"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

docs/src/lib/ClimaCoreMakie.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ ClimaCoreMakie.jl provides functionality for plotting ClimaCore fields extending
99
```@docs
1010
fieldheatmap
1111
fieldcontourf
12+
FieldLine
13+
fieldheatmap!
14+
fieldline
15+
fieldline!
16+
FieldContourf
17+
FieldHeatmap
18+
fieldcontourf!
1219
```

src/CommonGrids/CommonGrids.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ function ExtrudedCubedSphereGrid(
171171
h_topology::Topologies.AbstractDistributedTopology = Topologies.Topology2D(
172172
context,
173173
h_mesh,
174+
Topologies.spacefillingcurve(h_mesh),
174175
),
175176
horizontal_layout_type = DataLayouts.IJFH,
176177
z_mesh::Meshes.IntervalMesh = DefaultZMesh(
@@ -261,6 +262,7 @@ function CubedSphereGrid(
261262
h_topology::Topologies.AbstractDistributedTopology = Topologies.Topology2D(
262263
context,
263264
h_mesh,
265+
Topologies.spacefillingcurve(h_mesh),
264266
),
265267
horizontal_layout_type = DataLayouts.IJFH,
266268
enable_mask::Bool = false,

src/Topologies/topology2d.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,26 @@ end
702702

703703
domain(topology::Topology2D) = domain(topology.mesh)
704704
nelems(topology::Topology2D) = length(topology.elemorder)
705+
706+
"""
707+
uses_spacefillingcurve(topology::Topology2D) -> Bool
708+
709+
Return `true` if the topology uses a space-filling curve for element ordering,
710+
`false` if it uses the default ordering (e.g., `CartesianIndices`).
711+
712+
# Examples
713+
714+
```julia
715+
topology = Topology2D(context, mesh)
716+
if uses_spacefillingcurve(topology)
717+
println("Using space-filling curve ordering")
718+
else
719+
println("Using default Cartesian ordering")
720+
end
721+
```
722+
"""
723+
uses_spacefillingcurve(topology::Topology2D) = !(topology.elemorder isa CartesianIndices)
724+
705725
nlocalelems(topology::Topology2D) = length(topology.local_elem_gidx)
706726
function localelems(topology::Topology2D)
707727
topology.elemorder[topology.local_elem_gidx]

test/CommonGrids/CommonGrids.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Revise; include(joinpath("test", "CommonGrids", "CommonGrids.jl"))
55
import ClimaComms
66
ClimaComms.@import_required_backends
77
using ClimaCore.CommonGrids
8+
import ClimaCore.CommonGrids: ExtrudedCubedSphereGrid, CubedSphereGrid, Box3DGrid
89
using ClimaCore:
910
Geometry,
1011
Hypsography,
@@ -119,3 +120,43 @@ using Test
119120
@test grid isa Grids.SpectralElementGrid2D
120121
@test Grids.topology(grid).mesh isa Meshes.RectilinearMesh
121122
end
123+
124+
@testset "Space-filling curve usage in CommonGrids" begin
125+
@testset "ExtrudedCubedSphereGrid uses space-filling curve" begin
126+
grid = ExtrudedCubedSphereGrid(;
127+
z_elem = 10,
128+
z_min = 0,
129+
z_max = 1,
130+
radius = 10,
131+
h_elem = 10,
132+
n_quad_points = 4,
133+
)
134+
topology = Grids.topology(grid.horizontal_grid)
135+
@test Topologies.uses_spacefillingcurve(topology) == true
136+
end
137+
138+
@testset "CubedSphereGrid uses space-filling curve" begin
139+
grid = CubedSphereGrid(; radius = 10, n_quad_points = 4, h_elem = 10)
140+
topology = Grids.topology(grid)
141+
@test Topologies.uses_spacefillingcurve(topology) == true
142+
end
143+
144+
@testset "Box3DGrid uses space-filling curve" begin
145+
grid = Box3DGrid(;
146+
z_elem = 10,
147+
x_min = 0,
148+
x_max = 1,
149+
y_min = 0,
150+
y_max = 1,
151+
z_min = 0,
152+
z_max = 10,
153+
periodic_x = false,
154+
periodic_y = false,
155+
n_quad_points = 4,
156+
x_elem = 3,
157+
y_elem = 4,
158+
)
159+
topology = Grids.topology(grid.horizontal_grid)
160+
@test Topologies.uses_spacefillingcurve(topology) == true
161+
end
162+
end

test/Fields/unit_field.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ end
909909
staggering = Grids.CellCenter(),
910910
)
911911
test_adapt(ecs_space_fn)
912-
test_adapt_types(ecs_space_fn; broken_space_type_match = true)
912+
test_adapt_types(ecs_space_fn)
913913

914914
cs_space_fn(dev) = CubedSphereSpace(;
915915
device = dev,
@@ -918,7 +918,7 @@ end
918918
h_elem = 10,
919919
)
920920
test_adapt(cs_space_fn)
921-
test_adapt_types(cs_space_fn; broken_space_type_match = true)
921+
test_adapt_types(cs_space_fn)
922922

923923
column_space_fn(dev) = ColumnSpace(;
924924
device = dev,
@@ -977,7 +977,7 @@ end
977977
y_elem = 4,
978978
)
979979
test_adapt(rect_space_fn)
980-
test_adapt_types(rect_space_fn; broken_space_type_match = true)
980+
test_adapt_types(rect_space_fn)
981981

982982
# FieldVector
983983
cspace = ExtrudedCubedSphereSpace(;

test/Topologies/cubedsphere_sfc.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Test
22

33
import ClimaCore:
4-
Domains, Fields, Geometry, Meshes, Operators, Spaces, Topologies
4+
ClimaComms, Domains, Fields, Geometry, Meshes, Operators, Spaces, Topologies
55

66
@testset "Space Filling Curve tests for a cubed sphere mesh with (16) elements per edge" begin
77
mesh = Meshes.EquiangularCubedSphere(Domains.SphereDomain(1.0), 16)
@@ -38,3 +38,22 @@ import ClimaCore:
3838
end
3939
end
4040
end
41+
42+
@testset "uses_spacefillingcurve tests" begin
43+
context = ClimaComms.SingletonCommsContext(ClimaComms.CPUSingleThreaded())
44+
@testset "cubed sphere with space-filling curve" begin
45+
mesh = Meshes.EquiangularCubedSphere(Domains.SphereDomain(1.0), 6)
46+
topology_sfc = Topologies.Topology2D(
47+
context,
48+
mesh,
49+
Topologies.spacefillingcurve(mesh),
50+
)
51+
@test Topologies.uses_spacefillingcurve(topology_sfc) == true
52+
end
53+
54+
@testset "cubed sphere with default ordering" begin
55+
mesh = Meshes.EquiangularCubedSphere(Domains.SphereDomain(1.0), 6)
56+
topology_default = Topologies.Topology2D(context, mesh)
57+
@test Topologies.uses_spacefillingcurve(topology_default) == false
58+
end
59+
end

test/Topologies/rectangle_sfc.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using IntervalSets
22
using Test
3+
using ClimaComms
34

45
import ClimaCore:
56
Domains, Fields, Geometry, Meshes, Operators, Spaces, Topologies
@@ -60,3 +61,24 @@ end
6061
end
6162
end
6263
end
64+
65+
@testset "uses_spacefillingcurve tests for rectangular mesh" begin
66+
device = ClimaComms.CPUSingleThreaded()
67+
context = ClimaComms.SingletonCommsContext(device)
68+
69+
@testset "rectangular mesh with space-filling curve" begin
70+
mesh = rectilinear_grid(4, 4, false, false)
71+
topology_sfc = Topologies.Topology2D(
72+
context,
73+
mesh,
74+
Topologies.spacefillingcurve(mesh),
75+
)
76+
@test Topologies.uses_spacefillingcurve(topology_sfc) == true
77+
end
78+
79+
@testset "rectangular mesh with default ordering" begin
80+
mesh = rectilinear_grid(4, 4, false, false)
81+
topology_default = Topologies.Topology2D(context, mesh)
82+
@test Topologies.uses_spacefillingcurve(topology_default) == false
83+
end
84+
end

0 commit comments

Comments
 (0)