better names

This commit is contained in:
Martin Diehl 2019-12-05 18:32:21 +01:00
parent b1ff178109
commit 4ddfd82304
2 changed files with 21 additions and 21 deletions

View File

@ -57,7 +57,7 @@ def gradient(size,field):
return np.fft.irfftn(gradient,axes=(0,1,2),s=field.shape[:3]) return np.fft.irfftn(gradient,axes=(0,1,2),s=field.shape[:3])
def coord0_cell(grid,size): def cell_coord0(grid,size):
"""Cell center positions (undeformed).""" """Cell center positions (undeformed)."""
delta = size/grid*0.5 delta = size/grid*0.5
x, y, z = np.meshgrid(np.linspace(delta[2],size[2]-delta[2],grid[2]), x, y, z = np.meshgrid(np.linspace(delta[2],size[2]-delta[2],grid[2]),
@ -67,7 +67,7 @@ def coord0_cell(grid,size):
return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3) return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
def displacement_fluct_cell(size,F): def cell_displacement_fluct(size,F):
"""Cell center displacement field from fluctuation part of the deformation gradient field.""" """Cell center displacement field from fluctuation part of the deformation gradient field."""
integrator = 0.5j*size/np.pi integrator = 0.5j*size/np.pi
@ -83,13 +83,13 @@ def displacement_fluct_cell(size,F):
return np.fft.irfftn(displacement,axes=(0,1,2),s=F.shape[:3]) return np.fft.irfftn(displacement,axes=(0,1,2),s=F.shape[:3])
def displacement_avg_cell(size,F): def cell_displacement_avg(size,F):
"""Cell center displacement field from average part of the deformation gradient field.""" """Cell center displacement field from average part of the deformation gradient field."""
F_avg = np.average(F,axis=(0,1,2)) F_avg = np.average(F,axis=(0,1,2))
return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),coord0_cell(F.shape[:3],size)) return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),cell_coord0(F.shape[:3],size))
def coord0_node(grid,size): def node_coord0(grid,size):
"""Nodal positions (undeformed).""" """Nodal positions (undeformed)."""
x, y, z = np.meshgrid(np.linspace(0,size[2],1+grid[2]), x, y, z = np.meshgrid(np.linspace(0,size[2],1+grid[2]),
np.linspace(0,size[1],1+grid[1]), np.linspace(0,size[1],1+grid[1]),
@ -98,12 +98,12 @@ def coord0_node(grid,size):
return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3) return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
def displacement_fluct_node(size,F): def node_displacement_fluct(size,F):
return cell_2_node(displacement_fluct_cell(size,F)) return cell_2_node(cell_displacement_fluct(size,F))
def displacement_avg_node(size,F): def node_displacement_avg(size,F):
F_avg = np.average(F,axis=(0,1,2)) F_avg = np.average(F,axis=(0,1,2))
return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),coord0_node(F.shape[:3],size)) return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),node_coord0(F.shape[:3],size))
def cell_2_node(cell_data): def cell_2_node(cell_data):
@ -124,9 +124,9 @@ def node_2_cell(node_data):
def regrid(size,F,new_grid): def regrid(size,F,new_grid):
"""tbd.""" """tbd."""
c = coord0_cell(F.shape[:3][::-1],size) \ c = cell_coord0(F.shape[:3][::-1],size) \
+ displacement_avg_cell(size,F) \ + cell_displacement_avg(size,F) \
+ displacement_fluct_cell(size,F) + cell_displacement_fluct(size,F)
outer = np.dot(np.average(F,axis=(0,1,2)),size) outer = np.dot(np.average(F,axis=(0,1,2)),size)
for d in range(3): for d in range(3):
@ -134,5 +134,5 @@ def regrid(size,F,new_grid):
c[np.where(c[:,:,:,d]>outer[d])] -= outer[d] c[np.where(c[:,:,:,d]>outer[d])] -= outer[d]
tree = spatial.cKDTree(c.reshape((-1,3)),boxsize=outer) tree = spatial.cKDTree(c.reshape((-1,3)),boxsize=outer)
d,i = tree.query(coord0_cell(new_grid,outer)) d,i = tree.query(cell_coord0(new_grid,outer))
return i return i

View File

@ -5,23 +5,23 @@ from damask import grid_filters
class TestGridFilters: class TestGridFilters:
def test_coord0_cell(self): def test_cell_coord0(self):
size = np.random.random(3) size = np.random.random(3)
grid = np.random.randint(8,32,(3)) grid = np.random.randint(8,32,(3))
coord = grid_filters.coord0_cell(grid,size) coord = grid_filters.cell_coord0(grid,size)
assert np.allclose(coord[0,0,0],size/grid*.5) and coord.shape == tuple(grid[::-1]) + (3,) assert np.allclose(coord[0,0,0],size/grid*.5) and coord.shape == tuple(grid[::-1]) + (3,)
def test_coord0_node(self): def test_node_coord0(self):
size = np.random.random(3) size = np.random.random(3)
grid = np.random.randint(8,32,(3)) grid = np.random.randint(8,32,(3))
coord = grid_filters.coord0_node(grid,size) coord = grid_filters.node_coord0(grid,size)
assert np.allclose(coord[-1,-1,-1],size) and coord.shape == tuple(grid[::-1]+1) + (3,) assert np.allclose(coord[-1,-1,-1],size) and coord.shape == tuple(grid[::-1]+1) + (3,)
def test_coord0(self): def test_coord0(self):
size = np.random.random(3) size = np.random.random(3)
grid = np.random.randint(8,32,(3)) grid = np.random.randint(8,32,(3))
c = grid_filters.coord0_cell(grid+1,size+size/grid) c = grid_filters.cell_coord0(grid+1,size+size/grid)
n = grid_filters.coord0_node(grid,size) + size/grid*.5 n = grid_filters.node_coord0(grid,size) + size/grid*.5
assert np.allclose(c,n) assert np.allclose(c,n)
@pytest.mark.parametrize('mode',[('cell'),('node')]) @pytest.mark.parametrize('mode',[('cell'),('node')])
@ -31,7 +31,7 @@ class TestGridFilters:
grid = np.random.randint(8,32,(3)) grid = np.random.randint(8,32,(3))
F = np.random.random(tuple(grid)+(3,3)) F = np.random.random(tuple(grid)+(3,3))
F += np.eye(3) - np.average(F,axis=(0,1,2)) F += np.eye(3) - np.average(F,axis=(0,1,2))
assert np.allclose(eval('grid_filters.displacement_avg_{}(size,F)'.format(mode)),0.0) assert np.allclose(eval('grid_filters.{}_displacement_avg(size,F)'.format(mode)),0.0)
@pytest.mark.parametrize('mode',[('cell'),('node')]) @pytest.mark.parametrize('mode',[('cell'),('node')])
def test_displacement_fluct_vanishes(self,mode): def test_displacement_fluct_vanishes(self,mode):
@ -39,4 +39,4 @@ class TestGridFilters:
size = np.random.random(3) # noqa size = np.random.random(3) # noqa
grid = np.random.randint(8,32,(3)) grid = np.random.randint(8,32,(3))
F = np.broadcast_to(np.random.random((3,3)), tuple(grid)+(3,3)) # noqa F = np.broadcast_to(np.random.random((3,3)), tuple(grid)+(3,3)) # noqa
assert np.allclose(eval('grid_filters.displacement_fluct_{}(size,F)'.format(mode)),0.0) assert np.allclose(eval('grid_filters.{}_displacement_fluct(size,F)'.format(mode)),0.0)