Skip to content

Commit 7cf57f7

Browse files
committed
Added test cases for Bingham Material
1 parent 377a82a commit 7cf57f7

1 file changed

Lines changed: 217 additions & 0 deletions

File tree

tests/test_bingham.py

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
import pytest
2+
import jax.numpy as jnp
3+
from diffmpm.material import Bingham
4+
from diffmpm.particle import Particles
5+
from diffmpm.element import Quadrilateral4Node
6+
from diffmpm.constraint import Constraint
7+
from diffmpm.node import Nodes
8+
9+
particles_element_targets = [
10+
(
11+
Particles(
12+
jnp.array([[0.5, 0.5]]).reshape(1, 1, 2),
13+
(
14+
Bingham(
15+
{
16+
"density": 1000,
17+
"youngs_modulus": 1.0e7,
18+
"poisson_ratio": 0.3,
19+
"tau0": 771.8,
20+
"mu": 0.0451,
21+
"critical_shear_rate": 0.2,
22+
"ndim": 2,
23+
}
24+
)
25+
),
26+
jnp.array([0]),
27+
),
28+
Quadrilateral4Node(
29+
(1, 1),
30+
1,
31+
(4.0, 4.0),
32+
[],
33+
Nodes(4, jnp.array([-2, -2, 2, -2, -2, 2, 2, 2]).reshape((4, 1, 2))),
34+
),
35+
jnp.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).reshape((6, 1)),
36+
),
37+
(
38+
Particles(
39+
jnp.array([[0.5, 0.5]]).reshape(1, 1, 2),
40+
(
41+
Bingham(
42+
{
43+
"density": 1000,
44+
"youngs_modulus": 1.0e7,
45+
"poisson_ratio": 0.3,
46+
"tau0": 771.8,
47+
"mu": 0.0451,
48+
"critical_shear_rate": 0.2,
49+
"ndim": 2,
50+
}
51+
)
52+
),
53+
jnp.array([0]),
54+
),
55+
Quadrilateral4Node(
56+
(1, 1),
57+
1,
58+
(4.0, 4.0),
59+
[(0, Constraint(0, 0.02)), (0, Constraint(1, 0.03))],
60+
Nodes(4, jnp.array([-2, -2, 2, -2, -2, 2, 2, 2]).reshape((4, 1, 2))),
61+
),
62+
jnp.array([-52083.3333333333, -52083.3333333333, 0.0, 0.0, 0.0, 0.0]).reshape(
63+
(6, 1)
64+
),
65+
),
66+
(
67+
Particles(
68+
jnp.array([[0.5, 0.5]]).reshape(1, 1, 2),
69+
(
70+
Bingham(
71+
{
72+
"density": 1000,
73+
"youngs_modulus": 1.0e7,
74+
"poisson_ratio": 0.3,
75+
"tau0": 200.0,
76+
"mu": 200.0,
77+
"critical_shear_rate": 0.2,
78+
"ndim": 2,
79+
}
80+
)
81+
),
82+
jnp.array([0]),
83+
),
84+
Quadrilateral4Node(
85+
(1, 1),
86+
1,
87+
(4.0, 4.0),
88+
[(0, Constraint(0, 2.0)), (0, Constraint(1, 3.0))],
89+
Nodes(4, jnp.array([-2, -2, 2, -2, -2, 2, 2, 2]).reshape((4, 1, 2))),
90+
),
91+
jnp.array(
92+
[-5208520.35574006, -5208613.86694342, 0.0, -233.778008402801, 0.0, 0.0]
93+
).reshape((6, 1)),
94+
),
95+
(
96+
Particles(
97+
jnp.array([[0.5, 0.5]]).reshape(1, 1, 2),
98+
(
99+
Bingham(
100+
{
101+
"density": 1000,
102+
"youngs_modulus": 1.0e7,
103+
"poisson_ratio": 0.3,
104+
"tau0": 200.0,
105+
"mu": 200.0,
106+
"critical_shear_rate": 0.2,
107+
"ndim": 2,
108+
"incompressible": True,
109+
}
110+
)
111+
),
112+
jnp.array([0]),
113+
),
114+
Quadrilateral4Node(
115+
(1, 1),
116+
1,
117+
(4.0, 4.0),
118+
[(0, Constraint(0, 2.0)), (0, Constraint(1, 3.0))],
119+
Nodes(4, jnp.array([-2, -2, 2, -2, -2, 2, 2, 2]).reshape((4, 1, 2))),
120+
),
121+
jnp.array(
122+
[-187.0224067222, -280.5336100834, 0.0, -233.778008402801, 0.0, 0.0]
123+
).reshape((6, 1)),
124+
),
125+
]
126+
127+
128+
@pytest.fixture
129+
def state_vars():
130+
return {"pressure": jnp.zeros(1)}
131+
132+
133+
@pytest.fixture
134+
def dt():
135+
return 1.0
136+
137+
138+
@pytest.mark.parametrize(
139+
"particles, element, target",
140+
particles_element_targets,
141+
)
142+
def test_compute_stress(particles, state_vars, element, target, dt):
143+
particles.update_natural_coords(element)
144+
if element.constraints:
145+
element.apply_boundary_constraints()
146+
particles.compute_strain(element, dt)
147+
stress = particles.material.compute_stress(None, particles, state_vars)
148+
assert jnp.allclose(stress, target)
149+
150+
151+
def test_key_not_present_in_material_properties():
152+
with pytest.raises(KeyError):
153+
material = Bingham(
154+
{
155+
"density": 1000,
156+
"youngs_modulus": 1.0e7,
157+
"poisson_ratio": 0.3,
158+
"tau0": 771.8,
159+
"critical_shear_rate": 0.2,
160+
"ndim": 2,
161+
}
162+
)
163+
164+
165+
@pytest.mark.parametrize(
166+
"particles, element, target, state_vars",
167+
[
168+
(Particles(
169+
jnp.array([[0.5, 0.5, 0.5, 0.5]]).reshape(2, 1, 2),
170+
(
171+
Bingham(
172+
{
173+
"density": 1000,
174+
"youngs_modulus": 1.0e7,
175+
"poisson_ratio": 0.3,
176+
"tau0": 200.0,
177+
"mu": 200.0,
178+
"critical_shear_rate": 0.2,
179+
"ndim": 2,
180+
}
181+
)
182+
),
183+
jnp.array([0,0]),
184+
),
185+
Quadrilateral4Node(
186+
(1, 1),
187+
1,
188+
(4.0, 4.0),
189+
[(0, Constraint(0, 2.0)), (0, Constraint(1, 3.0))],
190+
Nodes(4, jnp.array([-2, -2, 2, -2, -2, 2, 2, 2]).reshape((4, 1, 2))),
191+
),
192+
jnp.array(
193+
[
194+
-5208520.35574006,
195+
-5208613.86694342,
196+
0.0,
197+
-233.778008402801,
198+
0.0,
199+
0.0,
200+
-5208520.35574006,
201+
-5208613.86694342,
202+
0.0,
203+
-233.778008402801,
204+
0.0,
205+
0.0,
206+
]
207+
).reshape((2, 6, 1)),
208+
{"pressure": jnp.zeros((2, 1))}),
209+
],
210+
)
211+
def test_compute_stress_two_particles(particles, state_vars, element, target, dt):
212+
particles.update_natural_coords(element)
213+
if element.constraints:
214+
element.apply_boundary_constraints()
215+
particles.compute_strain(element, dt)
216+
stress = particles.material.compute_stress(None, particles, state_vars)
217+
assert jnp.allclose(stress, target)

0 commit comments

Comments
 (0)