SPH - Tips and Tricks

RealFlow's standard particle model is easy to use and gives great results, but beginners often struggle with the interaction between objects and SPH fluids. This leads to misunderstandings or problems. These issues are neither malfunctions, nor bugs, and therefore we want to clarify a few things here. 

Gaps Between Fluids and Objects

One of the most common questions with SPH fluids is how to avoid gaps between the fluid's surface and the interacting object's polygons? Fortunately, this issue is related to a single parameter and can be fixed easily.

When an object is created or imported to RealFlow the software analyses its dimensions. From these values RealFlow takes the largest one and uses it to determine the so-called collision distance. This parameter is responsible for the particle-object interaction's accuracy and tells the solver how closely the particles can approximate the object's surface. Since collision distance is a property of the object, not the fluid, the parameter is located under the object's “Node Params” panel:

Object node > Node Params > Liquid - Particles interaction > Collision distance

When you import an object from an external source, and take a look at “Collision distance” then you will always see a default value. In some cases, this value is very small or very big. With very small values you will get a better representation of the object's surface, but simulation times will increase as well. With large values, the simulation performs faster, but you will see the aforementioned gap.



Collision distance set to 0.3 and 0.01


If you are not satisfied with the given default you do not have to guess, but use a simple formula instead. Look for the node's largest side under Nodes > Scale. Then, take this value and insert it to this term:

Collision distance = Largest side * 0.02

Now, you have a very good starting value for your next test. For the final simulation, “Collision distance” can also be decreased to 1% (= largest side * 0.01), but this depends on the viewers distance to the objects, the body's size, and – that is very important – scene scale. For objects far away, “Collision distance” settings of 0.05 or higher are often satisfying.

Leaking Objects

Under certain circumstances, particles can interpenetrate an object's surface – the body is leaking. This phenomenon often occurs with fast moving or highly accelerated objects, for example during or shortly after the collision with another body. Very complex objects with lots of intersections or concave polygons also tend to leak.

 

Please bear in mind that these tips are only valid for standard particle fluids (“SPH fluids”), not RealFlow's Hybrido fluid system. Hybrido uses a completely different approach. Please follow this link to read more about how to improve Hybrido's fluid-object interaction.

 

Here are a couple of tips:

  • Increase the simulation's accuracy with Simulation Options > General > MIN/MAX substeps.

  • Please check whether your objects have small holes or openings. In cases like this, the only thing you can do is to try to close these holes inside your 3D program.

  • With fast moving objects, the most obvious workaround is to decelerate the node, to make it slower. If this is not an option, you can also try to increase “Collision distance” (see above).

  • If possible, try to use thicker or double-walled objects.

  • For objects with spherical or cubical shapes you can also attach/parent a “k Volume” or “k Sphere” daemon to the node: whenever a particle is leaving the object inside it will be deleted by the daemon immediately.

  • Use a larger scene scale.

  • Add a “k Speed” daemon. Particles, which leave an object are often very fast. With the daemon's “Max speed” and “Limit & Keep” parameters it is possible to define a maximum velocity. Information about the particles' speed can be found under the emitter's “Statistics” panel.

Particle Layers

Imagine the following simulation where you fill a container with a fluid. After a few frames you zoom in to the border between the object and the fluid. Here is what you will most probably see:

 

 

A layered look like this is often the result of an insufficient resolution, but even with very large amounts of particles it cannot be completely suppressed, because it is a technical limitation with SPH fluids. The good news is that these layers do not influence the fluid's mesh: as long as this effect is not very pronounced it can be neglected and you will not see any gaps or holes in your final meshes. Another positive side effect is that these layers help to relax the fluid much faster – the fluid comes to rest earlier.

Anyway, there are some parameters which promote the creation of these layers. On the object's side these settings are “Particle friction” and “Sticky”. Both properties will make the particles “adhere” to the object's surface. If they are very high you should consider decreasing them. Another parameter that influences the forming of layers is “Collision tolerance”. To get a better result, try to use a value of 0.0. Scene scale also plays an important role and with larger scales, the effect will vanish more and more.

