Neural SPH: Improved Neural Modeling of Lagrangian Fluid Dynamics

Artur P. Toshev1, Jonas A. Erbesdobler1, Nikolaus A. Adams1,2, Johannes Brandstetter3,4
1TUM AER, 2TUM MEP, 3JKU Linz, 4NXAI

Neural SPH improves Lagrangian fluid dynamics, showcased by physics modeling of the 2D dam break example after 80 rollout steps. Different models exhibit different physics behaviors. From top to bottom: GNS (Sanchez-Gonzalez et al., 2020), GNS with corrected force only (GNS\(_g\)), full Neural SPH-enhanced GNS (GNS\(_{g,p}\)), and the ground truth SPH simulation. The colors correspond to the density deviation from the reference density; the system is considered physical within 0.98-1.02.


Abstract

Smoothed particle hydrodynamics (SPH) is omnipresent in modern engineering and scientific disciplines. SPH is a class of Lagrangian schemes that discretize fluid dynamics via finite material points that are tracked through the evolving velocity field. Due to the particle-like nature of the simulation, graph neural networks (GNNs) have emerged as appealing and successful surrogates. However, the practical utility of such GNN-based simulators relies on their ability to faithfully model physics, providing accurate and stable predictions over long time horizons - which is a notoriously hard problem. In this work, we identify particle clustering originating from tensile instabilities as one of the primary pitfalls. Based on these insights, we enhance both training and rollout inference of state-of-the-art GNN-based simulators with varying components from standard SPH solvers, including pressure, viscous, and external force components. All Neural SPH-enhanced simulators achieve better performance than the baseline GNNs, often by orders of magnitude in terms of rollout error, allowing for significantly longer rollouts and significantly better physics modeling.

Smoothed Particle Hydrodynamics

Smoothed particle hydrodynamics (SPH) is a Lagrangian, mesh-free method for numerically solving differential equations, which is the prefered method to simulate problems with (a) free surfaces, (b) complex boundaries, (c) multi-phase flows, and (d) fluid-structure interactions. The method works by discretizing the domain with a set of particles at whose locations the physical quantities can then estimated by kernel interpolations. Thus, a summation over every interaction between particle \(i\) and all particles \(j\) within a given cutoff radius is carried out. Each interaction is then weighted using a radial kernel function \(W\), as illustrated below.


SPH kernel, source: Wikipedia.

In Neural SPH, the approximated governing equations are the incompressible Navier-Stokes equations (NSE) which are modeled by the so-called weakly compressible NSE given below.

\[ \begin{align} \frac{d}{dt}(\rho) &= - \rho ~ (\nabla \cdot \mathbf{u}), \label{eq1}\tag{1}\\ \frac{d}{dt}(\mathbf{u}) &= - \frac{1}{\rho} \nabla p ~ + ~ \frac{\nu}{V_{ref}L_{ref}} \nabla^2 \mathbf{u} ~ + ~ \mathbf{g}, \label{eq2}\tag{2} \end{align} \]

where \(\rho\) is the fluid density, \( \mathbf{u}\) its velocity, \(p\) the pressure, \(\nu\) the kinematic viscosity, \(V_{ref}\) a reference volume, \(L_{ref}\) a reference length, and \(\mathbf{g}\) the external force. The continuity equation Eq. \eqref{eq1} and the momentum equation Eq. \eqref{eq2} are coupled via an equation of state of the form

\[p(\rho) = p_{ref} \left( \frac{\rho}{\rho_{ref}} - 1 \right). \label{eq3}\tag{3}\] For a more visual introduction to SPH, see Matthias Teschner's slides.

The problem of long rollouts

Both classical numerics and learned approaches to Lagrangian fluid simulations face difficulties when evolving a systems over hundreds or thousands of steps. Some of the challenges for the classical methods are the evolution of particles at free surfaces / interfaces / boundaries, as well as particle clumping. After extensively analysing the failure modes of GNN-based Lagrangian CFD surrogates, we conclude that these same challenges are present in learned models and are the primary cause of frequently observed catastrophic failures.

To qualitatively understand clumping, in the figure below we plot the histogram of the per-particle number of neighbors after 400 steps of a 2D lid-driven cavity simulation, which has regions with high particle density. We see a pronounced increase in the number of particles with 8-10 neighbors, indicating clustering artifacts.

Number of neighbors mismatch due to particle clustering. Histogram of the number of neighbors of the 2D lid-driven cavity experiment after 400 rollout steps (average over all test rollouts).

Neural SPH

To address the challenges of long rollouts, we propose two key components to enhance the performance of GNN-based Lagrangian fluid simulations:

  1. External Force Treatment
  2. SPH Relaxation
inspired by traditional SPH solvers and aim to improve the physics modeling of the learned simulators.

1. External Force Treatment

The learning problem formulation by Sanchez-Gonzalez et al., 2020, strives for simplicity by asking the GNN to implicitly predict the effect of both inter-particle forces and external forces. On the example of the dam break experiment, we stress that if the model learned Physics correctly, then the bias term of the last decode layer should correspond to the gravitational force. However, on a pretrained checkpoint, we observed a bias term of more than 10x smaller than the respective gravitational acceleration!

