-
Notifications
You must be signed in to change notification settings - Fork 7
mesh: add get_mean_radius() + @collective_operation on radii accessors #206
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """MPI smoke test for the parallel-safe mesh radius accessors. | ||
|
|
||
| Run via mpi_runner.sh (mpirun -np N python ptest_0008_*.py). | ||
| Asserts: | ||
| - min/mean/max return positive, ordered values on every rank | ||
| - every rank sees IDENTICAL min, mean, max (parallel-consistent) | ||
| - the methods are tagged as @uw.collective_operation | ||
| """ | ||
| import underworld3 as uw | ||
|
|
||
| mesh = uw.meshing.Annulus( | ||
| radiusOuter=1.0, radiusInner=0.5, cellSize=1.0 / 16, qdegree=3) | ||
|
|
||
| rmin = mesh.get_min_radius() | ||
| rmean = mesh.get_mean_radius() | ||
| rmax = mesh.get_max_radius() | ||
|
|
||
| assert rmin > 0.0, f"rank {uw.mpi.rank}: min must be positive, got {rmin}" | ||
| assert rmin <= rmean <= rmax, ( | ||
| f"rank {uw.mpi.rank}: expected min <= mean <= max, got " | ||
| f"{rmin} <= {rmean} <= {rmax}") | ||
|
|
||
| # All ranks must agree to within float-round-off (the values come from | ||
| # global allreduce / gather, so any disagreement would indicate the | ||
| # accessor leaked rank-local state). | ||
| all_min = uw.mpi.comm.allgather(rmin) | ||
| all_mean = uw.mpi.comm.allgather(rmean) | ||
| all_max = uw.mpi.comm.allgather(rmax) | ||
|
|
||
| tol = 1.0e-12 | ||
| assert max(all_min) - min(all_min) < tol, ( | ||
| f"min_radius differs across ranks: {all_min}") | ||
| assert max(all_mean) - min(all_mean) < tol, ( | ||
| f"mean_radius differs across ranks: {all_mean}") | ||
| assert max(all_max) - min(all_max) < tol, ( | ||
| f"max_radius differs across ranks: {all_max}") | ||
|
|
||
| # Decorator must be present so any selective_ranks() misuse fails fast | ||
| for name in ("get_min_radius", "get_mean_radius", "get_max_radius"): | ||
| fn = getattr(mesh, name) | ||
| assert getattr(fn, "_is_collective", False), ( | ||
| f"rank {uw.mpi.rank}: {name} must be @uw.collective_operation") | ||
|
|
||
| if uw.mpi.rank == 0: | ||
| print(f"OK: min={rmin:.6f} mean={rmean:.6f} max={rmax:.6f} " | ||
| f"agree across {uw.mpi.size} ranks", flush=True) |
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,50 @@ | ||
| """Smoke tests for the parallel-safe mesh radius accessors. | ||
|
|
||
| Verifies that :meth:`Mesh.get_min_radius`, :meth:`Mesh.get_mean_radius`, | ||
| and :meth:`Mesh.get_max_radius` return sensible values in serial. | ||
| A matching MPI smoke test lives in tests/parallel/. | ||
| """ | ||
| import pytest | ||
|
|
||
| pytestmark = pytest.mark.level_1 | ||
|
|
||
|
|
||
| def _check_radii_ordering(mesh): | ||
| rmin = mesh.get_min_radius() | ||
| rmean = mesh.get_mean_radius() | ||
| rmax = mesh.get_max_radius() | ||
| assert rmin > 0.0, f"min radius must be positive, got {rmin}" | ||
| assert rmin <= rmean <= rmax, ( | ||
| f"expected min <= mean <= max, got " | ||
| f"min={rmin}, mean={rmean}, max={rmax}") | ||
|
|
||
|
|
||
| def test_mesh_radii_accessors_annulus(): | ||
| import underworld3 as uw | ||
| mesh = uw.meshing.Annulus( | ||
| radiusOuter=1.0, radiusInner=0.5, | ||
| cellSize=1.0 / 16, qdegree=3) | ||
| _check_radii_ordering(mesh) | ||
|
|
||
|
|
||
| def test_mesh_radii_accessors_box(): | ||
| import underworld3 as uw | ||
| mesh = uw.meshing.UnstructuredSimplexBox( | ||
| minCoords=(0.0, 0.0), maxCoords=(1.0, 1.0), | ||
| cellSize=1.0 / 16) | ||
| _check_radii_ordering(mesh) | ||
|
|
||
|
|
||
| def test_mesh_radii_accessors_are_collective(): | ||
| """The @uw.collective_operation decorator must be present so a | ||
| selective_ranks() misuse fails fast rather than deadlocking.""" | ||
| import underworld3 as uw | ||
| mesh = uw.meshing.Annulus( | ||
| radiusOuter=1.0, radiusInner=0.5, | ||
| cellSize=1.0 / 16, qdegree=3) | ||
| for name in ("get_min_radius", "get_mean_radius", | ||
| "get_max_radius"): | ||
| fn = getattr(mesh, name) | ||
| assert getattr(fn, "_is_collective", False), ( | ||
| f"{name} must be decorated with @uw.collective_operation " | ||
| f"so misuse inside selective_ranks() is caught early.") |
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.