Skip to main content

pyvista-sciml

A lightweight, framework-agnostic PyVista dataset accessor (mesh.sciml) for Scientific Machine Learning (SciML) and Neural PDE Surrogates on 3D Computational Fluid Dynamics (CFD) data.

pyvista-sciml bridges the translation and verification gap between traditional VTK/CFD simulation meshes and deep learning frameworks (JAX/Flax, PyTorch Geometric, NVIDIA Modulus) without introducing heavy framework dependencies or state-caching bugs.

Pillar C Vorticity Audit


Core Capabilities

  1. Pillar A — Mesh-to-Graph & Boundary Extraction (to_graph, boundary_mask)
    • Extracts deduplicated, bidirectional graph connectivity (edge_index) and C-contiguous (order="C") float32 node coordinates from structured or unstructured VTK meshes.
    • Projects named boundary surface patches (wall, inlet, outlet) onto mesh nodes using scale-invariant spatial tolerances.
  2. Pillar B — Physics Conservation & Force Auditing (audit_flow, integrate_drag_lift)
    • Computes pointwise velocity error alongside VTK spatial derivatives for mass conservation divergence ($\nabla \cdot \mathbf{u}$) and vorticity magnitude ($\Vert{}\nabla \times \mathbf{u}\Vert{}$).
    • Integrates surface pressure distributions across curved 3D bodies into dimensionless Drag ($C_D$) and Lift ($C_L$) coefficients.
  3. Pillar C — Standardized 3D Visual Diagnostics (compare)
    • Renders camera-linked 3-panel comparisons (Ground Truth vs. Surrogate Prediction vs. Absolute Spatial Error) with locked color limits (clim) so amplitude damping and phase errors cannot be masked by auto-scaled colorbars.

Installation

From Source (Local Development)

git clone https://github.com/<your-username>/pyvista-sciml.git
cd pyvista-sciml
pip install -e ".[dev]"

Dependencies

  • numpy >= 1.24
  • pyvista >= 0.43
  • scipy >= 1.10

(Intentionally free of jax and torch dependencies—outputs clean C-contiguous NumPy arrays compatible with any ML stack.)


Quick Start

Importing sciml_accessor automatically registers the .sciml accessor on all pyvista.DataSet objects. Top-level functional mirrors are also exported for static type checkers (mypy, pyright) and IDE autocomplete.

import numpy as np
import pyvista as pv
import sciml_accessor as sciml  # Registers .sciml on pv.DataSet

# 1. Load a 3D CFD mesh and boundary patches
mesh = pv.read("cylinder_wake.vtu")
patches = {
    1: pv.read("boundaries/cylinder_wall.vtp"),
    2: pv.read("boundaries/inlet.vtp"),
}

# 2. Pillar A: Extract deduplicated graph arrays for GNN / Neural Operator input
graph = mesh.sciml.to_graph(patches=patches)
# -> {"coords": (N, 3) float32, "edge_index": (2, E) int32, "node_type": (N,) int32}

# 3. Attach surrogate model predictions (e.g., from JAX/Flax or PyTorch Geometric)
mesh.point_data["u_pred"] = predicted_velocity  # (N, 3) float32
mesh.point_data["p_pred"] = predicted_pressure  # (N,) float32

# 4. Pillar B: Audit physical conservation laws & integrated aerodynamic forces
audited = mesh.sciml.audit_flow(pred_vel="u_pred", target_vel="u_true")
wall_surf = audited.extract_surface(algorithm="dataset_surface").threshold(
    value=[0.45, 0.68], scalars="r"
)
forces = wall_surf.sciml.integrate_drag_lift(
    pressure="p_pred", rho=1.0, u_inf=1.0, ref_area=1.0
)
print(f"Predicted Cd: {forces['Cd']:.4f}, Cl: {forces['Cl']:.4f}")

# 5. Pillar C: Render camera-linked, color-locked 3-panel comparison
pl = audited.sciml.compare(
    true_field="true_vorticity_mag",
    pred_field="pred_vorticity_mag",
    slice_normal="z",
    title_prefix="Vorticity:",
    off_screen=True,
)
pl.screenshot("vorticity_audit.png")
pl.close()

API Reference

