improve code reuse in tests - #352
Open
jacobmerson wants to merge 1 commit into
Open
Conversation
Factor the repeated mesh construction, function-space creation, field
sampling and evaluation boilerplate out of the individual test
translation units and into field_test_utils.h:
- BuildUnitSquare / MakeP1Space / MakeP0Space for the unit-square
simplex meshes used across the transfer and evaluation tests
- IntegrateP0Field / IntegrateP1Field for conservation checks
- EvaluateAndAssemble for the sample-then-assemble pattern shared by
the linear form integrator tests
- StandardOutsideCoords2D for out-of-bounds policy tests
SetField now dispatches on the arity of the supplied callable so the
same helper covers 2D and 3D layouts, and it samples the layout's DOF
coordinates directly instead of copying them into a fixed-rank view.
The evaluation helpers use rank-2 output views through MakeRank2View
rather than hand-built Rank2Views over rank-1 storage.
No behavioral change to the tests themselves.
jacobmerson
marked this pull request as ready for review
August 6, 2026 17:11
Collaborator
Author
|
@Sichao25 pretty sure this is mergable, it's just moving shared code out of individual tests and into the helper utils. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors and centralizes common test boilerplate for mesh/field construction, sampling, evaluation, and conservation checks into test/field_test_utils.h, and updates a broad set of unit tests to use these shared helpers (including unified 1D/2D output handling via MakeRank2View and standardized coordinate sets).
Changes:
- Introduces/extends
field_test_utils.hwith shared helpers (unit-square mesh builders, function-space builders, integration checks, evaluation helpers, standardized test coordinates, and generalizedSetField). - Updates many tests to call
pcms::testutilities (e.g.,linear_f,StandardOutsideCoords2D,EvaluateAndAssemble,CopyCoordinatesToHost) instead of duplicating logic. - Simplifies view handling in tests by favoring
make_array_view/MakeRank1Viewand rank-2 evaluation buffers viaMakeRank2View.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/test_xgc_reverse_classification.cpp | Uses make_array_view for serialized buffer handling. |
| test/test_uniform_grid_field.cpp | Switches repeated linear expression to pcms::test::linear_f and uses rank-2 output views for evaluation results. |
| test/test_svd_serial.cpp | Fixes RHS view allocation and improves a view name for clarity. |
| test/test_spr_meshfields.cpp | Replaces manual centroid computation with get_entity_centroids helper. |
| test/test_polynomial_reconstruction_mls_evaluation.cpp | Removes duplicated query-point helper and uses shared evaluation/check utilities and rank-2 outputs. |
| test/test_point_evaluator.cpp | Consolidates repeated evaluation patterns using shared helpers and standardized outside coordinates. |
| test/test_omega_h_mc_rhs_integrator.cpp | Uses shared unit-square mesh builders, CopyCoordinatesToHost, and shared assemble helper. |
| test/test_omega_h_mass_integrator.cpp | Uses shared unit-square mesh builder and shared P1 space factory. |
| test/test_omega_h_lagrange_field.cpp | Uses linear_f, shared outside coords, and shared evaluation helpers. |
| test/test_omega_h_intersection_rhs_integrator.cpp | Uses shared unit-square mesh builders, CopyCoordinatesToHost, and shared assemble helper. |
| test/test_mesh_intersection_field_transfer.cpp | Removes local mesh/integration helpers in favor of shared utilities and get_entity_centroids. |
| test/test_localization_factory.cpp | Replaces manual coordinate conversion with ConvertCoordsTo2D. |
| test/test_interpolation_on_ltx_mesh.cpp | Switches to make_array_view for host array/vector wrappers. |
| test/test_interpolation_class.cpp | Uses shared helpers to compare support results and simplify host data/view wrapping. |
| test/test_field_interpolation.cpp | Uses generalized SetField to populate quadratic DOF holders. |
| test/test_field_exchange_planner.cpp | Uses MakeRank1View to wrap the message buffer. |
| test/test_field_evaluation.cpp | Uses generalized SetField and clarifies quadratic DOF-holder sampling approach. |
| test/test_eqdsk.cpp | Uses shared device coordinate-view creation and rank-2 output evaluation handling. |
| test/field_test_utils.h | Adds/extends shared test helpers, including generalized SetField and rank-2 evaluation output utilities. |
Suppressed comments (1)
test/field_test_utils.h:112
- AreArraysEqualUnordered iterates [start,end) without validating the range against array sizes. If supports_ptr contains an invalid offset, this helper can read out-of-bounds and crash the test process instead of reporting a clean assertion failure.
inline bool AreArraysEqualUnordered(
const Omega_h::HostRead<Omega_h::LO>& array1,
const Omega_h::HostRead<Omega_h::LO>& array2, int start, int end)
{
std::unordered_map<Omega_h::LO, int> freq1, freq2;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+254
to
258
| static_assert(std::is_invocable_v<Func, Real, Real> || | ||
| std::is_invocable_v<Func, Real, Real, Real>, | ||
| "SetField requires func(x, y) or func(x, y, z)"); | ||
|
|
||
| auto dof_coords = layout.GetDOFHolderCoordinates().GetValues(); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Factor the repeated mesh construction, function-space creation, field sampling and evaluation boilerplate out of the individual test translation units and into field_test_utils.h:
SetField now dispatches on the arity of the supplied callable so the same helper covers 2D and 3D layouts, and it samples the layout's DOF coordinates directly instead of copying them into a fixed-rank view. The evaluation helpers use rank-2 output views through MakeRank2View rather than hand-built Rank2Views over rank-1 storage.