L EARNING L AGRANGIAN F LUID D YNAMICS WITH G RAPH N EURAL N ETWORKS
Anonymous authors
Paper under double-blind review
A BSTRACT
We present a data-driven model for ﬂuid simulation under Lagrangian representation.
Our model uses graphs to describe the ﬂuid ﬁeld, where physical quantities are encoded as node and edge features.
Instead of directly predicting the acceleration or position correction given the current state, we decompose the simulation scheme into separate parts - advection, collision, and pressure projection.
For these different reasoning tasks, we propose two kinds of graph neural network structures, node-focused networks and edge-focused networks.
By introducing physics prior knowledge, our model can be efﬁcient in terms of training and inference.
Our tests show that the learned model can produce accurate results and remain stable in scenarios with a large number of particles and different geometries.
Unlike many previous works, further tests demonstrate that our model is able to retain many important physical properties of incompressible ﬂuids, such as minor divergence and reasonable pressure distribution.
Additionally, our model can adopt a range of time step sizes different from ones using in the training set, which indicates its robust generalization capability.
I NTRODUCTION
For many science and engineering problems, ﬂuids are an essential integral part.
How to simulate ﬂuid dynamics accurately has long been studied by researchers and a large class of numerical models have been developed.
However, computing high-quality ﬂuid simulation is still computationally expensive despite the advances in computing power.
Also, the time of calculation usually increases drastically when the resolution of the simulating scene scales up.
A common way to alleviate computing costs is using a data-driven model.
Recent progress in the machine learning domain opens up the possibility of employing learning algorithms to learn and model ﬂuid dynamics.
In this paper, we propose a graph-based data-driven ﬂuid dynamics model (Fluid Graph Networks,
FGN), which consists of simple multi-layer perceptron and graph inductive architectures.
Our model predicts and integrates forward the movement of incompressible ﬂuids based on observations.
Compared to previous works in this domain (Ummenhofer et al., 2020; Sanchez-Gonzalez et al., 2020), our model enjoys traceability of physical properties of the system, like low velocity-divergence and constant particle density, and it can predict reasonable pressure distribution.
Experiments demonstrate that our model can remain stable and accurate in long-term simulation.
Although our model is entailed and customized for ﬂuid simulation, it can be extended to simulation of other dynamics under the Lagrangian framework, as it takes universal features (positions, velocities, particle density) under the Lagrangian framework as input.
R ELATED W ORKS
Our model is built upon the Lagrangian representation of ﬂuid, where continuous ﬂuids are discretized and approximated by a set of particles.
The most prominent advantage of the Lagrangian method is that the particle boundary is the material interface, which makes boundary conditions easy to impose, especially when the material interface is large and changing violently.
A well-known Lagrangian method is Smooth Particle Hydrodynamics (SPH)(Monaghan, 1988).
SPH and its variants are widely used in the numerical physic simulation, especially ﬂuid dynamics under various environments.
Particle-based ﬂuid simulation (Müller et al., 2003) introduces SPH model to simulate ﬂuids and generate realistic visual effects.
Moving particle semi-implicit method (MPS) (Koshizuka and Oka, 1996) markedly improves the accuracy and stability of incompressible ﬂuid simulation by introducing a pressure projection procedure that emulates Eulerian grid-based methods.
Weakly compressible SPH (WSPH)(Becker and Teschner, 2007) introduces equation of state to model the pressure during the simulation.
Predictive-corrective incompressible SPH (Solenthaler and Pajarola, 2009) and divergence-free SPH (Bender and Koschier, 2015) use iterative method to improve the accuracy of pressure calculation in incompressible ﬂow simulation.
Modeling ﬂuid dynamics in a data-driven way has been explored and studied by many researchers.
With advances in machine learning algorithms, many data-driven models employing machine learning algorithms have been built.
Ladický et al.
(2015) reformulate the Navier-Stokes equation as a regression problem and build a regressor using random forest, which signiﬁcantly improves the calculation efﬁciency.
Tompson et al.
(2016), Xiao et al.
(2020) learn the pressure projection under the Eulerian framework with a convolutional neural network, which accelerates the ﬂuid simulation.
Wiewel et al.
(2018) bring signiﬁcant speed-up by learning a reduced-order representation and predicting the pressure ﬁeld with an LSTM-based model.
Morton et al.
(2018) learn the dynamics of airﬂow around a cylinder based on Koopman theory.
de Avila Belbute-Peres et al.
(2020) predict ﬂuid ﬂow by combining grid-based method with graph convolutional neural networks.
Learning and reasoning particle dynamics under graph representation has the following beneﬁts and conveniences.
First, particle-based methods model physics phenomena as interactions between particles within a local area.
This imposes an inductive bias for learning under the Lagrangian framework: dynamics have a strong locality.
The locality of unstructured data under Lagrangian representation can be captured by aggregation operation on graphs, such as GCN and other variants (Kipf and
Welling, 2016; Hamilton et al., 2017).
Second, unlike Eulerian grid-based methods, Lagrangian particle-based methods do not have explicit and structured grid, which makes standard Convolutional
Neural Network (CNN) cannot be directly applied to particles without feature processing (Wang et al., 2018; Ummenhofer et al., 2020).
Third, many dynamics are based on pairwise relation between particles, like collision, which can be easily interpreted as edge attributes of a graph.
Given these factors, recently there have been a rich class of works that use graph neural networks (Scarselli et al., 2009) to learn and reason about underlying physics of interacting objects and particles.
(Battaglia et al., 2016;
Chang et al., 2016; Sanchez-Gonzalez et al., 2018; Li et al., 2018; Mrowca et al., 2018)
M ODEL 3. F LUID D YNAMICS
The governing equation for incompressible ﬂuids is the Navier-Stokes equation and the continuity equation as follows (Batchelor, 2000):
[Equation]
To describe the ﬂuid ﬁeld, there are two kinds of systems, Eulerian and Lagrangian ones.
In this work, we adopt a Lagrangian system.
A common method to solve the Navier-Stokes equation and discretize ﬂuids under the Lagrangian framework is Smooth Particle Hydrodynamics (SPH) method (Monaghan, 1988), where physical quantities at an arbitrary point in the space are approximated by the states of nearby particles.
In SPH, an arbitrary scalar (or vector) ﬁeld A ( r ) at location r can be represented by a convolution:
[Equation]
(3) where W is weighting function or smooth kernel as deﬁned in SPH, h is the smoothing length, which deﬁnes the range of particles to be considered and V ( r (cid:48) ) is the volume at r .
Numerically, the interpolation can be approximated by replacing the integration with a summation.
Based on this model, equation equation 1 and equation 2 can be discretized.
The discrete equation system is usually solved under a predictor-corrector scheme, prediction based on advection and correction based on physical properties (such as divergence-free constraint).
3. M ODEL
Fluids are time-dependent dynamical systems, where location of particles, r , is described by equation of form: d r /dt =
f ( r ) .
When building a data-driven model to learn and solve this system, we assume the system is Markovian, that is, the state of the system at time step n + 1 depends only on the state of the previous time step n .
The update mechanism in our model can be represented as:
[Equation]
Here { x n , v n } denotes the positional information and velocity of ﬂuid ﬁeld at time step n .
Datadriven model G θ , parameterized by θ , maps the state of time step n to time step n + 1 .
In order to build a robust and accurate data-driven model the structure of our model is physicinformed, which enables the model to give interpretable output without losing many physical properties of the system.
In general, our model mimics the predictor-corrector scheme and includes three parts, advection net, collision net, and pressure net.
They can be divided into two types of graph networks (GN) according to the network structure (Battaglia et al., 2018).
Speciﬁcally, advection net and pressure net are node-focused graph networks, while collision net is edge-focused networks.
As each of these networks has a speciﬁc task and different output, they are trained on different data separately.
Node-focused Graph Network Advection net is responsible for the prediction of advection effect and pressure net is responsible for pressure projection.
Considering a particle i , the node-focused graph network ﬁrst aggregates node features from neighbor particles { v j |∀ j ∈ N ( i ) } and output node embedding f i .
The embedding f i will then be passed to a processor g R . g R will predict the desirable physical quantities o
i (i.e. acceleration a in advection net and pressure p in pressure net).
The whole message passing procedure can be deﬁned as:
[Equation]
Edge-focused Graph Network To prevent particle penetration and increase model stability, we propose a graph network model that is responsible for predicting the effect of collision.
As the relative position and relative velocity will have different signs with different observation perspective (i.e. relative velocity v ij = − v ji ), thus the graph in collision net is directed.
In collision net, relative features, e ij (relative positions, relative velocities between particle i and j ), are passed to processor f R as edge features.
The processor will output the edge embedding r ij between each pair of nodes.
Lastly, edge embedding r ij is aggregated via aggregator f A , to gather the inﬂuence from all nearby particles and predict an overall effect o i on the center particle i .
The whole process is deﬁned as:
[Equation]
The advantage of using relative position and velocity instead of global ones as input features is that this explicitly imposes a spatial invariance to the network, given that collision between two particles is invariant to the global positions they are at.
I MPLEMENTATION
We adopt the numerical model in SPH to evaluate the physical quantities like particle density and differential operators like gradient.
To construct graph representation for particles, we establish edges between particles within the control radius.
4. U PDATE S CHEME
In general, given the state (position x n and velocity v n ) of the current time step n , we derive the state of next time step n + 1 by passing the state information through advection net, collision net, and pressure net sequentially.
The input features to advection net are positions and velocities of particles, [ x n , v n ] , along with g , which indicates the external body force per mass of ﬂuid, and viscosity parameter ν , which denotes the magnitude of ﬂuid viscosity.
The advection net predicts acceleration of particles:
[Equation]
and updates the state of ﬂuid particles to an intermediate state [ x ∗ , v ∗ ] .
[Equation]
Where a adv =
[ a adv 1 , ..., a adv N ] , x n = [ x n 1 , ..., v nN ] , v n =
[ v n 1 , ..., v nN ] for particles i ∈ { 1 , .., N } .
We will use the same notation throughout illustration.
The collision net takes relative positions and velocities between particles, [ x ∗ i − x ∗ j , v ∗ i − v ∗ j ] as input, and predicts correction to the velocity,
[Equation]
where [ x ∗ r , v ∗ r ] denotes the relative position and velocity in intermediate state.
The velocity is then updated with predicted correction:
[Equation]
The updated intermediate position and velocity are taken as input by the pressure net, along with particle number density ρ .
[Equation]
The state of ﬂuid ﬁeld is then updated to next time step n + 1 ,
[Equation]
[Equation]
Where ˆ p =
[ˆ p 1 , ..., ˆ p N ] , ρ = [ ρ 1 , ..., ρ N ] , ρ c is the density parameter of ﬂuid.
Predicting pressure of ﬂuid ﬁeld using particle density and velocity is based on the observation that advection will incur a temporary compression on ﬂuid body, which means ﬂuid density has changed.
Therefore the goal of pressure net is to impose a pressure projection to mitigate these deviations.
During the above calculation, the global positional information is only used to construct graph on ﬂuid particles and will not be passed into aggregator and processor as features.
The relative position and particle density are normalized before input.
4. N ETWORK A RCHITECTURES
For node-focused graph network, to derive a smooth response of the ﬁeld with respect to spatial location, the aggregation from layer
l − 1 to l is deﬁned as:
[Equation]
where the aggregator sums up the features f ( l − 1) j from neighbor vertices { v j | j ∈ N ( i ) } using smooth kernel as weight function, and here self-connection is added to every vertex.
Linear transformation
W and non-linear transformation σ are then applied to the aggregated features.
In practice we found that two layer of aggregations is enough for the model to produce reasonably accurate output (Adding more aggregation layers does not bring in signiﬁcant improvements).
As for the edge-focused network, the aggregation is simply deﬁned as:
[Equation]
where r ji is edge feature processed by processor, W is a linear transformation matrix.
The aggregation in the edge-focused network is at the last layer, so no non-linearity is included here.
The processors in both networks are implemented as shared MLP, where they are shared among nodes or edges depending on network types (e.g. in the node-focused network, the processor is an MLP shared among each node).
In a node-focused network, the processor has three hidden layers, with the input node embedding f of size 128.
In an edge-focused network, the processor has four hidden layers, with input edge attributes [ x r , v r ] of size 6.
E XPERIMENTS 5. T RAINING
Dataset We use the Moving Particle Semi-implicit method (MPS) (Koshizuka and Oka, 1996) with an improved pressure solver (Lee et al., 2011) to generate high-ﬁdelity simulation data of incompressible ﬂow.
MPS is a numerical method based on SPH which prioritizes accuracy over calculation speed.
It enforces the incompressibility of the ﬂuid ﬁeld by solving the pressure Poisson equation.
We created 20 scenes by randomly placing ﬂuid blocks, solid obstacles, initializing ﬂuid particles with random velocity (See A.2 for full detail of training dataset settings and training strategy).
Loss Function and Optimization We train three networks, advection net, collision net, and pressure net separately.
Each network is trained in a supervised way by optimizing the mean squared error between prediction ˆ y and ground truth y .
[Equation]
We normalize particle density before inputting into the pressure net, which accelerates and stabilizes training.
In the processor, we add LayerNorm (Ba et al., 2016) after activation to each layer (except [Table] for the output layer).
The parameters of the model are optimized with Adam (Kingma and Ba, 2014) optimizer.
We implement the model in PyTorch.
All the training and experiments are mainly carried out on NVIDIA GTX 1080Ti GPU.
5. E VALUATION
Baselines Besides the comparison against ground truth data, we also compare our model to two recent works that use data-driven approaches to simulate ﬂuids under the Lagrangian framework.
Ummenhofer et al.
(2020) use the continuous convolutional kernel to learn ﬂuid dynamics and they reported that their model has outperformed other works in this domain.
Sanchez-Gonzalez et al.
(2020) propose a graph network-based simulator (GNS) as a general-purpose physic simulator under
Lagrangian representation.
Our model and GNS both transform and pass messages of ﬂuid ﬁeld via graph structures, but GNS consists of a far larger and deeper network with multiple sub-blocks and thus contains much more parameters than ours.
For all baseline models, we adopt the same training strategy from original papers but train them on our dataset (See A.5 for full detail).
Metrics To conduct quantitative analysis, we evaluate model performance based on several metrics.
We report the asymmetric version of Chamfer Distance between the simulated results of different models and ground truth sequence.
The asymmetric Chamfer distance for two collections of particles
X, Y (from X to Y ) is deﬁned as:
[Equation]
where N is the total particle number of point cloud collection X , and distance function d ( x , y ) is evaluated using L2-norm (cid:107) x − y (cid:107) 2 .
We investigate two essential physical quantities for incompressible ﬂuid simulation - velocity divergence and particle density deviation of ﬂuid ﬁeld.
In addition, we use normalized mean absolute error (MAE) and relative tolerance to evaluate the error of advection net and pressure net on single frame inference respectively.
The normalized MAE from prediction ˆ y to ground truth y is deﬁned as:
[Equation]
The relative tolerance of the numerical solution ˆx to a linear system
A x = b can be deﬁned as:
[Equation]  R ESULTS
Performance In order to measure the performance of our FGN model as a physic simulator, we performed simulations on several different test cases.
In the ﬁrst two cases, dam collapse and water
Model
Dynamical system
Model Output
Evaluation metric
Error Advection Net [Equation] fall, we qualitatively measure the results of different models via visualization 1 of ﬂuids in Figure 4.
We report the physical property of simulation results and its Chamfer distance to ground truth data.
Quantitative results over the whole simulation sequence are listed in Table 1 (See Figurein A.3 for error trend ﬁgures).
The results show that our model FGN gives the best accuracy in retaining physical properties and position prediction.
In addition, we study the performance of each sub-network in our model as stand-alone solvers for sub-dynamical systems and report their relative error in Table 2.
For the advection net, we challenge it by applying a different set of material parameters (i.e. different gravity and viscosity parameters).
We report the normalized mean absolute error (MAE) between prediction and ground truth.
For pressure net, we evaluate the relative tolerance of its predicted solution ˆp to the discretized pressure poisson equation (i.e. A p = b ).
The relative low error demonstrates the capability of our sub-networks in learning and predicting physics.
[Table] Generalization To test out the model’s capability of generalization.
We apply our model to test cases with conditions that are beyond training distributions.
In the ﬁrst case, we study how our model will predict the pressure distribution of circular ﬂow around a cylinder.
This scene contains an inﬂow on the left side which keeps emitting particles during the simulation and an outﬂow on the right side.
We challenge our model’s robustness by applying different time step sizes to it.
Figure 4 shows qualitative comparison of model output under different time step sizes. In addition, we simulate on two scenes which contain much more complex geometries. Visualizations of two test scenarios containing complex geometries are shown in Figure 5. Although our model is trained with only a fairly small dataset, it remains accurate under several different conditions.
This demonstrates it capability of generalization and robustness. (More details on quantitative analysis are in A.3. Figure 10 shows position error trend under different time step sizes.
Figure 11 shows position error trend under complex scenes.) Ablation Study We test the performance of different types of aggregators used in pressure net, as pressure net has the largest impact on overall prediction accuracy. 2 We compare our aggregator against graph convolution networks (GCN) from Kipf and Welling (2016), Hamilton et al. (2017)’s graph SAGE using mean aggregator , and MLP w/o any graph aggregation operation.
In general, all aggregators give a similar performance on overall position prediction (similar Chamfer distance error), yet our model signiﬁcantly improves the quality of predictions in terms of maintaining a constant density (See Table 4 in A.4 for full detail).
In addition, we report the model size (parameter number) and runtime benchmark in Table 3.
Our model is very efﬁcient in terms of training and inference, as it has far less trainable parameters than others.
C ONCLUSION
In this paper, we present a data-driven Lagrangian ﬂuid model for incompressible ﬂuid simulation by decomposing simulation scheme as separate reasoning tasks based on Navier-Stokes equation.
It can preserve many essential physical properties of the ﬂuid ﬁeld such as low volume compression, and predict reasonable pressure distribution.
Our model also has generalization capability, where it can remain stable when extrapolating to a wide range of different geometries and adopting different time step sizes.
In general, our work is an advance in learning on unstructured data with graph neural networks, and enriches the paradigm of combining learning-based methods with physical models as well.
A PPENDIX A A. I MPLEMENTATION D ETAILS
Graph construction We build the graph by establishing edges between particles within limit radius.
We perform the neighborhood searching on GPU by using cell sort algorithm.
All the edge attributes are stored in sparse matrices.
Although the limit radius does not have signiﬁcant impact on training loss and larger limit radius will increase the computing cost drastically, we found that small limit radius can inﬂuence the long-term stability of the model.
For advection net and pressure projection net, we select the limit radius to be three times the particle diameter D (D = 0.050m), and 0.9D for collision net.
Numerical model
In general, we calculate all the gradient operators and smooth kernel based on numerical model of SPH.
In SPH model, particle density is deﬁned as:
[Equation]
For scalar quantity φ i at location r
i , we approximate its gradient by:
[Equation]
23) where n ∗ is the constant particle number density derived by calculating the maximum particle number density at the initial frame , d is the dimension of the problem, W ij denotes the smooth kernel function value between particle i and j .
Similarly velocity divergence is deﬁned as:
[Equation]
We adopt the same smooth kernel function from Koshizuka and Oka (1996), which is very simple to evaluate.
[Equation]
A. T RAINING
Dataset Generation We place one or two of the following basic obstacles (as shown in Figure 6) in training scenes.
In addition to obstacles, each scene is a cubic box (80x80x40) containing a ﬂuid block (25x25x10) (as shown in Figure 7).
We place the ﬂuid block at random place in the box and initialize its velocity of one direction by uniformly sampling from U (0 , 0 . 1) .
We generatedscenes adopting above settings and simulate each training scene to 1000 time steps with step size dt = 0 . 002 . Strategy In each time step of the ground truth simulator, there are mainly three steps. First, advect ﬂuids with body force and viscosity: [Equation]
[Equation] 27) and then solve the pressure poisson equation, [Equation] 28) lastly,
[Equation]
[Equation]
Here, we use [ x ∗ , v ∗ , g , ν ] as the training features and a ∗ (i.e. ( v ∗ − v n ) / ∆ t ) as the training label for advection net.
[ x ∗ , v ∗ ] and particle density ρ (evaluated based on x ∗ ) are the training features for pressure net, with pressure p as label. To train collision net, we simulate another particle system that is updated only based on elastic collision rule and applies no other dynamics. We use relative velocity and position before collision as inputs, and use velocity difference (i.e. ∆ v ) as output target. We train each network for 100,000 iterations of gradient updates and decay learning rate from 0 .to 0 .
For the training of three sub-networks (advection net, collision net, pressure net), the batch size of each network is 16, 4 and 32 respectively.
To allow the mini-batching of different graph, we mini-batch the adjacency matrix of different scenes by creating a large sparse matrix and stacking adjacency matrix on the diagonals.
[Figure]
A. M ETRICS E VALUATION D ETAILS
We show the error trend of dam collapse and water fall scene under different evaluation metrics in Figure 9. The position loss analysis of different time step sizes is shown in Figure 10. Position error of complex scenarios is shown in Figure 11.
A. A BLATION S TUDY D ETAILS
Performance of different graph message aggregate structures is listed in Table 4.
A. B ASELINES I MPLEMENTATION
Continuous Convolution We use the open-source implementation from Ummenhofer et al.
To give a fair benchmark result we train their network with our dataset.
Note our training dataset is much smaller than theirs and does not include complex geometries.
As in our work, we model [Table] solid obstacles and wall as virtual particles, so we transform these virtual particles into surface and corresponding normals before inputting them into CConv network.
The original CConv uses a time step size of 0.02s, but given such a large time step size, the qualitative results can be distinct from ground truth and other model with smaller time step size.
Hence during training and comparison we adopt a time step size of 0.002s for CConv model.
Graph Network-based Simulator We implemented GNS following the description in SanchezGonzalez et al.
We build GNS with 10 unshared GN blocks, conditioned on 5 previous velocities and input relative positions as edge features.
We chose the connectivity radius to be 2.1D, so that the number of neighbors is around 20.
Sanchez-Gonzalez et al.
(2020) use ﬁnite difference to calculate acceleration and velocity, but in our implementation we explicitly maintain an array to store the velocities of all particles.
Additionally, we do not use learned embedding but simple zero and one to indicate particle material type, as in our testing domain there are only two kinds of particles - solid and ﬂuid.
The loss function and training procedure are implemented as described in
Sanchez-Gonzalez et al.
(2020), including noise injection and similar normalization techniques.
For the implementation of GN block, as Sanchez-Gonzalez et al.
(2020) states "We use GNs without global features or global updates (similar to an interaction network)", so we implement the GN block update mechanism following the description in Battaglia et al.
[Equation]
[Equation]
33) where φ is the update function and implemented as MLP here, ρ is aggregation function which aggregates all the edge attributes to its center vertex, u is the global feature and here we append them to the nodal features as input feature, r k receiver and k denotes sender
In the testing stage, as authors did not state how to set initial velocities, so we just warm start the simulation by calculating the ﬁrst 5 frames using MPS method and apply GNS to the rest frames.