Skip to content

Commit 123f164

Browse files
committed
Key error, multiple particle test cases added
1 parent 1d6981e commit 123f164

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

diffmpm/material.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ def __compute_stress_per_particle(
251251

252252
shear_rate = jnp.sqrt(
253253
2.0 * (strain_r.T @ (strain_r) + strain_r[-3:].T @ strain_r[-3:])
254-
)
254+
).squeeze()
255255

256256
# Apparent_viscosity maps shear rate to shear stress
257257
# Check if shear rate is 0
258258

259259
apparent_viscosity_true = 2.0 * (
260-
(self.properties["tau0"] / shear_rate[0, 0]) + self.properties["mu"]
260+
(self.properties["tau0"] / shear_rate) + self.properties["mu"]
261261
)
262-
condition = (shear_rate[0, 0] * shear_rate[0, 0]) > (
262+
condition = (shear_rate * shear_rate) > (
263263
self.properties["critical_shear_rate"]
264264
* self.properties["critical_shear_rate"]
265265
)

tests/test_bingham.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,72 @@ def test_compute_stress(particles, state_vars, element, target, dt):
146146
particles.compute_strain(element, dt)
147147
stress = particles.material.compute_stress(None, particles, state_vars)
148148
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)