spiral galaxy formation simulation using embedded matlab

3
Spiral Galaxy Formation Simulation Using Embedded MATLAB Functions file:///E:/32bits/Matlab2007a/toolbox/simulink/simdemos/simgene ral/html... 1 of 3 08.07.2008 07:21 Run in the Command Window Spiral Galaxy Formation Simulation Using Embedded MATLAB Functions This model was inspired by the classic paper "Galactic Bridges and Tails" (Toomre & Toomre 1972). The original paper explained 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 are close enough, mutual gravitational forces cause spiral arms to form. Except for the "PlotAll" visualization block's use of plotting routines, all Embedded MATLAB function blocks in this model support code generation with Real-Time Workshop and Real-Time Workshop Embedded Coder. Demo Requirements: During this demonstration, Simulink generates code for the simulation in a Simulink project directory created in the current working directory (pwd). If you do not want to affect the current directory (or if you cannot generate files in this directory), you should change your working directory. Contents Opening the Model and Running the Simulation Model Description Closing the Model Comments About the Model References Opening the Model and Running the Simulation Open the model and run the simulation by executing the code below. If you are using MATLAB Help, select the code you want to execute and press F9 (or select code, right click on selection and select "Evaluate Selection"). The Simulink model will load, compile, and run. model = 'sldemo_eml_galaxy' ; open_system(model); sim(model); Open sldemo_eml_galaxy_script.m in the Editor

Upload: goulu

Post on 08-Apr-2018

306 views

Category:

Documents


1 download

TRANSCRIPT

8/7/2019 Spiral Galaxy Formation Simulation Using Embedded MATLAB

http://slidepdf.com/reader/full/spiral-galaxy-formation-simulation-using-embedded-matlab 1/3

l Galaxy Formation Simulation Using Embedded MATLAB Functions file:///E:/32bits/Matlab2007a/toolbox/simulink/simdemos/simgene

08.07.20

Run in the Command Window

Spiral Galaxy Formation Simulation Using Embedded MATLABFunctions

This model was inspired by the classic paper "Galactic Bridges and Tails" (Toomre & Toomre 1972).The original paper explained 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 areclose enough, mutual gravitational forces cause spiral arms to form.

Except for the "PlotAll" visualization block's use of plotting routines, all Embedded MATLAB functionblocks in this model support code generation with Real-Time Workshop and Real-Time WorkshopEmbedded Coder.

Demo Requirements: During this demonstration, Simulink generates code for the simulation in aSimulink project directory created in the current working directory (pwd). If you do not want toaffect the current directory (or if you cannot generate files in this directory), you should changeyour working directory.

Contents

Opening the Model and Running the Simulation

Model DescriptionClosing the ModelComments About the ModelReferences

Opening the Model and Running the Simulation

Open the model and run the simulation by executing the code below. If you are using MATLAB Help,select the code you want to execute and press F9 (or select code, right click on selection and select"Evaluate Selection"). The Simulink model will load, compile, and run.

model = 'sldemo_eml_galaxy';

open_system(model);

sim(model);

Open sldemo_eml_galaxy_script.m in the Editor

8/7/2019 Spiral Galaxy Formation Simulation Using Embedded MATLAB

http://slidepdf.com/reader/full/spiral-galaxy-formation-simulation-using-embedded-matlab 2/3

l Galaxy Formation Simulation Using Embedded MATLAB Functions file:///E:/32bits/Matlab2007a/toolbox/simulink/simdemos/simgene

08.07.20

Model Description

This section describes the model in detail and explains the role of each block in the model. The greenblocks initialize the simulation, the orange blocks are the core of the simulation, and the yellow blockmakes the galaxy animation view.

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 suchthat the galaxies will nearly collide at some point in time.

"ConstructGalaxy" Blocks

The initial conditions are passed to the Embedded MATLAB function blocks Construct Galaxy 1 andConstruct Galaxy 2. These Embedded MATLAB function blocks contain M-code that builds the galaxymodels.

In a typical galaxy, most of the mass is concentrated in its center as a super-massive black hole and/orstar agglomeration. We model the galaxy as a disc with radius r with most of its mass concentrated inthe inner circle of radius r/3. In addition to this super-massive nucleus, the "ConstructGalaxy" EmbeddedMATLAB function block creates 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 starsinitially 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 750 objects: 1 core for eachgalaxy and 349 stars around each core. These 750 objects interact according to Newtonian mechanics.

"Partition" Block

This Embedded MATLAB function block separates all 750 objects into two groups: heavy bodies and

8/7/2019 Spiral Galaxy Formation Simulation Using Embedded MATLAB

http://slidepdf.com/reader/full/spiral-galaxy-formation-simulation-using-embedded-matlab 3/3

l Galaxy Formation Simulation Using Embedded MATLAB Functions file:///E:/32bits/Matlab2007a/toolbox/simulink/simdemos/simgene

08 07 20

light bodies. The heavy bodies are the galaxy cores. The light bodies are the stars. Because the galaxycores are much heavier than individual stars, the model will consider only the heavy-heavy andheavy-light interactions. We can ignore the light-light body interactions. This will save a lot of time since748 out of 750 bodies in the model are light.

"ApplyGravity" Block

This Embedded MATLAB function block uses Newtonian mechanics to compute the velocities andpositions of the bodies at each step. The "combine" block is also an embedded MATLAB function block.It merges the data about heavy and light objects together.

"PlotAll" Block

This Embedded MATLAB function block plots the bodies in a figure and updates the position of eachstar at every step in the simulation.

Closing the Model

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

close_system(model,0);

clear model sldemo_eml_galaxy_output;

Note:

In this model signal logging is turned on (see the 'GalaxyBodies' signal and the little blue arrownext to it). The model saves output data in a Simulink.ModelDataLogs structure. Any otherdata is saved/modified in the model workspace to avoid cluttering MATLAB workspace.

To modify signal logging settings right-click on the signal line and select "Signal Properties". Inthis demo the signal name is 'GalaxyBodies' and "Log signal data" checkbox is checked.

The logged signal is saved to MATLAB workspace as 'sldemo_eml_galaxy_output'. This is aSimulink.ModelDataLogs data structure. 'GalaxyBodies' signal can be retrieved from thisstructure by typing sldemo_eml_galaxy_output.GalaxyBodies . See more about workingwith data structures in MATLAB Help "Accessing Data in Structure Arrays".

Comments About the Model

Despite its simplicity, this model provides insight into how our own galaxy evolved. The demo allows theuser to maximally simplify the model and run a fast simulation. The user can easily modify the demo byadding more galaxies.

References

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

Copyright 2006 The MathWorks, Inc.Published with MATLAB® 7.4