making new mechanics functions available for DADF5

+ testing them
This commit is contained in:
Martin Diehl 2020-02-15 17:56:20 +01:00
parent 118c03c485
commit 5235c27ad0
2 changed files with 86 additions and 25 deletions

View File

@ -516,7 +516,7 @@ class DADF5():
self.__add_generic_pointwise(__add_calculation,requested,pass_through)
def add_Cauchy(self,P='P',F='F'):
def add_Cauchy(self,F='F',P='P'):
"""
Add Cauchy stress calculated from 1. Piola-Kirchhoff stress and deformation gradient.
@ -537,8 +537,7 @@ class DADF5():
'Unit': P['meta']['Unit'],
'Description': 'Cauchy stress calculated from {} ({}) '.format(P['label'],
P['meta']['Description'])+\
'and deformation gradient {} ({})'.format(F['label'],
F['meta']['Description']),
'and {} ({})'.format(F['label'],F['meta']['Description']),
'Creator': 'dadf5.py:add_Cauchy v{}'.format(version)
}
}
@ -814,8 +813,7 @@ class DADF5():
'Unit': P['meta']['Unit'],
'Description': '2. Kirchhoff stress calculated from {} ({}) '.format(P['label'],
P['meta']['Description'])+\
'and deformation gradient {} ({})'.format(F['label'],
F['meta']['Description']),
'and {} ({})'.format(F['label'],F['meta']['Description']),
'Creator': 'dadf5.py:add_PK2 v{}'.format(version)
}
}
@ -871,33 +869,31 @@ class DADF5():
self.__add_generic_pointwise(__addPole,requested,{'pole':pole})
def add_principal_components(self,x):
def add_rotational_part(self,F='F'):
"""
Add principal components of symmetric tensor.
The principal components are sorted in descending order, each repeated according to its multiplicity.
Add rotational part of a deformation gradient.
Parameters
----------
x : str
Label of the dataset containing a symmetric tensor.
F : str
Label of the dataset containing a deformation gradient. Default value is F.
"""
def __add_principal_components(x):
def __add_rotational_part(F):
return {
'data': mechanics.principal_components(x['data']),
'label': 'lambda_{}'.format(x['label']),
'data': mechanics.rotational_part(F['data']),
'label': 'R({})'.format(F['label']),
'meta': {
'Unit': x['meta']['Unit'],
'Description': 'Pricipal components of {} ({})'.format(x['label'],x['meta']['Description']),
'Creator': 'dadf5.py:add_principal_components v{}'.format(version)
'Unit': F['meta']['Unit'],
'Description': 'Rotational part of {} ({})'.format(F['label'],F['meta']['Description']),
'Creator': 'dadf5.py:add_rotational_part v{}'.format(version)
}
}
requested = [{'label':x,'arg':'x'}]
requested = [{'label':F,'arg':'F'}]
self.__add_generic_pointwise(__add_principal_components,requested)
self.__add_generic_pointwise(__add_rotational_part,requested)
def add_spherical(self,x):
@ -941,8 +937,8 @@ class DADF5():
F : str, optional
Label of the dataset containing the deformation gradient. Default value is F.
t : {V, U}, optional
Type of the polar decomposition, V for right stretch tensor and U for left stretch tensor.
Defaults value is U.
Type of the polar decomposition, U for right stretch tensor and V for left stretch tensor.
Default value is U.
m : float, optional
Order of the strain calculation. Default value is 0.0.
@ -964,6 +960,37 @@ class DADF5():
self.__add_generic_pointwise(__add_strain_tensor,requested,{'t':t,'m':m})
def add_stretch_tensor(self,F='F',t='U'):
"""
Add stretch tensor calculated from a deformation gradient.
Parameters
----------
F : str, optional
Label of the dataset containing the deformation gradient. Default value is F.
t : {V, U}, optional
Type of the polar decomposition, U for right stretch tensor and V for left stretch tensor.
Default value is U.
"""
def __add_stretch_tensor(F,t):
return {
'data': mechanics.left_stretch(F['data']) if t == 'V' else mechanics.right_stretch(F['data']),
'label': '{}({})'.format(t,F['label']),
'meta': {
'Unit': F['meta']['Unit'],
'Description': '{} stretch tensor of {} ({})'.format('Left' if t == 'V' else 'Right',
F['label'],F['meta']['Description']),
'Creator': 'dadf5.py:add_stretch_tensor v{}'.format(version)
}
}
requested = [{'label':F,'arg':'F'}]
self.__add_generic_pointwise(__add_stretch_tensor,requested,{'t':t})
def __add_generic_pointwise(self,func,datasets_requested,extra_args={}):
"""
General function to add pointwise data.

