4
$\begingroup$

I have just started implementing a fluid simulator based on the navier stokes equation. I am following Jos Stam's paper to do so. In this paper, it says that the velocity field must be mass conserving. Which I understand as, the velocity that flows into a cell should be the same the velocity that flows out. To get this mass conserving field, the hodge decomposition is used, and the text says:

"every vector field is the sum of a mass conserving field and a gradient field." 
Velocity field = mass conserving field + gradient field

1) Is there a intuitive way to understand why this statement above is true? Maybe I have to read more on Hodge decomposition to understand this.

2) The text also says that the gradient field can be computed by solving the poisson equation, Is there a simple explantion of why the poisson equation can be used to approximate this field? I'm wondering what else could be used instead.

Could you point me to some resources that help understand my two questions intuitively, before delving into all the math?

$\endgroup$
5
$\begingroup$

Suppose I have a fluid which, like water, is incompressible; that is, its density is constant. I can find out how this fluid is flowing; let's say I inject dye at various points and follow how the dye particles move. I can estimate a velocity at each point, a velocity field $\mathbf{w}$. But water is incompressible; this means that the true velocity field $\mathbf{u}$ has to be mass-conserving. I want to "correct" my estimate $\mathbf{w}$ to find the closest mass-conserving velocity field.

The local accumulation or depletion of the fluid is computed with the divergence of the vector field, $\operatorname{div}\mathbf{w}$. (Stam writes the divergence of $\mathbf{w}$ as $\nabla\cdot\mathbf{w}$.) The divergence is a derivative, which is important here because that means it's linear; the divergence of the sum of two vector fields is the sum of their divergences: $$ \operatorname{div}(\mathbf{u} + \mathbf{v}) = \operatorname{div}\mathbf{u} + \operatorname{div}\mathbf{v}. $$ We want to find a mass-conserving field; that is, we want to find a field with zero divergence. That means that we want to construct a field $\mathbf{v}$ with the same divergence as $\mathbf{w}$; then $$ \operatorname{div}\mathbf{w} - \operatorname{div}\mathbf{v} = \operatorname{div}(\mathbf{w} - \mathbf{v}) = 0 $$ so we can get our mass-conserving field $\mathbf{u} = \mathbf{w} - \mathbf{v}$.

The only question is how we construct a field with a given divergence. For reasons I'll explain a few paragraphs down, we say that $\mathbf{v}$ is the gradient of some scalar field $q$, $\mathbf{v} = \operatorname{grad}q$. (Stam writes this as $\nabla q$.) Then we have $$ \operatorname{div}\mathbf{w} = \operatorname{div}\mathbf{v} = \operatorname{div}\operatorname{grad}q.$$ It's worth looking at what this says. The divergence of a vector field is a scalar field; at each point, it gives the local accumulation or depletion of the fluid. Both the divergence and the gradient are derivatives (which is why they can also both be written with $\nabla$). The equation is thus saying that the scalar field (the divergence of $\mathbf{w}$) is a particular second derivative of the scalar field $q$. This derivative is called the Laplacian (Stam writes it as $\nabla^2 q$). The differential equation relating scalar fields $q$ and $a$ $$ \operatorname{div}\mathrm{grad}\ q = a $$ is the Poisson equation. It's not so much that you use it to estimate $q$ as that it's the actual definition of $q$.

So, to "correct" our estimate $\mathbf{w}$, we can compute its divergence (a scalar field) $$ f = \operatorname{div}\mathbf{w}, $$ solve the Poisson equation to find the scalar field $q$ $$ \operatorname{div}\operatorname{grad} q = f, $$ then subtract $\operatorname{grad}q$ from $\mathbf{w}$ to find our mass-conserving velocity field $$ \mathbf{u} = \mathbf{w} - \operatorname{grad}q. $$


Above we just assumed that $\mathbf{v} = \operatorname{grad}q$ for some $q$. What we actually want is to find a field $\mathbf{v}$ that is in some sense the "smallest" field with the given divergence, so we can find the "closest" mass-conserving field $\mathbf{u} = \mathbf{w} - \mathbf{v}$; here I'll explain how the gradient of a scalar field satisfies this requirement.

We have a fixed amount of fluid moving through our space. If our flow is mass-conserving, then we have a conserved amount of fluid, without local accumulation or depletion. If we have any motion at all, then, the fluid must move in cycles. In the same way as we measure the local accumulation with the divergence operator, we can measure the local cyclic behaviour of the flow by using another vector operator, the curl (which can be written $\nabla\times\mathbf{v}$). The curl at a point gives, broadly speaking, the axis about which the flow is circling near that point.

Now, consider the gradient of a scalar field, $\operatorname{grad} q$. (For instance, $q(x,y) = \sin x \cos y$.) The potential can be drawn as a height field: plot of z = sin(x)*cos(y) Then the gradient of this field puts at each point a vector pointing in the steepest uphill direction: vector field grad(sin(x) * cos(y)) But since you're always going "uphill" as quickly as you can, I think it's clear that there's no circulation in this vector field! In fact, for any scalar potential $q$, $$ \operatorname{curl}\operatorname{grad}q = 0 ! $$

There's also a second similar identity: $\operatorname{div}\operatorname{curl}\mathbf{v} = 0$; unfortunately, I can't think of a good intuition for that one. (But look at this Math.SX answer for a more mathematical explanation.) We can use these two identities to explicitly write the Hodge decomposition: $\mathbf{w} = \mathbf{v} + \mathbf{u}$, where $\mathbf{v}$ has no curl, and $\mathbf{u}$ has no divergence, or $$ \mathbf{w} = \operatorname{grad}q + \operatorname{curl}\mathbf{\nu},¹ $$ for some scalar field $q$ and vector field $\mathbf{\nu}$.


¹The Hodge decomposition is actually more complicated if your space isn't simple, i.e. finite and ball-like; on more complicated spaces, like say the surface of a torus, we have curl-free fields which aren't the gradient of anything, and divergence-free fields which aren't the curl of anything. For most fluid modelling in CG, though, this isn't usually an issue.

$\endgroup$
  • $\begingroup$ Thanks for the answer! your explanation of origin of the formula used in Stam's paper, really helps to get a deeper understanding of the math. $\endgroup$ – Meg99 Oct 21 '18 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.