As said, it is actually not necessary to do something against these layers, and they cannot be removed or prevented completely. But, if you feel a need to get rid of them, please follow our suggestions above.

Calm Fluid Surfaces

When a fluid is poured into a glass or any other container you will see an up and down motion for a certain amount of time. A little later, the fluid comes to rest and forms an even surface. RealFlow mimics this behaviour, but it can take some time before the fluid is totally calm. During this time you can observe the fluid sloshing and moving. One method is simply to sit and wait until the fluid has relaxed, but this can be a very time consuming task. It is much better to support this process with RealFlow's “k Speed” daemon. Please follow these steps:

  1. Start the simulation without the influence of the “k Speed” daemon.

  2. Fill the object until the desired water level has been reached and let the simulation run for a few more frames.

  3. Set the emitter's “Speed” parameter to 0.

  4. Create an initial state and activate “Reset To Initial State”; reset the scene.

  5. Add/Or activate the “k Speed” daemon.

  6. Set “Limit & Keep” to “Yes”.

  7. Create two animation keys for “Max speed” with values of 1.0 (frame 0) and 0.01 (frame 200)

  8. Simulate. At frame 200 the fluid should be calm and relaxed.

  9. Create a new initial state for your final simulation.

 

This procedure will help you get an even fluid surface you can use as a starting point for a new simulation. Depending on the number of particles, this process can take a while. We therefore recommend disabling the viewport during simulation (Alt + D) or using the Command Line version:

Simulation button context menu > Command line

Inside & Outside

Sometimes it is necessary to fill a closed object, e.g. a sphere or a cube, from the outside, but when you try to do this, the particles will collide with the object's surface and the particles cannot enter the body. To change this, all you have to do is to change the object's collision normal under:

Object selection > Node Params > Liquid - Particles Interaction > Collision normal

  • "Both". This is the default setting: particles from the outside will be reflected at the object's surface. When the emitter is placed inside the object, the particles cannot leave the node.

  • "Inside". Particles from emitters which are placed outside the object are allowed to enter the body and they will collide with the nodes inside.

  • "Outside". Particles will be able to leave a closed object. If the particle comes from outside the body they will collide with the outer surface.

What You Should Know About the “Fill Object” Emitter

With RealFlow's “Fill Object” emitter it is easy to fill all kinds of volumes, glasses, containers, or the inside of any object. Depending on the emitter's “Resolution” value and the object's complexity, this process can take up to one or two minutes. For low-resolution setups, the task should be completed within a few seconds.

The emitter provides a couple of options to customize the filling process. You can tell RealFlow whether the object should be filled completely or to a certain percentage, it is possible to remove individual particle layers, or cover the object's surface only. All this is just a matter of a few mouse clicks, but there are also some important things you should know about this emitter.

 

The Filled Volume – Collapsing Fluids

When the emitter is filling an object it places particles using a constant distance in between. This distance is the same in all spatial directions (XYZ) and depends on the particles' radius. The radius, on the other hand, is determined by the emitter's “Resolution”. Very high “Resolution” values mean a small radius, and that the particles will be packed much denser. With small “Resolution” settings, the distance between the particles becomes greater.

