Tutorials - EPhysLab-UVigo/VisualSPHysics GitHub Wiki

Floating box

In this case we are going to simulate a floating box moved by the action of the waves produced by a piston. This case is included in the official package of DualSPHysics . You can find extra documentation about this case in the official guide or the WIKI.

In this case it is assumed that you have installed VisualSPHysics addon for Blender, if not, you can check the installation page of this wiki.

Remember to save your project frequently to avoid loosing your work if something crashes!!

  1. So, once we have unzipped the DualSPHysics package, go to the DualSPHysics_v4.2\examples\main\11_Floating folder.
  2. Open the CaseFloating_Def.xml with a text editor. Then modify the line <definition dp="0.1" units_comment="metres (m)"> and set the parameter dp to 0.25. In this way we will reduce the number of particles, so the simulation will run faster and it will be easier to learn.
  3. We will also modify the writing time step. We will make an animation with 24fps, so we will modify the line <parameter key="TimeOut" value="0.1" comment="Time out data" units_comment="seconds" /> and change the value parameter to 0.04.
  4. Now we can run the simulation. If you have a Nvidia GPU run the script wCaseFloating_win64_GPU.bat if not wCaseFloating_win64_CPU.bat. There are also scripts for GNU/Linux! (xCaseFloating_linux64_GPU.sh and xCaseFloating_linux64_CPU.sh).
  5. Once we have run the simulation script, we can load it into Blender. So open Blender and create a new project.
  6. Delete the existing cube of the scene. For this select it with right mouse button, press x key and enter key.
  7. Now we will import the isosurface of the water. So press Shift+A, go to Mesh and click on DualSPHysics object. Go to DualSPHysics_v4.2\examples\main\11_Floating\CaseFloating_out\surface folder. On the lower left part of the window, check Object Type: Fluid Object, Smooth Shading and Validate mesh. Now double click on any Surface_XXXX.vtk file to import the sequence.
  8. Now we will import the floating box in a very similar way. So press Shift+A, go to Mesh and click on DualSPHysics object. Go to DualSPHysics_v4.2\examples\main\11_Floating\CaseFloating_out\boundary folder. On the lower left part of the window, check Object Type: Other and Transfer UV Maps. Now double click on any Surface_XXXX.vtk file to import the sequence.
  9. We can see that if we click on the timeline an change frame, the isosurface and the cube position are updated.
  10. Now we are going to make the foam simulation. For this we will open the system console, here we can see the simulation progress and details. In order to open it, just go to Window menu and click on Toggle System Console. If you are running Blender from GNU/Linux, this option is not available, in order to see the system console, just open a terminal and launch Blender from it by typing blender.
  11. Select the water body by right clicking on it. Now, in the Physics panel, you can find a section named DualSPHysics foam simulation. Here, we will make some modification:
  12. Input Path: here we will introduce the folder were the particle vtk files are placed (C:\path\to\DualSPHysics_v4.2\examples\main\11_Floating\CaseFloating_out\particles\).
  13. Input Prefix: the name prefix of the particle vtk files (PartFluid_).
  14. Ouput Path: select a folder were the foam vtk files will be placed.
  15. Output Prefix: the name of the foam vtk files (optional).
  16. XML: here, select the XML file generated by gencase C:\path\to\DualSPHysics_v4.2\examples\main\11_Floating\CaseFloating_out\CaseFloating.xml.
  17. Set Ending step to 250.
  18. The default parameters will produce almost no foam particles in this case, so we will increase the Trapped air multiplier and Wave crests multiplier to 300.00. If this number is too low, no foam particles will be produced. But if it is too high, too much particles will be produced, so the simulation will be very slow and Blender could crash trying to load a huge amount of particles. So we have to play with this parameters, take a look to the system console to see number of particles produced e.g. [Stage 10] Append new particles! Total diffuse particles: XXXX.
  19. We will set Enable custom domain limits to avoid foam generation in the paddle zone. So we will set Min X to 2.00.
  20. Now click on Run Foam Simulation button to start the simulation. The Blender window will freeze during the process (this should be improved!), but you can see the log of the simulation on the system console.
  21. If you don't like the results, remember to delete the blender foam object before running the simulation again!
  22. Now you have your DualSPHysics simulation with foam in Blender. Now you can add some nice shaders for each object.
  23. The fluid simulation will look ugly because we employed a very low number of fluid particles. So once you have finished you can try a simulation with a lower dp like 0.1.