Merge remote-tracking branch 'origin/development' into CLI-material

This commit is contained in:
Sharan Roongta 2023-06-13 12:59:39 +02:00
commit 342b33c17f
2 changed files with 116 additions and 63 deletions

View File

@ -186,8 +186,6 @@ def displacement_fluct_point(size: _FloatSequence,
Fluctuating part of the cell center displacements.
"""
integrator = 0.5j*_np.array(size,float)/_np.pi
k_s = _ks(size,F.shape[:3],False)
k_s_squared = _np.einsum('...l,...l',k_s,k_s)
k_s_squared[0,0,0] = 1.0
@ -195,7 +193,7 @@ def displacement_fluct_point(size: _FloatSequence,
displacement = -_np.einsum('ijkml,ijkl,l->ijkm',
_np.fft.rfftn(F,axes=(0,1,2)),
k_s,
integrator,
_np.array([0.5j/_np.pi]*3),
) / k_s_squared[...,_np.newaxis]
return _np.fft.irfftn(displacement,axes=(0,1,2),s=F.shape[:3])

View File

@ -2,6 +2,7 @@ import pytest
import numpy as np
from damask import grid_filters
from damask import mechanics
from damask import Grid
from damask import seeds
@ -36,7 +37,7 @@ class TestGridFilters:
_cells,_size,_origin = eval(f'grid_filters.cellsSizeOrigin_coordinates0_{mode}(coord0.reshape(-1,3,order="F"))')
assert np.allclose(cells,_cells) and np.allclose(size,_size) and np.allclose(origin,_origin)
def test_displacement_fluct_equivalence(self):
def test_displacement_fluct_periodic(self):
"""Ensure that fluctuations are periodic.""" # noqa
size = np.random.random(3)
cells = np.random.randint(8,32,(3))
@ -80,21 +81,75 @@ class TestGridFilters:
grid_filters.displacement_avg_node])
def test_displacement_avg_vanishes(self,function):
"""Ensure that random fluctuations in F do not result in average displacement.""" # noqa
size = np.random.random(3)
size = np.random.random(3) + 1.0
cells = np.random.randint(8,32,(3))
F = np.random.random(tuple(cells)+(3,3))
F += np.eye(3) - np.average(F,axis=(0,1,2))
assert np.allclose(function(size,F),0.0)
@pytest.mark.parametrize('function',[grid_filters.displacement_avg_point,
grid_filters.displacement_avg_node])
def test_displacement_avg_vanishes_simple(self,function):
F = np.eye(3)
size = np.random.random(3) + 1.0
F_c = F.copy()
F_t = F.copy()
F_c[0,0] = 0.8
F_t[0,0] = 1.2
F_no_avg = np.concatenate([np.broadcast_to(_,(10,20,20,3,3)) for _ in [F_t,F_c]])
assert np.allclose(function(size,F_no_avg),0.0)
@pytest.mark.parametrize('function',[grid_filters.displacement_fluct_point,
grid_filters.displacement_fluct_node])
def test_displacement_fluct_vanishes(self,function):
def test_displacement_fluct_vanishes_avg(self,function):
"""Ensure that constant F does not result in fluctuating displacement.""" # noqa
size = np.random.random(3)
cells = np.random.randint(8,32,(3))
F = np.broadcast_to(np.random.random((3,3)), tuple(cells)+(3,3))
assert np.allclose(function(size,F),0.0)
displacement_fluct_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.cos(np.pi*2*nodes[...,0]/size[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.sin(np.pi*2*nodes[...,0]/size[0])/np.pi/2*size[0]',
'0.0',
'np.sin(np.pi*2*nodes[...,2]/size[2])/np.pi/2*size[2]'])]
@pytest.mark.parametrize('F_def,u_def',displacement_fluct_test_data)
def test_displacment_fluct_analytic(self,F_def,u_def):
size = np.random.random(3)+1.0
cells = np.random.randint(8,32,(3))
nodes = grid_filters.coordinates0_point(cells,size)
my_locals = locals() # needed for list comprehension
F = np.stack([np.broadcast_to(eval(F,globals(),my_locals),cells) for F in F_def],axis=-1).reshape(tuple(cells) + (3,3))
u = np.stack([np.broadcast_to(eval(u,globals(),my_locals),cells) for u in u_def],axis=-1).reshape(tuple(cells) + (3,))
assert np.allclose(u,grid_filters.displacement_fluct_point(size,F))
def test_coordinates(self):
cells = np.array([np.random.randint(40,100)*2,2,2])
size = (np.random.rand(3)+0.8)*cells
F = np.broadcast_to(np.eye(3),tuple(cells)+(3,3)).copy()
F[...,0,0] += np.expand_dims(0.1*np.sin(np.linspace(0,2*np.pi,cells[0],False))+
np.random.rand(cells[0])*0.05,(-1,-2))
c_n = grid_filters.coordinates_node(size,F)[:,0,0,0]
l_0 = (size/cells)[0]
l = c_n[1:] - c_n[:-1]
epsilon_reconstructed = (l-l_0)/l_0
epsilon_direct = mechanics.strain(F,'V',1)[:,0,0,0,0]
assert np.corrcoef(epsilon_reconstructed,epsilon_direct)[0,1] > 0.99
@pytest.mark.parametrize('function',[grid_filters.cellsSizeOrigin_coordinates0_point,
grid_filters.cellsSizeOrigin_coordinates0_node])
def test_invalid_coordinates(self,function):