As long as there is no external force acting on the particles this grid remains stable (you will see a motion, but this is the result of the fluid's internal forces). Once you add a force, e.g. a “Gravity” daemon, and simulate, the fluid starts to collapse. This is a normal process, because the particles are now free to move and try to get together as close as possible. The object has been filled completely at the beginning of the simulation, but you might end up with just 50% once the fluid has relaxed.

There are situations where this loss of volume is not an issue, but if you really want to get a completely filled object you should consider a different solution:

Instead of a “Fill Object” emitter it is often better to use a standard “Circle” or “Square” emitter and fill the object over time – just like filling a glass with water in real life. Place the emitter inside the object and start the simulation. If the amount of particles is not sufficient, please increase “Resolution” and/or “Speed”. Once the node is filled, stop the simulation, set “Speed” to 0, and create an initial state. Please do not overdo the filling process, because otherwise your object might leak. If you can see particles leaving the object, simply create the initial state from an earlier point in time.

 

Inside vs. Inside

There are differences in how the “Fill Object” emitter interprets an object's inside. This becomes obvious when you use the emitter in combination with a double-walled object, for example a glass. This, actually very simple body, demonstrates perfectly that “inside” is not always “inside”. If you try to fill a double-walled glass you will see that RealFlow places the particles inside the space between the inner and outer surface. The area that is filled with water in the real world remains empty.

Unfortunately, there is no function available to choose which part of an object should be filled, because this differentiation is made by RealFlow internally. Despite of that, we can offer two effective workarounds:

  1. Create a single-walled proxy of the object you want to fill and import it to RealFlow. Once the fluid has been created you can deactivate the proxy and use the original object instead.
  2. Use another emitter instead and fill the glass to the desired level. Once the fluid has reached this mark, set the emitter's “Speed” value to 0. Alternatively, it is also possible to use the “Volume” option instead of a continuous stream. This way, the fluid will behave similar to the “Fill Object” emitter and collapse at the beginning of the simulation.


Double- and single-walled glasses and how they are filled. The left particle representation is hollow inside.

Torn Fluids and Holes

One thing that can often be seen with SPH fluids is that the particles break apart into more or less small drops. As a result, the particles are not capable of forming thin and coherent sheets of fluid as you might have seen in real life. Instead you will see a torn and ripped particle cloud. Unfortunately, there are no emitter settings to avoid this phenomenon, but you can use the “Sheeter” daemon to fill these holes at simulation time.

This daemon provides a wide variety of settings to customize the hole-filling process and you can even choose how many gaps you want to close with fresh particles. Even with the “Sheeter” daemon's default settings you will get satisfying results, but there are also parameters to handle difficult situations, e.g. very thin particle layers from the “Linear” emitter.

For more information about this daemon and its options, please visit its documentation page.

 

Python-scripted tendrils without (left) and with (right) RealFlow's "Sheeter" daemon.

 

How to Stop An Emitter From Creating Particles?

This question is often asked in forums and therefore, we want to show you a few methods of stopping the emission of particles:

  1. Limit the number of particles. Under the emitter's Node Params > Particles panel you can see a parameter named “Max particles”. By default it is set to a value of roughly 2.15 billion, which is the maximum number RealFlow can handle. If you only want to emit a defined number of particles simply decrease this value. Once the new limit has been reached, the emitter will stop creating fresh particles.
  2. Set the emitter's “Speed” value to 0. To do this, go to Node Params and open the last tab (it wears the name of the emitter type, e.g. “Circle” or “Linear”). You can stop the simulation at any point in time and change the parameter to 0.
  3. Animate the emitter's “Speed” to 0. Another method is to gradually decrease the value by animating it: enter the start value (e.g. 2.0), shift the timeline slider to the first frame of the animation, right-click on the “Speed” value, and choose “Add key”. Then, go to the last frame, enter 0.0, right-click, and create another key.
  4. Use an expression. With expressions it is possible to control the behaviour of a parameter without adding animation keys. Instead, formulas or conditions are used. Like in the method above, the emitter's “Speed” value is used. Right-click on it and choose “Open Curve”. At the “Curve Editor's” bottom you can see an empty field. There, enter the following expression: if(f>74,2.0,0.0)
    If the current frame is greater than 74 the emitter's speed will drop from 2.0 to 0.0. If you want to change emission speed from 3.6 to 0.0 at frame 165, for example, change the expression to: if(f>164,3.6,0.0)