Pillar A: Graph & Boundary Extraction

  • mesh.sciml.to_graph(patches=None) -> dict[str, np.ndarray] Extracts deduplicated bidirectional edges from 2D/3D cells (edge_index of shape (2, E)), C-contiguous float32 node coordinates (coords of shape (N, 3)), and integer boundary labels (node_type of shape (N,)).
  • mesh.sciml.boundary_mask(patches, rtol=1e-4) -> np.ndarray Maps a dictionary of {label_id: patch_dataset} surfaces onto volume mesh nodes using a bounding-box-scaled k-d tree tolerance. Unmatched nodes default to 0 (interior fluid); higher label IDs take priority on shared corner nodes.

Pillar B: Physics & Engineering Auditing

  • mesh.sciml.audit_flow(pred_vel="u_pred", target_vel="u_true") -> pv.DataSet Returns a shallow copy of the dataset with vel_abs_err, pred_divergence, true_divergence, pred_vorticity_mag, and true_vorticity_mag attached to point_data.
  • mesh.sciml.integrate_drag_lift(pressure, rho=1.0, u_inf=1.0, ref_area=1.0) -> dict[str, float] Auto-extracts a PolyData surface if given an UnstructuredGrid, orients outward cell normals, weights by exact cell area, and integrates surface pressure into {"Cd": float, "Cl": float}.

Pillar C: Visual Diagnostics

  • mesh.sciml.compare(true_field, pred_field, slice_normal="z", title_prefix="", off_screen=False) -> pv.Plotter Creates a 3-panel pv.Plotter with linked cameras (pl.link_views()) and locked clim color bounds across Ground Truth and Prediction alongside an Absolute Error panel.

Functional Mirrors (Type-Checker Friendly)

Every accessor method can also be called directly as a typed module function:

  • sciml_accessor.to_graph(mesh, patches=...)
  • sciml_accessor.audit_flow(mesh, pred_vel=..., target_vel=...)
  • sciml_accessor.compare(mesh, true_field=..., pred_field=...)

Design Principles & Best Practices

  • Offline ETL Only for Training: Use mesh.sciml.to_graph() in an offline preprocessing step to export static topology once to .zarr or .hdf5 before training. Do not call PyVista inside a live GPU DataLoader loop.
  • Stateless & Chainable: Methods never cache internal tensor state on Python attributes and always return shallow pv.DataSet copies so native PyVista filters (.slice(), .threshold(), .save()) can be chained safely.

Project Structure & Testing

pyvista-sciml/
├── sciml_demo/
│   ├── sciml_accessor.py       # Core accessor & functional mirrors
│   └── demo_visual.py          # 3D cylinder wake demonstration script
├── tests/
│   └── test_sciml_accessor.py  # Pytest suite covering Pillars A, B, and C
└── README.md

Run the test suite with:

pytest tests/ -v

License

MIT License

Metadata

Release files for pyvista-sciml 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyvista-sciml 0.1.0
File Size Uploaded Provenance Actions
pyvista_sciml-0.1.0.tar.gz 254.3 kB Without provenance Details for pyvista_sciml-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyvista-sciml 0.1.0
File Interpreter ABI Platform Actions
pyvista_sciml-0.1.0-py3-none-any.whl Python 3 none any Details for pyvista_sciml-0.1.0-py3-none-any.whl

Total release size: 261.8 kB

Release files / pyvista_sciml-0.1.0.tar.gz

Download URL pyvista_sciml-0.1.0.tar.gz
Size 254.3 kB
Tags Source
SHA-256 checksum
How to use checksums
50fd9d00a1d71ae9b1f594545985ba711f65f87085ea2d440dcfd6b59d7a3a13
BLAKE2b-256 checksum
How to use checksums
ee0f1515f1afd75adf3519d436d02201f68903954ae8cedd271b533077737c77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / pyvista_sciml-0.1.0-py3-none-any.whl

Download URL pyvista_sciml-0.1.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
609d0151b27e9e943549a41eaa36c66c3ccd116b2d870c871d51c33bb270a71e
BLAKE2b-256 checksum
How to use checksums
b2a46fa9df044b464ec59091df8d1e10347594b61e51ecc0275d737426e7b123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Security for pyvista-sciml 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page