Skip to content

Commit

Permalink
updated wall tests to be easier to run
Browse files Browse the repository at this point in the history
  • Loading branch information
rykerfish committed Nov 25, 2024
1 parent 5516d71 commit 7b63938
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/test_wall_mobility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np

from libMobility import DPStokes, NBody
import libMobility
from utils import compute_M

# NOTE: Some of the following tests will only pass if compiled with double precision.
Expand All @@ -12,6 +13,8 @@
"NBody": {"algorithm": "advise"},
}

precision = np.float32 if NBody.precision == "float" else np.float64

@pytest.mark.parametrize(
("Solver", "periodicity", "tol", "ref_file"),
[
Expand All @@ -21,6 +24,9 @@
],
)
def test_self_mobility_linear(Solver, periodicity, tol, ref_file):
if precision == np.float32 and Solver.__name__ == "DPStokes":
pytest.skip("The test is only valid for double precision due to how reference data was generated.")

xymax = 76.8
params = wall_params[Solver.__name__]
needsTorque = False
Expand All @@ -33,8 +39,6 @@ def test_self_mobility_linear(Solver, periodicity, tol, ref_file):
hydrodynamicRadius = 1.0
eta = 1/4/np.sqrt(np.pi)

precision = np.float32 if Solver.precision == "float" else np.float64

solver = Solver(*periodicity)
solver.setParameters(**params)
numberParticles = 1
Expand Down Expand Up @@ -75,6 +79,9 @@ def test_self_mobility_linear(Solver, periodicity, tol, ref_file):
],
)
def test_pair_mobility_linear(Solver, periodicity, ref_file, tol):
if precision == np.float32 and Solver.__name__ == "DPStokes":
pytest.skip("The test is only valid for double precision due to how reference data was generated.")

xymax = 76.8
params = wall_params[Solver.__name__]
needsTorque = False
Expand All @@ -88,7 +95,6 @@ def test_pair_mobility_linear(Solver, periodicity, ref_file, tol):
radH = 1.0 # hydrodynamic radius
eta = 1/4/np.sqrt(np.pi)

precision = np.float32 if Solver.precision == "float" else np.float64
tol = 100*np.finfo(precision).eps

solver = Solver(*periodicity)
Expand Down Expand Up @@ -132,6 +138,9 @@ def test_pair_mobility_linear(Solver, periodicity, ref_file, tol):
],
)
def test_self_mobility_angular(Solver, periodicity, ref_file):
if precision == np.float32 and Solver.__name__ == "DPStokes":
pytest.skip("The test is only valid for double precision due to how reference data was generated.")

zmax = 19.2
xymax = 76.8
params = wall_params[Solver.__name__]
Expand All @@ -147,8 +156,6 @@ def test_self_mobility_angular(Solver, periodicity, ref_file):
refM = ref['M']
refHeights = ref['heights'].flatten()

precision = np.float32 if Solver.precision == "float" else np.float64

solver = Solver(*periodicity)
solver.setParameters(**params)
numberParticles = 1
Expand Down Expand Up @@ -191,6 +198,9 @@ def test_self_mobility_angular(Solver, periodicity, ref_file):
)
@pytest.mark.parametrize("offset", ["x", "y"])
def test_pair_mobility_angular(Solver, periodicity, ref_file, offset):
if precision == np.float32 and Solver.__name__ == "DPStokes":
pytest.skip("The test is only valid for double precision due to how reference data was generated.")

zmax = 19.2
xymax = 76.8
params = wall_params[Solver.__name__]
Expand All @@ -206,8 +216,6 @@ def test_pair_mobility_angular(Solver, periodicity, ref_file, offset):
refM = ref['M']
refHeights = ref['heights'].flatten()

precision = np.float32 if Solver.precision == "float" else np.float64

nP = 2
solver = Solver(*periodicity)
solver.setParameters(**params)
Expand Down Expand Up @@ -253,9 +261,4 @@ def test_pair_mobility_angular(Solver, periodicity, ref_file, offset):
for i in range(0, nSeps):
for k in range(0, nHeights):
diff = abs(allM[i,k] - refM[i,k])
temp = diff < tol
if not np.all(temp):
print(diff)
print(np.where(temp == False))
breakpoint()
assert np.all(diff < tol)

0 comments on commit 7b63938

Please sign in to comment.