Learning, Solving and Optimizing PDEs with TensorGalerkin: an efficient high-performance Galerkin assembly algorithm

Shizheng Wen, Mingyuan chi, Tianwei Yu, Ben Moseley, Mike Yan Michelis, Pu Ren, Hao Sun, Siddhartha Mishra

Solving Partial Differential Equations (PDEs) is the mathematical backbone of modern engineering, driving everything from bridge design to weather forecasting. While the Finite Element Method (FEM) remains the industry standard for handling complex geometries, integrating it with modern deep learning frameworks like PyTorch has revealed a significant "Python problem."

In standard deep learning ecosystems, FEM "assembly"—the process of building a massive global matrix from millions of tiny local elements—is notoriously inefficient. Traditional implementations rely on loops that create highly fragmented computational graphs, leading to massive memory overhead and sluggish performance. Conversely, newer Physics-Informed Neural Networks (PINNs) often struggle with accuracy and the computation of high-order derivatives.

To bridge this gap, researchers have introduced TensorGalerkin, a high-performance framework that brings the mathematical rigor and speed of FEM to the PyTorch ecosystem. By reformulating matrix assembly as a highly optimized "Map-Reduce" operation, TensorGalerkin achieves massive speedups and enables physics-informed machine learning on millions of degrees of freedom where standard methods crash.

The TensorGalerkin Framework

TensorGalerkin treats PDE assembly as a strictly tensorized Map-Reduce operation, bypassing the inefficiencies of traditional element-wise looping:

  1. Stage I: Batch-Map: Instead of iterating over individual elements, the framework "lifts" the element index to a batch dimension. It leverages torch.einsum to compute all local stiffness matrices simultaneously in a single, fused GPU kernel.
  2. Stage II: Sparse-Reduce: To construct the global system, TensorGalerkin replaces slow "scatter-add" operations with a precomputed routing strategy executed via Sparse Matrix Multiplication (SpMM).

Crucially, this architecture is co-designed with PyTorch's autograd engine. Because the assembly is handled by a few monolithic tensor operations, the computational graph contains $O(1)$ nodes. This means the memory overhead remains constant, even if the underlying mesh scales to millions of elements.

Building on this foundation, the authors developed three specialized tools:

  • TensorMesh: A high-speed numerical PDE solver.
  • TensorPILS: A physics-informed learning system that utilizes analytical gradients from the FEM basis rather than relying on automatic differentiation (AD) for spatial derivatives.
  • TensorOpt: An end-to-end differentiable pipeline tailored for inverse design and topology optimization.

Key Insights and Innovations

  • The $O(1)$ Graph Advantage: In typical AD-based physics solvers, memory consumption scales linearly with the number of points. TensorGalerkin severs this link, allowing the framework to scale effortlessly to 11.6 million degrees of freedom (DoFs) on a single GPU.
  • Analytical Gradients over AD: For physics-informed learning, the authors demonstrated that using the analytical gradients of FEM shape functions is significantly faster and more stable than forcing PyTorch to differentiate through a neural network twice, as is standard in PINNs.
  • Differentiable Sparse Solvers: By integrating with the torch-sla library, TensorGalerkin can differentiate directly through the linear solver without "unrolling" iterations, resulting in vastly leaner optimization loops.

Experimental Benchmarks and Results

The framework was rigorously evaluated across a diverse set of benchmarks using unstructured triangular and tetrahedral meshes (generated via Gmsh). Tasks ranged from 3D Poisson and Linear Elasticity on complex geometries to time-dependent PDEs (the Wave and Allen-Cahn equations) and topology optimization (the 2D Cantilever Beam).

Highlights from the results include: * Raw Speed: The GPU-accelerated TensorMesh solver operates 3x faster than FEniCS (a premier CPU solver) for Poisson problems, and over an order of magnitude faster for elasticity simulations. * Unprecedented Scaling: In physics-informed tasks, TensorPILS is 4 to 6 times faster than traditional PINNs. While PINN baselines ran out of memory at 5.8 million DoFs, TensorPILS continued to scale linearly without crashing. * High-Frequency Accuracy: On 2D high-frequency Poisson tasks featuring discontinuous "checkerboard" forcing functions, TensorPILS achieved 50% less error than the nearest baseline (Deep Ritz) while running twice as fast. * Optimization Efficiency: For topology optimization, TensorOpt achieved a 3.7x total speedup over JAX-FEM, primarily by eliminating Python loop overhead and JIT-recompilation delays.

Limitations and Future Directions

The primary limitation of TensorGalerkin is its requirement that the target PDE possesses a variational (weak) form. While this covers the vast majority of common physics equations, certain complex non-linear or non-conservative systems may not be directly compatible.

Looking ahead, the authors plan to extend the framework to support non-conforming methods, such as Discontinuous Galerkin, to encompass an even broader class of PDEs. Future work will also explore more sophisticated time-stepping techniques and the application of TensorGalerkin to large-scale, real-world 3D engineering control problems.

Summary updated

BibTeX
@inproceedings{wen2026learning,
  author = {Shizheng Wen and Mingyuan chi and Tianwei Yu and Ben Moseley and Mike Yan Michelis and Pu Ren and Hao Sun and Siddhartha Mishra},
  title = {{Learning, Solving and Optimizing PDEs with TensorGalerkin: an efficient high-performance Galerkin assembly algorithm}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=xpIUvw8ANa},
}
Figure