Skip to content

Feature Proposal: Postprocessor Class for Mesh-to-Mesh Interpolation #60

Description

@vieirasaulo

🚀 Feature Proposal: Postprocessor Class for Mesh-to-Mesh Interpolation

Context

It's common to work with multiple finite element meshes that represent the same or similar spatial domains but differ in resolution, refinement, or topology. A typical use case includes:

  • Transferring simulation results from one mesh (e.g., coarse mesh from a solver) to another (e.g., refined mesh for visualization or post-processing).
  • Performing mesh adaptivity or remeshing and needing to preserve solution fields.
  • Comparing results across simulation runs with differing discretizations.

Currently, interpolating scalar/vector fields (both nodal and elemental) between two unstructured 2D triangular meshes requires custom logic involving:

  1. Delaunay triangulation and barycentric coordinate evaluation for node interpolation (scipy.spatial.Delaunay)
  2. Nearest-neighbor search (scipy.spatial.cKDTree).

These are non-trivial operations that can benefit from a standardized, reusable interface that in my opinion fits very well pandamesh.


Feature

I propose the introduction of a Postprocessor utility class that provides mesh-to-mesh interpolation capabilities. This would serve as a general-purpose post-processing tool to:

  • Interpolate nodal attributes from one mesh onto another using barycentric interpolation.
  • Interpolate elemental attributes using centroid-based nearest-neighbor mapping.
  • Support multi-dimensional attributes (e.g., scalar fields, vector fields).
  • Handle invalid or out-of-bounds queries gracefully.

Proposed API (Sketch)

class Postprocessor:
    def __init__(
        self,
        source_nodes: np.ndarray,
        source_elements: np.ndarray,
    ):
        ...

    def interpolate_to(
        self,
        nodal_attributes: np.ndarray,
        elemental_attributes: np.ndarray,
        target_nodes: np.ndarray,
        target_elements: np.ndarray,
    ) -> Tuple[np.ndarray, np.ndarray]:
        """
        Interpolate nodal and elemental attributes to a new mesh.
        Returns:
            interpolated_nodal_attributes: shape (N2, Dn)
            interpolated_elemental_attributes: shape (M2, De)
        """
        ...

I’ve already prototyped something and would be happy to contribute a pull request including:

  • The Postprocessor class with interpolate_to method. This is what I can see for now, but likely other use cases might emerge.
  • Unit tests and examples using basic geometries
  • Clear docstrings

Please let me know if this aligns with your roadmap or if you'd like to discuss further before I submit the PR!

Thanks for the great library 🙌

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions