From 2d14790863bb3ebbef8aee5ebd17cbf656543642 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 Apr 2020 05:08:47 +0200 Subject: [PATCH 01/13] the result of a differential operator operating on a constant field is 0 --- python/tests/test_grid_filters.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index eb359006a..35f28bb0d 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -101,6 +101,7 @@ class TestGridFilters: with pytest.raises(ValueError): function(uneven) + @pytest.mark.parametrize('mode',[True,False]) @pytest.mark.parametrize('function',[grid_filters.node_coord0_gridSizeOrigin, grid_filters.cell_coord0_gridSizeOrigin]) @@ -120,3 +121,20 @@ class TestGridFilters: grid = np.random.randint(8,32,(3)) F = np.broadcast_to(np.eye(3), tuple(grid)+(3,3)) assert all(grid_filters.regrid(size,F,grid) == np.arange(grid.prod())) + + + @pytest.mark.parametrize('differential_operator',[grid_filters.curl, + grid_filters.divergence, + grid_filters.gradient]) + def test_differential_operator_constant(self,differential_operator): + size = np.random.random(3)+1.0 + grid = np.random.randint(8,32,(3)) + shapes = { + grid_filters.curl: [(3,),(3,3)], + grid_filters.divergence:[(3,),(3,3)], + grid_filters.gradient: [(1,),(3,)] + } + for shape in shapes[differential_operator]: + field = np.ones(tuple(grid)+shape)*np.random.random()*1.0e5 + assert np.allclose(differential_operator(size,field),0.0) + From 9273c887824fa940f3be541958e7f933247b9a26 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 27 Apr 2020 06:10:48 +0200 Subject: [PATCH 02/13] [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)) From 0650f46ab1540c3e995df1d188a75a95c8b5ae69 Mon Sep 17 00:00:00 2001 From: Vitesh Shah Date: Mon, 4 May 2020 16:57:08 +0200 Subject: [PATCH 03/13] Tests for gradient --- python/tests/test_grid_filters.py | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 84d2ef771..2ee062ee5 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -168,3 +168,63 @@ class TestGridFilters: curl = curl.reshape(tuple(grid) + ((3,3) if len(curl_def)==9 else (3,))) assert np.allclose(curl,grid_filters.curl(size,field)) + + grad_test_data = [(['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], + ['0.0', '0.0', '0.0', + '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', + '0.0', '0.0', '0.0' ]), + + (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), + + (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), + + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', + '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', + '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + + (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]) + ] + +# @pytest.mark.parametrize('field_def,grad_def', +# [(['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], +# ['0.0', '0.0', '0.0', +# '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', +# '0.0', '0.0', '0.0' ]) +# ]) + @pytest.mark.parametrize('field_def,grad_def',grad_test_data) + + def test_grad(self,field_def,grad_def): +# size = np.random.random(3)+1.0 +# grid = np.random.randint(8,32,(3)) + size = np.array([1.0,1.0,1.0]) + grid = np.array([2,5,3]) + + nodes = grid_filters.cell_coord0(grid,size) +# print('y nodes are',nodes[...,1]) +# print('inner bracket is',np.pi*2*nodes[...,1]/size[1]) + my_locals = locals() # needed for list comprehension + + print('field length is',len(field_def)) + field = np.stack([np.broadcast_to(eval(f,globals(),my_locals),grid) for f in field_def],axis=-1) + print('field initial shape is',field.shape) + field = field.reshape(tuple(grid) + ((3,3) if len(field_def)==9 else (3,))) + print('field is',field.shape) + grad = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in grad_def], axis=-1) + grad = grad.reshape(tuple(grid) + ((3,3) if len(grad_def)==9 else (3,))) + print('gradient is',grad.shape) + print('code gradient is',grid_filters.gradient(size,field)) + assert np.allclose(grad,grid_filters.gradient(size,field)) + From 307debebd45e2fbad925c297bd2b3d03f2fba8ef Mon Sep 17 00:00:00 2001 From: Vitesh Shah Date: Tue, 5 May 2020 10:14:27 +0200 Subject: [PATCH 04/13] Correct shapes for gradient calculations --- python/tests/test_grid_filters.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 2ee062ee5..8170ba7af 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -189,42 +189,32 @@ class TestGridFilters: '0.0', '0.0', '0.0', '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), - (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])'], + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ + 'np.sin(np.pi*2*nodes[...,2]/size[2])'], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]) + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), + + (['8.0' ], + ['0.0', '0.0', '0.0' ]) ] -# @pytest.mark.parametrize('field_def,grad_def', -# [(['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], -# ['0.0', '0.0', '0.0', -# '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', -# '0.0', '0.0', '0.0' ]) -# ]) @pytest.mark.parametrize('field_def,grad_def',grad_test_data) def test_grad(self,field_def,grad_def): -# size = np.random.random(3)+1.0 -# grid = np.random.randint(8,32,(3)) - size = np.array([1.0,1.0,1.0]) - grid = np.array([2,5,3]) + size = np.random.random(3)+1.0 + grid = np.random.randint(8,32,(3)) nodes = grid_filters.cell_coord0(grid,size) -# print('y nodes are',nodes[...,1]) -# print('inner bracket is',np.pi*2*nodes[...,1]/size[1]) my_locals = locals() # needed for list comprehension - print('field length is',len(field_def)) field = np.stack([np.broadcast_to(eval(f,globals(),my_locals),grid) for f in field_def],axis=-1) - print('field initial shape is',field.shape) - field = field.reshape(tuple(grid) + ((3,3) if len(field_def)==9 else (3,))) - print('field is',field.shape) + field = field.reshape(tuple(grid) + ((3,) if len(field_def)==3 else (1,))) grad = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in grad_def], axis=-1) grad = grad.reshape(tuple(grid) + ((3,3) if len(grad_def)==9 else (3,))) - print('gradient is',grad.shape) - print('code gradient is',grid_filters.gradient(size,field)) + assert np.allclose(grad,grid_filters.gradient(size,field)) From bd518b28067b75c57d3bb13dbfc6e24327fb4708 Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 12:44:56 +0200 Subject: [PATCH 05/13] test_curl done --- python/tests/test_curl.py | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 python/tests/test_curl.py diff --git a/python/tests/test_curl.py b/python/tests/test_curl.py new file mode 100644 index 000000000..52e12d223 --- /dev/null +++ b/python/tests/test_curl.py @@ -0,0 +1,63 @@ +import pytest +import numpy as np +from damask import grid_filters + + +class TestGridFilters: + + + @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'] + ), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','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'] + ), + (['5.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,1]/size[1])'], + ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', + '0.0', '0.0', '0.0', + '0.0', '0.0', '0.0'] + ), + (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], + ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ + '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ + '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])'] + ), + (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], + ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ + '0.0',\ + '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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)) + + \ No newline at end of file From 8b4baecdee110da3e54efa6cb40505d437004e83 Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 12:54:24 +0200 Subject: [PATCH 06/13] better looking test fields --- python/tests/test_curl.py | 81 ++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/python/tests/test_curl.py b/python/tests/test_curl.py index 52e12d223..c3bcc2682 100644 --- a/python/tests/test_curl.py +++ b/python/tests/test_curl.py @@ -6,46 +6,47 @@ from damask import grid_filters class TestGridFilters: - @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'] - ), - (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', - 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', - 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','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'] - ), - (['5.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,1]/size[1])'], - ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', - '0.0', '0.0', '0.0', - '0.0', '0.0', '0.0'] - ), - (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], - ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ - '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ - '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])'] - ), - (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], - ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ - '0.0',\ - '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'] - ) - ]) + curl_test_data =[(['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'] + ), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','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'] + ), + (['5.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,1]/size[1])'], + ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', + '0.0', '0.0', '0.0', + '0.0', '0.0', '0.0'] + ), + (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], + ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ + '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ + '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])'] + ), + (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], + ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ + '0.0',\ + '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'])] + + + @pytest.mark.parametrize('field_def,curl_def',curl_test_data) + def test_curl(self,field_def,curl_def): size = np.random.random(3)+1.0 grid = np.random.randint(8,32,(3)) From d4091a21a8becd0e6d5adf1907ef493bdea730ad Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 13:05:53 +0200 Subject: [PATCH 07/13] grad test done --- python/tests/test_grad.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 python/tests/test_grad.py diff --git a/python/tests/test_grad.py b/python/tests/test_grad.py new file mode 100644 index 000000000..d02c57cdc --- /dev/null +++ b/python/tests/test_grad.py @@ -0,0 +1,49 @@ +import pytest +import numpy as np +from damask import grid_filters + + +class TestGridFilters: + + grad_test_data = [(['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], + ['0.0', '0.0', '0.0', + '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', + '0.0', '0.0', '0.0' ]), + (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), + (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ + 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', + '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', + '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), + (['8.0' ], + ['0.0', '0.0', '0.0' ])] + + @pytest.mark.parametrize('field_def,grad_def',grad_test_data) + + def test_grad(self,field_def,grad_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,) if len(field_def)==3 else (1,))) + grad = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in grad_def], axis=-1) + grad = grad.reshape(tuple(grid) + ((3,3) if len(grad_def)==9 else (3,))) + + assert np.allclose(grad,grid_filters.gradient(size,field)) + \ No newline at end of file From a122a307b9d714eccb2259a78cc7a20a2694571d Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 14:14:18 +0200 Subject: [PATCH 08/13] div test done --- python/tests/test_div.py | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 python/tests/test_div.py diff --git a/python/tests/test_div.py b/python/tests/test_div.py new file mode 100644 index 000000000..f703c5371 --- /dev/null +++ b/python/tests/test_div.py @@ -0,0 +1,63 @@ +import pytest +import numpy as np +from damask import grid_filters + + +class TestGridFilters: + + + div_test_data =[(['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0', + '0.0' , '0.0', '0.0', + '0.0' , '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]' ,'0.0', '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.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0'] + ), + (['1.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], + ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] + ), + ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]'] + ), + (['400.0', '0.0', '0.0', + 'np.sin(np.pi*2*nodes[...,0]/size[0])', 'np.sin(np.pi*2*nodes[...,1]/size[1])', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '10.0', '6.0' ], + ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','0.0' ] + ), + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]',] + ), + (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], + ['-np.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]'] + ) + + + ] + + + @pytest.mark.parametrize('field_def,div_def',div_test_data) + + def test_div(self,field_def,div_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,))) + div = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in div_def], axis=-1) + if len(div_def)==3: + div = div.reshape(tuple(grid) + ((3,))) + else: + div=div.reshape(tuple(grid)) + + assert np.allclose(div,grid_filters.divergence(size,field)) + \ No newline at end of file From 26f55781aedede7f2acc6ef1715938b0b1bcfb7c Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 14:26:15 +0200 Subject: [PATCH 09/13] merge test into gridFilters --- python/tests/test_div.py | 63 ---------- python/tests/test_grad.py | 49 -------- python/tests/test_grid_filters.py | 188 ++++++++++++++++++++---------- 3 files changed, 126 insertions(+), 174 deletions(-) delete mode 100644 python/tests/test_div.py delete mode 100644 python/tests/test_grad.py diff --git a/python/tests/test_div.py b/python/tests/test_div.py deleted file mode 100644 index f703c5371..000000000 --- a/python/tests/test_div.py +++ /dev/null @@ -1,63 +0,0 @@ -import pytest -import numpy as np -from damask import grid_filters - - -class TestGridFilters: - - - div_test_data =[(['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0', - '0.0' , '0.0', '0.0', - '0.0' , '0.0', '0.0'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]' ,'0.0', '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.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0'] - ), - (['1.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], - ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] - ), - ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]'] - ), - (['400.0', '0.0', '0.0', - 'np.sin(np.pi*2*nodes[...,0]/size[0])', 'np.sin(np.pi*2*nodes[...,1]/size[1])', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '10.0', '6.0' ], - ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','0.0' ] - ), - (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]',] - ), - (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], - ['-np.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]'] - ) - - - ] - - - @pytest.mark.parametrize('field_def,div_def',div_test_data) - - def test_div(self,field_def,div_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,))) - div = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in div_def], axis=-1) - if len(div_def)==3: - div = div.reshape(tuple(grid) + ((3,))) - else: - div=div.reshape(tuple(grid)) - - assert np.allclose(div,grid_filters.divergence(size,field)) - \ No newline at end of file diff --git a/python/tests/test_grad.py b/python/tests/test_grad.py deleted file mode 100644 index d02c57cdc..000000000 --- a/python/tests/test_grad.py +++ /dev/null @@ -1,49 +0,0 @@ -import pytest -import numpy as np -from damask import grid_filters - - -class TestGridFilters: - - grad_test_data = [(['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], - ['0.0', '0.0', '0.0', - '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', - '0.0', '0.0', '0.0' ]), - (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), - (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), - (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ - 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', - '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', - '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), - (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), - (['8.0' ], - ['0.0', '0.0', '0.0' ])] - - @pytest.mark.parametrize('field_def,grad_def',grad_test_data) - - def test_grad(self,field_def,grad_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,) if len(field_def)==3 else (1,))) - grad = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in grad_def], axis=-1) - grad = grad.reshape(tuple(grid) + ((3,3) if len(grad_def)==9 else (3,))) - - assert np.allclose(grad,grid_filters.gradient(size,field)) - \ No newline at end of file diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 8170ba7af..6a30481c9 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -139,68 +139,32 @@ class TestGridFilters: 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)) - - grad_test_data = [(['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], - ['0.0', '0.0', '0.0', - '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', - '0.0', '0.0', '0.0' ]), - - (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), - - (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), - - (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ - 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', - '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', - '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), - - (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), - - (['8.0' ], - ['0.0', '0.0', '0.0' ]) - ] + grad_test_data = [ + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], + ['0.0', '0.0', '0.0', + '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', + '0.0', '0.0', '0.0' ]), + (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), + (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ + 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', + '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', + '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), + (['8.0' ], + ['0.0', '0.0', '0.0' ])] @pytest.mark.parametrize('field_def,grad_def',grad_test_data) @@ -218,3 +182,103 @@ class TestGridFilters: assert np.allclose(grad,grid_filters.gradient(size,field)) + + curl_test_data =[ + (['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']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','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']), + (['5.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,1]/size[1])'], + ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', + '0.0', '0.0', '0.0', + '0.0', '0.0', '0.0']), + (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], + ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ + '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ + '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])']), + (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], + ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ + '0.0',\ + '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'])] + + @pytest.mark.parametrize('field_def,curl_def',curl_test_data) + + 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)) + + + div_test_data =[ + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0', + '0.0' , '0.0', '0.0', + '0.0' , '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]' ,'0.0', '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.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0']), + (['1.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], + ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] + ), + ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + (['400.0', '0.0', '0.0', + 'np.sin(np.pi*2*nodes[...,0]/size[0])', 'np.sin(np.pi*2*nodes[...,1]/size[1])', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '10.0', '6.0' ], + ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','0.0' ]), + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]',]), + (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], + ['-np.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]']) + ] + + @pytest.mark.parametrize('field_def,div_def',div_test_data) + + def test_div(self,field_def,div_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,))) + div = np.stack([np.broadcast_to(eval(c,globals(),my_locals),grid) for c in div_def], axis=-1) + if len(div_def)==3: + div = div.reshape(tuple(grid) + ((3,))) + else: + div=div.reshape(tuple(grid)) + + assert np.allclose(div,grid_filters.divergence(size,field)) + + From d977f2ad254736f36b91e3b05228d9af339ed088 Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 14:26:54 +0200 Subject: [PATCH 10/13] already merged --- python/tests/test_curl.py | 64 --------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 python/tests/test_curl.py diff --git a/python/tests/test_curl.py b/python/tests/test_curl.py deleted file mode 100644 index c3bcc2682..000000000 --- a/python/tests/test_curl.py +++ /dev/null @@ -1,64 +0,0 @@ -import pytest -import numpy as np -from damask import grid_filters - - -class TestGridFilters: - - - curl_test_data =[(['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'] - ), - (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', - 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', - 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','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'] - ), - (['5.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,1]/size[1])'], - ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', - '0.0', '0.0', '0.0', - '0.0', '0.0', '0.0'] - ), - (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], - ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ - '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ - '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])'] - ), - (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], - ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ - '0.0',\ - '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'])] - - - @pytest.mark.parametrize('field_def,curl_def',curl_test_data) - - 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)) - - \ No newline at end of file From fcd0028b83ef5428032abfdcbe91ee6dcd8a5ae3 Mon Sep 17 00:00:00 2001 From: "f.basile" Date: Wed, 6 May 2020 14:33:04 +0200 Subject: [PATCH 11/13] avoid line length limit (maximum line length 182 > 132 --- python/tests/test_grid_filters.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 6a30481c9..3d06ee01c 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -181,7 +181,10 @@ class TestGridFilters: grad = grad.reshape(tuple(grid) + ((3,3) if len(grad_def)==9 else (3,))) assert np.allclose(grad,grid_filters.gradient(size,field)) - + + + + curl_test_data =[ (['np.sin(np.pi*2*nodes[...,2]/size[2])', '0.0', '0.0', @@ -208,7 +211,9 @@ class TestGridFilters: ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0']), - (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], + (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', \ + '8*np.sin(np.pi*2*nodes[...,0]/size[0])', \ + '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])']), @@ -251,11 +256,17 @@ class TestGridFilters: ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ + 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', \ + 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), (['400.0', '0.0', '0.0', - 'np.sin(np.pi*2*nodes[...,0]/size[0])', 'np.sin(np.pi*2*nodes[...,1]/size[1])', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + 'np.sin(np.pi*2*nodes[...,0]/size[0])', \ + 'np.sin(np.pi*2*nodes[...,1]/size[1])', \ + 'np.sin(np.pi*2*nodes[...,2]/size[2])', '0.0', '10.0', '6.0' ], - ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','0.0' ]), + ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'\ + '+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]'\ + '+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','0.0' ]), (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]',]), (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], From c8701a46657f1d8bee9c096bc44a4b05b04a21bb Mon Sep 17 00:00:00 2001 From: Vitesh Shah Date: Fri, 8 May 2020 12:15:10 +0200 Subject: [PATCH 12/13] Cleanup/better readability --- python/tests/test_grid_filters.py | 83 +++++++++++++++++++------------ 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 3d06ee01c..3dbc665c0 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -144,25 +144,31 @@ class TestGridFilters: ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], - ['0.0', '0.0', '0.0', - '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', - '0.0', '0.0', '0.0' ]), - (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), + + (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], + ['0.0', '0.0', '0.0', + '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', + '0.0', '0.0', '0.0' ]), + + (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), + (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ - 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + 'np.sin(np.pi*2*nodes[...,2]/size[2])'], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), + (['8.0' ], ['0.0', '0.0', '0.0' ])] @@ -187,36 +193,41 @@ class TestGridFilters: curl_test_data =[ - (['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' ], + (['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'], + + (['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']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','np.sin(np.pi*2*nodes[...,2]/size[2])', 'np.sin(np.pi*2*nodes[...,0]/size[0])','np.cos(np.pi*2*nodes[...,1]/size[1])','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']), + (['5.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,1]/size[1])'], ['0.0', '0.0', '-2*np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0']), + (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', \ '8*np.sin(np.pi*2*nodes[...,0]/size[0])', \ '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ - '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ - '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])']), + '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ + '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])']), + (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ '0.0',\ @@ -240,35 +251,41 @@ class TestGridFilters: div_test_data =[ - (['np.sin(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[...,0]/size[0])', '0.0', '0.0', + '0.0' , '0.0', '0.0', + '0.0' , '0.0', '0.0'], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]' ,'0.0', '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', '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.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0']), - (['1.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], - ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] + + (['1.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], + ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] ), - ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + + ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', \ 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + (['400.0', '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,0]/size[0])', \ 'np.sin(np.pi*2*nodes[...,1]/size[1])', \ 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '10.0', '6.0' ], + '0.0', '10.0', '6.0'], ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'\ - '+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]'\ - '+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]','0.0' ]), + '+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]'\ + '+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', '0.0' ]), + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]',]), + (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], ['-np.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]']) ] From 6928a8290fbab2506b53fffed673484f037fbf55 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 10 May 2020 13:02:26 +0200 Subject: [PATCH 13/13] less whitespace, alingment only within one vector/tensor --- python/tests/test_grid_filters.py | 154 ++++++++++++++---------------- 1 file changed, 74 insertions(+), 80 deletions(-) diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index 3dbc665c0..ab60c0446 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -140,44 +140,45 @@ class TestGridFilters: grad_test_data = [ - (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]','0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '0.0']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[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[...,1]/size[1])', '0.0' ], - ['0.0', '0.0', '0.0', - '0.0', '-np.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '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.pi*2/size[1]*np.sin(np.pi*2*nodes[...,1]/size[1])', '0.0', + '0.0', '0.0', '0.0' ]), - (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), + (['1.0', '0.0', '2.0*np.cos(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])']), - (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), + (['np.cos(np.pi*2*nodes[...,2]/size[2])', '3.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['0.0', '0.0', '-np.sin(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[...,2]/size[2])*np.pi*2/size[2]']), - (['np.sin(np.pi*2*nodes[...,0]/size[0])','np.sin(np.pi*2*nodes[...,1]/size[1])',\ - 'np.sin(np.pi*2*nodes[...,2]/size[2])'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', - '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', - '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])', + 'np.sin(np.pi*2*nodes[...,1]/size[1])', + 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0', + '0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0', + '0.0', '0.0', 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), - (['np.sin(np.pi*2*nodes[...,0]/size[0])' ], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0' ]), + (['np.sin(np.pi*2*nodes[...,0]/size[0])'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]', '0.0', '0.0']), - (['8.0' ], - ['0.0', '0.0', '0.0' ])] + (['8.0'], + ['0.0', '0.0', '0.0' ]) + ] @pytest.mark.parametrize('field_def,grad_def',grad_test_data) - def test_grad(self,field_def,grad_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 @@ -187,22 +188,19 @@ class TestGridFilters: grad = grad.reshape(tuple(grid) + ((3,3) if len(grad_def)==9 else (3,))) assert np.allclose(grad,grid_filters.gradient(size,field)) - - - - - - curl_test_data =[ - (['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'], + + + curl_test_data = [ + (['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'], + (['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']), @@ -221,20 +219,22 @@ class TestGridFilters: '0.0', '0.0', '0.0', '0.0', '0.0', '0.0']), - (['4*np.sin(np.pi*2*nodes[...,2]/size[2])', \ - '8*np.sin(np.pi*2*nodes[...,0]/size[0])', \ + ([ '4*np.sin(np.pi*2*nodes[...,2]/size[2])', + '8*np.sin(np.pi*2*nodes[...,0]/size[0])', '16*np.sin(np.pi*2*nodes[...,1]/size[1])'], - ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', \ - '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', \ + ['16*np.pi*2/size[1]*np.cos(np.pi*2*nodes[...,1]/size[1])', + '4*np.pi*2/size[2]*np.cos(np.pi*2*nodes[...,2]/size[2])', '8*np.pi*2/size[0]*np.cos(np.pi*2*nodes[...,0]/size[0])']), - (['0.0', 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', '0.0'], - ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ - '0.0',\ - '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'])] + (['0.0', + 'np.cos(np.pi*2*nodes[...,0]/size[0])+5*np.cos(np.pi*2*nodes[...,2]/size[2])', + '0.0'], + ['5*np.sin(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', + '0.0', + '-np.sin(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]']) + ] - @pytest.mark.parametrize('field_def,curl_def',curl_test_data) - + @pytest.mark.parametrize('field_def,curl_def',curl_test_data) def test_curl(self,field_def,curl_def): size = np.random.random(3)+1.0 grid = np.random.randint(8,32,(3)) @@ -251,47 +251,43 @@ class TestGridFilters: div_test_data =[ - (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0', - '0.0' , '0.0', '0.0', - '0.0' , '0.0', '0.0'], - ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]' ,'0.0', '0.0']), + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0', + '0.0' , '0.0', '0.0', + '0.0' , '0.0', '0.0'], + ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]','0.0', '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', '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.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]', '0.0']), - (['1.0', '0.0', '0.0', - '0.0', '0.0', '0.0', - '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], - ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] + (['1.0', '0.0', '0.0', + '0.0', '0.0', '0.0', + '0.0', '0.0', '2*np.cos(np.pi*2*nodes[...,2]/size[2])' ], + ['0.0', '0.0', '-2.0*np.pi*2/size[2]*np.sin(np.pi*2*nodes[...,2]/size[2])'] ), - ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], + ([ '23.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '100.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '0.0', 'np.sin(np.pi*2*nodes[...,2]/size[2])'], ['np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]',\ - 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', \ - 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), + 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', \ + 'np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]']), - (['400.0', '0.0', '0.0', - 'np.sin(np.pi*2*nodes[...,0]/size[0])', \ - 'np.sin(np.pi*2*nodes[...,1]/size[1])', \ - 'np.sin(np.pi*2*nodes[...,2]/size[2])', - '0.0', '10.0', '6.0'], - ['0.0','np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]'\ - '+np.cos(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]'\ - '+np.cos(np.pi*2*nodes[...,2]/size[2])*np.pi*2/size[2]', '0.0' ]), + (['400.0', '0.0', '0.0', + 'np.sin(np.pi*2*nodes[...,0]/size[0])', 'np.sin(np.pi*2*nodes[...,1]/size[1])', 'np.sin(np.pi*2*nodes[...,2]/size[2])', + '0.0', '10.0', '6.0'], + ['0.0','np.sum(np.cos(np.pi*2*nodes/size)*np.pi*2/size,axis=-1)', '0.0' ]), - (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], + (['np.sin(np.pi*2*nodes[...,0]/size[0])', '0.0', '0.0'], ['np.cos(np.pi*2*nodes[...,0]/size[0])*np.pi*2/size[0]',]), - (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], + (['0.0', 'np.cos(np.pi*2*nodes[...,1]/size[1])', '0.0' ], ['-np.sin(np.pi*2*nodes[...,1]/size[1])*np.pi*2/size[1]']) ] - - @pytest.mark.parametrize('field_def,div_def',div_test_data) - + + @pytest.mark.parametrize('field_def,div_def',div_test_data) + def test_div(self,field_def,div_def): size = np.random.random(3)+1.0 grid = np.random.randint(8,32,(3)) @@ -308,5 +304,3 @@ class TestGridFilters: div=div.reshape(tuple(grid)) assert np.allclose(div,grid_filters.divergence(size,field)) - -