Blenderyard

December 28, 2014

DualSPHysics fluid visualization with Blender

Filed under: Blender — blenderyard @ 2:24 PM

CaseMonkey_vimeo

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.

Advertisements

5 Comments »

  1. It’d be great to have a tutorial on this method – I have downloaded DualSPhysics and am going through the docs but there is a lot to plow through..

    Comment by Steve — December 29, 2014 @ 6:14 PM

  2. This is amazing and exactly what I’m looking for! Could you please help me to figure out your workflow on this?

    Comment by orsatti — May 20, 2015 @ 6:03 PM

  3. Could you please share your scipt? it would be realy realy nice to have it. because i can not code. 🙂

    Comment by Paul — February 9, 2016 @ 11:51 AM

  4. We are playing with DualSPHysics right now. but the only way I was able to get an animation into blender was to export an STL sequence from Paraview and then import those files into a blender project and then offset an animation turning the visability of individual meshes on and off. Will you share your VTK script?

    Comment by Jacob Thorup — February 17, 2016 @ 6:04 PM

    • I’ve posted a comment regarding my findings. Should you be interested, find me at the included link to my linkedin profile.

      Comment by Filipe Dias — April 28, 2016 @ 10:12 PM


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: