From 580e01bd1c4d02ec2f327d2dfd4f1fc15ccdf269 Mon Sep 17 00:00:00 2001 From: Daniel Otto de Mentock Date: Mon, 29 Aug 2022 11:44:50 +0000 Subject: [PATCH] fix grid add primitive bug --- python/damask/_grid.py | 2 +- python/tests/test_Grid.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index e5c36413f..5810f89c2 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -1206,7 +1206,7 @@ class Grid: coords_rot = R.broadcast_to(tuple(self.cells))@coords with np.errstate(all='ignore'): - mask = np.sum(np.power(coords_rot/r,2.0**np.array(exponent)),axis=-1) > 1.0 + mask = np.sum(np.power(np.abs(coords_rot)/r,2.0**np.array(exponent)),axis=-1) > 1.0 if periodic: # translate back to center mask = np.roll(mask,((c/self.size-0.5)*self.cells).round().astype(np.int64),(0,1,2)) diff --git a/python/tests/test_Grid.py b/python/tests/test_Grid.py index 05344d28d..fc1af09b6 100644 --- a/python/tests/test_Grid.py +++ b/python/tests/test_Grid.py @@ -299,7 +299,6 @@ class TestGrid: G_2 = Grid(np.ones(g,'i'),s,o).add_primitive(diameter,center2,exponent) assert np.count_nonzero(G_1.material!=2) == np.count_nonzero(G_2.material!=2) - @pytest.mark.parametrize('center',[np.random.randint(4,10,(3)), np.random.randint(2,10), np.random.rand()*4, @@ -315,6 +314,14 @@ class TestGrid: G_2 = Grid(np.ones(g,'i'),s).add_primitive(.3,center,1,fill,Rotation.from_random(),inverse,periodic=periodic) assert G_1 == G_2 + @pytest.mark.parametrize('exponent',[1,np.inf,np.random.random(3)*2.]) + def test_add_primitive_shape_symmetry(self,exponent): + """Shapes defined in the center should always produce a grid with reflection symmetry along the coordinate axis.""" + o = np.random.random(3)-.5 + s = np.random.random(3)*5. + grid = Grid(np.zeros(np.random.randint(8,32,3),'i'),s,o).add_primitive(np.random.random(3)*3.,o+s/2.,exponent) + for axis in [0,1,2]: + assert np.all(grid.material==np.flip(grid.material,axis=axis)) @pytest.mark.parametrize('selection',[1,None]) def test_vicinity_offset(self,selection):