-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_kinematics.py
More file actions
116 lines (95 loc) · 2.89 KB
/
test_kinematics.py
File metadata and controls
116 lines (95 loc) · 2.89 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import pytest
import ufl
from pulse import kinematics, utils
def test_SecondOrderIdentity(u) -> None:
assert kinematics.SecondOrderIdentity(u) == ufl.Identity(3)
@pytest.mark.parametrize(
"cls, factor",
(
(kinematics.DeformationGradient, 2),
(kinematics.IsochoricDeformationGradient_from_u, pow(8, -1 / 3) * 2),
),
)
def test_DeformationGradient(cls, factor, u) -> None:
r"""Test deformation gradient for a linear displacement field, i.e
.. math::
u(x) = x
Notes
-----
If not isochoric then
.. math::
\mathbf{F} = I + \nabla u = I + I = 2I
If isochoric then
.. math::
\mathbf{F}_{\mathrm{iso}} = J^{-1/3} F = 8^{-1/3} F = 8^{-1/3} 2 I
"""
u.interpolate(lambda x: x)
F = cls(u)
assert F.ufl_shape == (3, 3)
# Since u is linear (u = x), F = I + I = 2 I
zero = F - factor * ufl.Identity(3)
assert utils.matrix_is_zero(zero)
@pytest.mark.parametrize(
"cls, factor",
(
(kinematics.DeformationGradient, 4),
(kinematics.IsochoricDeformationGradient_from_u, pow(8, -2 / 3) * 4),
),
)
def test_RightCauchyGreen(cls, factor, u) -> None:
u.interpolate(lambda x: x)
F = cls(u)
C = kinematics.RightCauchyGreen(F)
assert C.ufl_shape == (3, 3)
zero = C - factor * ufl.Identity(3)
assert utils.matrix_is_zero(zero)
@pytest.mark.parametrize(
"cls, factor",
(
(kinematics.DeformationGradient, 4),
(kinematics.IsochoricDeformationGradient_from_u, pow(8, -2 / 3) * 4),
),
)
def test_LeftCauchyGreen(cls, factor, u) -> None:
u.interpolate(lambda x: x)
F = cls(u)
B = kinematics.LeftCauchyGreen(F)
assert B.ufl_shape == (3, 3)
zero = B - factor * ufl.Identity(3)
assert utils.matrix_is_zero(zero)
@pytest.mark.parametrize(
"cls, factor",
(
(kinematics.DeformationGradient, 1),
(kinematics.IsochoricDeformationGradient_from_u, pow(8, -1 / 3) * 2 - 1),
),
)
def test_EngineeringStrain(cls, factor, u) -> None:
u.interpolate(lambda x: x)
F = cls(u)
E = kinematics.EngineeringStrain(F)
assert E.ufl_shape == (3, 3)
zero = E - factor * ufl.Identity(3)
assert utils.matrix_is_zero(zero)
@pytest.mark.parametrize(
"cls, factor",
(
(kinematics.DeformationGradient, 1.5),
(kinematics.IsochoricDeformationGradient_from_u, 0.5 * (pow(8, -2 / 3) * 4 - 1)),
),
)
def test_GreenLagrangeStrain(cls, factor, u) -> None:
u.interpolate(lambda x: x)
F = cls(u)
E = kinematics.GreenLagrangeStrain(F)
assert E.ufl_shape == (3, 3)
zero = E - factor * ufl.Identity(3)
assert utils.matrix_is_zero(zero)
def test_PiolaTransform(u):
u.interpolate(lambda x: x)
F = kinematics.DeformationGradient(u)
A = F
B = kinematics.PiolaTransform(A, F)
C = kinematics.InversePiolaTransform(B, F)
zero = A - C
assert utils.matrix_is_zero(zero)