@@ -4,44 +4,53 @@ using XESMF
44using SparseArrays
55using LinearAlgebra
66
7- z = ( - 1 , 0 )
8- southernmost_latitude = - 80
9- radius = Oceananigans . Grids . R_Earth
7+ for arch in archs
8+ @testset " XESMF extension [ $( typeof (arch)) ] " begin
9+ @info " Testing XESMF regridding [ $( typeof (arch)) ]... "
1010
11- llg_coarse = LatitudeLongitudeGrid (; size= (176 , 88 , 1 ),
12- longitude= (0 , 360 ),
13- latitude= (southernmost_latitude, 90 ),
14- z, radius)
11+ z = (- 1 , 0 )
12+ southernmost_latitude = - 80
13+ radius = Oceananigans. Grids. R_Earth
1514
16- llg_fine = LatitudeLongitudeGrid (; size= (360 , 180 , 1 ),
17- longitude= (0 , 360 ),
18- latitude= (southernmost_latitude, 90 ),
19- z, radius)
15+ llg_coarse = LatitudeLongitudeGrid (arch ; size= (176 , 88 , 1 ),
16+ longitude= (0 , 360 ),
17+ latitude= (southernmost_latitude, 90 ),
18+ z, radius)
2019
21- tg = TripolarGrid (; size= (360 , 170 , 1 ), z, southernmost_latitude, radius)
20+ llg_fine = LatitudeLongitudeGrid (arch; size= (360 , 170 , 1 ),
21+ longitude= (0 , 360 ),
22+ latitude= (southernmost_latitude, 90 ),
23+ z, radius)
2224
23- @testset " XESMF extension " begin
25+ tg = TripolarGrid (arch; size = ( 360 , 170 , 1 ), z, southernmost_latitude, radius)
2426
25- for (src_grid, dst_grid) in ((llg_coarse, llg_fine),
26- (llg_fine, llg_coarse),
27- (tg, llg_fine))
2827
29- @info " Regridding from $(nameof (typeof (src_grid))) to $(nameof (typeof (dst_grid))) "
28+ for (src_grid, dst_grid) in ((llg_coarse, llg_fine),
29+ (llg_fine, llg_coarse),
30+ (tg, llg_fine))
3031
31- src_field = CenterField (src_grid)
32- dst_field = CenterField (dst_grid)
32+ @info " Regridding from $(nameof (typeof (src_grid))) to $(nameof (typeof (dst_grid))) "
3333
34- λ₀, φ₀ = 150 , 30. # degrees
35- width = 12 # degrees
36- set! (src_field, (λ, φ, z) -> exp (- ((λ - λ₀)^ 2 + (φ - φ₀)^ 2 ) / 2 width^ 2 ))
34+ src_field = CenterField (src_grid)
35+ dst_field = CenterField (dst_grid)
3736
38- R = XESMF. Regridder (dst_field, src_field)
39- @test R. weights isa SparseMatrixCSC
37+ λ₀, φ₀ = 150 , 30. # degrees
38+ width = 12 # degrees
39+ set! (src_field, (λ, φ, z) -> exp (- ((λ - λ₀)^ 2 + (φ - φ₀)^ 2 ) / 2 width^ 2 ))
4040
41- regrid! (dst_field, R , src_field)
41+ regridder = XESMF . Regridder (dst_field, src_field)
4242
43- # ∫ dst_field dA = ∫ src_field dA
44- @test isapprox (first (Field (Integral (dst_field, dims= (1 , 2 )))),
45- first (Field (Integral (src_field, dims= (1 , 2 )))), rtol= 1e-4 )
43+ if arch isa CPU
44+ @test regridder. weights isa SparseMatrixCSC
45+ elseif arch isa GPU{CUDABackend}
46+ @test regridder. weights isa CUDA. CUSPARSE. CuSparseMatrixCSC
47+ end
48+
49+ regrid! (dst_field, regridder, src_field)
50+
51+ # ∫ dst_field dA ≈ ∫ src_field dA
52+ @test @allowscalar isapprox (first (Field (Integral (dst_field, dims= (1 , 2 )))),
53+ first (Field (Integral (src_field, dims= (1 , 2 )))), rtol= 1e-4 )
54+ end
4655 end
4756end
0 commit comments