Main Content

Spiral Galaxy Formation Simulation Using MATLAB Function Blocks

This example shows how to simulate galaxy formation by using MATLAB Function blocks. The paper "Galactic Bridges and Tails" (Toomre & Toomre 1972) inspires this model. The paper explains how disc shaped galaxies could develop spiral arms. Two disc shape galaxies originally are far apart. They then fly by each other and almost collide. Once the galaxies closely approach each other, mutual gravitational forces cause spiral arms to form.

Model Description

Open the sldemo_eml_galaxy model to view the design.

model = "sldemo_eml_galaxy";
open_system(model);

The model contains three primary parts. The green blocks initialize the simulation, the orange blocks model the core of the simulation, and the yellow block plots the galaxy animation.

Except for the PlotAll visualization block's use of plotting routines, all MATLAB Function blocks in this model support code generation with Simulink® Coder™ and Embedded Coder™.

Initial Conditions

The model requires initial conditions for each galaxy. The initial conditions are: galaxy radius in parsecs (rp), galaxy mass in solar mass units (cm), galaxy position in parsecs (pos), and galaxy velocity in m/s (vel).

In the model, Constant blocks specify the initial conditions. The initial conditions have been chosen such that the galaxies approach each other during simulation.

Construct Galaxy Blocks

The MATLAB Function blocks Construct Galaxy 1 and Construct Galaxy 2 accept the initial conditions. These MATLAB Function blocks contain MATLAB® code that builds the galaxy models.

In a typical galaxy, most of the mass is concentrated in its center as a super-massive black hole and/or star agglomeration. The blocks model the galaxy as a disc with radius r with most of its mass concentrated in the inner circle of radius r/3. In addition to this super-massive nucleus, the Construct Galaxy MATLAB Function blocks each create 349 random stars with masses ranging from 4 to 24 solar masses. These stars are randomly positioned within distance r/3 and r from the center of the galaxy. The stars initially move in circular orbits around the galaxy core. Every object (star or galaxy core) has mass, position (x, y, z), and velocity (Vx, Vy, Vz).

Matrix Concatenation Block

This block joins information about both galaxies. At this point the model has 700 objects: 1 core for each galaxy and 349 stars around each core. These objects interact according to Newtonian mechanics.

Partition bodies into heavy and light Block

This MATLAB Function block separates all 700 objects into two groups: heavy bodies and light bodies. The heavy bodies are the galaxy cores. The light bodies are the stars. Because the galaxy cores are much heavier than individual stars, the model will consider only the heavy-heavy and heavy-light interactions. We can ignore the light-light body interactions. This will save a lot of time since 698 out of 700 bodies in the model are light.

Apply Newtonian gravitation Block

This MATLAB Function block uses Newtonian mechanics to compute the velocities and positions of the bodies at each step. The "combine" block is also a MATLAB Function block. It merges the data about heavy and light objects together.

Plot all bodies Block

This MATLAB Function block plots the bodies in a figure and updates the position of each star at every step in the simulation.

Run the Simulation

Run the simulation to view the spiral galaxy formation.

sim(model);

Close the Model

Close the model without saving any changes. Clear data generated by simulation.

close_system(model,0);
clear model sldemo_eml_galaxy_output;

Notes: * In this model, signal logging is turned on. Observe that the GalaxyBodies signal has a little blue signal logging antenna on it. The model saves output data in a Dataset object. Any other data is saved/modified in the model workspace to avoid cluttering the MATLAB workspace. * To modify signal logging settings, right-click on the signal line and select Signal Properties. In this example, the signal name is GalaxyBodies and the Log signal data checkbox is checked. * The logged data is saved to the MATLAB workspace as a Dataset object with the name sldemo_eml_galaxy_output. Information on the GalaxyBodies signal can be retrieved from this object by typing sldemo_eml_galaxy_output.get('GalaxyBodies') which returns a Simulink.SimulationData.Signal object.

Comments About the Model

Despite its simplicity, this model provides insight into how our own galaxy evolved. This example allows the user to maximally simplify the model and run a fast simulation. Modify this example by adding more galaxies.

References

Toomre, Alar; Toomre, Juri; "Galactic Bridges and Tails"; Astrophysical Journal, Vol. 178, pp. 623-666 (1972); 12/1972;