1
+ #=
2
+ julia --project
3
+ using Revise; include(joinpath("test", "Spaces", "ddss1_cs.jl"))
4
+ =#
1
5
using Test
2
6
using ClimaComms
3
7
ClimaComms. @import_required_backends
@@ -13,29 +17,68 @@ import ClimaCore:
13
17
Topologies,
14
18
DataLayouts
15
19
16
- @testset " DSS on Equiangular Cubed Sphere mesh (ne = 3, serial run)" begin
17
- device = ClimaComms. device () # ClimaComms.CUDADevice()
18
- context = ClimaComms. SingletonCommsContext (device)
19
- context_cpu =
20
- ClimaComms. SingletonCommsContext (ClimaComms. CPUSingleThreaded ())
21
-
22
- println (" running test on $device device" )
23
-
24
- domain = Domains. SphereDomain (300.0 )
20
+ function get_space_cs (:: Type{FT} ; context, R = 300.0 ) where {FT}
21
+ domain = Domains. SphereDomain {FT} (300.0 )
25
22
mesh = Meshes. EquiangularCubedSphere (domain, 3 )
26
23
topology = Topologies. Topology2D (context, mesh)
27
- topology_cpu = Topologies. Topology2D (context_cpu, mesh)
28
24
quad = Quadratures. GLL {4} ()
29
25
space = Spaces. SpectralElementSpace2D (topology, quad)
30
- space_cpu = Spaces. SpectralElementSpace2D (topology_cpu, quad)
26
+ return space
27
+ end
31
28
32
- x = ones (space)
33
- x_cpu = ones (space_cpu)
29
+ function get_space_and_buffers (:: Type{FT} ; context) where {FT}
30
+ init_state_covariant12 (local_geometry, p) =
31
+ Geometry. Covariant12Vector (1.0 , - 1.0 )
32
+ init_state_covariant123 (local_geometry, p) =
33
+ Geometry. Covariant123Vector (1.0 , - 1.0 , 1.0 )
34
+
35
+ R = FT (6.371229e6 )
36
+ npoly = 2
37
+ z_max = FT (30e3 )
38
+ z_elem = 3
39
+ h_elem = 2
40
+ device = ClimaComms. device (context)
41
+ @info " running dss-Covariant123Vector test on $(device) " h_elem z_elem npoly R z_max FT
42
+ # horizontal space
43
+ domain = Domains. SphereDomain {FT} (R)
44
+ horizontal_mesh = Meshes. EquiangularCubedSphere (domain, h_elem)
45
+ horizontal_topology = Topologies. Topology2D (
46
+ context,
47
+ horizontal_mesh,
48
+ Topologies. spacefillingcurve (horizontal_mesh),
49
+ )
50
+ quad = Quadratures. GLL {npoly + 1} ()
51
+ h_space = Spaces. SpectralElementSpace2D (horizontal_topology, quad)
52
+ # vertical space
53
+ z_domain = Domains. IntervalDomain (
54
+ Geometry. ZPoint {FT} (zero (z_max)),
55
+ Geometry. ZPoint {FT} (z_max);
56
+ boundary_names = (:bottom , :top ),
57
+ )
58
+ z_mesh = Meshes. IntervalMesh (z_domain, nelems = z_elem)
59
+ z_topology = Topologies. IntervalTopology (context, z_mesh)
60
+ z_center_space = Spaces. CenterFiniteDifferenceSpace (z_topology)
61
+ space = Spaces. ExtrudedFiniteDifferenceSpace (h_space, z_center_space)
62
+ args = (Fields. local_geometry_field (space), Ref (nothing ))
63
+ y12 = init_state_covariant12 .(args... )
64
+ y123 = init_state_covariant123 .(args... )
65
+ dss_buffer12 = Spaces. create_dss_buffer (y12)
66
+ dss_buffer123 = Spaces. create_dss_buffer (y123)
67
+ return (; space, y12, y123, dss_buffer12, dss_buffer123)
68
+ end
34
69
70
+ @testset " DSS on Equiangular Cubed Sphere mesh (ne = 3, serial run)" begin
71
+ FT = Float64
72
+ device = ClimaComms. device ()
73
+ context = ClimaComms. SingletonCommsContext (device)
74
+ println (" running test on $device device" )
75
+ space = get_space_cs (FT; context)
76
+ space_cpu = get_space_cs (FT; context)
77
+ x = ones (space)
35
78
Spaces. weighted_dss! (x)
36
- Spaces. weighted_dss! (x_cpu)
37
79
38
- @test parent (x_cpu) ≈ Array (parent (x))
80
+ @test Array (parent (x)) ≈ ones (size (parent (x))) # TODO : improve the quality of this test
81
+
39
82
wrong_field = map (Fields. coordinate_field (space)) do cf
40
83
(; a = Float64 (0 ))
41
84
end
@@ -60,113 +103,57 @@ end
60
103
61
104
@testset " DSS of Covariant12Vector & Covariant123Vector on extruded Cubed Sphere mesh (ne = 3, serial run)" begin
62
105
FT = Float64
63
- context = ClimaComms. SingletonCommsContext (ClimaComms. CUDADevice ())
64
- context_cpu =
65
- ClimaComms. SingletonCommsContext (ClimaComms. CPUSingleThreaded ()) # CPU context for comparison
66
- R = FT (6.371229e6 )
67
-
68
- npoly = 4
69
- z_max = FT (30e3 )
70
- z_elem = 10
71
- h_elem = 4
72
- println (
73
- " running dss-Covariant123Vector test on $(context. device) ; h_elem = $h_elem ; z_elem = $z_elem ; npoly = $npoly ; R = $R ; z_max = $z_max ; FT = $FT " ,
74
- )
75
- # horizontal space
76
- domain = Domains. SphereDomain (R)
77
- horizontal_mesh = Meshes. EquiangularCubedSphere (domain, h_elem)
78
- horizontal_topology = Topologies. Topology2D (
79
- context,
80
- horizontal_mesh,
81
- Topologies. spacefillingcurve (horizontal_mesh),
82
- )
83
- horizontal_topology_cpu = Topologies. Topology2D (
84
- context_cpu,
85
- horizontal_mesh,
86
- Topologies. spacefillingcurve (horizontal_mesh),
87
- )
88
- quad = Quadratures. GLL {npoly + 1} ()
89
- h_space = Spaces. SpectralElementSpace2D (horizontal_topology, quad)
90
- h_space_cpu = Spaces. SpectralElementSpace2D (horizontal_topology_cpu, quad)
91
-
92
- # vertical space
93
- z_domain = Domains. IntervalDomain (
94
- Geometry. ZPoint (zero (z_max)),
95
- Geometry. ZPoint (z_max);
96
- boundary_names = (:bottom , :top ),
97
- )
98
- z_mesh = Meshes. IntervalMesh (z_domain, nelems = z_elem)
99
- z_topology = Topologies. IntervalTopology (context, z_mesh)
100
- z_topology_cpu = Topologies. IntervalTopology (context_cpu, z_mesh)
101
-
102
- z_center_space = Spaces. CenterFiniteDifferenceSpace (z_topology)
103
- z_center_space_cpu = Spaces. CenterFiniteDifferenceSpace (z_topology_cpu)
104
-
105
- hv_center_space =
106
- Spaces. ExtrudedFiniteDifferenceSpace (h_space, z_center_space)
107
-
108
- hv_center_space_cpu =
109
- Spaces. ExtrudedFiniteDifferenceSpace (h_space_cpu, z_center_space_cpu)
106
+ device = ClimaComms. device ()
107
+ nt = get_space_and_buffers (FT; context = ClimaComms. context (device))
110
108
111
109
# test DSS for a Covariant12Vector
112
- init_state_covariant12 (local_geometry, p) =
113
- Geometry. Covariant12Vector (1.0 , - 1.0 )
114
-
115
- y12 =
116
- init_state_covariant12 .(
117
- Fields. local_geometry_field (hv_center_space),
118
- Ref (nothing ),
119
- )
120
- y12_cpu =
121
- init_state_covariant12 .(
122
- Fields. local_geometry_field (hv_center_space_cpu),
123
- Ref (nothing ),
124
- )
125
-
126
- dss_buffer12 = Spaces. create_dss_buffer (y12)
127
- dss_buffer12_cpu = Spaces. create_dss_buffer (y12_cpu)
128
110
# ensure physical velocity is continous across SE boundary for initial state
129
- Spaces. weighted_dss! (y12 => dss_buffer12)
130
- Spaces. weighted_dss! (y12_cpu => dss_buffer12_cpu)
111
+ Spaces. weighted_dss! (nt. y12 => nt. dss_buffer12)
112
+ init = copy (nt. y12)
113
+ Spaces. weighted_dss! (nt. y12, nt. dss_buffer12)
114
+ @test init ≈ nt. y12
115
+ # ensure physical velocity is continous across SE boundary for initial state
116
+ Spaces. weighted_dss! (nt. y123, nt. dss_buffer123)
117
+ init = copy (nt. y123)
118
+ Spaces. weighted_dss! (nt. y123, nt. dss_buffer123)
119
+ @test init ≈ nt. y123
120
+ end
131
121
132
- yinit12 = copy (y12)
133
- yinit12_cpu = copy (y12_cpu)
122
+ # TODO : remove once the quality of the above test is improved
123
+ (ClimaComms. device () isa ClimaComms. CUDADevice) &&
124
+ @testset " GPU-vs-CPU test: DSS of Covariant12Vector & Covariant123Vector on extruded Cubed Sphere mesh (ne = 3, serial run)" begin
125
+ FT = Float64
126
+ cpu_device = ClimaComms. CPUSingleThreaded ()
127
+ gpu_device = ClimaComms. CUDADevice ()
128
+ gpu =
129
+ get_space_and_buffers (FT; context = ClimaComms. context (gpu_device))
130
+ cpu =
131
+ get_space_and_buffers (FT; context = ClimaComms. context (cpu_device))
134
132
135
- Spaces. weighted_dss! (y12, dss_buffer12)
136
- Spaces. weighted_dss! (y12_cpu, dss_buffer12_cpu)
137
- @test yinit12 ≈ y12
138
- @test yinit12_cpu ≈ y12_cpu
139
- @test parent (y12_cpu) ≈ Array (parent (y12))
133
+ # test DSS for a Covariant12Vector
134
+ # ensure physical velocity is continous across SE boundary for initial state
135
+ Spaces. weighted_dss! (cpu. y12 => cpu. dss_buffer12)
136
+ Spaces. weighted_dss! (gpu. y12 => gpu. dss_buffer12)
140
137
141
- # test DSS for a Covariant123Vector
142
- init_state_covariant123 (local_geometry, p) =
143
- Geometry. Covariant123Vector (1.0 , - 1.0 , 1.0 )
138
+ inity12 = (; cpu = copy (cpu. y12), gpu = copy (gpu. y12))
144
139
145
- y123 =
146
- init_state_covariant123 .(
147
- Fields. local_geometry_field (hv_center_space),
148
- Ref (nothing ),
149
- )
150
- y123_cpu =
151
- init_state_covariant123 .(
152
- Fields. local_geometry_field (hv_center_space_cpu),
153
- Ref (nothing ),
154
- )
140
+ Spaces. weighted_dss! (cpu. y12, cpu. dss_buffer12)
141
+ Spaces. weighted_dss! (gpu. y12, gpu. dss_buffer12)
155
142
156
- dss_buffer123 = Spaces. create_dss_buffer (y123)
157
- dss_buffer123_cpu = Spaces. create_dss_buffer (y123_cpu)
143
+ @test inity12. cpu ≈ cpu. y12
144
+ @test inity12. gpu ≈ gpu. y12
145
+ @test parent (cpu. y12) ≈ Array (parent (gpu. y12))
158
146
159
- # ensure physical velocity is continous across SE boundary for initial state
160
- Spaces. weighted_dss! (y123, dss_buffer123)
161
- Spaces. weighted_dss! (y123_cpu, dss_buffer123_cpu )
147
+ # ensure physical velocity is continous across SE boundary for initial state
148
+ Spaces. weighted_dss! (cpu . y123, cpu . dss_buffer123)
149
+ Spaces. weighted_dss! (gpu . y123, gpu . dss_buffer123 )
162
150
163
- yinit123 = copy (y123)
164
- yinit123_cpu = copy (y123_cpu)
151
+ inity123 = (; cpu = copy (cpu. y123), gpu = copy (gpu. y123))
165
152
166
- Spaces. weighted_dss! (y123, dss_buffer123)
167
- Spaces. weighted_dss! (y123_cpu, dss_buffer123_cpu )
153
+ Spaces. weighted_dss! (cpu . y123, cpu . dss_buffer123)
154
+ Spaces. weighted_dss! (gpu . y123, gpu . dss_buffer123 )
168
155
169
- @test yinit123 ≈ y123
170
- @test yinit123_cpu ≈ y123_cpu
171
- @test parent (y123_cpu ) ≈ Array (parent (y123))
172
- end
156
+ @test inity123 . cpu ≈ cpu . y123
157
+ @test inity123 . gpu ≈ gpu . y123
158
+ @test parent (cpu . y123 ) ≈ Array (parent (gpu . y123))
159
+ end
0 commit comments