Our idea is to split the terms on the right-hand side of the momentum equation Eq. \eqref{eq2} into \([...] + \mathbf{g}\) and add the external forces back to the learned acceleration in the integrator, essentially forcing the model to learn only inter-particle forces. Implementing this idea requires special attention because we train on 100-times larger time steps than the reference SPH solver, while we only have access to instantaneous external forces. Thus, the accumulated external force over \(M=100\) SPH steps needs to be removed from the full acceleration \(\mathbf{a}\), leading to

\[\mathbf{a} = \texttt{GNN}(\textbf{X}^{t_{k-H-1}:t_k}, \mathbf{g}) + \mathbf{g}_{M}^{FD}. \label{eq4}\tag{4}\]

External Force Treatment: our extension to the original GNS training procedure is colored in green. We denote the model trained with our extension as GNN\(_g\), opposed to GNN. Note: the frames above correspond to steps [0, 20, 40, 60], rather than [0, 1, 2, 3], to better visualize the differences.


2. SPH Relaxation

In addition to the external force treatment, we propose to apply an SPH relaxation after each learned solver step to improve the poor particle distribution observed in the number on neighbors figure above. Notably, our relaxation is a applied only during inference and does not require retraining the model. We propose an SPH relaxation procedure which (a) uses only the particle coordinates, i.e. no other physical quantities such as density and velocity, and (b) can handle free surfaces as well as walls discretized with one dummy particle layer. Ultimately, the relaxation consists of the \(l\) loops of the following two steps:

\[ \begin{align} \mathbf{a} &= \alpha \frac{-1}{\rho} \nabla p ~ + ~ \alpha \beta \nabla^2 \mathbf{u} , \label{eq5}\tag{5}\\ \mathbf{p} &= \mathbf{p} ~ + ~ \mathbf{a}, \label{eq6}\tag{6} \end{align} \]

where the time step and the pre-factors are hidden in the hyperparameters \(\alpha\) and \(\beta\). Furthermore, according to the weakly compressible assumption, density fluctuations should not exceed \(\sim1\%\). Due to the use of density summation, we set all \(\rho < 0.98\rho_{ref}\) to \(\rho_{ref}\) , and all \(\rho > 1.02 \rho_{ref}\) to \(1.02\rho_{ref}\). Our relaxation implementation is based on the JAX-SPH codebase, but we stress that our approach does not require a differentiably solver, as the relaxation solely operates on the particle coordinates.
Consult our full paper for various further implementation details.


SPH Relaxation: our particle relaxation procedure applied after each learned solver step. The relaxation is applied only during inference. Note: the frames above correspond to steps [0, 20, 40, 60], rather than [0, 1, 2, 3], to better visualize the differences.

Experiments

We evaluate the performance of Neural SPH on all 7 LagrangeBench datasets, and both the GNS and SEGNN models. Our results are summarized in the table below, but the appendix of the paper includes various further results including: rollout visualizations, velocity and acceleration histograms, and extensive hyperparameter studies. Overall, we find that Neural SPH significantly improves the physics modeling of GNN-based Lagrangian fluid simulations, at the cost of a slightly increased computational overhead, while the Neural SPH hyperparameters are robust and easy to tune.


Performance measures averaged over a rollout of 400 steps. An additional subscript \(_g\) indicates that external forces are removed from the model outputs, subscript \(p\) indicates that the SPH relaxation has a pressure term, and subscript \(\nu\) that the viscosity term is added to the SPH relaxation. The numbers in the table are averaged over all test trajectories. MSE\(_{400}\) corresponds to: MSE\(_{120}\) for 2D TGV, MSE\(_{55}\) for 3D TGV, and MSE\(_{395}\) for 2D DAM, as these are the full trajectory lengths excluding initial history size H = 5.


Dam Break

The dam break experiment is a challenging test case for fluid simulations due to the free-surface dynamics and wall interactions.



2D dam break rollout of test trajectory 0. Same as the figure at the top, but the full trajectory.


Lid Driven Cavity

The lid-driven cavity experiment is a standard benchmark for incompressible fluid simulations and is used to test the ability of the model to handle fixed and moving no-slip walls.



Density and velocity magnitude of 2D lid-driven cavity over 400 rollout steps (left to right): GNS, GNS\(_p\), SPH. The colors in the first row correspond to the density deviation from the reference density; the system is considered physical within 0.98-1.02.


Reverse Poiseuille Flow

The reverse Poiseuille flow case consists of two opposed channel flows (without walls) with the lower half of the domain being forced left and the upper half being forced right. This experiment tests the ability of the model to handle spatially varying external forces.



Velocity magnitudes histogram of 2D reverse Poiseuille flow after 400 rollout steps (averaged over all rollouts). Our GNS\(_{g,p,\nu}\) matches the ground truth distribution of SPH.



Ablations on RPF 2D with GNS-10-128 over the simulation length. Each plot corresponds to a different performance measure, namely (1) position MSE, (2) kinetic energy MSE, (3) Sinkhorn MSE, (4) density deviation from reference, (5) Dirichlet energy, (6) Chamfer distance. Solid line indicated the mean, and the intervals indicate the 0.25 and 0.75 quantiles over the test trajectories.

Correspondence

In case of any questions, please reach out to artur.toshev[at]tum.de

BibTeX

@article{toshev2024neural
  author    = {Toshev, Artur P and Erbesdobler, Jonas A and Adams, Nikolaus A and Brandstetter, Johannes},
  title     = {Neural SPH: Improved Neural Modeling of Lagrangian Fluid Dynamics},
  journal   = {arXiv preprint arXiv:2402.06275},
  year      = {2024},
}