Neural Conservation Laws: A Divergence-Free Perspective
Abstract
We investigate the parameterization of deep neural networks that by design satisfy the continuity equation, a fundamental conservation law.
This is enabled by the observation that solutions of the continuity equation can be represented as a divergence-free vector field.
We hence propose building divergence-free neural networks through the concept of differential forms, and with the aid of automatic differentiation, realize two practical constructions.
As a result, we can parameterize pairs of densities and vector fields that always satisfy the continuity equation by construction, foregoing the need for extra penalty methods or expensive numerical simulation. Furthermore, we prove these models are universal and so can be used to represent any divergence-free vector field.
Finally, we experimentally validate our approaches on neural network-based solutions to fluid equations, solving for the Hodge decomposition, and learning dynamical optimal transport maps.
Introduction
Modern successes in deep learning are often attributed to the expressiveness of black-box neural networks.
These models are known to be universal function approximators [Hornik et al., 1989]—but this flexibility comes at a cost.
In contrast to other parametric function approximators such as Finite
Elements [Schroeder and Lube, 2017], it is hard to bake exact constraints into neural networks.
Existing approaches often resort to penalty methods to approximately satisfy constraints—but these increase the cost of training and can produce inaccuracies in downstream applications when the constraints are not exactly satisfied.
For the same reason, theoretical analysis of soft-constrained models also becomes more difficult.
On the other hand, enforcing hard constraints on the architecture can be challenging and even once enforced, it is often unclear whether the model remains sufficiently expressive within the constrained function class.
In this work we discuss an approach to directly bake in two constraints into deep neural networks: (i) having a divergence of zero and (ii) exactly satisfying the continuity equation .
One of our key insights is that the former directly leads into the latter , so the first portion of the paper focuses on divergence-free vector fields.
These represent a special class of vector fields which have widespread use in the physical sciences.
In computational fluid dynamics, divergence-free vector fields are used to model incompressible fluid interactions formalized by the Euler or Navier-Stokes equations.
In R 3 we know that the curl of a vector field has a divergence of zero, which has seen many uses in graphics simulations ( e.g. , Eisenberger et al.
Perhaps less well-known is that lurking behind this fact is the generalization of divergence and curl through differential forms [Cartan, 1899], and the powerful identity d 2 = 0 .
We first explore this generalization, then discuss two constructions derived from it for parmaterizing divergence-free vector fields.
While this approach has been partially discussed previously [Barbarosie, 2011, Kelliher, 2021], it is not extensively known and to the best of our knowledge has not been explored by the machine learning community. b
A = J b − J T b eq.
A
Av = div ( A ) eq.
(4) v
Concretely, we derive two approaches—visualized in Figure 1—to transform sufficiently smooth neural networks into divergence-free neural networks, made efficient by automatic differentiation and recent advances in vectorized and composable transformations [Bradbury et al., 2018, Horace He, 2021].
Furthermore, both approaches can theoretically represent any divergence-free vector field.
We combine these new modeling tools with the observation that solutions of the continuity equation— a partial differential equation describing the evolution of a density under a flow —can be characterized jointly as a divergence-free vector field.
As a result, we can parameterize neural networks that, by design, always satisfy the continuity equation, which we coin Neural Conservation Laws (NCL).
While prior works either resorted to penalizing errors [Raissi et al., 2019] or numerically simulating the density given a flow [Chen et al., 2018], baking this directly into the model as a constraint allows us to forego extra penalty terms and expensive numerical simulations.
Constructing divergence-free vector fields
We will use the notation of differential forms in R n for deriving the divergence-free and universality properties of our vector field constructions.
We provide a concise overview of differential forms in
Appendix A. For a more extensive introduction see e.g. , Do Carmo [1998], Morita [2001].
Without this formalism, it is difficult to show either of these two properties; however, readers who wish to skip the derivations can jump to the matrix formulations in equation 4 and equation 7.
Let us denote A k ( R n ) as the space of differential k -forms, d : A k ( R n )
→ A k +1 ( R n ) as the exterior derivative, and ⋆ : A k ( R n )
→ A n − k ( R n ) as the Hodge star operator that maps each k -form to an ( n - k )-form. {+Identifying a vector field v : R d → R d as a 1 -form, v = (cid:80) ni =
+}
v i dx i , we can express the divergence div ( v ) as the composition d ⋆ v .
To parameterize a divergence-free vector field v : R n → R n , we note that from the properties of differential forms, taking an arbitrary ( n - 2 )-form µ ∈ A n − 2 ( R n ) we have that
[Equation]
and since ⋆ is its own inverse up to a sign, it follows that
[Equation]
is divergence free.
We write the parameterization v = ⋆dµ explicitly in coordinates.
Since a basis for A n − 2 ( R n ) can be chosen to be ⋆ ( dx i ∧ dx j ) , we can write µ = 12 (cid:80) ni,j =1 µ ij ⋆ ( dx i ∧ dx j ) , where µ ji = − µ ij Now a direct calculation shows that up to a constant sign (see Appendix-A.1)
[Equation]
This formula is suggestive of a simple matrix formulation: If we let A : R n → R n × n be the antisymmetric matrix-valued function where A ij = µ ij then the divergence-free vector field v = ⋆dµ can be written as taking row-wise divergence of A , i.e. ,
[Equation]
However, this requires parameterizing O ( n 2 ) functions.
A more compact representation, which starts from a vector field, can also be derived.
The idea behind this second construction is to model µ instead as µ = δν , where ν ∈ A n − 1 ( R n ) .
Putting this together with equation 2 we get that
[Equation]
is a divergence-free vector field.
To provide equation 5 in matrix formulation we first write ν ∈
A n − 1 ( R n ) in the ( n - 1 )-form basis, i.e. , ν = (cid:80) ni
=
ν i ⋆ dx i .
Then a direct calculation provides up to a constant sign
[Equation]
So, given an arbitrary vector field b : R n → R n , and denoting J b as the Jacobian of b , we can construct A as
[Equation]
where J b denotes the Jacobian of b .
To summarize, we have two constructions for divergence-free vector fields v :
Matrix-field : (equations 2 and 4) v is represented using an anti-symmetric matrix field A .
Vector-field : (equations 5 and 4+7) v is represented using a vector field b .
[Figure]
As we show in the next section, these two approaches are maximally expressive ( i.e. , universal), meaning they can approximate arbitrary smooth divergence-free vector fields.
However, empirically these two constructions can exhibit different practical trade-offs.
The matrix-field construction has a computational advantage as it requires one less Jacobian computation, though it requires more components—
O ( n 2 ) vs. O ( n ) —to represent than the vector-field construction.
This generally isn’t a concern as all components can be computed in parallel.
However, the vector-field construction can make it easy to bake in additional constraints; an example of this is discussed in Section 7.1, where a non-negativity constraint is imposed for modeling continuous-time probability density functions.
In Figure 2 we show wallclock times for evaluating the divergence-free vector field based on our two constructions.
Both exhibit quadratic scaling with the number of dimensions due to the row-wise divergence in equation 4, while the vector-field construction has an extra Jacobian computation.
2.1 Universality
Both the matrix-field and vector-field representations are universal, i.e. they can model arbitrary divergence-free vector fields.
The main tool in the proof is the Hodge decomposition theorem [Morita, 2001, Berger, 2003].
For simplicity we will be working on a periodic piece of R n , namely the torus T n = [ − M, M ] n / ∼ where ∼ means identifying opposite edges of the n -dimensional cube, and
M > 0 is arbitrary.
Vector fields with compact support can always be encapsulated in T n with M >sufficiently large.
As T n is locally identical to R n , all the previous definitions and constructions hold.
Theorem 2.1.
The matrix and vector-field representations are universal in T , possibly only missing a constant vector field.
A formal proof of this result is in Appendix B.1.
Neural Conservation Laws
We now discuss a key aspect of our work, which is parameterizing solutions of scalar conservation laws.
Conservation laws are a focal point of mathematical physics and have seen applications in machine learning, with the most well known examples being conserved scalar quantities often referred to as density, energy, or mass.
Formally, a conservation law can be expressed as a first-order PDE written in divergence form as ∂ρ∂t + div ( j ) = 0 , where j is known as the flux, and the divergence is taken over spatial variables.
In the case of the continuity equation, there is a velocity field u which describes the flow and the flux is equal to the density times the velocity field:
[Equation]
where ρ : R n → R and u : R n → R n .
One can then interpret the equation to mean that u transports ρ (0 , · ) to ρ ( t, · ) continuously – without teleporting, creating or destroying mass.
Such an interpretation plays a key role in physics simulations as well as the dynamic formulation of optimal transport [Benamou and Brenier, 2000].
In machine learning, the continuity equation appears when using continuous normalizing flows [Chen et al., 2018]—which also have been used to approximate solutions to dynamical optimal transport.
[Finlay et al., 2020, Tong et al., 2020, Onken et al., 2021]
These, however, only model the velocity u and rely on numerical simulation to solve for the density ρ , which can be costly and time-consuming.
Instead, we observe that equation 8 can be expressed as a divergence-free vector field by augmenting the spatial dimensions with the time variable, resulting in a vector field v that takes as input ( t, x ) and outputs ( ρ, ρu ) .
Then equation 8 is equivalent to
[Equation]
where the divergence operator is now taken with respect to the joint system ( t, x [Equation]
, i
[Equation]
We thus propose modeling solutions of conservation laws by parameterizing the divergence-free vector field v .
Specifically, we parameterize a divergence-free vector field v and set v 1 = ρ and v 2: n +1 = ρu , allowing us to recover the vector field as u = v 2: n +1 ρ , assuming ρ ̸ = 0 .
This allows us to enforce the continuity equation at an architecture level. Compared to simulation-based modeling approaches, we completely forego such computationally expensive simulation procedures.
Related Works
Baking in constraints in deep learning Existing approaches to enforcing constraints in deep neural networks can induce constraints on the derivatives, such as convexity [Amos et al., 2017] or
Lipschitz continuity [Miyato et al., 2018].
More complicated formulations involve solving numerical problems such as using solutions of convex optimization problems [Amos and Kolter, 2017], solutions of fixed-points iterations [Bai et al., 2019], and solutions of ordinary differential equations [Chen et al., 2018].
These models can help provide more efficient approaches or alternative algorithms for handling downstream applications such as constructing flexible density models [Chen et al., 2019, Lu et al., 2021] or approximating optimal transport paths [Tong et al., 2020, Makkuva et al., 2020, Onken et al., 2021].
However, in many cases, there is a need to solve a numerical problem in which the solution may only be approximated up to some numerical accuracy; for instance, the need to compute the density flowing through a vector field under the continuity equation [Chen et al., 2018].
Applications of differential forms Differential forms and more generally, differential geometry, have been previously applied in manifold learning—see e.g. Arvanitidis et al.
[2021] and Bronstein et al.
[2017] for an in-depth overview.
Most of the applications thus far have been restricted to 2 ordimensions—either using identities like div ◦ curl = 0 in 3D for fluid simulations [Rao et al., 2020], or for learning geometric invariances in 2D images or 3D space [Gerken et al., 2021, Li et al., 2021].
Neural approximations to PDE solutions
As a demonstration of our method, we apply it to neural-based PDE simulations of fluid dynamics.
First, we apply it to a problem consisting of modelling idealized fluid flow on the flat Torus, then, to showcase the ability to handle boundaries, another in the open unit ball B ⊆ R 3 .
While these are toy examples, they demonstrate the value of our method in comparison to existing approaches—namely that we can exactly satisfy the continuity equation and preserve exact mass.
The Euler equations of incompressible flow The incompressible Euler equations [Feynman et al., 1989] form an idealized model of inviscid fluid flow, governed by the system of partial [-differentialequations 
-]differential equations
[Equation]
in three unknowns: the fluid velocity u ( t, x ) ∈ R 3 , the pressure p ( t, x ) , and the fluid density ρ ( t, x ) .
While the fluid velocity and density are usually given at t = 0 , the initial pressure is not required.
Typically, on a bounded domain Ω ⊆ R n , these are supplemented by the free-slip boundary condition and initial conditions
[Equation]
The density ρ plays a critical role since in addition to being a conserved quantity, it influences the dynamics of the fluid evolution over time.
In numerical simulations, satisfying the continuity equation as closely as possible is desirable since the equations in (10) are coupled.
Error in the density feeds into error in the velocity and then back into the density over time.
In the finite element literature, a great deal of effort has been put towards developing conservative schemes that preserve mass (or energy in the more general compressible case)—see Guermond and Quartapelle [2000] and Almgren et al.
[1998] for an overview.
But since the application of physics informed neural networks (PINNs) to fluid problems is much newer, conservative constraints have only been incorporated as penalty terms into the loss [Mao et al., 2020, Jin et al., 2021].
5.1 Physics informed neural networks
Physics Informed Neural Networks (PINNs; Raissi et al.
[2019, 2017]) have recently received renewed attention as an application of deep neural networks.
While using neural networks as approximate solutions to PDE had been explored before Lagaris et al.
[1998], modern advances in automatic differentiation algorithms have made the application to much more complex problems feasible [Raissi et al., 2019].
The “physics” in the name is derived from the incorporation of physical terms into the loss function, which consist of adding the squared residual norm of a PDE.
For example, to train a neural network ϕ
=
[ ρ, p, u ] to satisfy the Euler equations, the standard choice of loss to fit to is
[Equation]
where γ = ( γ F , γ I , γ div γ Cont , γ G ) denotes suitable coefficients (hyperparameter).
The loss term L G ensures fluid does not pass through boundaries, when they are present.
Similar approaches were taken in [Mao et al., 2020] and [Jagtap et al., 2020] for related equations.
While schemes of this nature are very easy to implement, they have the drawback that since PDE terms are only penalized and not strictly enforced, one cannot make guarantees as to the properties of the solution.
To showcase the ability of our method to model conservation laws, we will parameterize the density and vector field as v =
[ ρ, ρu ] , as detailed in Section 3.
This means we can omit the term L Cont as described in Section 5.1 from the training loss.
The divergence penalty, L div remains when modeling incompressible fluids, since u is not necessarily itself divergence-free.
In order to stablize training, we can modify the loss terms L F , L G , L I to avoid division by ρ .
This is detailed in Appendix B.2.
5.2 Incompressible variable density inside the 3D unit ball
We first construct a simple unit within a bounded domain, specifically, we will consider the Euler equations inside B (0 , 1) ⊆
R 3 , with the initial conditions
[Equation]
[Equation]
As a baseline, we compare against a parameterization that uses the divergence-free vector field only for the incompressible constraint.
This is equivalent to the curl approach described in Rao et al. [2020]; another neural network is used to parameterize ρ .
In contrast, our generalized formulation of divergence-free fields allow us to model the continuity equation exactly, as in this case, [ ρ, ρu ] is 4 dimensional.
We parameterize our method using v =
[ ρ, ρu ] , as detailed in Section 3, with the vector-field approach Section 2. t = 0. t = 0. t = 0.
[Figure]
t = 0.
t = 0. t = 0. [Figure] The results for training both networks are shown in Figure 3.
Surprisingly, even though both architectures signficantly improve the training loss after a comparable number of iterations (see Appendix C), the curl approach fails to advect the density accurately, whereas our conservation approach evolves the density as it should given the initial conditions.
5.3 Incompressible variable density flow on T
As a more involved experiment, we model the Euler equations on the flat 2-Torus T 2 .
This was parameterized as a multilayer perceptron pre-composed with the periodic embedding ι : [0 , 1] 2 → T
[Equation]
The continuity equation is enforced exactly, using the method detailed in Section 3, so the L Cont term is omitted from L total .
The initial velocity and density [-areρ 
-]are
[Equation]
where z = θ ( x, y, 1) .
Here we used the matrix-field parameterization as referred to in Section 2, as it is empirically more flexible in low dimensions.
We also include the harmonic component from
Hodge decomposition, which is just a constant vector field, to ensure we have full universality.
Full methodology for the experiment is detailed in Appendix C.
The results of evolving the flow for time t ∈ [0 , 1 / 3 ] are shown in Figure 4, as well as a comparison with a reference finite element solution generated by the conservative splitting method from [Guermond and Quartapelle, 2000].
In general, our model fits the initial conditions well and results in fluid-like movement of the density, however small approximation errors can accumulate from simulating over a longer time horizon.
To highlight this, we also plotted the best result we were able to achieve with a standard PINN.
Although the
PINN made progress minimizing the loss, it was unable to properly model the dynamics of the fluid evolution.
While this failure can likely be corrected by tuning the γ constant (see Section 5.1), we were unable to find a combination that fit the equation correctly.
By contrast, our NCL model worked with the first configuration we tried.
Learning the Hodge decomposition
Using our divergence-free models, we can also learn the Hodge decomposition of a vector field itself.
Informally, the Hodge decomposition states that any vector field can be expressed as the combination of a gradient field ( i.e. gradient of a scalar function) and a divergence-free field.
There are many scenarios where a neural network modelling a vector field should be a gradient field (theoretically), such as score matching [Song and Ermon, 2019], Regularization by Denoising [Hurault et al., 2022], amortized optimization [Xue et al., 2020], and meta-learned optimization [Andrychowicz et al., 2016]. Many works, however, have reported that parameterizing such a field as the gradient of a potential P I
NN N C L F E M t =0.
t =0. t =0. t =0. [Figure]
{+Iteration 
+}
T r a i n i n g
L o ss
PINN
{+NCL (b) Convergence of training loss 
+}
Iteration 1010| * |
PINN NCL [Figure] hinders performance, and as such they opt to use an unconstrained vector field.
Learning the Hodge decomposition can then be used to remove any extra divergence-free, i.e. rotational, components of the unconstrained model. As a demonstration of the ability of our model to scale in dimension, we construct a synthetic experiment where we have access to the ground truth Hodge decomposition. This provides a benchmark to validate the accuracy of our method.
As such, we construct the target field ˆ v as
[Equation]
(13) where η is a fixed divergence-free neural network, and w is a fixed scalar network.
We use the same embedding from Section 5.3, but extended to T n , for n ∈ { 25 , 50 , 100 } .
We then parameterize another divergence-free model v θ which has a different architecture than the target η . Inspired by the
Hodge decomposition, we propose using the following objective for training:
[Equation]
(14) where J ˆ v − v θ denotes the Jacobian of ˆ v − v θ . In the notation of differential forms, this corresponds to minimizing ∥ δ (ˆ v − v θ ) ∥ F , which when zero implies v θ
= ˆ v + δµ , where µ is an arbitrary n -form.
However, since v θ is divergence-free, it must hold δµ = −∇ w , i.e. the left-over portion of ˆ v − v θ is a gradient field, because the components of the Hodge decomposition are orthogonal [Warner, 1983].
[Figure]
For evaluation, we plot the squared L 2 norm to the ground truth η against wall clock time.
While this demonstration is admittedly artificial, it serves to show that our model scales efficiently to moderately high dimensions – significantly beyond those achievable using grid based discretizations of divergencefree fields (see Bhatia et al. [2013] for an overview of such methods).
The results are shown in Figure 5.
While larger dimensions are slower, we are still able to recover the ground truth in dimensions up to 100.
Dynamical optimal transport
The calculation of optimal transport (OT) maps between two densities of interest p 0 and p 1 serves as a powerful tool for computing distances between distributions.
Moreover, the inclusion of
OT into machine learning has inspired multiple works on building efficient or stable generative models [Arjovsky et al., 2017, Tong et al., 2020, Makkuva et al., 2020, Huang et al., 2020, Finlay et al., 2020, Rout et al., 2021, Rozen et al., 2021].
In particular, we are interested in the dynamical formulation of Benamou and Brenier [2000], which is a specific instance where the transport map is characterized through a vector field.
Specifically, we wish to solve the optimization problem
[Equation]
subject to the boundary constraints, ρ (0 , · )
= p 0 ( · ) and ρ (1 , · )
=
p 1 ( · ) , as well as remaining non-negative ρ ≥ 0 on the domain and satisfying the continuity equation ∂ρ∂t + div ( ρu ) = 0 .
In many existing cases, the models for estimating either ρ and equation 15 are completely decoupled from the generative model or transport map [Arjovsky et al., 2017, Makkuva et al., 2020], or in some cases ρ would be computed through numerical simulation and equation 15 estimated through samples [Chen et al., 2018, Finlay et al., 2020, Tong et al., 2020].
These approaches may not be ideal as they require an auxiliary process to satisfy or approximate the continuity equation.
In contrast, our NCL approach allows us to have access to a pair of ρ and u that always satisfies the continuity equation, without the need for any numerical simulation.
As such, we only need to match the boundary conditions, and will automatically have access to a vector field u that transports mass from ρ (0 , · ) to ρ (1 , · ) .
In order to find an optimal vector field, we can then optimize u with respect to the objective in equation 15.
7.1 Parameterizing non-negative densities with subharmonic functions
In this setting, it is important that our density is non-negative for the entire domain and within the time interval between 0 and 1.
Instead of adding another loss function to satisfy this condition, we show how we can easily bake this condition into our model through the vector-field parameterization.
Recall for the vector-field parameterization of the continuity equation, we have a vector field b θ ( y ) with y =
[ t, x ] , for t ∈ [0 , 1] , x ∈ R n .
This results in the parameterization
[Equation]
We now make the adjustment that ∂b 2: n +1 ∂t = 0 .
This condition does not reduce the expressivity of the formulation, as ρ can still represent any density function.
Interestingly, this modification does imply that ρ = ∇ 2 b 1 with ∇ 2 being the Laplacian operator, so that satisfying the boundary conditions is equivalent to solving a time-dependent Poisson’s equation ∇ 2 b 1 ( t, · ) =
p t .
Furthermore, the class of subharmonic functions is exactly the set of functions g that satisfies ∇ 2 g (0 , · ) ≥ 0 .
In one dimension, this corresponds to the class of convex functions but is a strict generalization of convex functions in higher dimensions.
With this in mind, we propose using the parameterization
[Equation]
ϕ [Equation] z
[Equation]
[Equation] with E 1 being the exponential integral function, and w k , a k ∈ R + and b k ∈ R n are free functions of t .
This a weighted sum of generalized linear models, where the choice of nonlinear function ϕ is chosen because it is the exact solution to the Poisson’s equation for a standard normal distribution when n = 2 , i.e. ∇ 2 ϕ =
N (0 , I ) , while for n ≥ 2 this remains a subharmonic function.
As such, this can be seen as a generalization of a mixture model, which are often referenced to be universal density approximators, albeit requiring many mixture components [Goodfellow et al., 2016].
7.2 Experiments
We experiment with pairs of 2D densities (visualized in Figure 6) and fit a pair of ( ρ, u ) to equationwhile satisfying boundary conditions.
Specifically, we train with the loss
[Equation]
where ˜ p i is a mixture between p i and a uniform density over a sufficiently large area, for i = 0 , 1 , and λ is a hyperparameter.
We use a batch size of 256 and set K =128 (from equation 17).
Qualitative results are displayed in Figure 6, which include interpolations between pairs of densities.
[Figure] [Figure]
Furthermore, we can use the trained models to estimate the Wasserstein distance, by transforming samples from p 0 through the learned vector field to time t =1.
We do this for 5000 samples and compare the estimated value to (i) one estimated by that of a neural network trained through a minimax optimization formulation [Makkuva et al., 2020] [Figure] and (ii) one estimated by that of a discrete
OT solver [Bonneel et al., 2011] based on kernel density approximation and interfaced through the pot library [Flamary et al., 2021].
Estimated squared Wasserstein distance as a function of wallclock time are shown in Figure 7.
We see that our estimated values roughly agree with the discrete OT algorithm.
However, the baseline minimax approach consistently underestimates the optimal transport distance.
This is an issue with the minimax formulation not being able to cover all of the modes, and has been commonly observed in the literature ( e.g. Salimans et al.
[2016], Che et al.
[2017], Srivastava et al.
Moreover, in order to stabilize minimax optimization in practice, Makkuva et al.
[2020] made use of careful optimization tuning such as reducing momentum
[Radford et al., 2016].
In contrast, our NCL approach is a simple optimization problem.
Conclusion
We proposed two constructions for building divergence-free neural networks from an original unconstrained smooth neural network, where either an original matrix field or vector field is parameterized.
We found both to be useful in practice: the matrix field approach is generally more flexible, while the vector field approach allows the addition of extra constraints such as a non-negativity constraint.
We combined these methods with the insight that the continuity equation can reformulated as a divergence-free vector field, and this resulted in a method for building deep neural networks that are constrained to always satisfy the continuity equation, which we refer to as Neural Conservation Laws.
Currently, these models are difficult to scale due to extensive use of automatic differentiation for computing divergence of neural networks.
It may be possible to combine our approach with parameterizations that provide cheap divergence computations
[Chen and Duvenaud, 2019].
Nevertheless, the development of efficient batching and automatic differentiation tools is an active research area, so we expect these tools to improve as development progresses. Acknowledgements
We acknowledge the Python community [Van Rossum and Drake Jr, 1995, Oliphant, 2007] and the core set of tools that enabled this work, including PyTorch [Paszke et al., 2019], functorch [Horace He, 2021], torchdiffeq [Chen, 2018], J AX [Bradbury et al., 2018], Flax
[Heek et al., 2020],
Hydra [Yadan, 2019], Jupyter [Kluyver et al., 2016], Matplotlib [Hunter, 2007], numpy [Oliphant, 2006, Van Der Walt et al., 2011] and SciPy [Jones et al., 2014].
Jack Richter-Powell would also like to thank David Duvenaud and the Vector Institute for graciously supporting them over the last year.
A Preliminaries: Differential forms in R n
We provide an in-depth explanation of our divergence-free construction in this section.
We will use the notation of differential forms in R n that will help derivations and proofs in the paper.
Below we provide basic definitions and properties of differential forms, for more extensive introduction see e.g. , [Do Carmo, 1998, Morita, 2001].
We let x = ( x 1 , . . .
, x n ) ∈ R n , and dx 1 , . .
dx n the coordinate differentials, i.e. , dx i ( x )
= x i for all i ∈ [ n ] = { 1 , . . . , n } .
The linear vector space of k -forms in R n , denoted Λ k
( R n ) , is the space of k -linear alternating maps
[Equation]
A k -linear alternating map φ is linear in each of its coordinates and satisfies φ ( . .
, v, . . .
, u, . . . )
=
− φ ( . . .
, u, . .
, v, . . . ) .
The space Λ k ( R n ) is a linear vector space with a basis of alternating k -forms denoted dx
i 1 ∧ · · · ∧ dx i k .
The way these k -forms act on k -vectors, v 1 , . .
, v k ∈ R n is as a signed volume function:
[Equation]
Expanding an arbitrary element ω ∈ Λ k
( R n ) in this basis gives
[Equation]
where i 1 , .
, i k ∈ [ n ] , I =
( i
The space of differential k -forms (also called k -forms in short), denoted A k ( R n ) , is defined by smoothly assigning to each x ∈ R n a k -linear alternating form
w ∈ Λ
k
( R n ) .
That is
[Equation]
22) where f I : R n → R are smooth scalar functions.
Note that A 0 ( R n ) is the space of smooth scalar functions over R n .
The differential operator can be seen as a linear operator d : A 0 ( R n )
→
A 1 ( R n ) defined by
[Equation]
[Equation]
The exterior derivative d : A k ( R n ) → A k +1 ( R n ) is a linear differential operator generalizing the differential to arbitrary differential k -forms:
[Equation]
[Equation]
where the exterior product ω
∧ η of two forms ω
=
(cid:80)
I f
I dx I , η = (cid:80)
J g J dx J is defined by extending equation 20 linearly, that is, ω ∧ η = (cid:80) I,J f
I g J dx
I
∧ dx J .
An imporant property of the exterior derivative is that ddω = 0 for all ω .
This property can be checked using the definition in equation 24 and the symmetry of mixed partials, ∂ 2 f ∂x i ∂x j = ∂ 2 f ∂x j ∂x i .
The hodge operator ⋆ : A k ( R n ) →
A n − k
( R n ) matches to each k -form an n − k -form by extending the rule
[Equation]
(25) linearly, where σ = sign([ I, J ]) is the sign of the permutation ( I, J )
=
( i 1 , . .
, i k , j 1 , . .
, i n − k ) of [ n ] .
The hodge star is (up to a sign) its own inverse, ⋆ ⋆ ω =
( − 1) k ( n − k ) ω , for all
ω ∈
A k ( R n ) .
The d operator has an adjoint operator δ : A k ( R n )
→ A k − 1 ( R n ) defined by
[Equation]
A vector field v ( x ) =
( v 1 ( x ) , . . .
, v n ( x )) in R n can be identified with a 1-form v = (cid:80) ni
=1 v i ( x ) dx i .
The divergence of v , denoted div ( v ) can be expressed using exterior derivative :
[Equation]
where in the second equality we used the definition of ⋆ , the definition of d and the fact that dx i
∧
{+dx i = 
+}
(can be seen from the repeating rows in the matrix inside the determinant in equation 20).
Note that the n -form div( v ) dx 1 ∧ · · · ∧ dx n is identified via ⋆ with the function ( i.e. , 0 -form) div( v ) .
A.1 Derivations of equation 3 and equation
We will need the following identity below, for µ ∈ Ω k ( M ) , expressed as
[Equation]
we have
[Equation]
which follows by linearity of ⋆ over C ∞ ( M ) and the identity ⋆⋆ =
( − 1) k ( n − k ) .
Here, we derive the expression for equation 3.
For µ ∈ Ω n − 2 ( M ) , the exterior derivative is given by equation 24.
However, in this case, since dx i ∧ dx i = 0 , we can expand
[Equation]
where equation 33 follows by re-indexing i as j
[Equation]
and then equation 34 by anti-symmetry µ ij = − µ ji and ⋆ ( dx i ∧ dx j )
= − ⋆ ( dx j ∧ dx i ) .
Applying ⋆ then gives (by equation 28), ⋆dµ
[Equation]
⋆
[Equation]
To derive equation equation 6, it suffices to start by noting δ = ⋆d⋆ , and so
[Equation]
[Equation]
[Equation]
then since ⋆ ( dx i ∧ dx j ) = − ⋆ ( dx j ∧ dx i ) , we have − ( − 1) n − 1 (cid:88)
i<j (cid:20) ∂ν i ∂x j − ∂ν j ∂x i (cid:21) ⋆
[Equation]
B Proofs and derivations B.1 Universality
Theorem 2.1.
The matrix and vector-field representations are universal in T , possibly only missing a constant vector field.
Proof.
First, consider a divergence-free vector field and its representation as a 1-form v ∈ A 1 ( T ) .
Then v being divergence-free means d⋆v = 0 .
We denote by c = ( c 1 , . . .
, c n ) ∈ R
n a constant vector field; note that c is also a well defined vector field over T .
We will use the notation c to denote the corresponding constant 1-form.
We claim ⋆v = dµ + ⋆c , where µ ∈ A n − 2 ( T ) , and ⋆c ∈
A n − 1 ( S ) is constant.
This can be shown with Hodge decomposition [Morita, 2001] of ⋆v ∈ A n − 1 ( T ) :
[Equation]
[Equation]
where µ ∈ A n − 2 ( T ) , τ ∈ A n ( T ) and h ∈ A n − 1 is a harmonic n -1-form.
Note that the harmonic n -1-forms over T are simply constant.
Taking d of both sides leads to d ⋆ v =
[Equation]
Since we assumed v is div-free, d
{+⋆ v = 
+}
and we get dδτ = 0 .
Since dδτ = 0 = δδτ then δτ is harmonic (constant) as well.
So far we showed ⋆v = dµ + ⋆c , which shows the universality of the matrix-field representation (up to a constant).
To show universality of the vector-field representation we need to show that:
[Equation]
The left inclusion ⊃ is true since δν ∈
A n − 2 ( T ) .
For the right inclusion ⊂ we take an arbitrary µ ∈ A n − 2 ( T ) and decompose it with Hodge: µ = dω + δν + h ,
where ω ∈ A n − 3 ( T ) ,
ν ∈ A n − 1 ( T ) , and h ∈ A n − 2 ( T ) is harmonic.
Taking d of both sides leaves us with dµ = dδν that shows that dµ + ⋆c is included in the right set.
B.2 Stabilizing training for fluid simulations
In order to stabilize training, we can modify the loss terms L F , L G , L I to avoid division by ρ .
As before v = [ ρ, ρu ] ,and
[Equation]
In practice, we noticed this improved training stability significantly, which is intuitive since the possibility of a division by 0 is removed.
The derivation of ˜ L G , and ˜ L I is simply scaling by ρ .
We derive ˜
L F and ˜ L div by repeatedly applying the product rules for the Jacobian and divergence operators and solving for ρ 2 , 3 scaled copies of the residuals.
Below, we use the convention that the gradient and divergence operators only act in spatial variables, but the ˜ ∇ , ˜ div operators include time
[Equation]
Derivation of ˜ L div :
To derive ˜ L div , we consider ˜
[Equation]
(59) by construction div (cid:18) ρ (cid:18)u (cid:19)(cid:19) = 0 , and since ˜ div (cid:18) 1 u (cid:19)
= div ( u ) , multiplying both sides by ρ we find
[Equation]
Derivation of ˜ L F To derive ˜ L F , we will start at the end.
We multiply the momentum term of the
Euler system
[Equation]
we start by applying the product rule to ρu
[Equation]
multiplying by ρ 2 and solving for ρ 3 ∂u∂t yields
[Equation]
which can be computed without dividing by ρ .
Now we apply the Jacobian scalar product rule
[Equation]
contracting with ρ 2 u yields that
[Equation]
which gives
[Equation]
which can also be computed without invoking division by ρ .
Together, equation 63 and equationyield ˜ L F .
C Implementation Details C.1 Tori Example Details
For the Tori example, we used the matrix formulation of the NCL model.
The matrix was parameterized as the output of a 4 layer, 512-wide Multi-Layer Perceptron with softplus activation.
We trained this model for 50,000 steps of stochastic gradient descent using a batch size of 1000.
The weight vector γ was fixed with γ F = 3 × 10 − 3 , γ I = 30 , γ div = 0 .
Instead of choosing a fixed set of colocation points (as is common in the PINN literature see Raissi et al.
[2017]), we sampled uniformly on the unit square [0 , 1] 2 . ??
shows an larger view of the results presented in
Section 5.3.
Here we trained the model for an additional 50,000 steps for a total of 70,000 steps.
For the Finite-Element reference solution, we solved the system on a 50 x 50 grid with periodic boundary conditions implemented with a mixed Lagrange element scheme.
The splitting scheme used was the inviscid case of Guermond and Quartapelle [2000], with time step dt = 0 . 001 .
C.2 3d Ball Example Details
For the comparison in Figure 9 we used a 4-layer, 128 wide feed forward network for both the Curl
PINN and the NCL.
Stopped training both models after 10000 steps of stochastic gradient descent with batch size of 1000.
While this is much less than Section 5.3, the difference can be explained by the initial condition being much less complex.
For the NCL model, we used γ F = 0 .
1 , γ div = 0 .
1 , γ G = 0 .
1 , γ I = 30 .
For the CURL model, we used γ F = 0 .
1 , γ G = 0 .
1 , γ cont = 10 , γ I =
A larger plot of the comparison is shown in Figure 9.
[Figure]