Examples of distributed vector usage

Vector 0: Simple vector initialization

This example show several basic functionalities of the distributed vector vector_dist. The distributed vector is a set of particles in an N-dimensional space. In this example it is shown how to:

The source code of the example Vector/0_simple/main.cpp. The full doxygen documentation Vector_0_simple.

See also our video lectures dedicated to this topic Video 1, Video 2


Example 1: Vector Ghost layer

This example shows the properties of ghost_get and ghost_put - functions that synchronize the ghosts layer for a distributed vector vector_dist.

In this example it is shown how to:

The source code of the example Vector/1_ghost_get_put/main.cpp. The full doxygen documentation Vector_1_ghost_get.


Example 2: Cell-lists and Verlet-lists

This example shows the properties of ghost_get and ghost_put - functions that synchronize the ghosts layer for a distributed vector vector_dist.

Key points:

The source code of the example Vector/1_celllist/main.cpp. The full doxygen documentation Vector_1_celllist.


Example 3: GPU vector

This example shows how to create a vector data-structure with vector_dist_gpu to access a vector_dist-alike data structure from GPU accelerated computing code.

Key points:

The source code of the example Vector/1_gpu_first_step/main.cpp. The full doxygen documentation Vector_1_gpu_first_step.


Example 4: HDF5 Save and load

This example show how to save and load a vector to/from the parallel file format HDF5.

Key points:

The source code of the example Vector/1_HDF5_save_load/main.cpp. The full doxygen documentation Vector_1_HDF5.


Example 5: Vector expressions

This example shows how to use vector expressions to apply mathematical operations and functions on particles. The example also shows to create a point-wise applicable function

where $A_q$ is the property $A$ of particle $q$, $x_p, x_q$ are positions of particles $p, q$ correspondingly.

Key points:

The source code of the example Vector/2_expressions/main.cpp. The full doxygen documentation Vector_2_expression.


Example 6: Molecular Dynamics with Lennard-Jones potential (Cell-List)

This example shows a simple Lennard-Jones molecular dynamics simulation in a stable regime. The particles interact with the interaction potential

$A_q$ is the property $A$ of particle $q$, $x_p, x_q$ are positions of particles $p, q$ correspondingly, $\sigma$ is a free parameter, $r$ is the distance between the particles.

Key points:

The source code of the example Vector/3_molecular_dynamic/main.cpp. The full doxygen documentation Vector_3_md_dyn.


Example 7: Molecular Dynamics with Lennard-Jones potential (Verlet-List) [1/3]

The physical model in the example is identical to Molecular Dynamics with Lennard-Jones potential (Cell-List). Please refer to it for futher details. Key points:

The source code of the example Vector/3_molecular_dynamic/main_vl.cpp. The full doxygen documentation Vector_3_md_vl.


Example 7: Molecular Dynamics with Lennard-Jones potential (Symmetric Verlet-List) [2/3]

This example is an extension to Molecular Dynamics with Lennard-Jones potential (Verlet-List). It shows how better performance can be achieved for symmetric interaction models with symmetric Verlet-list compared to the standard Verlet-list. Key points:

The source code of the example Vector/5_molecular_dynamic_sym/main.cpp. The full doxygen documentation Vector_5_md_vl_sym.


Example 7: Molecular Dynamics with Lennard-Jones potential (Symmetric CRS Verlet-List) [3/3]

This example is an extension to Molecular Dynamics with Lennard-Jones potential (Verlet-List) and Molecular Dynamics with Lennard-Jones potential (Verlet-List). It shows how better performance can be achieved for symmetric interaction models with symmetric Verlet-list compared to the standard Verlet-list. Key points:

The source code of the example Vector/5_molecular_dynamic_sym/main.cpp. The full doxygen documentation Vector_5_md_vl_sym.


Example 8: Molecular Dynamics with Lennard-Jones potential (GPU)

The physical model in the example is identical to Molecular Dynamics with Lennard-Jones potential (Cell-List) and Molecular Dynamics with Lennard-Jones potential (Verlet-List). Please refer to those for futher details. Key points:

The source code of the example Vector/3_molecular_dynamic_gpu/main_vl.cpp. The full doxygen documentation Vector_3_md_dyn_gpu.


Example 9: Molecular Dynamics with Lennard-Jones potential (GPU optimized)

The physical model in the example is identical to Molecular Dynamics with Lennard-Jones potential (Cell-List), Molecular Dynamics with Lennard-Jones potential (Verlet-List) and is based on Molecular Dynamics with Lennard-Jones potential (GPU). Please refer to those for futher details. Key points:

The source code of the example Vector/3_molecular_dynamic_gpu_opt/main_vl.cpp. The full doxygen documentation Vector_3_md_dyn_gpu_opt.


