Skip to content

Commit 1607646

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

File tree

2 files changed

+209
-3
lines changed

2 files changed

+209
-3
lines changed

diffmpm/material.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ def __thermodynamic_pressure(self, volumetric_strain):
198198
# Compute the stress
199199
def compute_stress(self, dstrain, particles, state_vars:dict):
200200
"""
201-
Computes the stress for the Bingham material
201+
Computes the stress for the Bingham material.
202202
203-
Arguments
204-
---------
203+
Parameters
204+
----------
205205
dstrain: array_like
206206
The strain rate tensor for the particles
207207
particles: diffmpm.particles.Particles

tests/test_bingham.py

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
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+
@pytest.mark.parametrize(
128+
"particles, element, target",
129+
particles_element_targets,
130+
)
131+
def test_compute_stress(particles, element, target):
132+
particles.update_natural_coords(element)
133+
if element.constraints:
134+
element.apply_boundary_constraints()
135+
particles.compute_strain(element, 1.0)
136+
stress = particles.material.compute_stress(None, particles, {"pressure": jnp.zeros(1)})
137+
assert jnp.allclose(stress, target)
138+
139+
140+
def test_key_not_present_in_material_properties():
141+
with pytest.raises(KeyError):
142+
material = Bingham(
143+
{
144+
"density": 1000,
145+
"youngs_modulus": 1.0e7,
146+
"poisson_ratio": 0.3,
147+
"tau0": 771.8,
148+
"critical_shear_rate": 0.2,
149+
"ndim": 2,
150+
}
151+
)
152+
153+
154+
@pytest.mark.parametrize(
155+
"particles, element, target, state_vars",
156+
[
157+
(Particles(
158+
jnp.array([[0.5, 0.5, 0.5, 0.5]]).reshape(2, 1, 2),
159+
(
160+
Bingham(
161+
{
162+
"density": 1000,
163+
"youngs_modulus": 1.0e7,
164+
"poisson_ratio": 0.3,
165+
"tau0": 200.0,
166+
"mu": 200.0,
167+
"critical_shear_rate": 0.2,
168+
"ndim": 2,
169+
}
170+
)
171+
),
172+
jnp.array([0,0]),
173+
),
174+
Quadrilateral4Node(
175+
(1, 1),
176+
1,
177+
(4.0, 4.0),
178+
[(0, Constraint(0, 2.0)), (0, Constraint(1, 3.0))],
179+
Nodes(4, jnp.array([-2, -2, 2, -2, -2, 2, 2, 2]).reshape((4, 1, 2))),
180+
),
181+
jnp.array(
182+
[
183+
-5208520.35574006,
184+
-5208613.86694342,
185+
0.0,
186+
-233.778008402801,
187+
0.0,
188+
0.0,
189+
-5208520.35574006,
190+
-5208613.86694342,
191+
0.0,
192+
-233.778008402801,
193+
0.0,
194+
0.0,
195+
]
196+
).reshape((2, 6, 1)),
197+
{"pressure": jnp.zeros((2, 1))}),
198+
],
199+
)
200+
def test_compute_stress_two_particles(particles, state_vars, element, target):
201+
particles.update_natural_coords(element)
202+
if element.constraints:
203+
element.apply_boundary_constraints()
204+
particles.compute_strain(element, 1.0)
205+
stress = particles.material.compute_stress(None, particles, state_vars)
206+
assert jnp.allclose(stress, target)

0 commit comments

Comments
 (0)