|
1 | 1 | import jax.numpy as jnp |
2 | 2 | import pytest |
3 | 3 | from diffmpm.materials import LinearElastic, SimpleMaterial |
| 4 | +from diffmpm.particle import Particles |
4 | 5 |
|
5 | | -material_dstrain_stress_targets = [ |
| 6 | +particles_dstrain_stress_targets = [ |
6 | 7 | ( |
7 | | - SimpleMaterial({"E": 10, "density": 1}), |
| 8 | + Particles( |
| 9 | + jnp.array([[0.5, 0.5]]).reshape(1, 1, 2), |
| 10 | + SimpleMaterial({"E": 10, "density": 1}), |
| 11 | + jnp.array([0]), |
| 12 | + ), |
8 | 13 | jnp.ones((1, 6, 1)), |
9 | 14 | jnp.ones((1, 6, 1)) * 10, |
10 | 15 | ), |
11 | 16 | ( |
12 | | - LinearElastic({"density": 1, "youngs_modulus": 10, "poisson_ratio": 1}), |
| 17 | + Particles( |
| 18 | + jnp.array([[0.5, 0.5]]).reshape(1, 1, 2), |
| 19 | + LinearElastic({"density": 1, "youngs_modulus": 10, "poisson_ratio": 1}), |
| 20 | + jnp.array([0]), |
| 21 | + ), |
13 | 22 | jnp.ones((1, 6, 1)), |
14 | 23 | jnp.array([-10, -10, -10, 2.5, 2.5, 2.5]).reshape(1, 6, 1), |
15 | 24 | ), |
16 | 25 | ( |
17 | | - LinearElastic({"density": 1000, "youngs_modulus": 1e7, "poisson_ratio": 0.3}), |
| 26 | + Particles( |
| 27 | + jnp.array([[0.5, 0.5]]).reshape(1, 1, 2), |
| 28 | + LinearElastic( |
| 29 | + {"density": 1000, "youngs_modulus": 1e7, "poisson_ratio": 0.3} |
| 30 | + ), |
| 31 | + jnp.array([0]), |
| 32 | + ), |
18 | 33 | jnp.array([0.001, 0.0005, 0, 0, 0, 0]).reshape(1, 6, 1), |
19 | 34 | jnp.array([1.63461538461538e4, 12500, 0.86538461538462e4, 0, 0, 0]).reshape( |
20 | 35 | 1, 6, 1 |
21 | 36 | ), |
22 | 37 | ), |
23 | 38 | ( |
24 | | - LinearElastic({"density": 1000, "youngs_modulus": 1e7, "poisson_ratio": 0.3}), |
| 39 | + Particles( |
| 40 | + jnp.array([[0.5, 0.5]]).reshape(1, 1, 2), |
| 41 | + LinearElastic( |
| 42 | + {"density": 1000, "youngs_modulus": 1e7, "poisson_ratio": 0.3} |
| 43 | + ), |
| 44 | + jnp.array([0]), |
| 45 | + ), |
25 | 46 | jnp.array([0.001, 0.0005, 0, 0.00001, 0, 0]).reshape(1, 6, 1), |
26 | 47 | jnp.array( |
27 | 48 | [1.63461538461538e4, 12500, 0.86538461538462e4, 3.84615384615385e01, 0, 0] |
|
30 | 51 | ] |
31 | 52 |
|
32 | 53 |
|
33 | | -@pytest.mark.parametrize("material, dstrain, target", material_dstrain_stress_targets) |
34 | | -def test_compute_stress(material, dstrain, target): |
35 | | - stress = material.compute_stress(dstrain) |
| 54 | +@pytest.mark.parametrize("particles, dstrain, target", particles_dstrain_stress_targets) |
| 55 | +def test_compute_stress(particles, dstrain, target): |
| 56 | + particles.dstrain = dstrain |
| 57 | + stress = particles.material.compute_stress(particles) |
36 | 58 | assert jnp.allclose(stress, target) |
0 commit comments