/
stress.py
98 lines (80 loc) · 3.11 KB
/
stress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
This module provides the Stress class used to create, manipulate, and
calculate relevant properties of the stress tensor.
"""
from __future__ import annotations
import math
import numpy as np
from pymatgen.core.tensors import SquareTensor
__author__ = "Joseph Montoya"
__copyright__ = "Copyright 2012, The Materials Project"
__credits__ = "Maarten de Jong, Mark Asta, Anubhav Jain"
__version__ = "1.0"
__maintainer__ = "Joseph Montoya"
__email__ = "montoyjh@lbl.gov"
__status__ = "Production"
__date__ = "July 24, 2018"
class Stress(SquareTensor):
"""
This class extends SquareTensor as a representation of the
stress.
"""
symbol = "s"
def __new__(cls, stress_matrix):
"""
Create a Stress object. Note that the constructor uses __new__
rather than __init__ according to the standard method of
subclassing numpy ndarrays.
Args:
stress_matrix (3x3 array-like): the 3x3 array-like
representing the stress
"""
obj = super().__new__(cls, stress_matrix)
return obj.view(cls)
@property
def dev_principal_invariants(self):
"""
Returns the principal invariants of the deviatoric stress tensor,
which is calculated by finding the coefficients of the characteristic
polynomial of the stress tensor minus the identity times the mean
stress.
"""
return self.deviator_stress.principal_invariants * np.array([1, -1, 1])
@property
def von_mises(self):
"""Returns the von Mises stress."""
if not self.is_symmetric():
raise ValueError(
"The stress tensor is not symmetric, Von Mises stress is based on a symmetric stress tensor."
)
return math.sqrt(3 * self.dev_principal_invariants[1])
@property
def mean_stress(self):
"""Returns the mean stress."""
return 1 / 3 * self.trace()
@property
def deviator_stress(self):
"""Returns the deviatoric component of the stress."""
if not self.is_symmetric:
raise ValueError("The stress tensor is not symmetric, so deviator stress will not be either")
return self - self.mean_stress * np.eye(3)
def piola_kirchoff_1(self, def_grad):
"""
Calculates the first Piola-Kirchoff stress.
Args:
def_grad (3x3 array-like): deformation gradient tensor
"""
if not self.is_symmetric:
raise ValueError("The stress tensor is not symmetric, PK stress is based on a symmetric stress tensor.")
def_grad = SquareTensor(def_grad)
return def_grad.det * np.dot(self, def_grad.inv.trans)
def piola_kirchoff_2(self, def_grad):
"""
Calculates the second Piola-Kirchoff stress.
Args:
def_grad (3x3 array-like): rate of deformation tensor
"""
def_grad = SquareTensor(def_grad)
if not self.is_symmetric:
raise ValueError("The stress tensor is not symmetric, PK stress is based on a symmetric stress tensor.")
return def_grad.det * np.dot(np.dot(def_grad.inv, self), def_grad.inv.trans)