DAMASK_EICMD/python/damask/mechanics.py

322 lines
7.6 KiB
Python
Raw Normal View History

"""Finite-strain continuum mechanics."""
from . import tensor
import numpy as _np
def Cauchy_Green_deformation_left(F):
2019-10-30 22:35:44 +05:30
"""
Calculate left Cauchy-Green deformation tensor (Finger deformation tensor).
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
F : numpy.ndarray of shape (...,3,3)
Deformation gradient.
Returns
-------
B : numpy.ndarray of shape (...,3,3)
Left Cauchy-Green deformation tensor.
2019-10-30 22:35:44 +05:30
"""
return _np.matmul(F,tensor.transpose(F))
2019-11-27 16:49:37 +05:30
def Cauchy_Green_deformation_right(F):
2019-11-27 16:49:37 +05:30
"""
Calculate right Cauchy-Green deformation tensor.
2019-11-27 16:49:37 +05:30
Parameters
----------
F : numpy.ndarray of shape (...,3,3)
Deformation gradient.
Returns
-------
C : numpy.ndarray of shape (...,3,3)
Right Cauchy-Green deformation tensor.
2019-11-27 16:49:37 +05:30
"""
return _np.matmul(tensor.transpose(F),F)
def Cauchy(P,F):
"""
Calculate the Cauchy (true) stress.
Resulting tensor is symmetrized as the Cauchy stress needs to be symmetric.
Parameters
----------
P : numpy.ndarray of shape (...,3,3)
First Piola-Kirchhoff stress.
F : numpy.ndarray of shape (...,3,3)
Deformation gradient.
Returns
-------
sigma : numpy.ndarray of shape (...,3,3)
Cauchy stress.
2019-10-30 22:35:44 +05:30
"""
sigma = _np.einsum('...,...ij,...kj->...ik',1.0/_np.linalg.det(F),P,F)
return tensor.symmetric(sigma)
def deviatoric_part(T):
"""
Calculate deviatoric part of a tensor.
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
T : numpy.ndarray of shape (...,3,3)
Tensor of which the deviatoric part is computed.
Returns
-------
T' : numpy.ndarray of shape (...,3,3)
Deviatoric part of T.
2019-10-19 16:40:46 +05:30
2019-10-30 22:35:44 +05:30
"""
return T - _np.einsum('...ij,...->...ij',_np.eye(3),spherical_part(T))
2020-03-03 03:41:05 +05:30
def maximum_shear(T_sym):
2019-10-30 22:35:44 +05:30
"""
Calculate the maximum shear component of a symmetric tensor.
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
T_sym : numpy.ndarray of shape (...,3,3)
Symmetric tensor of which the maximum shear is computed.
2019-10-19 16:40:46 +05:30
Returns
-------
gamma_max : numpy.ndarray of shape (...)
Maximum shear of T_sym.
2019-10-30 22:35:44 +05:30
"""
w = tensor.eigenvalues(T_sym)
2020-06-10 00:57:08 +05:30
return (w[...,0] - w[...,2])*0.5
2019-10-19 12:21:51 +05:30
def Mises_strain(epsilon):
2019-10-30 22:35:44 +05:30
"""
Calculate the Mises equivalent of a strain tensor.
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
epsilon : numpy.ndarray of shape (...,3,3)
Symmetric strain tensor of which the von Mises equivalent is computed.
2019-10-19 16:40:46 +05:30
Returns
-------
epsilon_vM : numpy.ndarray of shape (...)
Von Mises equivalent strain of epsilon.
2019-10-30 22:35:44 +05:30
"""
2020-03-20 13:19:33 +05:30
return _Mises(epsilon,2.0/3.0)
2020-02-15 18:40:16 +05:30
def Mises_stress(sigma):
2019-10-30 22:35:44 +05:30
"""
Calculate the Mises equivalent of a stress tensor.
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
sigma : numpy.ndarray of shape (...,3,3)
Symmetric stress tensor of which the von Mises equivalent is computed.
2019-10-19 16:40:46 +05:30
Returns
-------
sigma_vM : numpy.ndarray of shape (...)
Von Mises equivalent stress of sigma.
2019-10-30 22:35:44 +05:30
"""
2020-03-20 13:19:33 +05:30
return _Mises(sigma,3.0/2.0)
def PK2(P,F):
2019-10-30 22:35:44 +05:30
"""
Calculate the second Piola-Kirchhoff stress.
Resulting tensor is symmetrized as the second Piola-Kirchhoff stress
needs to be symmetric.
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
P : numpy.ndarray of shape (...,3,3)
First Piola-Kirchhoff stress.
2020-06-10 00:57:08 +05:30
F : numpy.ndarray of shape (...,3,3)
Deformation gradient.
2019-10-19 16:40:46 +05:30
Returns
-------
S : numpy.ndarray of shape (...,3,3)
Second Piola-Kirchhoff stress.
2019-10-30 22:35:44 +05:30
"""
2020-06-10 00:57:08 +05:30
S = _np.einsum('...jk,...kl->...jl',_np.linalg.inv(F),P)
return tensor.symmetric(S)
2020-03-03 03:41:05 +05:30
def rotational_part(T):
"""
Calculate the rotational part of a tensor.
Parameters
----------
2020-06-10 00:57:08 +05:30
T : numpy.ndarray of shape (...,3,3)
Tensor of which the rotational part is computed.
Returns
-------
R : numpy.ndarray of shape (...,3,3)
Rotational part.
"""
2020-03-20 13:19:33 +05:30
return _polar_decomposition(T,'R')[0]
2020-03-03 03:41:05 +05:30
def spherical_part(T,tensor=False):
2019-10-30 22:35:44 +05:30
"""
Calculate spherical (hydrostatic) part of a tensor.
2019-10-30 22:35:44 +05:30
Parameters
----------
T : numpy.ndarray of shape (...,3,3)
Tensor of which the hydrostatic part is computed.
2020-02-15 18:40:16 +05:30
tensor : bool, optional
Map spherical part onto identity tensor. Defaults to false
Returns
-------
p : numpy.ndarray of shape (...)
unless tensor == True: shape (...,3,3)
Spherical part of tensor T, e.g. the hydrostatic part/pressure
of a stress tensor.
2019-10-19 16:40:46 +05:30
2019-10-30 22:35:44 +05:30
"""
sph = _np.trace(T,axis2=-2,axis1=-1)/3.0
return _np.einsum('...jk,...->...jk',_np.eye(3),sph) if tensor else sph
2019-10-25 17:00:20 +05:30
2020-02-15 18:40:16 +05:30
def strain_tensor(F,t,m):
2019-10-30 22:35:44 +05:30
"""
Calculate strain tensor from deformation gradient.
2020-02-15 18:40:16 +05:30
For details refer to https://en.wikipedia.org/wiki/Finite_strain_theory and
https://de.wikipedia.org/wiki/Verzerrungstensor
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
F : numpy.ndarray of shape (...,3,3)
Deformation gradient.
2020-02-15 18:40:16 +05:30
t : {V, U}
Type of the polar decomposition, V for left stretch tensor
and U for right stretch tensor.
2020-02-15 18:40:16 +05:30
m : float
Order of the strain.
2019-10-25 17:00:20 +05:30
Returns
-------
epsilon : numpy.ndarray of shape (...,3,3)
Strain of F.
2019-10-30 22:35:44 +05:30
"""
2020-02-15 18:40:16 +05:30
if t == 'V':
w,n = _np.linalg.eigh(Cauchy_Green_deformation_left(F))
2020-02-15 18:40:16 +05:30
elif t == 'U':
w,n = _np.linalg.eigh(Cauchy_Green_deformation_right(F))
2019-10-25 17:00:20 +05:30
2020-02-15 18:40:16 +05:30
if m > 0.0:
eps = 1.0/(2.0*abs(m)) * (+ _np.matmul(n,_np.einsum('...j,...kj->...jk',w**m,n))
- _np.einsum('...jk->...jk',_np.eye(3)))
2020-02-15 18:40:16 +05:30
elif m < 0.0:
eps = 1.0/(2.0*abs(m)) * (- _np.matmul(n,_np.einsum('...j,...kj->...jk',w**m,n))
+ _np.einsum('...jk->...jk',_np.eye(3)))
2020-02-15 18:40:16 +05:30
else:
2020-05-28 02:02:35 +05:30
eps = _np.matmul(n,_np.einsum('...j,...kj->...jk',0.5*_np.log(w),n))
2019-10-25 17:00:20 +05:30
2020-06-10 00:57:08 +05:30
return eps
2020-02-15 18:40:16 +05:30
def stretch_left(T):
"""
Calculate left stretch of a tensor.
Parameters
----------
T : numpy.ndarray of shape (...,3,3)
Tensor of which the left stretch is computed.
Returns
-------
V : numpy.ndarray of shape (...,3,3)
Left stretch tensor from Polar decomposition of T.
"""
return _polar_decomposition(T,'V')[0]
def stretch_right(T):
"""
Calculate right stretch of a tensor.
Parameters
----------
T : numpy.ndarray of shape (...,3,3)
Tensor of which the right stretch is computed.
Returns
-------
U : numpy.ndarray of shape (...,3,3)
Left stretch tensor from Polar decomposition of T.
"""
return _polar_decomposition(T,'U')[0]
2020-03-20 13:19:33 +05:30
def _polar_decomposition(T,requested):
2019-10-30 22:35:44 +05:30
"""
Perform singular value decomposition.
2019-10-30 22:35:44 +05:30
Parameters
----------
2020-06-10 00:57:08 +05:30
T : numpy.ndarray of shape (...,3,3)
Tensor of which the singular values are computed.
requested : iterable of str
Requested outputs: R for the rotation tensor,
V for left stretch tensor and U for right stretch tensor.
2019-10-30 22:35:44 +05:30
"""
u, _, vh = _np.linalg.svd(T)
2020-06-10 00:57:08 +05:30
R = _np.einsum('...ij,...jk->...ik',u,vh)
2019-10-30 22:35:44 +05:30
output = []
if 'R' in requested:
output.append(R)
if 'V' in requested:
2020-06-10 00:57:08 +05:30
output.append(_np.einsum('...ij,...kj->...ik',T,R))
2019-10-30 22:35:44 +05:30
if 'U' in requested:
2020-06-10 00:57:08 +05:30
output.append(_np.einsum('...ji,...jk->...ik',R,T))
2019-10-30 22:35:44 +05:30
return tuple(output)
2020-02-15 18:40:16 +05:30
2020-03-20 13:19:33 +05:30
def _Mises(T_sym,s):
2020-02-15 18:40:16 +05:30
"""
Base equation for Mises equivalent of a stres or strain tensor.
Parameters
----------
2020-06-10 00:57:08 +05:30
T_sym : numpy.ndarray of shape (...,3,3)
Symmetric tensor of which the von Mises equivalent is computed.
2020-02-15 18:40:16 +05:30
s : float
Scaling factor (2/3 for strain, 3/2 for stress).
2020-03-03 03:41:05 +05:30
2020-02-15 18:40:16 +05:30
"""
2020-03-03 03:41:05 +05:30
d = deviatoric_part(T_sym)
2020-06-10 00:57:08 +05:30
return _np.sqrt(s*_np.einsum('...jk->...',d**2.0))