L EARNING I NCOMPRESSIBLE F LUID D YNAMICS FROM S CRATCH - T OWARDS F AST , D IFFERENTIABLE F LUID M ODELS THAT G ENERALIZE
A BSTRACT
Fast and stable ﬂuid simulations are an essential prerequisite for applications ranging from computer-generated imagery to computer-aided design in research and development.
However, solving the partial differential equations of incompressible ﬂuids is a challenging task and traditional numerical approximation schemes come at high computational costs.
Recent deep learning based approaches promise vast speed-ups but do not generalize to new ﬂuid domains, require ﬂuid simulation data for training, or rely on complex pipelines that outsource major parts of the ﬂuid simulation to traditional methods.
In this work, we propose a novel physics-constrained training approach that generalizes to new ﬂuid domains, requires no ﬂuid simulation data, and allows convolutional neural networks to map a ﬂuid state from time-point t to a subsequent state at time t + dt in a single forward pass.
This simpliﬁes the pipeline to train and evaluate neural ﬂuid models.
After training, the framework yields models that are capable of fast ﬂuid simulations and can handle various ﬂuid phenomena including the Magnus effect and Kármán vortex streets.
We present an interactive real-time demo to show the speed and generalization capabilities of our trained models.
Moreover, the trained neural networks are efﬁcient differentiable ﬂuid solvers as they offer a differentiable update step to advance the ﬂuid simulation in time.
We exploit this fact in a proof-of-concept optimal control experiment.
Our models signiﬁcantly outperform a recent differentiable ﬂuid solver in terms of computational speed and accuracy.
I NTRODUCTION
Simulating the behavior of ﬂuids by solving the incompressible Navier-Stokes equations is of great importance for a wide range of applications and accurate as well as fast ﬂuid simulations are a long-standing research goal.
On top of simulating the behavior of ﬂuids, several applications such as sensitivity analysis of ﬂuids or gradient-based control algorithms rely on differentiable ﬂuid simulators that allow to propagate gradients throughout the simulation (Holl et al.
Recent advances in deep learning aim for fast and accurate ﬂuid simulations but rely on vast datasets and / or do not generalize to new ﬂuid domains.
Kim et al.
(2019) present a framework to learn parameterized ﬂuid simulations and allow to interpolate efﬁciently in between such simulations.
However, their work does not generalize to new domain geometries that lay outside the training data.
Kim & Lee (2020) train a RNN-GAN that produces turbulent ﬂow ﬁelds within a pipe domain, but do not show generalization results beyond pipe domains.
Xie et al.
(2018) introduce a tempoGAN to perform temporally consistent superresolution of smoke simulations.
This allows to produce plausible high-resolution smoke-density ﬁelds for arbitrary low-resolution inputs, but our ﬂuid model should output a complete ﬂuid state description consisting of a velocity and a pressure ﬁeld.
Tompson et al.
(2017) present how a Helmholtz projection step can be learned to accelerate
Eulerian ﬂuid simulations.
This method generalizes to new domain geometries, but a particle tracer is needed to deal with the advection term of the Navier-Stokes equations.
Furthermore, as Eulerian ﬂuids do not model viscosity, effects like e.g. the Magnus effect or Kármán vortex streets cannot be simulated.
Geneva & Zabaras (2020) propose a physics-informed framework to learn the entire update step for the Burgers equations in 1D and 2D, but no generalization results for new domain geometries are demonstrated.
All of the aforementioned methods rely on the availability of vast amounts of data from ﬂuid-solvers such as FEniCS, OpenFOAM or Mantaﬂow.
Most of these methods do not generalize well or outsource a major part of the ﬂuid simulation to traditional methods such as low-resolution ﬂuid solvers or a particle tracer.
In this work, we propose a novel unsupervised training framework to learn incompressible ﬂuid dynamics from scratch.
It does not require any simulated ﬂuid-data (neither as ground truth data, nor to train an adversarial network, nor to initialize frames for a physics-constrained loss) and generalizes to ﬂuid domains unseen during training.
It allows CNNs to learn the entire update-step of mapping a ﬂuid domain from time-point t to t + dt without having to rely on low resolution ﬂuid-solvers or a particle-tracer.
In fact, we will demonstrate that a physicsconstrained loss function combined with a simple strategy to recycle ﬂuid-data generated by the neural network at training time sufﬁces to teach CNNs ﬂuid dynamics on increasingly realistic statistics of ﬂuid states.
This drastically simpliﬁes the training pipeline.
get efﬁciently unrolled in time by recurrently applying the trained model on a ﬂuid state.
Furthermore, the ﬂuid models include viscous friction and handle effects such as the Magnus effect and Kármán vortex streets.
On top of that, we show by a gradient-based optimal control example how backpropagation through time can be used to differentiate the ﬂuid simulation
Code and pretrained models are publicly available at https://github.com/aschethor/
Unsupervised_Deep_Learning_of_Incompressible_Fluid_Dynamics/ .
R ELATED W ORK
In literature, several different approaches can be found that aim to approximate the dynamics of
PDEs in general and ﬂuids in particular with efﬁcient, learning-based surrogate models.
Lagrangian methods such as smoothed particle hydrodynamcs (SPH) Gingold & Monaghan (1977) handle ﬂuids from the perspective of many individual particles that move with the velocity ﬁeld.
Following this approach, learning-based methods using regression forests by Ladický et al.
, graph neural networks by Mrowca et al.
; Li et al.
and continuous convolutions by
Ummenhofer et al.
(2020) have been developed.
In addition, Smooth Particle Networks (SP-Nets) by Schenck & Fox (2018) allow for differentiable ﬂuid simulations within the Lagrangian frame of reference.
These Lagrangian methods are particularly suitable when a ﬂuid domain exhibits large, dynamic surfaces (e.g. waves or droplets).
However, to simulate the dynamics within a ﬂuid domain accurately, Eulerian methods , that treat the Navier-Stokes equations in a ﬁxed frame of reference, are usually better suited.
Continuous Eulerian methods allow for mesh-free solutions by mapping domain coordinates (e.g. x , y , t ) directly onto ﬁeld values (e.g. velocity (cid:126)v / pressure p ) (Sirignano & Spiliopoulos (2018);
Grohs et al.
Khoo et al.
Recent applications focused on ﬂow through porous media (Zhu & Zabaras (2018); Zhu et al.
; Tripathy & Bilionis (2018)),
ﬂuid modeling (Yang et al.
Raissi et al.
(2018)), turbulence modeling (Geneva & Zabaras (2019); Ling et al.
and modeling of molecular dynamics (Schöberl et al.
Training is usually based on physics-constrained loss functions that penalize residuals of the underlying PDEs.
Similar to our approach, Raissi et al.
(2019) uses vector potentials to obtain continuous divergence-free velocity ﬁelds to approximate the incompressible Navier-Stokes equations.
Continuous methods return smooth, accurate results and can overcome the curse of dimensionality of discrete techniques in high-dimensional PDEs (Grohs et al.
However, these networks are trained on a speciﬁc domain and cannot generalize to new environments or be used in interactive scenarios.
Discrete Eulerian methods , on the other hand, aim to solve the underlying PDEs on a grid and early work dates back to Harlow & Welch (1965) and Stam (1999).
Accelerating such traditional works with deep learning techniques is a major ﬁeld of research and all of the methods mentioned in the introduction fall into this category.
Further methods include the approach by Thuerey et al.
(2019) to learn solutions of the Reynolds-averaged Navier-Stokes equations for airfoil ﬂows, but requires large amounts of training data and does not generalize beyond airfoil ﬂows.
In the work by Um et al.
(2020), a correction step is learned that brings solutions of a low-resolution differentiable ﬂuid solver closer to solutions of a high-resolution ﬂuid simulation.
However, generalization results for new domain geometries were not presented.
The works of Mohan et al.
(2020) and Kim et al.
(2019) show that vector potentials are suitable to enforce the incompressibility constraint in ﬂuids but do not generalize to new ﬂuid domains beyond their training data.
M ETHOD
In this section, we brieﬂy review the incompressible Navier-Stokes equations, which are to be solved by the neural network.
Then, we explain how the Helmholtz decomposition can be exploited to ensure incompressibility within the ﬂuid domain.
Furthermore, we provide details of our discrete spatio-temporal ﬂuid representation and introduce the ﬂuid model.
Afterwards, we formulate a physics-constrained loss function based on residuals of the Navier-Stokes equations and introduce a pressure regularization term for very high Reynolds numbers.
Finally, we explain the unsupervised training strategy.
3. I NCOMPRESSIBLE N AVIER -S TOKES E QUATIONS
Most ﬂuids can be modeled with the incompressible Navier-Stokes equations - a set of non-linear equations that describe the interplay of a velocity ﬁeld (cid:126)v and a pressure ﬁeld p within a ﬂuid domain Ω :
[Equation]
incompressibility on Ω (1)
[Equation]
conservation of momentum on Ω (2)
Here, ρ describes the ﬂuid density and µ the viscosity.
Equation 1 states that the ﬂuid is incompressible and thus (cid:126)v is divergence-free.
Equation 2 states that the change in momentum of ﬂuid particles must correspond to the sum of forces that arise from the pressure gradient, viscous friction and external forces.
Here, external forces on the ﬂuid (such as e.g. gravity) can be neglected, so we set (cid:126)f = 0 .
These incompressible Navier-Stokes equations shall be solved by a CNN given initial conditions
[Equation]
0 and p 0 at the beginning of the simulation and Dirichlet boundary conditions which constrain the velocity ﬁeld at the domain boundary ∂ Ω :
[Equation]
3. H ELMHOLTZ D ECOMPOSITION
A common method to ensure incompressibility of a ﬂuid (see Equation 1) is to project the ﬂow ﬁeld onto the divergence-free part of its Helmholtz decomposition.
The Helmholtz theorem states that every vector ﬁeld (cid:126)v can be decomposed into a curl-free part ( ∇ q ) and a divergence-free part ( ∇× (cid:126)a ): (cid:126)v = ∇ q + ∇ × (cid:126)a (4)
Note, that ∇ × ( ∇ q ) =
(cid:126) 0 and ∇ · ( ∇ × (cid:126)a ) = 0 .
The Helmholtz projection consists of solving the Poisson problem ∇ · (cid:126)v = ∆ q for q , followed by substracting ∇ q from the original ﬂow ﬁeld.
However, solving the Poisson equation on arbitrary domains comes at high computational costs for classical methods and one has to rely e.g. on conjugate gradient methods to approximate its solution.
Here, we propose a different approach and directly try to learn a vector potential (cid:126)a with (cid:126)v = ∇ × (cid:126)a .
This ensures that the network outputs a divergence-free velocity ﬁeld within the domain Ω and automatically solves Equation 1.
In this work, we consider 2D ﬂuid simulations, so only the zcomponent of (cid:126)a , a z , is of interest since v z and all derivatives with respect to the z -axis are zero:
[Equation]
3. D ISCRETE S PATIO - TEMPORAL F LUID R EPRESENTATION
Marker-And-Cell (MAC) grid To solve the Navier-Stokes equations, we represent the relation between a z , v x , v y , p on a 2D staggered marker-and-cell (MAC) grid (see Figure 1a).
Therefore, we discretise time and space as follows:
[Equation]
Obtaining gradient, divergence, Laplace and curl operations on this grid with ﬁnite differences is straight forward and can be efﬁciently implemented with convolutions (see appendix A).
[Figure]
[Figure]
Explicit, Implicit, Implicit-Explicit (IMEX) time integration methods The discretization of the time domain is needed to deal with the time-derivative of the velocity ﬁeld ∂(cid:126)v ∂t in Equation 2, which becomes:
[Equation]
The goal is to take as large as possible timesteps dt while maintaining stable and accurate solutions.
Stability and accuracy largely depend on the deﬁnition of v t (cid:48) .
In literature, choosing v t (cid:48)
= v t is often referred to as explicit integration methods and frequently leads to unstable behavior.
Choosing v t (cid:48)
= v t
+ dt is usually associated with implicit integration methods and gives stable solutions at the cost of numerical dissipation.
Implicit-Explicit (IMEX) methods, which set v t (cid:48)
= ( v t + v t + dt ) /are
a compromise between both methods and considered to be more accurate but less stable than implicit methods.
3. F LUID M ODEL
We represent the ﬂuid dynamics by a recurrent model that maps the ﬂuid state p t ,(cid:126)a t for timestep t and the domain description Ω t + dt ,(cid:126)v t + dt d to the ﬂuid state p t + dt ,(cid:126)a t + dt of the next timestep.
Here, p t describes the pressure ﬁeld and (cid:126)a t describes the vector potential of (cid:126)v t .
For t = 0 , we consider initial states p
=
and (cid:126)a 0 = (cid:126) 0 , however, other initial conditions could be considered as well.
Ω t
+ dt is a binary mask that contains the domain geometry and is 1 for the ﬂuid domain andeverywhere else.
For the boundary of the domain, we simply take the inverse of Ω : ∂ Ω = 1 − Ω .
(cid:126)v t + dt d represents the Dirichlet boundary conditions and contains a velocity ﬁeld that must be matched by (cid:126)v t
+ dt at the domain boundaries.
Figure 1b shows a diagram of the ﬂuid model.
First, (cid:0) p t ,(cid:126)a t , Ω t + dt ,(cid:126)v t + dt d (cid:1) are taken to derive a slightly more meaningful feature representation that comprises (cid:0) p t , a t , ∇ × a t , Ω t + dt , ∂ Ω t + dt , Ω t + dt · ∇ × a t , Ω t + dt · p t , ∂ Ω t + dt · (cid:126)v t + dt d (cid:1) .
These features can be very efﬁciently computed with convolutions and are then fed into a U-Net
(Ronneberger et al. (2015)) with a reduced number of channels (the exact network conﬁguration can be found in appendix B).
The mean of the U-Net output is set to 0 in order to keep p and (cid:126)a well deﬁned and prevent drifting offset values.
Finally, the output is added to p t and (cid:126)a t to obtain the updated ﬂuid state p t + dt
and (cid:126)a t + dt .
3. P HYSICS - CONSTRAINED L OSS FUNCTION
Using the residuals of the Navier-Stokes equations (Equations 1 and 2), we can formulate the following loss terms on Ω and ∂ Ω : [Equation] divergence
[Equation]
momentum loss on Ω
[Equation]
boundary loss on ∂ Ω
[Equation]
[Equation]
Combining the described loss terms, we obtain the following loss function:
[Equation]
[Equation]
where α, β, γ are hyperparameters that weight the contributions of the different loss terms.
Note that if we use a vector potential (cid:126)v = ∇ × (cid:126)a , L d = 0 is automatically fulﬁlled and we can set α = 0 .
This loss function can be computed very efﬁciently with convolutions in O ( N ) (where N = number of grid cells), whereas solving the Navier-Stokes equations explicitly would be computationally a lot more expensive.
For detailed descriptions regarding the fully discretized loss-function, we refer to appendix A.
3. P RESSURE R EGULARIZATION
For very high Reynolds numbers (see Equation 13) and inviscid ﬂows, training becomes unstable as viscous friction cannot dissipate enough energy out of the system.
This leads to unrealistic gradients in (cid:126)v and p .
For such cases, we introduce an additional regularization term for the loss function (11) that can be traded off with L p to stabilize training:
[Equation]
The intuition behind this regularization term is, that we want to penalize unrealistically high energies in the pressure ﬁeld.
3. T RAINING S TRATEGY
Training starts with initializing a pool { Ω 0 k , ( v d ) 0 k , ( a z )
k , p 0 k } of randomized domains Ω 0 k and boundary conditions ( v d )
k as well as initial conditions for the vector potential and pressure ﬁelds that we both set to zero ( ( a z )
k = 0 and p 0 k = 0 ).
The resolution of our training domains is 100x grid cells and example-domains of the training pool are shown in appendix C. Note that our training pool does not rely on any previously simulated ﬂuid-data.
At each training step, a random mini-batch { Ω tk , ( v d ) tk , ( a z ) tk , p tk } { k ∈ minibatch } is drawn from the pool and fed into the neural network which is designed to predict the velocity ( (cid:126)v t + dt k = ∇ ×
(cid:126)a t + dt k ) and pressure ( p t + dt k ) ﬁelds of the next time step.
Based on a physics-constrained loss-function (Equation 11), we update the weights of the network using the Adam optimizer (Kingma & Ba (2015)).
At the end of each training step, the pool is updated by replacing the old vector potential and pressure ﬁelds ( a z ) tk , p tk by the newly predicted ones ( a z ) t + dt k , p t + dt k .
This recycling strategy ﬁlls the training pool with more and more realistic ﬂuid states as the model becomes better at simulating ﬂuid dynamics.
From time to time, old environments of the training pool are replaced by new randomized environments and the vector potential as well as the pressure ﬁelds are reset to 0.
This increases the variance of the training pool and helps the neural network to learn "cold starts" from (cid:126) 0 -velocity and 0 -pressure ﬁelds.
Besides the ﬂuid model described above, which we denote as (cid:126)a -Net in the following, we also trained an ablation model, (cid:126)v -Net, that directly learns to predict the velocity ﬁeld without a vector potential.
For the implementation of both models, we used the popular machine learning framework Pytorch and trained the models on a NVidia GeForce RTX 2080 Ti.
Training converged after about 1 day.
The hyperparameters in the loss-function for the (cid:126)a -Net were β = 1 and γ = 20 .
The reason for choosing a higher weight for the loss term L b than for L p was the observation, that errors in
L b can lead to unrealistic ﬂows leaking through boundaries.
For the ablation study ( (cid:126)v -Net), we used α = 100 , β = 1 , γ = 0 .
Here, we had to choose a very high weight for L d to ensure incompressibility of the ﬂuid, otherwise unrealistic source and sink effects start to appear.
For L b , on the other hand, we used a very low weight as the boundary conditions can be trivially learned by the (cid:126)v -Net.
We used these parameter settings for all experiments.
R ESULTS
To evaluate the potential of our method, we assess its ability to reproduce physical effects such as Kármán vortex streets and the Magnus effect.
In addition, we demonstrate its generalization capability and real-time performance.
Finally, we test the ﬂuid models quantitatively.
4. Q UALITATIVE E VALUATION
Qualitative analysis of wake dynamics Qualitative effects in ﬂuid dynamics such as the wake dynamics behind an obstacle are closely related to the Reynolds number.
It is a dimensionless quantity deﬁned by:
[Equation]
Here, ρ is the ﬂuid density, (cid:107) (cid:126)v (cid:107) is the ﬂuid speed, D is the diameter of the obstacle, and µ is the viscosity.
(We use the units of the grid).
We retrained models for different values of µ and ρ to compare the ﬂuid behavior for a wide range of Reynolds numbers.
Figure 2 shows, that the trained models are able to predict the wake dynamics behind an obstacle in good accordance with qualitative expectations from ﬂuid dynamics.
As a rule of thumb, for Re (cid:28) 1 , the ﬂow becomes time-reversible.
This can be noticed in Figure 2a by the symmetry of the ﬂow before and after the obstacle and the nearly constant pressure gradient within the pipe.
Starting from Re ≈ 10 , the ﬂow is still laminar but a static wake is forming behind the obstacle (see Figure 2b).
For Reynolds numbers Re > ≈ 90 , Kármán vortex streets start to appear (see Figure 2c).
A Kármán vortex street consists of clock and counterclockwise spinning vortices that are generated at the obstacle and then start moving in a regularly oscillating pattern with the ﬂow.
For very large Reynolds numbers or inviscid ﬂows, the ﬂow ﬁeld becomes turbulent, which can be recognized by the irregular patterns behind the obstacle in Fig 2d.
[Figure]
Magnus effect The Magnus effect appears when a ﬂow interacts with a rotating body.
It is widely known e.g. in sports such as soccer or tennis where spin is used to deﬂect the path of a ball.
The reason for the deﬂection stems from a low pressure ﬁeld where the surface of the object moves along ﬂow direction and a high pressure ﬁeld where the object surface moves against the ﬂow.
Figure 3a shows, that our models are able to reproduce the Magnus effect around a rotating cylinder. [Figure] [Figure]
Analysis of generalization capability We tested the networks capability to generalize to objects not seen during training.
Figure 3b shows the networks capability to meet boundary conditions of an airfoil and return a plausible pressure ﬁeld that produces lift (see low pressure on top of wing).
Note that in contrast to the approach by Thuerey et al.
(2019), which learns simpliﬁed, time-averaged solutions of the Navier-Stokes equations, our method is able to simulate the full incompressible
Navier-Stokes equations for an airfoil without relying on any ground truth data or having seen airfoilgeometries during training.
In fact, the network was only trained on simple randomized domains as highlighted in appendix C and Figure 7.
Possible reasons for the networks generalization capabilities are:
• During training, the network gets confronted with an inﬁnite number of different ﬂowﬁelds and randomized domain conﬁgurations because the training pool gets updated at every training step.
This prevents the network from over-ﬁtting.
• The dynamics of a ﬂuid-particle are mostly determined by its local neighborhood / surrounding particles.
This means, the update step for a certain cell on the MAC grid is mostly determined by close / neighboring MAC-grid cells.
Since more complicated shapes can be seen locally as a composition of basic shapes (e.g. the front of the wing can be locally regarded as a cylinder), it sufﬁces to train on basic shapes that provide the network with enough examples to generalize to more complicated shapes.
Further generalization examples are provided in appendix D.
Real-time capability The ﬂuid simulation can be easily parallelized and takes low computational costs as one time-integration step consists just of a single forward pass through a convolutional neural network.
This enables for example interactive real-time simulations.
We implemented a demo that allows to interact with a ﬂuid by moving obstacles, rotating spheres and changing the ﬂow speed within a pipe (see video in supplementary material and source code).
Our method runs at 250 timesteps per second on a 100x300 grid.
In the respective experiments, we used a NVidia
GeForce RTX
Ti consuming about 860 MB of GPU memory.
4. Q UANTITATIVE E VALUATION
We compare our method ( (cid:126)a -Net) quantitatively with PhiFlow by Holl et al.
Phiﬂow is a recent, open source, differentiable ﬂuid simulator based on a MAC grid data structure.
Furthermore, we provide an ablation study ( (cid:126)v -Net) that does not make use of the Helmholtz decomposition but directly works on the velocity ﬁeld (cid:126)v .
Quantitative comparison of different ﬂuid solvers is challenging, as their performance is highly dependent on factors like the geometry of the domain, ﬂuid parameters such as viscosity or density, ﬂow speed or the timestep of the integrator.
As benchmarks for ﬂuid simulations on MAC grids are not yet available, we built a simple toy domain on a 100 x 100 grid which simulates a ﬂow around an obstacle within a pipe (more details are provided in appendix E).
First, we compared the computational speed on a CPU and GPU by comparing the integration time-steps per second (see Table 1).
The (cid:126)v -Net as well as the (cid:126)a -Net are signiﬁcantly faster than
PhiFlow (11x on CPU and 40x on GPU) as they do not rely on an iterative conjugate gradient solver but instead use a single forward pass through a convolutional neural network that can be easily parallelized on a GPU.
To provide a fair comparison on L d , we set the velocity ﬁeld at the boundaries equal to (cid:126)v d .
This enables us to compute L d for the (cid:126)a -Net architecture on the domain boundaries which would otherwise have zero divergence everywhere.
This way, L d can be interpreted as a metric on how well the orthogonal components of the Dirichlet boundary conditions are met (i.e. no ﬂow leaks through the boundaries).
For dt = 4 , we outperformed Phiﬂow by several orders of magnitude.
For both, L d and L p , the (cid:126)a -Net architecture signiﬁcantly outperformed the more naive (cid:126)v -Net approach.
Furthermore, we investigated stability by evaluating the evolution of L p and L d for the (cid:126)a -Net over time (see Figure 4).
As the ﬂuid state is initialized with a z = 0 and p = 0 , the (cid:126)a -Net has to perform a cold-start which is the reason for high L p and L d during the ﬁrst circa 70 steps.
Afterwards, the (cid:126)a -Net continues an accurate and stable ﬂuid simulation.
[Table]
4. O PTIMAL C ONTROL OF V ORTEX S HEDDING F REQUENCY
In this section, we present a proof-of-concept experiment that aims at controlling the shedding frequency of a Kármán vortex street behind an obstacle by changing the ﬂow speed (see Figure 5a).
To this end, we exploit our previously trained differentiable ﬂuid models.
[Figure]
First, we measure the y-component of the velocity ﬁeld v y ( t ) behind an obstacle (see white box in Figure 5a) over 200 time steps.
Then, we compute the frequency spectrum V y ( f ) of v y ( t ) using the fast Fourier transform (see Figure 5b).
Now, we want to adjust the inﬂow / outﬂow boundary conditions in (cid:126)v d such that E [ | V y ( f ) | 2 ]
= ˆ f .
Here, ˆ f is the target frequency.
To optimize (cid:126)v d , we deﬁne a loss function L =
( E [ | V y ( f ) | 2 ] − ˆ f ) 2 and compute the gradients ∂L∂(cid:126)v d with backpropagation through time.
This is possible since all parts of the loss function including the ﬂuid simulation that is performed by our trained neural ﬂuid model as well as the fast Fourier transform are differentiable.
Computing the gradients with a standard automatic differentiation library (Pytorch) took 3.5 seconds for all 200 time steps on our 200x100 domain setup. This is considerably faster than the current state-of-the-art differentiable ﬂuid solver by Takahashi et al. (2021) which takes 5.42 seconds for only 30 time steps on a smaller 128x128 grid.
The update steps of (cid:126)v d are done using the ADAMoptimizer and converge after approximately 70 iterations (see Figure 5c).
We want to emphasize that differentiable ﬂuid simulations are limited to scenarios with low Reynolds numbers as in the presence of turbulences, chaotic behavior will lead to exploding gradients.
D ISCUSSION AND O UTLOOK
In this work, we present an unsupervised learning scheme for the incompressible Navier-Stokes equations and introduce a ﬂuid model that uses a vector potential to output divergence-free velocity ﬁelds.
Qualitative results of our trained ﬂuid models are in good accordance with expectations from ﬂuid dynamics for a wide range of Reynolds numbers and generalize to unknown ﬂuid domains.
Quantitative assessment showed superior performance in terms of accuracy and speed compared to
Phiﬂow and an ablation study that directly predicts the velocity ﬁeld.
We present a real-time demo and demonstrate how differentiability can be used in a proof-of-concept ﬂuid control scenario.
We believe that our ﬂuid models can signiﬁcantly speed up more sophisticated ﬂuid control pipelines such as described by Holl et al.
First experiments of extending this approach to 3D deliver encouraging results and are topic of future research.
Furthermore, on top of Dirichlet boundary conditions, Neumann boundary conditions and multi-phase domains could be incorporated in future ﬂuid models as well.
A P HYSICS -C ONSTRAINED L OSS ON A MAC G RID
As mentioned in Section 3.3 of the paper, our method relies on a staggered marker-and-cell grid representation for the vector potential as well as the velocity and pressure ﬁelds.
In the following, we provide further details on how to apply this representation to learn incompressible ﬂuid dynamics.
To calculate the velocity ﬁeld (cid:126)v = ∇ × (cid:126)a of a vector potential (cid:126)a on a MAC grid in 2D, we have to compute the curl as follows:
[Equation]
If this vector potential is inserted into the divergence operator on a MAC grid, we can show that ∇ · (cid:126)v i,j = 0 is indeed fulﬁlled:
[Equation]
Thus, for the (cid:126)a -Net, the incompressibility equation is automatically fulﬁlled and no further training on the divergence loss L d is required.
However, for the (cid:126)v -Net, the residuals of the divergence are still of importance:
[Equation]
The residuals of the momentum equation in x -direction can be computed as follows:
[Equation]
Here
[Equation]
we use the following isotropic Laplace operator:
[Equation]
The derivation of the advection term for R p x is a bit more complex since on a MAC grid, v x and v y are displaced by half a pixel in x -direction and y -direction.
To obtain the residuals of the momentum equation in y -direction, ( R p y )
i,j , one has to take ( R p x ) i,j and swap x
and y and the indices respectively.
Now, the discretized loss terms can be written as follows:
[Equation]
Note, that all mentioned operations can be efﬁciently implemented with convolutions.
To obtain the ﬁnal velocities on a square grid, we project the velocity ﬁelds of the MAC grid back onto the (cid:126)a -grid using linear interpolation:
[Equation]
B N ETWORK ARCHITECTURE
Our ﬂuid model is based on the U-Net architecture (Ronneberger et al.
with fewer channels (see Figure 6).
As the pressure ﬁeld and vector potential can have an arbitrary offset, we always normalize the mean of the pressure ( ∆ p ) and vector potential ( ∆ a z ) to 0 to keep these ﬁelds welldeﬁned and prevent drifting offset values.
C E XAMPLES OF T RAINING D OMAINS
The domains we used for training consist of 100 × 300 grids.
We used 3 different randomized domains as exemplary depicted in Figure 7.
First, we have boxes with randomized height and width that ﬂoat on randomized paths inspired by Brownian motion in a pipe with randomized ﬂow speed.
Second, we have the same setup but replaced the boxes by cylinders with randomized radii and angular velocities in order to learn the Magnus effect.
Finally, we have a folded pipe system with randomized ﬂow speed, that is randomly ﬂipped along the x -axis.
D F URTHER E XAMPLES OF G ENERALIZATION
Note that the network was only trained on simple domain geometries as presented in appendix C.
Still, as can be seen in Figure 8, the network is capable of generalizing to far more complicated domain geometries (e.g. shark, car).
Figure 8c shows that it can generalize to multiple objects in the scene, although the training set contained at most one object per scene.
And Figure 8d shows that we can alter the outer boundary conditions as well.
For real-time simulations, please have a look at our source code and the supplementary video.
E Q UANTITATIVE ANALYSIS : T HE B ENCHMARK P ROBLEM
Figure 9 shows the domain Ω and v d on a 100 × 100 grid which was used as the benchmark problem for quantitative analysis.
The ﬂow speed for the inlet and outlet was set to 0.5.
The timestep of the integrator was set to dt = 4 and the viscosity and ﬂuid density were set to µ = 0 .
1 and ρ =respectively.
[Figure]
[Figure]
F Q UALITATIVE C OMPARISON OF (cid:126)a -N ET AND (cid:126)v -N ET
We give a qualitative example to show the beneﬁts of using a vector potential
Figuredemonstrates that the (cid:126)a -Net ﬁnds plausible solutions for a folded pipe domain while the (cid:126)v -Net looses most of the ﬂow in the center of the domain.
This is in good accordance with quantitative results shown in section 1.
The folded pipe domain is particularly difﬁcult to learn as the ﬂow ﬁeld contains long range dependencies to the inlet and outlet (as shown in the bottom row in Figure 7).
G T RAINING WITHOUT RESETTING ENVIRONMENTS
We performed an ablation study to investigate what happens if we do not reset old environments from time to time and, thus, do not continuously present the ﬂuid model with cold starts during training.
Figure 11 shows that in this case, large error spikes appear in the validation curve.
These error spikes appear since the model has troubles to perform a cold start as can be seen in Figure 11b: compared
[Figure] [Figure]
to a properly trained model (see Figure 4) the model takes longer to perform a cold start (casteps) and converges to a solution with high L p - and L d - losses.
By resetting the environments from time to time during training, we can prevent these error spikes as shown in Figure 11c
[Figure]