December 28, 2014

DualSPHysics fluid visualization with Blender

Filed under: Blender — blenderyard @ 2:24 PM


The movie clip above is an experimental product out of a personal pilot project to investigate a CGI workflow that integrates DualySPHysics for GPU-accelerated particle-based fluid simulations and Blender for geometry definition and visualization.

Fluid dynamics simulations are popular Blender applications and visual outcomes are always fascinating.  Blender has a particle-based fluid simulator based on the so-called smoothed particle hydrodynamics (SPH) method.  The SPH simulation code in Blender offers an easy-to-use tool for fluid dynamics visualization.  The main drawback of the SPH implementation in Blender is efficiency, where an external GPU-accelerated SPH code like DualSPHysics comes in handy.

In the present case study, DualSPHysics 3.1 and Blender 2.72 were tested.  Blender was used for defining the simulation domain and the initial geometry of fluid particles.  The prepared mesh data was then exported in STL format and included as part of input parameters to the DualSPHysics program.  Fluid simulations were executed using an NVIDIA Quadro 4000 card on a desktop PC running 64-bit Windows 7.  Finally, polygonized simulation results in VTK format were imported back to Blender for animation rendering and video editing.  The first half of the video shows ray-traced water surface, whereas the second part presents the magnitude of fluid velocity.

Exporting STL files was done using a regular exporting function in Blender.  On the other hand, I was not able to find a working VTK mesh importer for the latest version of Blender, probably because VTK is a general-purpose scientific data format.  I ended up in having to write a VTK impoter myself.  Mesh format conversion was straightforward, while the magnitude of particle velocity was visualized through vertex colors in Blender.  A user-friendly GUI tool called the DualSPHysics Pre-processing Interface (part of the DualSPHysics package) was used for configuring simulation cases.  Before visualizing the SPH simulation results in Blender, ParaView was used for previewing a sequence of generated VTK polygon files.

Performance results of the simulation are summarized below:

  • Particle count: 2 877 560 particles (particle distance set to 0.01 meter).
  • Allocated memory: 1007.76 MB on GPU and 93.37 MB on CPU.
  • Execution time: 14.5 hours.
  • Simulated duration: 2.76 seconds (69 frames at the interval of 0.04 second).

For performance comparisons, a benchmark case (CaseWavemaker in the DualSPHysics package) was executed using the same GPU as well as with a quad-core CPU (Intel Xeon W3656 3.2 GHz).  The execution time for running the same benchmark case (161 809 particles) on GPU and on CPU was 45.68 minutes and 4.03 hours, respectively.  Although the CPU run was multi-threaded, the GPU run was more than 5 times faster.

In conclusion, DualSPHysics offers a reliable and efficient solution for particle-based fluid dynamics simulations in CGI applications for visual art and entertainment.

Related work: GPU-accelerated SPH codes

Besides DualSPHysics there are several GPU-accelerated SPH codes that are freely available, including:

Differences are mainly in features (e.g., support for floating objects) and implementations (obviously CUDA or OpenCL, and support for multiple GPU cards), as well as maturity (code stability, and availability of user friendly tools).

Related work: Particle meshers for Blender

Since SPH simulation results are represented by a number of particles, a particle mesher is necessary to convert the particles to surface meshes for visualization.  There are different approaches proposed to implement a particle mesher in Blender, including Python add-on scripts and built-in mesh modifiers based on metaballs, the OpenVDB library, or the algorithm called marching cubes (MC).

Metaball-based methods are easy to implement but do not scale.  OpenVDB-based methods are likely more efficient but introduce an external library dependency.  MC-based native implementations seem the most promising way to go but also most demanding in terms of coding.  As of this writing none of the options above is applicable to polygonization of millions of particles resulting from realistic SPH simulations.  An upside of DualSPHysics in this regard is that it comes with a fast and efficient MC-based particle mesher.


Create a free website or blog at