Skip to content

improve code reuse in tests - #352

Open
jacobmerson wants to merge 1 commit into
SCOREC:developfrom
jacobmerson:test-utils-reuse
Open

improve code reuse in tests#352
jacobmerson wants to merge 1 commit into
SCOREC:developfrom
jacobmerson:test-utils-reuse

Conversation

@jacobmerson

Copy link
Copy Markdown
Collaborator

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.

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 jacobmerson changed the title test: share common setup helpers via field_test_utils.h improve code reuse in tests Aug 6, 2026
@jacobmerson
jacobmerson marked this pull request as ready for review August 6, 2026 17:11
@jacobmerson
jacobmerson requested a lite review from Copilot August 14, 2026 02:25
@jacobmerson

Copy link
Copy Markdown
Collaborator Author

@Sichao25 pretty sure this is mergable, it's just moving shared code out of individual tests and into the helper utils.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.h with shared helpers (unit-square mesh builders, function-space builders, integration checks, evaluation helpers, standardized test coordinates, and generalized SetField).
  • Updates many tests to call pcms::test utilities (e.g., linear_f, StandardOutsideCoords2D, EvaluateAndAssemble, CopyCoordinatesToHost) instead of duplicating logic.
  • Simplifies view handling in tests by favoring make_array_view / MakeRank1View and rank-2 evaluation buffers via MakeRank2View.

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 thread test/field_test_utils.h
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants