Skip to content

Commit

Permalink
regenerated refs using gpu implementations from dpstokes library. tes…
Browse files Browse the repository at this point in the history
…ts are now passing if the same kernel parameters are used as the ref implementation
  • Loading branch information
rykerfish committed Jun 6, 2024
1 parent 1ce606a commit 4392903
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 19 deletions.
Binary file removed tests/ref/pair_mobility_bw_w4.mat
Binary file not shown.
Binary file added tests/ref/pair_mobility_bw_w4_gpu.mat
Binary file not shown.
Binary file removed tests/ref/pair_mobility_sc_w4.mat
Binary file not shown.
Binary file added tests/ref/pair_mobility_sc_w4_gpu.mat
Binary file not shown.
Binary file removed tests/ref/self_mobility_bw_w4.mat
Binary file not shown.
Binary file added tests/ref/self_mobility_bw_w4_gpu.mat
Binary file not shown.
Binary file removed tests/ref/self_mobility_sc_w4.mat
Binary file not shown.
Binary file added tests/ref/self_mobility_sc_w4_gpu.mat
Binary file not shown.
33 changes: 14 additions & 19 deletions tests/test_wall_mobility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
@pytest.mark.parametrize(
("Solver", "periodicity", "ref_file"),
[
(DPStokes, ("periodic", "periodic", "single_wall"), "self_mobility_bw_w4.mat"),
(DPStokes, ("periodic", "periodic", "two_walls"), "self_mobility_sc_w4.mat"),
(DPStokes, ("periodic", "periodic", "single_wall"), "self_mobility_bw_w4_gpu.mat"),
(DPStokes, ("periodic", "periodic", "two_walls"), "self_mobility_sc_w4_gpu.mat"),
(NBody, ("open", "open", "single_wall"), "self_mobility_bw_ref_noimg.mat")
],
)
Expand Down Expand Up @@ -59,21 +59,22 @@ def test_self_mobility(Solver, periodicity, ref_file):
M /= normMat
allM[i] = M

scipy.io.savemat('./temp/test_data/test_' + ref_file, {'M': allM, 'heights': refHeights})
# uncomment to save datafile for test plots
# scipy.io.savemat('./temp/test_data/test_' + ref_file, {'M': allM, 'heights': refHeights})

diags = [np.diag(matrix) for matrix in allM]
ref_diags = [np.diag(matrix)[0:3] for matrix in refM] # only take diagonal elements from forces

if Solver.__name__ == "DPStokes": # NBody ref only goes down to a height of z=1
assert np.all(np.diag(allM[0]) == [0,0,0]), "Self mobility is not zero on the wall at z=0"

assert np.allclose(diags, ref_diags, atol=1e-2), "Self mobility does not match reference"
assert np.allclose(diags, ref_diags, atol=1e-6), "Self mobility does not match reference"

@pytest.mark.parametrize(
("Solver", "periodicity", "ref_file"),
[
# (DPStokes, ("periodic", "periodic", "single_wall"), "pair_mobility_bw_w4.mat"),
# (DPStokes, ("periodic", "periodic", "two_walls"), "pair_mobility_sc_w4.mat"),
(DPStokes, ("periodic", "periodic", "single_wall"), "pair_mobility_bw_w4_gpu.mat"),
(DPStokes, ("periodic", "periodic", "two_walls"), "pair_mobility_sc_w4_gpu.mat"),
(NBody, ("open", "open", "single_wall"), "pair_mobility_bw_ref_noimg.mat")
],
)
Expand Down Expand Up @@ -110,17 +111,18 @@ def test_pair_mobility(Solver, periodicity, ref_file):

allM = np.zeros((nSeps, nHeights, 3*numberParticles, 3*numberParticles), dtype=precision)
for i in range(0,nSeps):
for j in range(0, nHeights):
for k in range(0, nHeights):
xpos = xymax/2
positions = np.array([[xpos+seps[i]/2, xpos, refHeights[j]],
[xpos-seps[i]/2, xpos, refHeights[j]]], dtype=precision)
positions = np.array([[xpos+seps[i]/2, xpos, refHeights[k]],
[xpos-seps[i]/2, xpos, refHeights[k]]], dtype=precision)
solver.setPositions(positions)

M = compute_M(solver, numberParticles)
M /= normMat
allM[i][j] = M
allM[i][k] = M

scipy.io.savemat('./temp/test_data/test_' + ref_file, {'M': allM, 'heights': refHeights})
# uncomment to save datafile for test plots
# scipy.io.savemat('./temp/test_data/test_' + ref_file, {'M': allM, 'heights': refHeights})

## xx component
indx = 4
Expand Down Expand Up @@ -158,11 +160,4 @@ def checkComponent(indx, indy, allM, refM, nSeps, nHeights):
else:
diff = np.abs(xx - xx_ref)/xx_ref

assert diff < 1e-3, f"Pair mobility does not match reference for component {indx}, {indy}, {xx}, {xx_ref}"


if __name__ == "__main__":
test_self_mobility(DPStokes, ("periodic", "periodic", "single_wall"), "self_mobility_bw.mat")
test_self_mobility(DPStokes, ("periodic", "periodic", "two_walls"), "self_mobility_sc.mat")
test_self_mobility(NBody, ("open", "open", "single_wall"), "self_mobility_bw_ref_noimg.mat")
# test_pair_mobility(DPStokes, ("periodic", "periodic", "single_wall"), "pair_mobility_bw.mat")
assert diff < 1e-3, f"Pair mobility does not match reference for component {indx}, {indy}, {xx}, {xx_ref}"

0 comments on commit 4392903

Please sign in to comment.