automated type checking for mechanics
This commit is contained in:
parent
2d25dfcdf2
commit
0bc267c76b
|
@ -95,13 +95,12 @@ mypy:
|
||||||
stage: python
|
stage: python
|
||||||
script:
|
script:
|
||||||
- cd $DAMASKROOT/python
|
- cd $DAMASKROOT/python
|
||||||
- mypy damask/mechanics.py
|
- mypy damask/tensor.py damask/mechanics.py
|
||||||
except:
|
except:
|
||||||
- master
|
- master
|
||||||
- release
|
- release
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###################################################################################################
|
###################################################################################################
|
||||||
compile_grid_Intel:
|
compile_grid_Intel:
|
||||||
stage: compile
|
stage: compile
|
||||||
|
|
|
@ -5,13 +5,15 @@ All routines operate on numpy.ndarrays of shape (...,3,3).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from . import tensor as _tensor
|
from typing import Sequence
|
||||||
from . import _rotation
|
|
||||||
|
|
||||||
import numpy as _np
|
import numpy as _np
|
||||||
|
|
||||||
|
from . import tensor as _tensor
|
||||||
|
from . import _rotation
|
||||||
|
|
||||||
def deformation_Cauchy_Green_left(F):
|
|
||||||
|
def deformation_Cauchy_Green_left(F: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate left Cauchy-Green deformation tensor (Finger deformation tensor).
|
Calculate left Cauchy-Green deformation tensor (Finger deformation tensor).
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ def deformation_Cauchy_Green_left(F):
|
||||||
return _np.matmul(F,_tensor.transpose(F))
|
return _np.matmul(F,_tensor.transpose(F))
|
||||||
|
|
||||||
|
|
||||||
def deformation_Cauchy_Green_right(F):
|
def deformation_Cauchy_Green_right(F: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate right Cauchy-Green deformation tensor.
|
Calculate right Cauchy-Green deformation tensor.
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ def deformation_Cauchy_Green_right(F):
|
||||||
return _np.matmul(_tensor.transpose(F),F)
|
return _np.matmul(_tensor.transpose(F),F)
|
||||||
|
|
||||||
|
|
||||||
def equivalent_strain_Mises(epsilon):
|
def equivalent_strain_Mises(epsilon: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate the Mises equivalent of a strain tensor.
|
Calculate the Mises equivalent of a strain tensor.
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ def equivalent_strain_Mises(epsilon):
|
||||||
return _equivalent_Mises(epsilon,2.0/3.0)
|
return _equivalent_Mises(epsilon,2.0/3.0)
|
||||||
|
|
||||||
|
|
||||||
def equivalent_stress_Mises(sigma):
|
def equivalent_stress_Mises(sigma: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate the Mises equivalent of a stress tensor.
|
Calculate the Mises equivalent of a stress tensor.
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ def equivalent_stress_Mises(sigma):
|
||||||
return _equivalent_Mises(sigma,3.0/2.0)
|
return _equivalent_Mises(sigma,3.0/2.0)
|
||||||
|
|
||||||
|
|
||||||
def maximum_shear(T_sym):
|
def maximum_shear(T_sym: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate the maximum shear component of a symmetric tensor.
|
Calculate the maximum shear component of a symmetric tensor.
|
||||||
|
|
||||||
|
@ -102,7 +104,7 @@ def maximum_shear(T_sym):
|
||||||
return (w[...,0] - w[...,2])*0.5
|
return (w[...,0] - w[...,2])*0.5
|
||||||
|
|
||||||
|
|
||||||
def rotation(T):
|
def rotation(T: _np.ndarray) -> _rotation.Rotation:
|
||||||
"""
|
"""
|
||||||
Calculate the rotational part of a tensor.
|
Calculate the rotational part of a tensor.
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ def rotation(T):
|
||||||
return _rotation.Rotation.from_matrix(_polar_decomposition(T,'R')[0])
|
return _rotation.Rotation.from_matrix(_polar_decomposition(T,'R')[0])
|
||||||
|
|
||||||
|
|
||||||
def strain(F,t,m):
|
def strain(F: _np.ndarray, t: str, m: float) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate strain tensor (Seth–Hill family).
|
Calculate strain tensor (Seth–Hill family).
|
||||||
|
|
||||||
|
@ -160,7 +162,7 @@ def strain(F,t,m):
|
||||||
return eps
|
return eps
|
||||||
|
|
||||||
|
|
||||||
def stress_Cauchy(P,F):
|
def stress_Cauchy(P: _np.ndarray, F: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate the Cauchy stress (true stress).
|
Calculate the Cauchy stress (true stress).
|
||||||
|
|
||||||
|
@ -182,7 +184,7 @@ def stress_Cauchy(P,F):
|
||||||
return _tensor.symmetric(_np.einsum('...,...ij,...kj',1.0/_np.linalg.det(F),P,F))
|
return _tensor.symmetric(_np.einsum('...,...ij,...kj',1.0/_np.linalg.det(F),P,F))
|
||||||
|
|
||||||
|
|
||||||
def stress_second_Piola_Kirchhoff(P,F):
|
def stress_second_Piola_Kirchhoff(P: _np.ndarray, F: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate the second Piola-Kirchhoff stress.
|
Calculate the second Piola-Kirchhoff stress.
|
||||||
|
|
||||||
|
@ -205,7 +207,7 @@ def stress_second_Piola_Kirchhoff(P,F):
|
||||||
return _tensor.symmetric(_np.einsum('...ij,...jk',_np.linalg.inv(F),P))
|
return _tensor.symmetric(_np.einsum('...ij,...jk',_np.linalg.inv(F),P))
|
||||||
|
|
||||||
|
|
||||||
def stretch_left(T):
|
def stretch_left(T: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate left stretch of a tensor.
|
Calculate left stretch of a tensor.
|
||||||
|
|
||||||
|
@ -223,7 +225,7 @@ def stretch_left(T):
|
||||||
return _polar_decomposition(T,'V')[0]
|
return _polar_decomposition(T,'V')[0]
|
||||||
|
|
||||||
|
|
||||||
def stretch_right(T):
|
def stretch_right(T: _np.ndarray) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Calculate right stretch of a tensor.
|
Calculate right stretch of a tensor.
|
||||||
|
|
||||||
|
@ -241,7 +243,7 @@ def stretch_right(T):
|
||||||
return _polar_decomposition(T,'U')[0]
|
return _polar_decomposition(T,'U')[0]
|
||||||
|
|
||||||
|
|
||||||
def _polar_decomposition(T,requested):
|
def _polar_decomposition(T: _np.ndarray, requested: Sequence[str]) -> tuple:
|
||||||
"""
|
"""
|
||||||
Perform singular value decomposition.
|
Perform singular value decomposition.
|
||||||
|
|
||||||
|
@ -257,21 +259,21 @@ def _polar_decomposition(T,requested):
|
||||||
u, _, vh = _np.linalg.svd(T)
|
u, _, vh = _np.linalg.svd(T)
|
||||||
R = _np.einsum('...ij,...jk',u,vh)
|
R = _np.einsum('...ij,...jk',u,vh)
|
||||||
|
|
||||||
output = ()
|
output = []
|
||||||
if 'R' in requested:
|
if 'R' in requested:
|
||||||
output+=(R,)
|
output+=[R]
|
||||||
if 'V' in requested:
|
if 'V' in requested:
|
||||||
output+=(_np.einsum('...ij,...kj',T,R),)
|
output+=[_np.einsum('...ij,...kj',T,R)]
|
||||||
if 'U' in requested:
|
if 'U' in requested:
|
||||||
output+=(_np.einsum('...ji,...jk',R,T),)
|
output+=[_np.einsum('...ji,...jk',R,T)]
|
||||||
|
|
||||||
if len(output) == 0:
|
if len(output) == 0:
|
||||||
raise ValueError('output needs to be out of V, R, U')
|
raise ValueError('output needs to be out of V, R, U')
|
||||||
|
|
||||||
return output
|
return tuple(output)
|
||||||
|
|
||||||
|
|
||||||
def _equivalent_Mises(T_sym,s):
|
def _equivalent_Mises(T_sym: _np.ndarray, s: float) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Base equation for Mises equivalent of a stress or strain tensor.
|
Base equation for Mises equivalent of a stress or strain tensor.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
[mypy-scipy.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-h5py.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-vtk.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-PIL.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-matplotlib.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-yaml.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-pandas.*]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
[mypy-wx.*]
|
||||||
|
ignore_missing_imports = True
|
Loading…
Reference in New Issue