top of page
Untitled design (9).png

Magnetohydrodynamic
Simulation of the Sun

 Core simulation:
7 million points & 17 million voxels in under 5 hours

 

 
Josh Meister created custom solvers for electric and magnetic fields to drive particle interactions by implementing real world physics.  Using GridMarkets, he was able to simulate and render several orders of magnitude more detail than he could otherwise.

 

​​Explore the in-depth explanations below to uncover the details of the process or DOWNLOAD THE SCENE and try it yourself.

​

The goal was to capture the complex, magnetohydrodynamic behaviors of charged particles in and around the Sun.  Doing this meant writing custom solvers for electromagnetic fields and particle interactions, implementing equations and data from real-world measurements, and running simulations at a scale and resolution that would normally be out of reach for a typical workstation. 

​

By partnering with GridMarkets, I was able to leverage cloud-based computing and rendering resources to push the simulation far beyond my local capabilities.
 

by Josh Meister - Dec 2024

Untitled design (9).png

Realistic Simulation of the Sun

 

Simulation @ GridMarkets 

Credit: Josh Meister

​

Dark background write some formulas  in grey, like  the Lorentz force law F=q(E+v×B), repr


Core Solver and Equations

 

Writing a magnetohydrodynamic solver was a unique challenge.  The approach to creating such a solver in Houdini required extensive research and ingenuity. The core idea behind this solver is the interaction of charged particles with each other—both in a fluid sense and electromagnetically.  Basic fluid dynamics are handled easily using Houdini’s tools for pressure projection and particle advection, but the electromagnetic aspects required a fully custom setup.

​

Luckily, the equations governing these interactions are well understood and documented.​

​​

​As charged particles move, they generate an electromagnetic field around them, which can be decomposed into two vector fields - an electric field and a magnetic field.  â€‹Treating these as two separate vector fields simplifies the equations and allows for convenient implementation within Houdini.

​

Oliver Heaviside, an English mathematician from the late 19th century, derived the equations needed to calculate these fields directly from the motion of a charged particle, building on Coulomb’s law and the Biot–Savart law.  These equations are explained clearly in the following lecture: Electricity and Magnetism B-Fields from Moving Charges by Lana Sheridan (Feb 2018). You can run these formulas in a volume wrangle, looping over every charged particle in the simulation to create the electric and magnetic fields required for subsequent steps.

Once the electric and magnetic fields have been generated, the Lorentz force law: F=q(E+v×B) can be used to calculate the force exerted on the particles. In this equation:

  • q is the particle’s charge

  • v is its velocity

  • E is the electric field at the particle’s position

  • B is the magnetic field at the particle’s position.

​

This succinct yet powerful equation explains how particles are pushed in the direction of the electric field and experience a force perpendicular to both their velocity and the magnetic field.

​​

These components form the core mathematical framework needed to capture the interplay between the EM field and the charged particles that, in turn, shape the field itself. To implement these equations properly, careful consideration must be given to the units involved. Distance, time, and charge had to be chosen specifically for the large scale of this project, and fundamental constants were adjusted accordingly.

​

The Sun’s differential rotation also had to be accounted for as it plays a crucial role in the formation of the large-scale magnetic field. To ensure the simulation reflected proper latitudinal variations in the solar plasma flow, measurements from Snodgrass & Ulrich (1990, The Astrophysical Journal) were used to define this rotational component throughout the simulation.
​

Untitled design (9).png
Untitled design (11)_edited_edited.png


Optimizations

 

In order to simulate at the level of fidelity and scale that this project required, optimization was of utmost importance throughout the entire process. Since every particle in the simulation affects every voxel in the electromagnetic field calculations, as particle counts and field resolutions increase, the calculations multiply quadratically.​

 

The first and most impactful optimization was migrating the core of the solver to OpenCL. Writing the solver in OpenCL allows these dense point calculations to be run in parallel on the GPU, reducing computation time by orders of magnitude from the VEX solver. With the help of GridMarkets, the solver was even further optimized through clever math shortcuts and data transfer optimizations between the CPU and GPU.

 

As a final and important optimization, I implemented a distance-based LOD system to decrease the quadratic nature of the field calculations. This system uses a sparse representation of the dense point data during calculations between distant points, and it reserves the dense calculations for nearby interactions. This optimization system is inspired by the Barnes-Hut algorithm, which is commonly used in N-Body simulations to reduce computational complexity from O(n²) to O(n log n), while retaining high mathematical accuracy.

 

Through the use of these optimizations, as well as GridMarkets' powerful GPUs, the final core simulation was able to be run with 7 million points and 17 million voxels in under 5 hours. With the original O(n^2) VEX implementation on my machine, this same simulation would have taken over a year and a half to complete. At the simulation's final resolution, that's an improvement of around 2,600x over the naive VEX implementation.

​

Untitled design (10).png
write _Final Results_ in a black background_edited_edited.jpg


Final Results and Rendering

 

After the core simulation is run and the electromagnetic field is computed, the final rendering phase begins. 

This includes running a large simulation of over 200 million charged particles being pushed around by gravity; surface pressure; and the Lorentz force from the precomputed electromagnetic field.

​

These particles form the Sun's corona and are the primary element used for the final render.  They are shaded based on values such as acceleration, charge, and the surrounding electromagnetic field.  Subsequently, they are converted to curves for rendering efficiency and motion blur.  The scene is finally rendered with a point count of half a billion points, as well as rasterized volumes for distant elements of the corona.

 

Thanks to GridMarkets’ powerful compute resources and rendering capabilities, simulating and rendering this vast number of points and curves was a swift and painless process.

​

Far Render.jpg


Conclusion

 

This project demonstrated that a complex magnetohydrodynamic simulation of the Sun is possible with careful optimization, strategic use of OpenCL, and the immense computational power of GridMarkets' servers. The results offer a detailed and dynamic portrayal of a Sun that is both physically grounded and artistically compelling.​

 

I want to give an enormous thank you to GridMarkets for giving me the opportunity to use their services in the creation of this piece, and to Adam Ferestad for being an amazing supervisor and collaborator throughout my time working on this project.

​


By: GridMarkets marketing

​

bottom of page