-
Notifications
You must be signed in to change notification settings - Fork 2
Support for non square boxes in DPStokes #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
23b55b2
feat(dpstokes): allow non-square boxes
RaulPPelaez 513075d
test: add test for non-square boxes
RaulPPelaez df59f4e
chore: bump uammd
RaulPPelaez 97c5ee0
feat: recompute h using the smallest current value between X and Y
RaulPPelaez bbcf265
Merge branch 'main' into dpstokes_nonsquare
RaulPPelaez f72e852
slightly simplified existing wall tests
rykerfish 2edfa45
make particles initialize above the wall for dpstokes test
rykerfish f925731
add simple test for isotropy in dpstokes, it's failing
rykerfish 7b4f5b8
interface changes for variable beta per dimension in UAMMD for dpstokes
rykerfish 1715f6c
made box test more flexible
rykerfish 85c167a
added m=6 params for monopole for testing
rykerfish c65e6e6
Merge branch 'dpstokes_nonsquare' into variable_beta
rykerfish 1948aad
bump UAMMD version
rykerfish 581143b
w=6 and w=4 params for testing
rykerfish 83f65a0
add test comparing non-square dpstokes vs rpy
rykerfish 4304d21
beta selection that varies in x/y and uses smaller of the two in z. a…
rykerfish c577789
modified tests for torques
rykerfish ceb3c5e
modified betas for torques
rykerfish 50687a3
This merge adds automated selection of different beta parameters for …
rykerfish 86b7c83
Merge branch 'main' into dpstokes_nonsquare
rykerfish d87d407
format
rykerfish 19e1381
format (again)
rykerfish bee0bef
remove unused code
rykerfish 538eab1
format (finally
rykerfish c228573
fix wall test precision selection
rykerfish fa7b15f
Merge branch 'main' into dpstokes_nonsquare
rykerfish a1a9858
change beta to real3 to match uammd
rykerfish 00ad18f
revert small changes that broke wall tests
rykerfish d465873
more wall test fixes
rykerfish 3fb7ac5
fix to keep square domains consistent with old behavior
rykerfish c2a4728
add wall test comparing to rpy
rykerfish 4ad62d7
regenerated dpstokes reference data for angular wall tests
rykerfish 4f16012
remove test that disallowed non-square boxes
rykerfish aec3d9e
fix: remove dt from DPStokes interface to reflect UAMMD changes
rykerfish 443421b
build: bump UAMMD version
rykerfish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import numpy as np | ||
| import libMobility as lm | ||
|
|
||
|
|
||
| def compute_with_dpstokes(pos, lx, ly, forces=None, torques=None): | ||
| params = {"viscosity": 1 / (6 * np.pi), "hydrodynamicRadius": 1.73} | ||
| dpstokes = lm.DPStokes("periodic", "periodic", "single_wall") | ||
| torques_on = True if torques is not None else False | ||
| dpstokes.setParameters(Lx=lx, Ly=ly, zmin=-8.0, zmax=8.0) | ||
| dpstokes.initialize(**params, includeAngular=torques_on) | ||
| dpstokes.setPositions(pos) | ||
| mf_dp, mt_dp = dpstokes.Mdot(forces=forces, torques=torques) | ||
| if torques_on: | ||
| return mt_dp | ||
| else: | ||
| return mf_dp | ||
|
|
||
|
|
||
| def test_non_square_box(): | ||
| nP = 10 | ||
| pos_or = np.random.uniform(-8, 8, (nP, 3)).astype(np.float32) | ||
| forces_or = np.random.uniform(-1, 1, (nP, 3)).astype(np.float32) | ||
| forces_or -= np.mean(forces_or, axis=0) # Center the forces around zero | ||
|
|
||
| L_fact = 2.0 | ||
| L_short = 16.0 | ||
| L_long = L_short * L_fact | ||
|
|
||
| mf_dp_cube = compute_with_dpstokes(pos_or, forces=forces_or, lx=L_short, ly=L_short) | ||
| mt_dp_cube = compute_with_dpstokes( | ||
| pos_or, torques=forces_or, lx=L_short, ly=L_short | ||
| ) | ||
|
|
||
| # This must be identical than doubling the box size in x and repeating the particles | ||
| pos = np.vstack((pos_or, pos_or + np.array([0.5 * L_long, 0.0, 0.0]))) | ||
| forces = np.vstack((forces_or, forces_or)) | ||
| mf_dp_lx = compute_with_dpstokes(pos, forces=forces, lx=L_long, ly=L_short)[ | ||
| : len(pos_or), : | ||
| ] | ||
| mt_dp_lx = compute_with_dpstokes(pos, torques=forces, lx=L_long, ly=L_short)[ | ||
| : len(pos_or), : | ||
| ] | ||
|
|
||
| # And the same for doubling the box size in y | ||
| pos = np.vstack((pos_or, pos_or + np.array([0.0, 0.5 * L_long, 0.0]))) | ||
| forces = np.vstack((forces_or, forces_or)) | ||
| mf_dp_ly = compute_with_dpstokes(pos, forces=forces, lx=L_short, ly=L_long)[ | ||
| : len(pos_or), : | ||
| ] | ||
| mt_dp_ly = compute_with_dpstokes(pos, torques=forces, lx=L_short, ly=L_long)[ | ||
| : len(pos_or), : | ||
| ] | ||
|
|
||
| assert np.allclose(mf_dp_lx, mf_dp_cube, rtol=1e-3, atol=1e-2) | ||
| assert np.allclose(mf_dp_ly, mf_dp_cube, rtol=1e-3, atol=1e-2) | ||
|
|
||
| assert np.allclose(mt_dp_lx, mt_dp_cube, rtol=1e-3, atol=1e-2) | ||
| assert np.allclose(mt_dp_ly, mt_dp_cube, rtol=1e-3, atol=1e-2) | ||
|
|
||
|
|
||
| def test_isotropy(): | ||
| L0 = 16.0 | ||
| L_fact = 2.0 | ||
|
|
||
| f_x = np.array([1.0, 0.0, 0.0]) | ||
| f_y = np.array([0.0, 1.0, 0.0]) | ||
|
|
||
| n_runs = 5 | ||
| for _ in range(n_runs): | ||
| pos = np.random.uniform(-8, 8, (3)).astype(np.float32) | ||
|
|
||
| mf_x = compute_with_dpstokes(pos, forces=f_x, lx=L0 * L_fact, ly=L0) | ||
| mf_y = compute_with_dpstokes(pos, forces=f_y, lx=L0, ly=L0 * L_fact) | ||
|
|
||
| mt_x = compute_with_dpstokes(pos, torques=f_x, lx=L0 * L_fact, ly=L0) | ||
| mt_y = compute_with_dpstokes(pos, torques=f_y, lx=L0, ly=L0 * L_fact) | ||
|
|
||
| assert np.allclose(mf_x[0], mf_y[1], rtol=1e-3, atol=1e-2) | ||
| assert np.allclose(mf_x[1], mf_y[0], rtol=1e-3, atol=1e-2) | ||
| assert np.allclose(mf_x[2], mf_y[2], rtol=1e-3, atol=1e-2) | ||
|
|
||
| assert np.allclose(mt_x[0], mt_y[1], rtol=1e-3, atol=1e-2) | ||
| assert np.allclose(mt_x[1], mt_y[0], rtol=1e-3, atol=1e-2) | ||
| assert np.allclose(mt_x[2], mt_y[2], rtol=1e-3, atol=1e-2) | ||
|
|
||
|
|
||
| def test_non_square_matching_rpy(): | ||
|
|
||
| a = np.random.uniform(0.5, 2.0) | ||
| eta = 1 / (6 * np.pi * a) | ||
| L_min = 100 * a # need a fairly large domain to neglect periodic effects | ||
| Lx = np.random.uniform(L_min, 3.0 * L_min) | ||
| Ly = np.random.uniform(L_min, 3.0 * L_min) | ||
| max_height = 10.0 * a | ||
| min_height = 1.5 * a # need a buffer for regularized kernels to match | ||
|
|
||
| solver = lm.DPStokes("periodic", "periodic", "single_wall") | ||
| solver.setParameters(Lx=Lx, Ly=Ly, zmin=0.0, zmax=max_height) | ||
| solver.initialize(hydrodynamicRadius=a, viscosity=eta, includeAngular=True) | ||
|
|
||
| rpy = lm.NBody("open", "open", "single_wall") | ||
| rpy.setParameters(wallHeight=0.0) | ||
| rpy.initialize(hydrodynamicRadius=a, viscosity=eta, includeAngular=True) | ||
|
|
||
| F = np.eye(6) | ||
|
|
||
| heights = np.linspace(min_height, max_height, 20) | ||
|
|
||
| results_dpstokes = np.zeros((2 * len(heights), 3)) | ||
| results_rpy = np.zeros((2 * len(heights), 3)) | ||
|
|
||
| for i, h in enumerate(heights): | ||
| pos = np.array([0.0, 0.0, h]) | ||
|
|
||
| rpy.setPositions(pos) | ||
| solver.setPositions(pos) | ||
| for j in range(6): | ||
| f_j = F[0:3, j].copy() | ||
| t_j = F[3:6, j].copy() | ||
| mf_j, mt_j = solver.Mdot(forces=f_j, torques=t_j) | ||
| results_dpstokes[i] += mf_j | ||
| results_dpstokes[i + 3] += mt_j | ||
|
|
||
| mf_j, mt_j = rpy.Mdot(forces=f_j, torques=t_j) | ||
| results_rpy[i] += mf_j | ||
| results_rpy[i + 3] += mt_j | ||
|
|
||
| assert np.allclose(results_dpstokes, results_rpy, rtol=1e-3, atol=1e-2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.