Weekly Development Notes #49 – Viscosity Solver Improvements

Covering the weeks of February 15th – 26th, 2021.

Thanks for taking a look at our 49th development update for the FLIP Fluids liquid simulation addon for Blender! There wasn’t a dev update last week for the week prior as the work was mostly uninteresting: home office improvements, taxes, and a little bit of code cleanup.

However, last weeks development felt quite productive! I was able to finish up some large structural changes for how particles are stored in memory and in the simulation cache, added some functionality to the code to add custom attributes to the particles, and made some improvements to the viscosity solver.

Letter Transformation Using Force Fields

Check out Dennis’ cool force field test!

This effect uses a volume force to attract liquid into letter shapes. Transitioning between letters was achieved by keyframing the force field strength between letter objects, like a crossfade. A little bit of viscosity was added for a smooth flow, and upping the smooth modifier created a very smooth surface. The hue shift was a post processing effect created in DaVinci Resolve.

Viscosity Solver Improvements

The viscosity solver has undergone some structural changes to improve accuracy in the solver set up and how memory laid out. Changes like these, especially in a solver, can be a source of new bugs. If testing today’s experimental version, please let us know about any issues when using the viscosity feature such as crashes, error messages, or unexpected behaviour.

Bug Fix: Stream Velocity Bias

I was finally able to solve a long-standing bug in the viscosity solver where low viscosity streams would have a large noticeable velocity bias in the positive X/Y/Z direction. This bug was reported 21 months ago (issue #455)! I had tried a few times in the past to fix this, but with no success until recently.

To take another shot at this issue, I started by re-writing the viscosity solver from the start. During this re-write, I had noticed a simple mistake in the code. Part of the solver requires shifting the offset of a grid position by half of a voxel width. The mistake I made was that I had applied this offset twice in different areas of the code (and in different files), leading to a total offset of 1 voxel instead of half of a voxel. This is what caused the stream to always have a bias in the +X/+Y/+Z direction.

Viscosity stream bias bug

Viscosity Accuracy Option

The viscosity solver works by running a loop where each iteration improves on the ‘solution’ to the viscosity equation. There is an internal ‘error tolerance threshold‘ within the viscosity solver that is used to determine when the solver should stop running the loop. The more iterations that are run, the more accurate the solution is, but this also takes longer to compute.

During some testing, I noticed that you could get away with a much higher error tolerance in some situations. We’ve added an Accuracy setting to allow for user control over the error tolerance.

Viscosity solver accuracy setting

Decreasing the accuracy can greatly speed up a simulation. For example, the Viscous Net example scene ran in about 5h10m at an accuracy of 4, and in 3h30m at an accuracy of 1. Note: the default value of 4 is the amount of error tolerance used internally in earlier versions of the addon.

Force Field Experimental Version

This new experimental version update contains some large structural changes to how fluid particles are managed and stored, how the viscosity solver functions, as well as adds some fixes to bugs.

Want to try out these updates? They can be tested in our Force Field Experimental Builds Package in the latest version!

Release Notes v9.0.9.15 (03-MAR-2021)

  • Similar to the last experimental release, this version contains large structural changes in how the simulator functions which may be a potential source of bugs. Please let us know if you are experiencing any of the following issues:
    • Crashes or error messages during baking.
    • Out of Memory errors or simulations using an unusually large amount of memory.
    • Inability to pause, resume, or upscale a simulation.
    • Error messages when using a cache created by an older addon version.
  • Safety Factor (CFL Number) setting in the FLIP Fluid Advanced panel has moved from the Simulation Stability section to the Frame Substeps section. The Safety Factor option is more closely related to how the simulator calculates adaptive substeps.
  • Added an operator to the FLIP Fluid Helper sidebar menu to generate a Windows batch file (.bat) to command line render each frame of an animation one by one.
    • Operator will detect already rendered frames in the output directory and disregard these from the batch file.
    • Upon a render crash, the batch file will start up Blender again and begin rendering the next frame. In this way, you can minimize unrendered frames if your system is prone to render crashes.
    • Can be used outside of the FLIP Fluids addon to render a sequence of frames individually. There are some bugs in Blender which can cause an animation to be rendered incorrectly and a workaround to these issues is to render each frame one by one.
  • Viscosity Solver Improvements
    • Large structural changes to the viscosity solver code and memory layout. Please let us know about any baking crashes, error messages, or incorrect behaviour.
    • Bug Fix: Fixed issue where low viscosity streams would have a velocity bias in the positive X/Y/Z direction (issue #455).
    • Improved accuracy of viscosity solver setup.
    • Added an Accuracy option to the viscosity solver to control the solver error tolerance.
      • Decrease to speed up baking at the cost of accuracy. Increase to improve accuracy at the cost of baking speed. High viscosity thick or stiff fluids benefit the most from increasing accuracy. Low viscosity thin fluids often work well at the lowest accuracy. Setting above a value of 4 may have greatly diminishing returns on improvement.
      • The default value of 4 is the same amount of error tolerance used internally in previous versions.
  • Bug Fix: Fixed issue where disabling the whitewater feature and resuming a simulation would result in invalid whitewater cache files being generated in the cache directory.
  • Bug Fix: Fixed typo in code that would cause an error that would prevent a helpful error message from being displayed (Pull Request Here).
  • Bug Fix: Fixed UI issue where the Resume From Frame X label could be displayed in red text instead of the default white.

What’s Coming Next?

With the last few updates, there are have been some large changes in the code to allow for attaching custom attributes to particles and exporting attributes to the simulation cache. We’ll start by adding an optional ‘lifetime’ attribute to the fluid particles to control when generated particles should expire.

We’ll be updating with a new stable version of the addon in early April. And this version will have a nice ‘surprise‘ feature for you to play with 🙂