Example 10: Molecular Dynamics with Lennard-Jones potential (Particle reordering)

The physical model in the example is identical to Molecular Dynamics with Lennard-Jones potential (Cell-List), Molecular Dynamics with Lennard-Jones potential (Verlet-List). The example shows how reordering the data can significantly reduce the computational running time. Key points:

The source code of the example Vector/4_reorder/main_data_ord.cpp. The full doxygen documentation Vector_4_reo.


Example 11: Molecular Dynamics with Lennard-Jones potential (Cell-list reordering)

The physical model in the example is identical to Molecular Dynamics with Lennard-Jones potential (Cell-List), Molecular Dynamics with Lennard-Jones potential (Verlet-List). The example shows how reordering the data can significantly reduce the computational running time. Key points:

The source code of the example Vector/4_reorder/main_comp_ord.cpp. The full doxygen documentation Vector_4_comp_reo.


Example 12: Complex properties [1/2]

This example shows how to use complex properties in the distributed vector vector_dist

Key points:

The source code of the example Vector/4_complex_prop/main.cpp. The full doxygen documentation Vector_4_complex_prop.


Example 13: Complex properties [2/2]

This example shows how to use complex properties in the distributed vector vector_dist

Key points:

The source code of the example Vector/4_complex_prop/main.cpp. The full doxygen documentation Vector_4_complex_prop_ser.


Example 14: Multiphase Cell-lists and Verlet-lists

This example is an extension to Example 2: Cell-lists and Verlet-lists and ()[]. It shows how to use multi-phase cell-lists and Verlet-list using multiple instances of vector_dist. Key points:

The source code of the example Vector/4_multiphase_celllist_verlet/main.cpp. The full doxygen documentation Vector_4_mp_cl.


Example 16: Validation and debugging

This example shows how the flexibility of the library can be used to perform complex tasks for validation and debugging. Key points:

The source code of the example Vector/6_complex_usage/main.cpp. The full doxygen documentation Vector_6_complex_usage.


Example 17: Smoothed Particle Hydrodynamics (SPH) formulation on CPU [1/2]

This example shows the classical SPH Dam break simulation with Load Balancing and Dynamic load balancing. The example has been adopted from DualSPHysics. Please refer to the website of DualSPHysics and to the paper of Monaghan, 1992 for more details.

SPH Dam break simulation

Formulation

The SPH formulation used in this example code follow these equations

with the the viscosity term

and the constants defined as

The cubic kernel $W_{ab}$ defined as

its gradient $ \nabla W_{ab} $.

While the particle kernel support is given by

where $dp$ is the particle spacing. Please refer to the work of Monaghan, 1992 for more details on the variables and constants used.

The simulation uses an additional Tensile term to avoid the tensile instability. Please refer to Monaghan, 1999 for more details on this scheme.

Time-stepping

Dynamic time stepping is calculated in accordance with Monaghan, 1992

where

With the governing equations are written as

The Verlet time-stepping scheme Verlet, 1967 is used

Due to the integration over a staggered time interval, the equations of density and velocity are decoupled, which may lead to divergence of the integrated values. See DualSPHysics formulation.

Load Balancing

Domain decomposition multi-colored subdomains

In order to reach an optimal utilization of available computational resource we distribute the particles to reach a balanced simulation. To do this we set weights for each sub-sub-domain, decompose the space and distribute the particles accordingly.

The weights are set according to:

where $N_{fluid}$ Is the number of fluid particles in a sub-sub-domain and $ N_{boundary} $ is the number of boundary particles.

Implicitly the communication cost is given by $ \frac{V_{ghost}}{V_{sub-sub}} t_s $, while the migration cost is given by $ v_{sub-sub} $. In general $ t_s $ is the number of ghost_get calls between two rebalance calls.

Dynamic load balancing. Theory 1
Dynamic load balancing. Theory 2
Dynamic load balancing. Practice 1
Dynamic load balancing. Practice 2

Simulation results

Simulation video 1
Simulation video 2
Simulation dynamic load balancing video 1
Simulation dynamic load balancing video 2
Simulation countour prospective 1
Simulation countour prospective 2
Simulation countour prospective 3

Key points:

The source code of the example Vector/7_SPH_dlb/main.cpp. The full doxygen documentation Vector_7_sph_dlb.


Example 17: Smoothed Particle Hydrodynamics (SPH) formulation on CPU: optimized [2/2]

The physical model in the example is identical to Example 17: Smoothed Particle Hydrodynamics (SPH) formulation on CPU.

Key points:

The source code of the example Vector/7_SPH_dlb_opt/main.cpp. The full doxygen documentation Vector_7_sph_dlb_opt.


Example 18: Smoothed Particle Hydrodynamics (SPH) formulation on GPU [1/3]

