polishing

This commit is contained in:
Martin Diehl 2019-10-19 13:10:46 +02:00
parent b31de5d0f6
commit a665d5726d
2 changed files with 48 additions and 28 deletions

View File

@ -327,7 +327,7 @@ class DADF5():
""" """
Dataset for all points/cells. Dataset for all points/cells.
If more than one path is given, the dataset is composed of the individual contributions If more than one path is given, the dataset is composed of the individual contributions.
""" """
with h5py.File(self.filename,'r') as f: with h5py.File(self.filename,'r') as f:
shape = (self.Nmaterialpoints,) + np.shape(f[path[0]])[1:] shape = (self.Nmaterialpoints,) + np.shape(f[path[0]])[1:]
@ -383,6 +383,7 @@ class DADF5():
Label of the dataset containing the 1. Piola-Kirchhoff stress. Default value is P. Label of the dataset containing the 1. Piola-Kirchhoff stress. Default value is P.
F : str, optional F : str, optional
Label of the dataset containing the deformation gradient. Default value is F. Label of the dataset containing the deformation gradient. Default value is F.
""" """
def __add_Cauchy(F,P): def __add_Cauchy(F,P):
@ -410,10 +411,12 @@ class DADF5():
Parameters Parameters
---------- ----------
x : str x : str
Label of the dataset containing a symmetric stress or strain tensor Label of the dataset containing a symmetric stress or strain tensor.
""" """
def __add_Mises(x): def __add_Mises(x):
t = 'strain' if x['Unit'] == '1' else 'stress'
return { return {
'data': mechanics.Mises_strain(x) if t=='strain' else mechanics.Mises_stress(x), 'data': mechanics.Mises_strain(x) if t=='strain' else mechanics.Mises_stress(x),
'label': '{}_vM'.format(x['label']), 'label': '{}_vM'.format(x['label']),
@ -439,6 +442,7 @@ class DADF5():
Label of the dataset containing a vector or tensor. Label of the dataset containing a vector or tensor.
ord : {non-zero int, inf, -inf, fro, nuc}, optional ord : {non-zero int, inf, -inf, fro, nuc}, optional
Order of the norm. inf means numpys inf object. For details refer to numpy.linalg.norm. Order of the norm. inf means numpys inf object. For details refer to numpy.linalg.norm.
""" """
def __add_norm(x,ord): def __add_norm(x,ord):
@ -477,6 +481,7 @@ class DADF5():
---------- ----------
x : str x : str
Label of the dataset containing a scalar, vector, or tensor. Label of the dataset containing a scalar, vector, or tensor.
""" """
def __add_absolute(x): def __add_absolute(x):
@ -503,6 +508,7 @@ class DADF5():
---------- ----------
x : str x : str
Label of the dataset containing a tensor. Label of the dataset containing a tensor.
""" """
def __add_determinant(x): def __add_determinant(x):
@ -529,6 +535,7 @@ class DADF5():
---------- ----------
x : str x : str
Label of the dataset containing a tensor. Label of the dataset containing a tensor.
""" """
def __add_spherical(x): def __add_spherical(x):
@ -558,6 +565,7 @@ class DADF5():
---------- ----------
x : str x : str
Label of the dataset containing a tensor. Label of the dataset containing a tensor.
""" """
def __add_deviator(x): def __add_deviator(x):
@ -594,7 +602,8 @@ class DADF5():
description : str, optional description : str, optional
Human readable description of the result. Human readable description of the result.
vectorized : bool, optional vectorized : bool, optional
Indicate whether the formula is written in vectorized form. Indicate whether the formula is written in vectorized form. Default is True.
""" """
if vectorized is not True: if vectorized is not True:
raise NotImplementedError raise NotImplementedError
@ -636,6 +645,7 @@ class DADF5():
Defaults value is U. Defaults value is U.
ord : float, optional ord : float, optional
Order of the strain calculation. Default value is 0.0. Order of the strain calculation. Default value is 0.0.
""" """
def __add_strain_tensor(F,t,ord): def __add_strain_tensor(F,t,ord):
@ -664,6 +674,7 @@ class DADF5():
---------- ----------
x : str x : str
Label of the dataset containing a symmetric tensor. Label of the dataset containing a symmetric tensor.
""" """
def __add_principal_components(x): def __add_principal_components(x):
@ -690,6 +701,7 @@ class DADF5():
---------- ----------
x : str x : str
Label of the dataset containing a symmetric tensor. Label of the dataset containing a symmetric tensor.
""" """
def __add_maximum_shear(x): def __add_maximum_shear(x):
@ -720,6 +732,7 @@ class DADF5():
Details of the datasets to be used: label (in HDF5 file) and arg (argument to which the data is parsed in func). Details of the datasets to be used: label (in HDF5 file) and arg (argument to which the data is parsed in func).
extra_args : dictionary, optional extra_args : dictionary, optional
Any extra arguments parsed to func. Any extra arguments parsed to func.
""" """
def job(args): def job(args):
"""Call function with input data + extra arguments, returns results + group.""" """Call function with input data + extra arguments, returns results + group."""

View File

@ -12,6 +12,7 @@ def Cauchy(F,P):
Deformation gradient. Deformation gradient.
P : numpy.array of shape (x,3,3) or (3,3) P : numpy.array of shape (x,3,3) or (3,3)
1. Piola-Kirchhoff stress. 1. Piola-Kirchhoff stress.
""" """
if np.shape(F) == np.shape(P) == (3,3): if np.shape(F) == np.shape(P) == (3,3):
sigma = 1.0/np.linalg.det(F) * np.dot(F,P) sigma = 1.0/np.linalg.det(F) * np.dot(F,P)
@ -34,23 +35,22 @@ def strain_tensor(F,t,ord):
t : {V, U} t : {V, U}
Type of the polar decomposition, V for right stretch tensor and U for left stretch tensor. Type of the polar decomposition, V for right stretch tensor and U for left stretch tensor.
ord : float ord : float
Order of the strain Order of the strain.
""" """
F_expanded = F if len(F.shape) == 3 else F.reshape(1,3,3)
if t == 'U': if t == 'U':
B = np.matmul(F_expanded,transpose(F_expanded)) B = np.matmul(F,transpose(F))
U,n = np.linalg.eigh(symmetric(B)) U,n = np.linalg.eigh(B)
l = np.log(U) if ord == 0 else U**ord - np.broadcast_to(np.ones(3),[U.shape[0],3]) lmd = np.log(U) if ord == 0 else \
U**ord - (np.broadcast_to(np.ones(3),[U.shape[0],3]) if len(F.shape) == 3 else np.ones(3))
elif t == 'V': elif t == 'V':
C = np.matmul(transpose(F_expanded),F_expanded) C = np.matmul(transpose(F),F)
V,n = np.linalg.eigh(symmetric(C)) V,n = np.linalg.eigh(C)
l = np.log(V) if ord == 0 else np.broadcast_to(np.ones(3),[V.shape[0],3]) - 1.0/V**ord lmd = np.log(V) if ord == 0 else \
- 1.0/V**ord + (np.broadcast_to(np.ones(3),[V.shape[0],3]) if len(F.shape) == 3 else np.ones(3))
epsilon = np.matmul(n,np.einsum('ij,ikj->ijk',l,n)) return np.dot(n,np.dot(np.diag(l),n.T)) if np.shape(F) == (3,3) else \
np.matmul(n,np.einsum('ij,ikj->ijk',lmd,n))
return epsilon.reshape((3,3)) if np.shape(F) == (3,3) else \
epsilon
def deviatoric_part(x): def deviatoric_part(x):
@ -60,7 +60,8 @@ def deviatoric_part(x):
Parameters Parameters
---------- ----------
x : numpy.array of shape (x,3,3) or (3,3) x : numpy.array of shape (x,3,3) or (3,3)
Tensor. Tensor of which the deviatoric part is computed.
""" """
return x - np.eye(3)*spherical_part(x) if np.shape(x) == (3,3) else \ return x - np.eye(3)*spherical_part(x) if np.shape(x) == (3,3) else \
x - np.einsum('ijk,i->ijk',np.broadcast_to(np.eye(3),[x.shape[0],3,3]),spherical_part(x)) x - np.einsum('ijk,i->ijk',np.broadcast_to(np.eye(3),[x.shape[0],3,3]),spherical_part(x))
@ -76,9 +77,9 @@ def spherical_part(x):
Parameters Parameters
---------- ----------
x : numpy.array of shape (x,3,3) or (3,3) x : numpy.array of shape (x,3,3) or (3,3)
Tensor. Tensor of which the hydrostatic part is computed.
"""
"""
return np.trace(x)/3.0 if np.shape(x) == (3,3) else \ return np.trace(x)/3.0 if np.shape(x) == (3,3) else \
np.trace(x,axis1=1,axis2=2)/3.0 np.trace(x,axis1=1,axis2=2)/3.0
@ -90,7 +91,8 @@ def Mises_stress(sigma):
Parameters Parameters
---------- ----------
sigma : numpy.array of shape (x,3,3) or (3,3) sigma : numpy.array of shape (x,3,3) or (3,3)
Symmetric stress tensor. Symmetric stress tensor of which the von Mises equivalent is computed.
""" """
s = deviatoric_part(sigma) s = deviatoric_part(sigma)
return np.sqrt(3.0/2.0*np.trace(s)) if np.shape(sigma) == (3,3) else \ return np.sqrt(3.0/2.0*np.trace(s)) if np.shape(sigma) == (3,3) else \
@ -104,7 +106,8 @@ def Mises_strain(epsilon):
Parameters Parameters
---------- ----------
epsilon : numpy.array of shape (x,3,3) or (3,3) epsilon : numpy.array of shape (x,3,3) or (3,3)
Symmetric strain tensor. Symmetric strain tensor of which the von Mises equivalent is computed.
""" """
s = deviatoric_part(epsilon) s = deviatoric_part(epsilon)
return np.sqrt(2.0/3.0*np.trace(s)) if np.shape(epsilon) == (3,3) else \ return np.sqrt(2.0/3.0*np.trace(s)) if np.shape(epsilon) == (3,3) else \
@ -118,7 +121,8 @@ def symmetric(x):
Parameters Parameters
---------- ----------
x : numpy.array of shape (x,3,3) or (3,3) x : numpy.array of shape (x,3,3) or (3,3)
Tensor. Tensor of which the symmetrized values are computed.
""" """
return (x+transpose(x))*0.5 return (x+transpose(x))*0.5
@ -130,10 +134,11 @@ def maximum_shear(x):
Parameters Parameters
---------- ----------
x : numpy.array of shape (x,3,3) or (3,3) x : numpy.array of shape (x,3,3) or (3,3)
Symmetric tensor. Symmetric tensor of which the maximum shear is computed.
""" """
w = np.linalg.eigvalsh(symmetric(x)) # eigenvalues in ascending order w = np.linalg.eigvalsh(symmetric(x)) # eigenvalues in ascending order
return (w[2] - w[0])*0.5 if np.shape(epsilon) == (3,3) else \ return (w[2] - w[0])*0.5 if np.shape(x) == (3,3) else \
(w[:,2] - w[:,0])*0.5 (w[:,2] - w[:,0])*0.5
@ -147,10 +152,11 @@ def principal_components(x):
Parameters Parameters
---------- ----------
x : numpy.array of shape (x,3,3) or (3,3) x : numpy.array of shape (x,3,3) or (3,3)
Symmetric tensor. Symmetric tensor of which the principal compontents are computed.
""" """
w = np.linalg.eigvalsh(symmetric(x)) # eigenvalues in ascending order w = np.linalg.eigvalsh(symmetric(x)) # eigenvalues in ascending order
return w[::-1] if np.shape(epsilon) == (3,3) else \ return w[::-1] if np.shape(x) == (3,3) else \
w[:,::-1] w[:,::-1]
@ -161,7 +167,8 @@ def transpose(x):
Parameters Parameters
---------- ----------
x : numpy.array of shape (x,3,3) or (3,3) x : numpy.array of shape (x,3,3) or (3,3)
Tensor. Tensor of which the transpose is computer.
""" """
return x.T if np.shape(x) == (3,3) else \ return x.T if np.shape(x) == (3,3) else \
np.transpose(x,(0,2,1)) np.transpose(x,(0,2,1))