@@ -244,3 +244,79 @@ def test_bcs():
244244 # top
245245 assert_array_equal (d [myg .ilo :myg .ihi + 1 , myg .jhi - 1 :myg .jhi + 1 ],
246246 - np .fliplr (d [myg .ilo :myg .ihi + 1 , myg .jhi + 1 :myg .jhi + 3 ]))
247+
248+
249+ # PolarGrid tests
250+ class TestPolarGrid (object ):
251+ @classmethod
252+ def setup_class (cls ):
253+ """ this is run once for each class before any tests """
254+ pass
255+
256+ @classmethod
257+ def teardown_class (cls ):
258+ """ this is run once for each class after all tests """
259+ pass
260+
261+ def setup_method (self ):
262+ """ this is run before each test """
263+ self .g = patch .PolarGrid (4 , 6 , ng = 2 , ymax = 1.5 )
264+
265+ def teardown_method (self ):
266+ """ this is run after each test """
267+ self .g = None
268+
269+ def test_dx_dy (self ):
270+ assert self .g .dx == 0.25
271+ assert self .g .dy == 0.25
272+
273+ def test_grid_coords (self ):
274+ assert_array_equal (self .g .x [self .g .ilo :self .g .ihi + 1 ],
275+ np .array ([0.125 , 0.375 , 0.625 , 0.875 ]))
276+ assert_array_equal (self .g .y [self .g .jlo :self .g .jhi + 1 ],
277+ np .array ([0.125 , 0.375 , 0.625 , 0.875 , 1.125 , 1.375 ]))
278+
279+ def test_grid_2d_coords (self ):
280+ assert_array_equal (self .g .x , self .g .x2d [:, self .g .jc ])
281+ assert_array_equal (self .g .y , self .g .y2d [self .g .ic , :])
282+
283+ def test_scratch_array (self ):
284+ q = self .g .scratch_array ()
285+ assert q .shape == (self .g .qx , self .g .qy )
286+
287+ def test_coarse_like (self ):
288+ q = self .g .coarse_like (2 )
289+ assert q .qx == 2 * self .g .ng + self .g .nx // 2
290+ assert q .qy == 2 * self .g .ng + self .g .ny // 2
291+
292+ def test_fine_like (self ):
293+ q = self .g .fine_like (2 )
294+ assert q .qx == 2 * self .g .ng + 2 * self .g .nx
295+ assert q .qy == 2 * self .g .ng + 2 * self .g .ny
296+
297+ def test_norm (self ):
298+ q = self .g .scratch_array ()
299+ # there are 24 elements, the norm L2 norm is
300+ # sqrt(dx*dy*24)
301+ q .v ()[:, :] = np .array ([[1 , 1 , 1 , 1 , 1 , 1 ],
302+ [1 , 1 , 1 , 1 , 1 , 1 ],
303+ [1 , 1 , 1 , 1 , 1 , 1 ],
304+ [1 , 1 , 1 , 1 , 1 , 1 ]])
305+
306+ assert q .norm () == np .sqrt (24 * self .g .dx * self .g .dy )
307+
308+ def test_equality (self ):
309+ g2 = patch .PolarGrid (2 , 5 , ng = 1 )
310+ assert g2 != self .g
311+
312+ def test_area_x (self ):
313+ A = self .g .area_x ()
314+ assert A [0 ,0 ] == (self .g .yr [0 ] - self .g .yl [0 ]) * (self .g .xr [0 ] - self .g .xl [0 ]) * 0.5
315+
316+ def test_area_y (self ):
317+ A = self .g .area_y ()
318+ assert A [0 ] == (self .g .xr - self .g .xl )
319+
320+ def test_cell_volumes (self ):
321+ V = self .g .cell_volumes ()
322+ assert V [0 ,0 ] == (self .g .yr [0 ] - self .g .yl [0 ]) * (self .g .xr [0 ] ** 2 - self .g .xl [0 ] ** 2 ) * 0.5
0 commit comments