The physical model in the example is identical to Example 17: Smoothed Particle Hydrodynamics (SPH) formulation on CPU with the computation-heavy subroutines being executed on GPU.

Simulation results

Simulation video 1
Simulation video 2
Simulation video 3

Key points:

The source code of the example Vector/7_SPH_dlb_gpu/main.cu. The full doxygen documentation Vector_7_sph_dlb_gpu.


Example 18: Smoothed Particle Hydrodynamics (SPH) formulation on GPU: optimized [2/3]

The physical model in the example is identical to Example 18: Smoothed Particle Hydrodynamics (SPH) formulation on GPU with the computation-heavy subroutines being executed on GPU optimized for improved coalesced memory access.

Key points:

The source code of the example Vector/7_SPH_dlb_gpu_opt/main.cu. The full doxygen documentation Vector_7_sph_dlb_gpu_opt.


Example 18: Smoothed Particle Hydrodynamics (SPH) formulation on GPU: opetimized [3/3]

The physical model in the example is identical to Example 18: Smoothed Particle Hydrodynamics (SPH) formulation on GPU: optimized with the computation-heavy subroutines being executed on GPU optimized for improved coalesced memory access and particle force calculation performed in 2 steps.

Key points:

The source code of the example Vector/7_SPH_dlb_gpu_more_opt/main.cu. The full doxygen documentation Vector_7_sph_dlb_gpu_opt.


Example 19: Discrete Element Method (DEM) simulation of the avalanche down the inclined plane

This example implements a Discrete Element Method (DEM) simulation using the Lorentz-force contact model.

Discrete Element Method (DEM) simulation of the avalanche down the inclined plane

A classical model for DEM simulations of spherical granular flows is the Silbert model, it includes a Herzian contact force and an elastic deformation of the grains. Each particles has a radius $R$, mass $m$, polar momentum $I$ and is represented by the location of its center of mass $r_{i}$.

When two particles $i$ and $j$ collide or are in contact, the elastic contact deformation is given by:

where $\vec{r_{ij}}$ is the distance vector connecting particle centers and $r_{ij} = {\lvert \vec{r}_{ij}\rvert}_2$ its module. The normal and tangential components of the relative velocity at the point of contact is given by

with $\vec{n_{ij}}=\vec{r_{ij}}/r_{ij}$ is the normal unit vector in direction of the distance vector, $\vec{\omega_i}$ is the angular velocity of a particle and $\vec{v_{ij}}=\vec{v_i}-\vec{v_j}$ the relative velocity between the two particles. The evolution of the elastic tangential displacement $\vec{u_{t_{ij}}}$ is integrated when two particles are in contact using:

Where $\delta t$ is the time step size. The deformation of the contacts points is stored for each particle and for each new contact point the elastic tangential displacement is initialized with $\vec{u_{t_{ij}}} = 0$. Thus for each pair of particle interacting the normal and tangential forces become:

where $k_{n,t}$ are the elastic constants in normal and tangential direction, respectively, and $\gamma_{n,t}$ the corresponding viscoelastic constants. The effective collision mass is given by $m_{\text{eff}}=\frac{m}{2}$. For each contact point in order to enforce Coulomb's law

the tangential force is bounded by the normal component force. In particular the elastic tangential displacement $\vec{u_{t_{ij}}}$ is adjusted with

This adjustment induce a truncation of the elastic displacement. The Coulomb condition is equivalent to the case where two spheres slip against each other without inducing additional deformations. Thus the deformation is truncated using:

Considering that each particle $i$ interact with all the particles $j$ is in touch with , the total resultant force on particle $i$ is then computed by summing the contributions of all pair particles $(i,j)$. Considering that the grains are also under the effect of the gravitational field we obtain that the total force is given by

where $\vec{g}$ is the acceleration due to gravity. Because particles has also rotational degree of freedoms, the total torque on particle $i$ is calculated using

$\vec{r}_i$ and angular velocities $\vec{\omega}_i$ for each particle $i$ at time step $n+1$, We integrate in time the equations using leap-frog scheme with time step given by

where $\vec{r}_i^{n},\vec{v}_i^{n},\vec{\omega}_i^{n}$ denotes respectively the position, the speed and the rotational speed of the particle $i$ at time step $n$, and $\delta t$ the time step size.

Simulation results

Simulation video 1

Key points:

The source code of the example Vector/8_DEM/main.cpp. The full doxygen documentation Vector_8_DEM.


Example 20: GPU CUDA interoperability

This example shows how to access and operate data arrays in GPU kernels via memory pointers obtained from distributed data-structures.

Key points:

The source code of the example Vector/9_gpu_cuda_interop/main.cu. The full doxygen documentation 9_gpu_cuda_interop.