1
+ using PlanktonIndividuals. Grids
2
+
3
+ using MeshArrays
4
+
5
+ function test_rectilinear_grid ()
6
+ grid = RectilinearGrid (size = (4 ,6 ,2 ), x = (0 ,12 ), y = (0 ,12 ), z = (0 ,- 8 ), halo = (2 ,2 ,2 ))
7
+
8
+ @test grid. Nx == 4
9
+ @test grid. Ny == 6
10
+ @test grid. Nz == 2
11
+
12
+ @test grid. Δx == 3.0
13
+ @test grid. Δy == 2.0
14
+ @test grid. dzC == [4.0 ,4.0 ,4.0 ,4.0 ,4.0 ,4.0 ]
15
+ @test grid. dzF == [4.0 ,4.0 ,4.0 ,4.0 ,4.0 ,4.0 ]
16
+
17
+ @test length (grid. xC) == 4 + 2 * 2
18
+ @test length (grid. yC) == 6 + 2 * 2
19
+ @test length (grid. zC) == 2 + 2 * 2
20
+ @test length (grid. xF) == 4 + 2 * 2
21
+ @test length (grid. yF) == 6 + 2 * 2
22
+ @test length (grid. zF) == 2 + 2 * 2
23
+
24
+ return nothing
25
+ end
26
+
27
+ function test_vertically_stretched_rectilinear_grid ()
28
+ zfs = [0.0 , - 1.0 , - 3.0 , - 5.0 , - 10.0 ]
29
+ grid = RectilinearGrid (size = (4 ,6 ,4 ), x = (0 ,12 ), y = (0 ,12 ), z = zfs, halo = (2 ,2 ,2 ))
30
+
31
+ @test grid. Nx == 4
32
+ @test grid. Ny == 6
33
+ @test grid. Nz == 4
34
+
35
+ @test grid. Δx == 3.0
36
+ @test grid. Δy == 2.0
37
+ @test grid. dzC == [1.0 ,1.0 ,1.5 ,2.0 ,3.5 ,5.0 ,5.0 ,5.0 ]
38
+ @test grid. dzF == [1.0 ,1.0 ,1.0 ,2.0 ,2.0 ,5.0 ,5.0 ,5.0 ]
39
+
40
+ @test grid. zF == [2.0 ,1.0 ,- 0.0 ,- 1.0 ,- 3.0 ,- 5.0 ,- 10.0 ,- 15.0 ]
41
+ @test grid. zC == [1.5 ,0.5 ,- 0.5 ,- 2.0 ,- 4.0 ,- 7.5 ,- 12.5 ,- 17.5 ]
42
+
43
+ @test length (grid. xC) == 4 + 2 * 2
44
+ @test length (grid. yC) == 6 + 2 * 2
45
+ @test length (grid. zC) == 4 + 2 * 2
46
+ @test length (grid. xF) == 4 + 2 * 2
47
+ @test length (grid. yF) == 6 + 2 * 2
48
+ @test length (grid. zF) == 4 + 2 * 2
49
+
50
+ return nothing
51
+ end
52
+
53
+ function test_rectilinear_areas_volumes ()
54
+ zfs = [0.0 , - 1.0 , - 3.0 , - 5.0 , - 10.0 ]
55
+ grid = RectilinearGrid (size = (4 ,6 ,4 ), x = (0 ,12 ), y = (0 ,12 ), z = zfs, halo = (2 ,2 ,2 ))
56
+ @test ΔxC (1 ,1 ,1 ,grid) == grid. Δx
57
+ @test ΔyC (1 ,1 ,1 ,grid) == grid. Δy
58
+ @test ΔzC (1 ,1 ,1 ,grid) == grid. dzC[1 ]
59
+ @test ΔxF (1 ,1 ,1 ,grid) == grid. Δx
60
+ @test ΔyF (1 ,1 ,1 ,grid) == grid. Δy
61
+ @test ΔzF (1 ,1 ,1 ,grid) == grid. dzF[1 ]
62
+ @test Ax (1 ,1 ,1 ,grid) == grid. Δy* grid. dzF[1 ]
63
+ @test Ay (1 ,1 ,1 ,grid) == grid. Δx* grid. dzF[1 ]
64
+ @test Az (1 ,1 ,1 ,grid) == grid. Δx* grid. Δy
65
+ @test volume (1 ,1 ,1 ,grid) == grid. Δx* grid. Δy* grid. dzF[1 ]
66
+
67
+ return nothing
68
+ end
69
+
70
+ function test_lat_lon_grid ()
71
+ grid = LatLonGrid (size = (360 ,160 ,10 ), lat = (- 80 ,80 ), lon = (- 180 ,180 ), z = (0 ,- 20 ))
72
+ @test grid. Nx == 360
73
+ @test grid. Ny == 160
74
+ @test grid. Nz == 10
75
+
76
+ @test length (grid. xC) == 360 + 2 * 2
77
+ @test length (grid. yC) == 160 + 2 * 2
78
+ @test length (grid. zC) == 10 + 2 * 2
79
+ @test length (grid. xF) == 360 + 2 * 2
80
+ @test length (grid. yF) == 160 + 2 * 2
81
+ @test length (grid. zF) == 10 + 2 * 2
82
+ end
83
+
84
+ function test_load_lat_lon_grid ()
85
+ MeshArrays. GRID_LL360_download ();
86
+ γ = MeshArrays. GridSpec (" PeriodicChannel" ,MeshArrays. GRID_LL360);
87
+ Γ = MeshArrays. GridLoad (γ;option= " full" );
88
+
89
+ grid_info= (XC= Γ. XC[1 ], YC= Γ. YC[1 ], RC= Γ. RC,
90
+ XW= Γ. XW[1 ], YS= Γ. YS[1 ], RF= Γ. RF,
91
+ DXC= Γ. DXC[1 ], DYC= Γ. DYC[1 ], DRC= Γ. DRC,
92
+ DXG= Γ. DXG[1 ], DYG= Γ. DYG[1 ], DRF= Γ. DRF,
93
+ RAW= Γ. RAW[1 ], RAS= Γ. RAS[1 ], RAC= Γ. RAC[1 ],
94
+ hFacC= ones (360 ,160 ,50 ), hFacW= ones (360 ,160 ,50 ), hFacS= ones (360 ,160 ,50 ))
95
+
96
+ mask = ones (360 ,160 ,50 )
97
+
98
+ grid = LoadLatLonGrid (;grid_info = grid_info, size = (360 ,160 ,50 ), lat = (- 80 ,80 ), lon= (- 180 ,180 ), landmask = mask)
99
+
100
+ @test grid. Nx == 360
101
+ @test grid. Ny == 160
102
+ @test grid. Nz == 50
103
+
104
+ @test length (grid. xC) == 360 + 2 * 2
105
+ @test length (grid. yC) == 160 + 2 * 2
106
+ @test length (grid. zC) == 50 + 2 * 2
107
+ @test length (grid. xF) == 360 + 2 * 2
108
+ @test length (grid. yF) == 160 + 2 * 2
109
+ @test length (grid. zF) == 50 + 2 * 2
110
+
111
+ @test minimum (grid. dzF) == 10.0
112
+ @test maximum (grid. dzF) == 456.5
113
+
114
+ return nothing
115
+ end
116
+
117
+ function test_lat_lon_areas_volumes ()
118
+ grid = LatLonGrid (size = (360 ,160 ,10 ), lat = (- 80 ,80 ), lon = (- 180 ,180 ), z = (0 ,- 20 ))
119
+ @test ΔxC (1 ,1 ,1 ,grid) == grid. dxC[1 ,1 ]
120
+ @test ΔyC (1 ,1 ,1 ,grid) == grid. dyC[1 ,1 ]
121
+ @test ΔzC (1 ,1 ,1 ,grid) == grid. dzC[1 ]
122
+ @test ΔxF (1 ,1 ,1 ,grid) == grid. dxF[1 ,1 ]
123
+ @test ΔyF (1 ,1 ,1 ,grid) == grid. dyF[1 ,1 ]
124
+ @test ΔzF (1 ,1 ,1 ,grid) == grid. dzF[1 ]
125
+ @test Ax (1 ,1 ,1 ,grid) == grid. Ax[1 ,1 ,1 ]
126
+ @test Ay (1 ,1 ,1 ,grid) == grid. Ay[1 ,1 ,1 ]
127
+ @test Az (1 ,1 ,1 ,grid) == grid. Az[1 ,1 ]
128
+ @test volume (1 ,1 ,1 ,grid) == grid. Vol[1 ,1 ,1 ]
129
+
130
+ return nothing
131
+ end
132
+
133
+ @testset " Grids" begin
134
+ @testset " Rectilinear Grid" begin
135
+ test_rectilinear_grid ()
136
+ test_vertically_stretched_rectilinear_grid ()
137
+ test_rectilinear_areas_volumes ()
138
+ grid = RectilinearGrid (size = (4 ,6 ,2 ), x = (0 ,12 ), y = (0 ,12 ), z = (0 ,- 8 ), halo = (2 ,2 ,2 ))
139
+ @test try
140
+ show (grid); println ()
141
+ true
142
+ catch err
143
+ println (" error in show(::RectilinearGrid)" )
144
+ println (sprint (showerror, err))
145
+ false
146
+ end
147
+ @test grid isa RectilinearGrid
148
+ end
149
+ @testset " Latitude Longitude Grid" begin
150
+ test_lat_lon_grid ()
151
+ test_load_lat_lon_grid ()
152
+ test_lat_lon_areas_volumes ()
153
+ grid = LatLonGrid (size = (360 ,160 ,10 ), lat = (- 80 ,80 ), lon = (- 180 ,180 ), z = (0 ,- 20 ))
154
+ @test try
155
+ show (grid); println ()
156
+ true
157
+ catch err
158
+ println (" error in show(::LatLonGrid)" )
159
+ println (sprint (showerror, err))
160
+ false
161
+ end
162
+ @test grid isa LatLonGrid
163
+ end
164
+ end
0 commit comments