@@ -23,11 +23,15 @@ import ClimaCore:
23
23
DeviceSideDevice
24
24
25
25
using ClimaCore. CommonSpaces
26
+ using ClimaCore. Utilities. Cache
26
27
import ClimaCore. DataLayouts: IJFH, VF, slab_index
27
28
28
29
on_gpu = ClimaComms. device () isa ClimaComms. CUDADevice
29
30
30
31
@testset " 2D spaces with mask" begin
32
+ # We need to test a fresh instance of the spaces, since
33
+ # masked spaces include data set by users.
34
+ Cache. clean_cache! ()
31
35
FT = Float64
32
36
context = ClimaComms. context ()
33
37
x_max = FT (1 )
@@ -57,6 +61,7 @@ on_gpu = ClimaComms.device() isa ClimaComms.CUDADevice
57
61
hspace = Spaces. SpectralElementSpace2D (htopology, quad; enable_mask = true )
58
62
mask = Spaces. get_mask (hspace)
59
63
@test mask isa DataLayouts. IJHMask
64
+ @test all (x -> x == true , parent (mask. is_active)) # test that default is true
60
65
Spaces. set_mask! (hspace) do coords
61
66
coords. x > 0.5
62
67
end
@@ -71,6 +76,9 @@ on_gpu = ClimaComms.device() isa ClimaComms.CUDADevice
71
76
@. f = 1 + ᶜx * 0 # tests copyto!
72
77
@test count (iszero, parent (f)) == 2
73
78
79
+ fbc = @. 1 + ᶜx * 0 # tests copy
80
+ @test Spaces. get_mask (axes (fbc)) isa DataLayouts. IJHMask
81
+
74
82
FT = Float64
75
83
ᶜspace = ExtrudedCubedSphereSpace (
76
84
FT;
@@ -92,8 +100,7 @@ on_gpu = ClimaComms.device() isa ClimaComms.CUDADevice
92
100
# Test that mask-field assignment works:
93
101
# TODO : we should make this easier
94
102
is_active = similar (mask. is_active)
95
- _is_active = Fields. field_values (float .(hᶠcoords. lat .> 0.5 ))
96
- is_active .= DataLayouts. replace_basetype (_is_active, Bool)
103
+ parent (is_active) .= parent (hᶠcoords. lat) .> 0.5
97
104
Spaces. set_mask! (ᶜspace, is_active)
98
105
99
106
Spaces. set_mask! (ᶜspace) do coords
@@ -131,6 +138,8 @@ on_gpu = ClimaComms.device() isa ClimaComms.CUDADevice
131
138
ᶠspace_no_mask = Spaces. face_space (ᶜspace_no_mask)
132
139
ᶠcoords_no_mask = Fields. coordinate_field (ᶠspace_no_mask)
133
140
c_no_mask = Fields. Field (FT, ᶜspace_no_mask)
141
+ @test_throws ErrorException (" Broacasted spaces are not the same." ) @. c_no_mask +
142
+ ᶜf
134
143
ᶠf_no_mask = Fields. Field (FT, ᶠspace_no_mask)
135
144
if ClimaComms. device (ᶜspace_no_mask) isa ClimaComms. CUDADevice
136
145
@. c_no_mask = div (Geometry. WVector (foo (ᶠf_no_mask, ᶠcoords_no_mask)))
162
171
163
172
expected_repr = """
164
173
SpectralElementSpace1D:
174
+ mask_enabled: false
165
175
context: SingletonCommsContext using $(nameof (typeof (device)))
166
176
mesh: 1-element IntervalMesh of IntervalDomain: x ∈ [-3.0,5.0] (periodic)
167
177
quadrature: 4-point Gauss-Legendre-Lobatto quadrature"""
348
358
space = Spaces. SpectralElementSpace2D (grid_topology, quad)
349
359
@test repr (space) == """
350
360
SpectralElementSpace2D:
361
+ mask_enabled: false
351
362
context: SingletonCommsContext using CPUSingleThreaded
352
363
mesh: 1×1-element RectilinearMesh of RectangleDomain: x ∈ [-3.0,5.0] (periodic) × y ∈ [-2.0,8.0] (:south, :north)
353
364
quadrature: 4-point Gauss-Legendre-Lobatto quadrature"""
0 commit comments