adding '_tensor' not needed

This commit is contained in:
Martin Diehl 2020-11-16 01:12:23 +01:00
parent b893967b68
commit 9b9d83d93c
5 changed files with 29 additions and 27 deletions

View File

@ -991,21 +991,21 @@ class Result:
@staticmethod
def _add_strain_tensor(F,t,m):
def _add_strain(F,t,m):
return {
'data': mechanics.strain_tensor(F['data'],t,m),
'data': mechanics.strain(F['data'],t,m),
'label': f"epsilon_{t}^{m}({F['label']})",
'meta': {
'Unit': F['meta']['Unit'],
'Description': f"Strain tensor of {F['label']} ({F['meta']['Description']})",
'Creator': 'add_strain_tensor'
'Creator': 'add_strain'
}
}
def add_strain_tensor(self,F='F',t='V',m=0.0):
def add_strain(self,F='F',t='V',m=0.0):
"""
Add strain tensor of a deformation gradient.
For details refer to damask.mechanics.strain_tensor
For details refer to damask.mechanics.strain
Parameters
----------
@ -1018,7 +1018,7 @@ class Result:
Order of the strain calculation. Defaults to 0.0.
"""
self._add_generic_pointwise(self._add_strain_tensor,{'F':F},{'t':t,'m':m})
self._add_generic_pointwise(self._add_strain,{'F':F},{'t':t,'m':m})
@staticmethod

View File

@ -40,9 +40,10 @@ def Cauchy_Green_deformation_right(F):
"""
return _np.matmul(tensor.transpose(F),F)
def Cauchy(P,F):
"""
Calculate the Cauchy (true) stress.
Calculate the Cauchy stress (true stress).
Resulting tensor is symmetrized as the Cauchy stress needs to be symmetric.
@ -201,9 +202,9 @@ def spherical_part(T,tensor=False):
return _np.einsum('...jk,...->...jk',_np.eye(3),sph) if tensor else sph
def strain_tensor(F,t,m):
def strain(F,t,m):
"""
Calculate strain tensor from deformation gradient.
Calculate strain tensor (SethHill family).
For details refer to https://en.wikipedia.org/wiki/Finite_strain_theory and
https://de.wikipedia.org/wiki/Verzerrungstensor
@ -319,3 +320,7 @@ def _Mises(T_sym,s):
"""
d = deviatoric_part(T_sym)
return _np.sqrt(s*_np.einsum('...jk->...',d**2.0))
# for compatibility
strain_tensor = strain

View File

@ -1,7 +1,4 @@
"""
Functionality for generation of seed points for Voronoi
or Laguerre tessellation.
"""
"""Functionality for generation of seed points for Voronoi or Laguerre tessellation."""
from scipy import spatial as _spatial
import numpy as _np

View File

@ -194,7 +194,7 @@ class TestResult:
def test_add_Mises_strain(self,default):
t = ['V','U'][np.random.randint(0,2)]
m = np.random.random()*2.0 - 1.0
default.add_strain_tensor('F',t,m)
default.add_strain('F',t,m)
label = f'epsilon_{t}^{m}(F)'
default.add_Mises(label)
loc = {label :default.get_dataset_location(label),
@ -280,11 +280,11 @@ class TestResult:
def test_add_strain(self,default):
t = ['V','U'][np.random.randint(0,2)]
m = np.random.random()*2.0 - 1.0
default.add_strain_tensor('F',t,m)
default.add_strain('F',t,m)
label = f'epsilon_{t}^{m}(F)'
loc = {'F': default.get_dataset_location('F'),
label: default.get_dataset_location(label)}
in_memory = mechanics.strain_tensor(default.read_dataset(loc['F'],0),t,m)
in_memory = mechanics.strain(default.read_dataset(loc['F'],0),t,m)
in_file = default.read_dataset(loc[label],0)
assert np.allclose(in_memory,in_file)

View File

@ -44,7 +44,7 @@ def spherical_part(T,tensor=False):
return sph if not tensor else np.eye(3)*sph
def strain_tensor(F,t,m):
def strain(F,t,m):
if t == 'V':
B = np.matmul(F,F.T)
@ -140,8 +140,8 @@ class TestMechanics:
assert np.allclose(single(P[i],F[i]),v)
@pytest.mark.parametrize('vectorized,single',[(mechanics.strain_tensor,strain_tensor)])
def test_vectorize_strain_tensor(self,vectorized,single):
@pytest.mark.parametrize('vectorized,single',[(mechanics.strain,strain)])
def test_vectorize_strain(self,vectorized,single):
F = np.random.rand(self.n,3,3)
F_vec = np.reshape(F,(self.n//10,10,3,3))
t = ['V','U'][np.random.randint(0,2)]
@ -172,25 +172,25 @@ class TestMechanics:
np.matmul(V,R))
@pytest.mark.parametrize('m',[0.0,np.random.random()*10.,np.random.random()*-10.])
def test_strain_tensor_no_rotation(self,m):
def test_strain_no_rotation(self,m):
"""Ensure that left and right stretch give same results for no rotation."""
F = np.broadcast_to(np.eye(3),[self.n,3,3])*np.random.rand(self.n,3,3)
assert np.allclose(mechanics.strain_tensor(F,'U',m),
mechanics.strain_tensor(F,'V',m))
assert np.allclose(mechanics.strain(F,'U',m),
mechanics.strain(F,'V',m))
@pytest.mark.parametrize('m',[0.0,np.random.random()*2.5,np.random.random()*-2.5])
def test_strain_tensor_rotation_equivalence(self,m):
def test_strain_rotation_equivalence(self,m):
"""Ensure that left and right strain differ only by a rotation."""
F = np.broadcast_to(np.eye(3),[self.n,3,3]) + (np.random.rand(self.n,3,3)*0.5 - 0.25)
assert np.allclose(np.linalg.det(mechanics.strain_tensor(F,'U',m)),
np.linalg.det(mechanics.strain_tensor(F,'V',m)))
assert np.allclose(np.linalg.det(mechanics.strain(F,'U',m)),
np.linalg.det(mechanics.strain(F,'V',m)))
@pytest.mark.parametrize('m',[0.0,np.random.random(),np.random.random()*-1.])
@pytest.mark.parametrize('t',['V','U'])
def test_strain_tensor_rotation(self,m,t):
def test_strain_rotation(self,m,t):
"""Ensure that pure rotation results in no strain."""
F = mechanics.rotational_part(np.random.rand(self.n,3,3))
assert np.allclose(mechanics.strain_tensor(F,t,m),
assert np.allclose(mechanics.strain(F,t,m),
0.0)
def test_rotation_determinant(self):