Skip to content

Commit 0f856db

Browse files
committed
Reformat to use with pytest
1 parent 144b1d3 commit 0f856db

9 files changed

Lines changed: 60 additions & 52 deletions

File tree

benchmarks/2d/__init__.py

Whitespace-only changes.

benchmarks/2d/uniaxial_nodal_forces/__init__.py

Whitespace-only changes.

benchmarks/2d/uniaxial_nodal_forces/test_benchmark.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@
33
import jax.numpy as jnp
44
from diffmpm import MPM
55

6-
curr_filepath = Path(__file__).absolute()
7-
curr_dir = curr_filepath.parent
8-
os.chdir(curr_dir)
9-
mpm = MPM("mpm-nodal-forces.toml")
10-
mpm.solve()
116

12-
result = jnp.load("results/uniaxial-nodal-forces/particles_0300.npz")
13-
## Step 300
14-
assert jnp.round(result["stress"][0, :, 0].min() - 0.5925210678182377, 6) == 0.0
15-
assert jnp.round(result["stress"][0, :, 0].max() - 0.5974539476363379, 6) == 0.0
7+
def test_benchmarks():
8+
curr_filepath = Path(__file__).absolute()
9+
curr_dir = curr_filepath.parent
10+
os.chdir(curr_dir)
11+
mpm = MPM("mpm-nodal-forces.toml")
12+
mpm.solve()
1613

17-
## Step 510
18-
result = jnp.load("results/uniaxial-nodal-forces/particles_0510.npz")
19-
assert jnp.round(result["stress"][0, :, 0].min() - 1.0026665338366039, 5) == 0.0
20-
assert jnp.round(result["stress"][0, :, 0].max() - 1.0112231542459431, 5) == 0.0
14+
result = jnp.load("results/uniaxial-nodal-forces/particles_0300.npz")
15+
## Step 300
16+
assert jnp.round(result["stress"][0, :, 0].min() - 0.5925210678182377, 6) == 0.0
17+
assert jnp.round(result["stress"][0, :, 0].max() - 0.5974539476363379, 6) == 0.0
2118

22-
## Step 750
23-
result = jnp.load("results/uniaxial-nodal-forces/particles_0750.npz")
24-
assert jnp.round(result["stress"][0, :, 0].min() - 1.0000053000532143, 5) == 0.0
25-
assert jnp.round(result["stress"][0, :, 0].max() - 1.0000225119807862, 5) == 0.0
19+
## Step 510
20+
result = jnp.load("results/uniaxial-nodal-forces/particles_0510.npz")
21+
assert jnp.round(result["stress"][0, :, 0].min() - 1.0026665338366039, 5) == 0.0
22+
assert jnp.round(result["stress"][0, :, 0].max() - 1.0112231542459431, 5) == 0.0
2623

27-
## Step 990
28-
result = jnp.load("results/uniaxial-nodal-forces/particles_0990.npz")
29-
assert jnp.round(result["stress"][0, :, 0].min() - 0.9999990078443788, 5) == 0.0
30-
assert jnp.round(result["stress"][0, :, 0].max() - 0.9999990292713694, 5) == 0.0
24+
## Step 750
25+
result = jnp.load("results/uniaxial-nodal-forces/particles_0750.npz")
26+
assert jnp.round(result["stress"][0, :, 0].min() - 1.0000053000532143, 5) == 0.0
27+
assert jnp.round(result["stress"][0, :, 0].max() - 1.0000225119807862, 5) == 0.0
28+
29+
## Step 990
30+
result = jnp.load("results/uniaxial-nodal-forces/particles_0990.npz")
31+
assert jnp.round(result["stress"][0, :, 0].min() - 0.9999990078443788, 5) == 0.0
32+
assert jnp.round(result["stress"][0, :, 0].max() - 0.9999990292713694, 5) == 0.0

benchmarks/2d/uniaxial_particle_traction/__init__.py

Whitespace-only changes.

benchmarks/2d/uniaxial_particle_traction/test_benchmark.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33
import jax.numpy as jnp
44
from diffmpm import MPM
55

6-
curr_filepath = Path(__file__).absolute()
7-
curr_dir = curr_filepath.parent
8-
os.chdir(curr_dir)
9-
mpm = MPM("mpm-particle-traction.toml")
10-
mpm.solve()
11-
result = jnp.load("results/uniaxial-particle-traction/particles_0300.npz")
12-
## Step 300
13-
assert jnp.round(result["stress"][0, :, 0].min() - 0.4450086768966724, 5) == 0.0
14-
assert jnp.round(result["stress"][0, :, 0].max() - 0.5966527842046769, 5) == 0.0
156

