From 9273c887824fa940f3be541958e7f933247b9a26 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 Apr 2020 06:10:48 +0200 Subject: [PATCH] [skip ci] WIP: migrating from PRIVATE repo --- python/tests/test_grid_filters.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 35f28bb0d..84d2ef771 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -138,3 +138,33 @@ class TestGridFilters: field = np.ones(tuple(grid)+shape)*np.random.random()*1.0e5 assert np.allclose(differential_operator(size,field),0.0) + + @pytest.mark.parametrize('field_def,curl_def', + [(['np.sin(np.pi*2*nodes[...,2]/size[2])', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '0.0' ], + ['0.0' , '0.0', '0.0', + 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', '0.0', '0.0', + '0.0', '0.0', '0.0'] + ), + (['np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0', '0.0', + '0.0', '0.0', '0.0', + 'np.cos(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['0.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + 'np.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', '0.0'] + ) + ]) + def test_curl(self,field_def,curl_def): + size = np.random.random(3)+1.0 + grid = np.random.randint(8,32,(3)) + + nodes = grid_filters.cell_coord0(grid,size) + my_locals = locals() # needed for list comprehension + + field = np.stack([np.broadcast_to(eval(f,globals(),my_locals),grid) for f in field_def],axis=-1) + field = field.reshape(tuple(grid) + ((3,3) if len(field_def)==9 else (3,))) + curl = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in curl_def], axis=-1) + curl = curl.reshape(tuple(grid) + ((3,3) if len(curl_def)==9 else (3,))) + + assert np.allclose(curl,grid_filters.curl(size,field))