Now we can digest this equation a little bit. Note this gives us an equations for the change in velocity. We would have to integrate again to get position. External forces are simple, they are just like forces in point based physics such as gravity. Density here is acting like mass in a discrete system. So ignoring pressure and viscosity, this looks just like Newton's equation of motion.
The pressure term simply says that fluids move from higher to lower pressure. In more formal language it accounts for the normal stress. That is pretty straight forward, only where does the pressure come from. How do we compute it? If a fluid is truly incompressible and conditions like temperature are homogeneous, then the pressure is constant. Therefore, the gradient of the pressure is zero. However, in other circumstances we can use a so-called "equation of state" to determine pressure. These are equations like the ideal gas law.
In this case we use something similar.
Where n/V is proportional to density and we simply lump the other terms into k. This equation says that pressure wants to equalize around some rest density, . k is a constant determining the speed with which it equalizes. By using the gradient of the pressure as a force, we are moving towards that rest density. Note that this tries to approximate an incompressible fluid. If k is very large, particles must stay at the rest density making it incompressible. This is only roughly based on physical intuition, and not on actual physical laws. Applications that require a more precise result might require a more realistic equation of state.
The viscosity term, , results from a simplification due to incompressibility. One aspect of this term that is confusing is that the laplacian usually applies to scalar fields, not vectors like velocity. In this case it refers to a vector made of the laplacian of each direction separately (in cartesian coordinates). This term says that velocities tend to average out or want to be the same.
One thing to note is how similar this is to the flocking simulation with multi-agent systems. The alignment rule is much like the viscosity. The pressure acts as the separation rule. The only thing absent is the cohesion rule, but that could be simulated as an attractive force between the particles. I just mention this to bring up the parallels between different phenomena and different simulation techniques. In fact real flocks have been observed to have fluid like properties like surface tension.
In this implementation of SPH we are ignoring the incompressibility equation. This equation states that divergence of the velocity is zero. Divergence measure how much of a source or sink a point in the field is, or put another way it measures how much an infinitesimal volume would stretch or shrink. So the divergence being zero everywhere says that no volume stretches or shrinks in the flow, thus the field done not compress. Solving this equation involves "projecting" the velocity field into a divergence free space. This can be a complex process, so here we merely approximate incompressibility.
One aspect that is missing from this definition of the Navier-Stokes equation which you often see is convection. This is often the most difficult part to deal with in many simulations and it comes from this equations.
The convection term indicates that velocity is changing in space as well as time. In simulations with fixed points, you need to account for the flow or convection of the velocity. Our simulation will be based on moving particles, so this term is taken care of implicitly. This is convenient because one of the reasons the convection term is difficult to deal with is it is "non-linear" which means the velocity appears twice in the equation.
This is accomplished using a kernel or smoothing function, W(r), which drops off with distance from a particle. Each particle holds various properties like density, velocity, perhaps temperature or other custom quantities. To find these quantities at any point in space separate from the particles you simply sum them all up with the weights.
This is the equation to compute some quantity, A, defined on each particle at any point in space, where r indicates position and we are summing over all particles. We are normalizing by volume (or mass over density) because each quantity of the particle is actually spread over some volume. What makes this method nice is how we can then estimate differentials. Recall that in the finite difference method we used subtraction between neighboring values to estimate differentials, and there were many different methods for doing so. Here we can simply apply differential precisely.
Because the quantites at the particles are actually constants, the differential only applies to the kernel function. Since we choose the kernel function, we can also get an analytical equation for its derivative. This allows us to easily calculate any derivative. Now solving our differential equation is fairly straight forward.
A more pneuonced distinction is Lagragian versus Eulerian methods. Eulerian methods look at quantities in at a fixed point in space. For instance finite difference methods are Eulerian. In these methods the convection term of the Navier-Stokes equation is very important. Lagragian methods follow quantities as they move, so SPH is Lagragian. Here convection is handled implicitly because the particle positions are moved as you integrate. Lagragian methods are useful when talking about moving objects such as deformable bodies.
First the pressure force. We compute the force the same way as we computed density. For each particle, the force is computed at that particles position.
There is a subtle problem with this equation. It leads to asymmetric forces. As we know, every action must have an equal and opposite reaction. Two approaches to making it symmetric have been suggested. They involve mathematically intuitive, but physically dubious revisions.
Now we have to compute the pressure at each point, which we can do based off our equation of state.
Note the bit of trickery to get an expression for computing density at each point. In computation, we would do this in several steps. First we compute the density at each particle. We use that to determine the pressure at each particle. Then we use the pressure at each particle to compute the pressure force.
The last remaining piece is viscosity.
Here this is also asymmetric. The way it is symmetrized it is by looking at the relative velocity between the two particles. This makes sense intuitively in that there is no viscous force if all the particles are moving at the same velocity.
They all must be normalized, as in they must sum to one. If a quantity is spread over some volume, then if you add up that quantity weighted by your kernel function in all space, you want to get the same quantity back.
The kernels have to go to zero at some specified smoothing distance, h. In addition, we want the derivatives also to go to zero at the same distance. The original formulation of SPH used a Gaussian function as the ideal kernel. This is your typical bell curve. However, it is computationally expensive, so other kernels have been developed that are based on polynomial splines.
In our model, for stability and accuracy we end up choosing different kernels for different purposes. Essentially we want each derivative of the kernel to have different properties, so we design a different kernel for the pressure gradient and the viscous force laplacian.
For the undifferentiated kernel, which we use to calculate density, we want a kernel that looks like a gaussian curve, a nice even distrobution. We also want it to be easy to compute. A suggested function is:
Problems occur for this kernel when we look at the gradient. The gradient determines the pressure force, and in this function the gradient tends towards zero as distance tends towards zero. This means the pressure gets weaker when particles get closer. This is exactly the opposite effect we want. So we can design a kernel for pressure in which we only care about the gradient.
Both of these kernels have the property that the laplacian is sometimes negative. However, we never want a negative viscous force. Therefore we need a kernel function whose laplacian is always positive.
So we use the first kernel when talking about undifferentiated quantities, the second for the gradient, and the third for the laplacian.
The density, mass and kernel length are realistic for water. However, the pressure constant is tiny compared to one computed using the ideal gas law. This should be as high as possible while still maintaining stability. Also, the viscosity is much higher than in reality. The kernel radius should be as small as possible, to reduce the amount of computation, but must include enough neighboring particles to allow for realistic behavior. These are just example values, and others are certainly possible.
- Compute density and pressurefor all particles
- Compute pressure and viscous forces for all particles
- Compute any external forces (like gravity)
- Sum all forces
- Integrate position and velocity with any old integrator (Leapfrog is common)
- repeat
How do we deal with boundary conditions? One method is pretending there are particles along boundaries, and the pressure force pushes back on the fluid. This method can be unrealistic. More complex methods involve actually enforcing incompressibility using Poisson solvers, which remove any velocity component normal to the boundary.
We may want to add additional properties to our fluid. One common property required for realistic fluids is surface tension. We can also look into multiple fluid interactions. Friction may be required at boundary conditions.
How can we extend SPH? We can look at other continuous problems with SPH. A common one is looking at elastic stress in solids. Can it make any sense to use SPH to solve reaction diffusion problems in which particles would not move? We can also add more elements to our fluid model like temperature or transport models for erosion and deposition.
We will address some of these issues in the following class.