16-
## Step 510
17-
result = jnp.load("results/uniaxial-particle-traction/particles_0510.npz")
18-
assert jnp.round(result["stress"][0, :, 0].min() - 0.7528092313640623, 5) == 0.0
19-
assert jnp.round(result["stress"][0, :, 0].max() - 1.0109599915279937, 5) == 0.0
7+
def test_benchmarks():
8+
curr_filepath = Path(__file__).absolute()
9+
curr_dir = curr_filepath.parent
10+
os.chdir(curr_dir)
11+
mpm = MPM("mpm-particle-traction.toml")
12+
mpm.solve()
13+
result = jnp.load("results/uniaxial-particle-traction/particles_0300.npz")
14+
## Step 300
15+
assert jnp.round(result["stress"][0, :, 0].min() - 0.4450086768966724, 5) == 0.0
16+
assert jnp.round(result["stress"][0, :, 0].max() - 0.5966527842046769, 5) == 0.0
2017

21-
## Step 750
22-
result = jnp.load("results/uniaxial-particle-traction/particles_0750.npz")
23-
assert jnp.round(result["stress"][0, :, 0].min() - 0.7500090055681591, 5) == 0.0
24-
assert jnp.round(result["stress"][0, :, 0].max() - 1.0000224746314728, 5) == 0.0
18+
## Step 510
19+
result = jnp.load("results/uniaxial-particle-traction/particles_0510.npz")
20+
assert jnp.round(result["stress"][0, :, 0].min() - 0.7528092313640623, 5) == 0.0
21+
assert jnp.round(result["stress"][0, :, 0].max() - 1.0109599915279937, 5) == 0.0
2522

26-
## Step 990
27-
result = jnp.load("results/uniaxial-particle-traction/particles_0990.npz")
28-
assert jnp.round(result["stress"][0, :, 0].min() - 0.750002924022295, 5) == 0.0
29-
assert jnp.round(result["stress"][0, :, 0].max() - 0.9999997782938734, 5) == 0.0
23+
## Step 750
24+
result = jnp.load("results/uniaxial-particle-traction/particles_0750.npz")
25+
assert jnp.round(result["stress"][0, :, 0].min() - 0.7500090055681591, 5) == 0.0
26+
assert jnp.round(result["stress"][0, :, 0].max() - 1.0000224746314728, 5) == 0.0
27+
28+
## Step 990
29+
result = jnp.load("results/uniaxial-particle-traction/particles_0990.npz")
30+
assert jnp.round(result["stress"][0, :, 0].min() - 0.750002924022295, 5) == 0.0
31+
assert jnp.round(result["stress"][0, :, 0].max() - 0.9999997782938734, 5) == 0.0

benchmarks/2d/uniaxial_stress/__init__.py

Whitespace-only changes.

benchmarks/2d/uniaxial_stress/test_benchmark.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import jax.numpy as jnp
44
from diffmpm import MPM
55

6-
curr_filepath = Path(__file__).absolute()
7-
curr_dir = curr_filepath.parent
8-
os.chdir(curr_dir)
9-
mpm = MPM("mpm-uniaxial-stress.toml")
10-
mpm.solve()
116

12-
result = jnp.load("results/uniaxial-stress-usf/particles_09.npz")
13-
true_stress_yy = -1.0
14-
true_stress_xx = 0.0
7+
def test_benchmarks():
8+
curr_filepath = Path(__file__).absolute()
9+
curr_dir = curr_filepath.parent
10+
os.chdir(curr_dir)
11+
mpm = MPM("mpm-uniaxial-stress.toml")
12+
mpm.solve()
1513

16-
assert jnp.round(result["stress"][0, :, 1].max() - true_stress_yy, 8) == 0.0
17-
assert jnp.round(result["stress"][0, :, 0].max() - true_stress_xx, 8) == 0.0
14+
result = jnp.load("results/uniaxial-stress-usf/particles_09.npz")
15+
true_stress_yy = -1.0
16+
true_stress_xx = 0.0
17+
18+
assert jnp.round(result["stress"][0, :, 1].max() - true_stress_yy, 8) == 0.0
19+
assert jnp.round(result["stress"][0, :, 0].max() - true_stress_xx, 8) == 0.0

benchmarks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)