View File

@ -48,7 +48,7 @@ class TestDADF5:
assert np.allclose(in_memory,in_file)
def test_add_Cauchy(self,default):
default.add_Cauchy('P','F')
default.add_Cauchy('F','P')
loc = {'F': default.get_dataset_location('F'),
'P': default.get_dataset_location('P'),
'sigma':default.get_dataset_location('sigma')}
@ -74,7 +74,7 @@ class TestDADF5:
assert np.allclose(in_memory,in_file)
def test_add_eigenvalues(self,default):
default.add_Cauchy('P','F')
default.add_Cauchy('F','P')
default.add_eigenvalues('sigma')
loc = {'sigma' :default.get_dataset_location('sigma'),
'lambda(sigma)':default.get_dataset_location('lambda(sigma)')}
@ -83,7 +83,7 @@ class TestDADF5:
assert np.allclose(in_memory,in_file)
def test_add_eigenvectors(self,default):
default.add_Cauchy('P','F')
default.add_Cauchy('F','P')
default.add_eigenvectors('sigma')
loc = {'sigma' :default.get_dataset_location('sigma'),
'v(sigma)':default.get_dataset_location('v(sigma)')}
@ -92,7 +92,7 @@ class TestDADF5:
assert np.allclose(in_memory,in_file)
def test_add_maximum_shear(self,default):
default.add_Cauchy('P','F')
default.add_Cauchy('F','P')
default.add_maximum_shear('sigma')
loc = {'sigma' :default.get_dataset_location('sigma'),
'max_shear(sigma)':default.get_dataset_location('max_shear(sigma)')}
@ -108,6 +108,24 @@ class TestDADF5:
in_file = default.read_dataset(loc['|F|_1'],0)
assert np.allclose(in_memory,in_file)
def test_add_PK2(self,default):
default.add_PK2('F','P')
loc = {'F':default.get_dataset_location('F'),
'P':default.get_dataset_location('P'),
'S':default.get_dataset_location('S')}
in_memory = mechanics.PK2(default.read_dataset(loc['F'],0),
default.read_dataset(loc['P'],0))
in_file = default.read_dataset(loc['S'],0)
assert np.allclose(in_memory,in_file)
def test_add_rotational_part(self,default):
default.add_rotational_part('F')
loc = {'F': default.get_dataset_location('F'),
'R(F)': default.get_dataset_location('R(F)')}
in_memory = mechanics.rotational_part(default.read_dataset(loc['F'],0))
in_file = default.read_dataset(loc['R(F)'],0)
assert np.allclose(in_memory,in_file)
def test_add_spherical(self,default):
default.add_spherical('P')
loc = {'P': default.get_dataset_location('P'),
@ -115,3 +133,19 @@ class TestDADF5:
in_memory = mechanics.spherical_part(default.read_dataset(loc['P'],0)).reshape(-1,1)
in_file = default.read_dataset(loc['p_P'],0)
assert np.allclose(in_memory,in_file)
def test_add_stretch_right(self,default):
default.add_stretch_tensor('F','U')
loc = {'F': default.get_dataset_location('F'),
'U(F)': default.get_dataset_location('U(F)')}
in_memory = mechanics.right_stretch(default.read_dataset(loc['F'],0))
in_file = default.read_dataset(loc['U(F)'],0)
assert np.allclose(in_memory,in_file)
def test_add_stretch_left(self,default):
default.add_stretch_tensor('F','V')
loc = {'F': default.get_dataset_location('F'),
'V(F)': default.get_dataset_location('V(F)')}
in_memory = mechanics.left_stretch(default.read_dataset(loc['F'],0))
in_file = default.read_dataset(loc['V(F)'],0)
assert np.allclose(in_memory,in_file)