Friends of tinySG, computational fluid dynamics has been in tinyScenegraphs project queue for a long time. In August 2013, a first milestone was reached with the GPU-based voxeliser. Two months later it is time to harvest some fruits grown on top of this base technology: Computational Fluid Dynamics (CFD) on polygonal models, calculated directly in tinySG.
The crowd of plugins for tinySG's scenegraph editor has grown by yet
another member, the tinyFluids plugin: It provides an interface
to the tinyFluids solver library as well as pre- and postprocessing
capabilities on scene- and simulation data.
Pre-Processing scene dataThe preprocessing step involves creating a simulation domain on a loaded scene. This basically involves the definition of (sub-)volume boundaries of the scene where fluid dynamics computations shall be performed. It also includes simulation parameter definitions like the direction and magnitude of flow or resolution (accuracy) of the simulation, as well as transformation of polygonal scene data into finite elements suitable for physics calculations.
Running a simulationRunning a simulation is all about selecting a solver and feeding it with parameters determined in the preprocessor step. The tinyFluids solver can run on either the CPU cores using OpenMP or the GPU using OpenGL compute shaders.To aid easy simulation domain setup, the solver may run with "empty" border cells, so that the fluid may flow around the specified simulation domain. A running simulation may update the scene with intermediate results regularly, so the user can verify early on that the parameters converge against a reasonable result or choose to abort before the maximum simulation step count is reached.
Once the simulation has finished, it's results may be saved to a vti file
for later re-import or analysis with the visualisation toolkit VTK.
Post-Processing simulation dataFinally, the post processor visualises the simulation results as the last step in simulation. A simulation may produce a scalar pressure field, a field of velocity vectors, temperature gradients, and many more results. tinyFluids aids all these applications of CFD by providing visualisation methods for both scalar and vector fields in both 2D and 3D, involving
PerformanceSince the tinyFluids solver may run on either the CPU or the GPU, performance comparisons between the two architectures are possible. The results are particularly interesting, because the CFD algorithm scales very well with available compute resources. If you ever wondered what use to make of all your CPU cores, here is an application that could set hundreds of cores under fire.The charts below show the CPU scalability for a number of different machines with very different price tags. The x-axis enumerates the processor type, along with the number of available cores. The z-axis specifies the number of cores being used for the simulation. The y-axis shows the total simulation run time in seconds on 800 iterations over 90,000 cells (lower values are better). Please note that the comparison is not entirely fair: Processors spread over various generations from Nehalem to Ivy Bridge, the T1090 ran on Linux, while all other systems utilised Windows 7. Nevertheless, the chart gives a good overview on scalability and a rough impression on relative system performance. OutlookAs always, there is much more left to do: The next step is definitely going to be a GPU implementation of the solver, using either OpenGL compute shaders or OpenCL. The algorithm should be a perfect match for a parallel implementation, using the full computational power of a GPU. It will be interesting to see how GPUs perform compared to an OpenMP implementation running on the CPU's cores.The fluid model used in tinyFluids is limited to special cases and cannot simulate turbulent flows. There are many extensions described in scientific papers that wait for their implementation. Furthermore, having this great solver code available, it should be interesting to utilise it for some more physics use cases, like heat dissipation or simulation of distribution of sound. Finally, I cannot neglect to concede that this project made some appetite for more physics. A likely candidate is the integration of the bullet physics engine into tinySG, taking care of some rigid body collisions/simulations.
Keep rendering, Acknowledgements and links:
Copyright by Christian Marten, 2009-2014 Last change: 03.11.2013 |