SPH
Examples

Example 1: Hello asteroid!

This example only creates a single asteroid with default material settings and runs a simulation with default settings for 1 second. Not a very interesting simulation, but it shows a minimal code necessary to run it.

View example

Example 2: Creating the Death Star

Here we show how to create an asteroid with custom shape. Specifically, we create a spherical asteroid with a large spherical crater on a surface (a "Death Star"). This can be easily generalized to create an arbitrary shape, provided it can be described using IDomain interface.

The example shows how to:

  • Implement a custom domain and use it to generate a body with arbitrary shape
Note
Check out the implemented domains (DomainEnum) before creating a custom domain.

View example

Example 3: Van der Waals equation of state

We show how to implement a custom equation state in the code. All equations of state derive from IEos interface, it is also necessary to manually create a material intead of having the material created from BodySettings parameters.

Many components of the code is designed in such a way that we can either specify it in BodySettings or RunSettings and let the code create it for us, or we can create a custom component and pass it into the constructor of the parent component. This example demonstrates how to do this for the EoS: we can either set the value of BodySettingsId::EOS, or we can add our custom EoS to the material.

The example shows how to:

  • Implement a custom EoS and plug it into the code
  • Create a body with arbitrary material
Note
Check out the implemented equations of state (EosEnum) before creating a custom one.

View example

Example 4: Simple collision

We finally create a minimalistic impact experiment. Using InitialConditions object, we create two bodies - the target and the impactor - and fire the impactor towards the target at 5 km/s. The example uses default SPH solver and does not include gravity.

The example shows how to:

  • Create multiple bodies in the simulation with generally different materials
  • Modify the velocities of the created bodies

View example

Example 5: Fragmentation and Reaccumulation

While it's ofter sufficient to run a single simulation, there are cases where we need to chain multiple simulations together. Here, we show how to implement a two-phase simulation. First phase is an impact and fragmentation of the asteroid, integrated using the default SPH solver, the second phase is a gravitational reaccumulation of the fragments, which is a solved using N-body solver.

The example shows how to

  • Access and modify the particle data
  • Convert the output of the fragmentation phase to the input of the reaccumulation (so called "hand-off")

View example

Example 6: Heat diffusion

The code is mostly specialized for SPH simulations, but it can be utilized for other computations as well. As long as explicit timestepping is sufficient and our solver can be implemented using ISolver interface, we can easily plug it to the framework. In the previous example, we showed how to use the code for N-body simulations (using NBodySolver), here we solve a one-dimensional heat diffusion equation using finite difference method.

We model a surface of an asteroid, periodically illuminated by the Sun as asteroid rotates. Only the vertical direction is modeled for simplicity. The output of the simulation is the surface temperature as a function of time. We see how the solution is relaxed to periodical function.

The example shows how to:

  • Create a custom solver and use it in the code
  • Implement and access a custom material
  • Customize the log messages and periodically save arbitrary data from the simulation to disk

View example