Skip to content

8. How to modify DualSPHysics for your application

Alejandro J. C. Crespo edited this page Mar 24, 2020 · 3 revisions

Modification of the source code

The presentation "Developing on DualSPHysics: examples on code modification and extension" by O. García-Feal given at the 4th DualSPHysics Users Workshop 2018 shows how to add new functionalities to DualSPHysics.

The resulting code is an official branch of the DualSPHysics repository in Github.

This presentation is also available in doc/guides.



Creating new cases

There are some files with more information that will guide users to create their own cases:

  • XML_GUIDE_v5.0.pdf in doc/guides.
  • ExternalModelsConversion_GUIDE.pdf in doc/guides.
  • The folder doc/xml_format contains templates: CaseTemplate.xml and _FmtXML_XXX.xml.


Source files of the SPH solver

To add new formulation or changes, the following files (in src/source) are the ones that require your attention:

CPU and GPU executions:

  • main.cpp
  • JCfgRun (.h .cpp)
  • JSph (.h .cpp)
  • JSphMk (.h .cpp)
  • JPartsLoad4 (.h .cpp)
  • JPartsOut (.h .cpp)
  • ParticlesDef.h
  • Types.h

For only CPU executions:

  • JSphCpu (.h .cpp)
  • JSphCpu (.h .cpp)
  • JSphCpuSingle (.h .cpp)
  • JCellDivCpu (.h .cpp)
  • JCellDivCpuSingle (.h .cpp)

For only GPU executions:

  • JSphGpu (.h .cpp)
  • JSphGpu_ker (.h .cu)
  • JSphGpuSingle (.h .cpp)
  • JCellDivGpu (.h .cpp)
  • JCellDivGpu_ker (.h .cu)
  • JCellDivGpuSingle (.h .cpp)
  • JCellDivGpuSingle_ker (.h .cu)

Please read Section 6.2 for a complete description of these files.



Example code “ToVtk”

The release includes not only the source files of DualSPHysics v4.4 but also the source files of a code named “ToVtk”. This code is provided to show how to load and interpret particle data, how to read .bi4 files and how to create .vtk or .csv files.



New variables defined by the user in DualSPHysics and in the post-processing tools

In the actual code, the particle data to be stored in the .bi4 files are: id, position, velocity and density. Other magnitudes such as mass, pressure, acceleration, vorticity, etc are computed starting from the first ones using the post-processing tools. However, the .bi4 format allows adding new arrays with particle data defined by the user, which can be managed by the post-processing codes.

Therefore, in order to store new data arrays in the .bi4 files, the user should follow the example included in the source files of DualSPHysics. The example is included in the function SavePartData() in the file JSph.cpp and shows how to store (in .bi4) an array with pressure of the particles computed starting from density. This example is explained here:

The new data arrays introduced by the users in the .bi4 files are recognized by the post-processing tools (PartVTK4, MeasureTool4 y IsoSurface4). If we want to obtain these data in VTK or CSV files, then the option –vars:name should be used.

Following, an example with PartVTK4 to obtain the data “pressure” is shown:

PartVTK4_win64.exe –dirin . -savevtk parts –vars:pressure