SPH Fluid Simulation | DevLog
Video: Simulating a planetary collision using a new method called smoothed-particle hydrodynamics (SPH).
Hopefully by now you’ve had time to check out Surface Grids & Lasers | Update 24 of Universe Sandbox. If you haven’t, time to get out from that rock you’ve been living under and start terraforming all those other rocks floating through space.
We plan to continue to add to the Surface Grids feature with even more detailed surface simulation through next year and beyond. Surface Grids is a massive new feature that changes a lot with the core simulation of objects in Universe Sandbox, and so far we’ve just scratched the surface of what it can do. We’re excited to explore its possibilities even more.
But right now, let’s turn our attention to something our physics developer, Alexander, has been working on. Introducing… smoothed-particle hydrodynamic fluid simulation. Let’s just call it SPH for now.
SPH is NOT included in Universe Sandbox yet. This is a behind-the-scenes look at a feature that we are still working on.
What is SPH and how does it work?
For a deep dive into the mechanics of SPH, check out this paper from our very own physics developer, written back in 2010 (interestingly, not written in relation to Universe Sandbox, but for another project that was similar in many ways — there’s a reason why we hired him many years ago to help build this new version of Universe Sandbox, and it had more to do with relevant experience than it did with his propensity for typos… *wink*).
Or if you’re curious about SPH, but perhaps not curious enough to read 35 pages on it, here’s a crash course:
SPH is a computational method commonly used for modeling fluids (though it can also handle solids). That might make you think that we’d use this for simulating something like water flow on a planet’s surface, but “fluid” here actually has more to do with simulating much larger objects.
On an astronomical scale, many of the objects you can simulate, like stars and galaxies, behave like fluids. This is also true for planets, whether it’s a gas giant or a rocky planet with, or even without, a molten core. And even in the case of large chunks of solid rock colliding with each other, there is such intense temperature and pressure that the materials behave more like fluid rather than rigid solids: they’ll stretch and distort and be torn apart, rather than splinter, crack, and shatter.
So in short, SPH will help create more detailed, realistic simulations of collisions, fragmentation, and formation of different types of objects in Universe Sandbox.
How? First, the material, such as a planet, is broken into a number of “particles” that each have properties such as mass, temperature, velocity, and position. You can see these particles clearly in any of the videos in this post.
But the “smoothed” part of “smoothed-particle hydrodynamics” means that these particles are just sample points of what is actually a continuous material, where they each contribute to the properties at a given point based on a weighted, smoothed, average. Together, they describe the properties that exist at any given point in a flow of material, but they themselves are not the material. Think of it like buoys in an ocean: the buoys will each monitor the properties at their location, and they are distinct from the continuous fluid, ie the ocean, that they are monitoring. So for the future of SPH in Universe Sandbox, the current debugging visuals, where you can see individual particles, will ideally be replaced by something that better represents the continuous fluid that is actually being modeled.
By tracking how each of these particles move, and more importantly how they move in relation to their neighbors, you can calculate pressure and viscosity (friction) at any point in
the fluid. And then you can estimate how this will move over time under different forces. Combine this with gravity and you start to see a simulation with emergent behavior that matches what we observe in real life.
Why SPH?
Because you get accurate simulation with emergent behavior, rather than disparate modeling of phenomena that needs to be stitched together. For example, with SPH, material will collect under the influence of gravity, but it will not all fall to the center of mass. Instead, as more material collects, the pressure increases and starts pushing out material, preventing a total collapse. The result is a spherical shape, and not because we specifically told it to become a sphere, but because that’s what happens when you simulate physics on a more granular level.
Or look at the case of Roche fragmentation, where a moon may be torn apart from the gravity of its host object “pulling” more on its near side than its far side. In our current simulation, pre-SPH, where we model how single points of mass move purely under the influence of gravity, we need special handling to calculate when and how this should happen, according to analytical models. But with SPH, this phenomenon just happens as the result of forces acting on the moon.
Why SPH specifically and not another method? When simulating space, there is more literal space than there is simulated material. SPH is great for handling cases like this where material is sparse. Other methods instead require simulating each point of space, seeing how each of these points changes (versus tracking only points specifically in a material), which would be very slow for anything like entire star systems.
Universe Sandbox is a unique physics simulator because we aim to make it an accessible, real-time, interactive experience. When compared to non-real-time simulations run on supercomputers, this presents a lot of limitations, and SPH is not immune to these. The biggest issue we will need to navigate as we continue development is the resolution of the model — to be really accurate and demonstrate smaller, local changes, you need a lot of sample points. But each point comes at the cost of a good chunk of computing power. So as with all features in Universe Sandbox, we’ll need to find a balance, with enough points to model things in interesting ways, but not so many that it becomes a slideshow.
So… what does it do?
Technical explanations are fun (…did I get that right?), but what you really want to know is what does this SPH thing mean for me and my planets? That’s also answered above: it will help create more detailed, realistic simulations of collisions, fragmentation, and formation of different types of objects in Universe Sandbox. But what you really, really want is a bunch of videos of this is in action. Understandable.
Quick disclaimer: SPH is a feature in its early stages of development. Visuals are for debugging purposes. Anything shown many not be representative of how it’ll appear and behave when included in an official Universe Sandbox update.
Two equal-sized bodies showing pulsating behavior as pressure and gravity tries to find a balance.
Two earths spinning the same direction and colliding. The result is a combined body with non-zero angular momentum from the individual momentums adding together in the same direction.
Increasing the density and speed of Mars before it impacts Earth and shoots right through it.
The existing simulation “Earth & Moon x25 Offset” showing all Earths collapsing and combining.
Results of the Moon fragmenting around Earth.
So in short, SPH will improve or make possible simulations of the following:
- Total fragmentation
- Tidal deformation and Roche fragmentation
- Accretion disks / object formation from debris
- Giant-impact hypothesis (moon formation!)
And in the longer term, we hope to apply it elsewhere, including more accurate galaxy collisions and star formation.
What’s Next
As you can see, SPH is already working pretty well within Universe Sandbox. But you can also see that it’s not exactly integrated with everything else yet. The visuals right now are intended solely for debugging purposes, and the transition from our standard planet visuals to the SPH particles is a little rough. Making visuals that look more like molten planets being torn apart will definitely take time, but we have some ideas in mind that we’re excited to explore.
The visuals are just one component of what we’ll need to work on to integrate SPH with Universe Sandbox. Making it work with other complex aspects of the simulation, like the new Surface Grids feature, will be its own can of worms. But we’re no strangers to technical challenges. And since we think SPH is worth experimenting with on its own, we hope to release an early version of it using the debug visuals and let you turn it on if you’re interested in checking it out. We don’t know when this will happen yet, but hopefully not too long into next year.
And hopefully before then, we’ll have a small update ready that will add some oft-requested color customization…
Last Updated: November 14, 2022
about 4 years ago
Please add it as soon as you can! It would be PERFECT for my book! It would be also interesting add it to simulate interstellar impacts with all thermodynamics into! I dont care if my computer will do all the calculations in 3 days.
about 4 years ago
this would be great as currently, you cant create rocheworlds. this would make the really nice elongated merging planets i wanted.