Conservative field transfer (integrator + Monte-Carlo projection)#335
Open
jacobmerson wants to merge 12 commits into
Open
Conservative field transfer (integrator + Monte-Carlo projection)#335jacobmerson wants to merge 12 commits into
jacobmerson wants to merge 12 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors conservative field transfer to use reusable integrator abstractions (mass + RHS) and a cached Galerkin projection solver, adds Monte Carlo (control-variate) conservative projection, and updates coupler/GID handling and Python bindings accordingly.
Changes:
- Replace legacy
calculate_mass_matrix/calculate_load_vectorand load-vector integrator paths withBilinearFormIntegrator/LinearFormIntegrator+GalerkinProjectionSolver. - Add Omega_h-specific conservative RHS integrators (mesh-intersection quadrature) and Monte Carlo RHS integrator, plus a control-variate projection operator.
- Introduce compact GID permutations and adjust field exchange planning/serialization; expose new transfer operators via Python and add new unit tests + example.
Reviewed changes
Copilot reviewed 53 out of 53 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_omega_h_mc_rhs_integrator.cpp | Adds tests for Monte Carlo RHS integrator and control-variate projection behavior. |
| test/test_omega_h_mass_integrator.cpp | Adds tests validating Omega_h mass-matrix assembly vs MeshField reference. |
| test/test_omega_h_intersection_rhs_integrator.cpp | Adds tests for intersection-based conservative RHS integrator correctness. |
| test/test_omega_h_form_integrator_utils.cpp | Adds tests for polygon vertex dedup/relink helper used in intersection integration. |
| test/test_mesh_intersection_field_transfer.cpp | Reworks/extends conservative projection tests (P0/P1, reordered/sparse GIDs, conservation). |
| test/test_load_vector.cpp | Removes legacy load vector test tied to deleted implementation. |
| test/test_field_exchange_planner.cpp | Adds tests ensuring exchange plans exclude GID headers and headers are inserted correctly. |
| test/CMakeLists.txt | Registers new tests and updates conditional test lists. |
| src/pcms/transfer/omega_h_mc_rhs_integrator.hpp | Defines Monte Carlo RHS integrator interface and sampling enum. |
| src/pcms/transfer/omega_h_mc_rhs_integrator.cpp | Implements Monte Carlo sample generation and COO RHS assembly. |
| src/pcms/transfer/omega_h_mass_integrator.hpp | Defines Omega_h mass-matrix integrator (P0/P1) and builder. |
| src/pcms/transfer/omega_h_mass_integrator.cpp | Implements PETSc COO mass-matrix assembly for Omega_h layouts. |
| src/pcms/transfer/omega_h_intersection_rhs_integrator.hpp | Defines intersection-based conservative RHS integrator and builder. |
| src/pcms/transfer/omega_h_intersection_rhs_integrator.cpp | Implements mesh-intersection quadrature point generation and RHS assembly. |
| src/pcms/transfer/omega_h_form_integrator_utils.hpp | Adds shared validation, intersection traversal, quadrature staging, and target basis helpers. |
| src/pcms/transfer/omega_h_control_variate_projection.hpp | Declares control-variate Monte Carlo conservative projection operator. |
| src/pcms/transfer/omega_h_control_variate_projection.cpp | Implements control-variate projection workflow (interpolate + residual projection). |
| src/pcms/transfer/omega_h_conservative_projection.hpp | Updates conservative projection to cache integrators/evaluator/solver (no per-call refactorization). |
| src/pcms/transfer/omega_h_conservative_projection.cpp | Implements cached projection Apply() using solver + permutation scatter. |
| src/pcms/transfer/mass_matrix_integrator.hpp | Renames helper to buildElementMassMatrix and fixes override signature. |
| src/pcms/transfer/linear_form_integrator.hpp | Introduces LinearFormIntegrator interface for RHS assembly. |
| src/pcms/transfer/bilinear_form_integrator.hpp | Introduces BilinearFormIntegrator interface for matrix assembly. |
| src/pcms/transfer/integration_point_set.hpp | Adds IntegrationPointSet wrapper for ordered integration coordinates. |
| src/pcms/transfer/conservative_projection_solver.hpp | Refactors solver into cached GalerkinProjectionSolver using integrator interfaces. |
| src/pcms/transfer/conservative_projection_solver.cpp | Implements cached KSP setup and Solve overloads (evaluator-driven and pre-sampled). |
| src/pcms/transfer/load_vector_integrator.hpp | Removes legacy supermesh load-vector integrator API. |
| src/pcms/transfer/load_vector_integrator.cpp | Removes legacy load-vector integrator implementation. |
| src/pcms/transfer/calculate_mass_matrix.hpp | Removes legacy PETSc mass matrix assembly API. |
| src/pcms/transfer/calculate_mass_matrix.cpp | Removes legacy mass matrix assembly implementation. |
| src/pcms/transfer/calculate_load_vector.hpp | Removes legacy PETSc load vector assembly API. |
| src/pcms/transfer/calculate_load_vector.cpp | Removes legacy load vector assembly implementation. |
| src/pcms/transfer/interpolator.h | Fixes include path for transfer operator header. |
| src/pcms/transfer/CMakeLists.txt | Wires in new transfer headers/sources and removes deprecated ones. |
| src/pcms/pythonapi/pythonapi.cpp | Initializes PETSc at import time when PETSc+MeshFields are enabled. |
| src/pcms/pythonapi/CMakeLists.txt | Links PETSc/MeshFields into Python module when needed for new transfer bindings. |
| src/pcms/pythonapi/bind_transfer_field.cpp | Exposes conservative and Monte Carlo/control-variate projections + sampling enum to Python. |
| src/pcms/pythonapi/bind_omega_h.cpp | Adds VTU read helper and fixes mesh construction in parallel VTK read. |
| src/pcms/pythonapi/bind_field_base.cpp | Improves numpy contiguity handling; exposes FunctionSpace::mesh and Lagrange backend selection. |
| src/pcms/localization/adj_search.cpp | Adjusts handling of exterior points and caps adaptive radius loop. |
| src/pcms/field/layout/omega_h_lagrange.h | Adds device GID accessor. |
| src/pcms/field/layout/omega_h_lagrange.cpp | Builds global-to-local permutation eagerly in constructors; implements GetGids(). |
| src/pcms/field/gid_permutation.hpp | Adds utilities for unmapped/sorted GID permutations and permutation construction. |
| src/pcms/field/gid_permutation.cpp | Implements permutation utilities and uniqueness checks. |
| src/pcms/field/field_layout.h | Adds global-to-local permutation API and eager-build helper/caches. |
| src/pcms/field/field_layout.cpp | Implements permutation cache building and accessors. |
| src/pcms/field/element_dispatch.h | Adds runtime-to-compile-time FE order dispatch helper. |
| src/pcms/field/CMakeLists.txt | Adds new field sources/headers to build. |
| src/pcms/coupler/serializer/xgc.h | Skips unmapped permutation entries during (de)serialization. |
| src/pcms/coupler/field_serializer.h | Skips unmapped permutation entries during (de)serialization and sorted extraction. |
| src/pcms/coupler/field_layout_communicator.cpp | Adjusts outgoing GID message layout/size to account for per-message headers. |
| src/pcms/coupler/field_exchange_planner.h | Clarifies exchange plan offsets/permutation exclude GID headers. |
| src/pcms/coupler/field_exchange_planner.cpp | Refactors GID message handling to insert/parse headers and support unmapped holders. |
| examples/python-api-example/example_conservative_transfer.py | Adds end-to-end Python example for conservative + Monte Carlo transfer and mixed-order cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+630
to
+638
| m.def( | ||
| "read_mesh_vtu", | ||
| [](const std::string& filepath, std::shared_ptr<Omega_h::Comm> comm) { | ||
| std::ifstream file(filepath, std::ios::binary); | ||
| if (!file.is_open()) { | ||
| throw std::runtime_error("Cannot open VTU file: " + filepath); | ||
| } | ||
| Omega_h::Mesh mesh(comm->library()); | ||
| Omega_h::vtk::read_vtu(file, comm, &mesh); |
| num_samples * 3); | ||
| d.coeffs = | ||
| Kokkos::View<Real*, DeviceMemorySpace>("mc_rhs_coeffs", num_samples * 3); | ||
| d.nverts = static_cast<PetscInt>(mesh.nverts()); |
| coo_cols(e) = g; | ||
| vals(e) = static_cast<PetscScalar>(area); | ||
| }); | ||
|
|
| } | ||
| } | ||
| }); | ||
|
|
| static_cast<PetscScalar>(coeffs(i * ndof + j)) * f; | ||
| } | ||
| }); | ||
|
|
| coo_vals(i * 3 + j) = static_cast<PetscScalar>(coeffs(i * 3 + j)) * f; | ||
| } | ||
| }); | ||
|
|
| { | ||
| detail::CheckOmegaHScalarP1Layout(target_coordinate_system, target_layout, | ||
| "OmegaHMonteCarloRHSIntegrator", "target"); | ||
| if (samples_per_element <= 0) { |
…trix / load_vector) Squashed original commits: 0a27b53, 0c0e697
…nsfer Squashed original commits: bad8434, eca15d1, b4af186, 26f35c6, b8baf3b, 6b1d7f2, dba7966, 5baf365, 4b00ac1 (mesh_fields_rhs_integrator churn from 26f35c6/b8baf3b dropped)
Squashed original commits: 844dc1c, b4a4545, 629419f (sobol_sequence churn dropped)
…y buffers Squashed original commits: e7488c6, 4e68c80
…fter #308) Squashed original commit: 75a3045
Currently the petsc-based solver is only needed for conservative projection which requires MeshFields. So petsc is only linked when PCMS_ENABLE_PETSC and PCMS_ENABLE_MESHFIELDS
Add a shared, format-agnostic GID-to-local permutation and use it so the transfer operators handle sparse or reordered global IDs correctly. This allows us to reuse the global-to-local mapping for things outside of the serialization such as setting up the petsc arrays.
…olders Split the GID (layout) message from the field (data) message and reuse the field GID-permutation primitives so exchanges handle overlap masks and reordered global IDs without corrupting payloads.
7dfbf1e to
5bda307
Compare
b4d81b3 to
6c13b7c
Compare
The python pcms module links libpetsc.so dynamically when python_api is ON, so PETSc lib dir must be on LD_LIBRARY_PATH for import to succeed.
clang-tidy bugprone-implicit-widening-of-multiplication-result (treated as error) flagged int*int products used to size 64-bit Views in the intersection/MC RHS integrators and the field-exchange-planner test. Perform the multiplication in size_t via an explicit cast.
Forward-declare the RHS integrators
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.
Adds conservative field-transfer support built on the integrator-based (Galerkin) and Monte-Carlo / control-variate projection operators, replacing the old
calculate_mass_matrix/load_vectorimplementation.Highlights:
Base is
jacobmerson/various-fixes(#340 ).