home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
useful
/
dist
/
dev
/
lang
/
ace
/
prgs
/
astronomy
/
galcolsim.b
next >
Wrap
Text File
|
1994-01-10
|
14KB
|
562 lines
{ Galaxy Collision Simulator
Galaxy Collision Program
by M.C. Schroeder and Neil F. Comins.
Appeared in Astronomy magazine, December 1988
as an IBM GW-BASIC program.
Adapted to Macintosh Turbo Pascal 1.1 by David J. Benn
Date: 4th April - 17th April, 2nd & 3rd May 1991
Adapted for ACE Amiga BASIC by David J. Benn
Date: 27th,28th November 1992,
7th January 1993,
11th October 1993,
18th December 1993
This program allows 2 galaxies to interact via
their gravitational fields. The TARGET galaxy
is a disk and the INTRUDER galaxy is treated as
a point mass. }
const SF2=2
const arr_size=1000
const aspect=0.625
const true=-1&
const false=0&
const SIM=1
const PARAMS=2
dim X(arr_size),Y(arr_size),Z(arr_size)
dim VX(arr_size),VY(arr_size),VZ(arr_size)
longint NRR,NRS,NS,DR
single M1,M2
single X1,Y1,Z1
single X2,Y2,Z2
single VX1,VY1,VZ1
single VX2,VY2,VZ2
longint NTSPR,sim_time
SUB title
title$ = "*** Galaxy Collision Simulator ***"
color 2
locate 2,40-len(title$)\2
PRINT title$
END SUB
SUB await_CR
color 3
PRINT
PRINT "Press <return> to begin simulation..."
while inkey$<>chr$(13):wend
END SUB
SUB instructions
string ans
PRINT
color 3
locate csrlin,25
PRINT "Do you want instructions? (y/n)"
repeat
ans = ucase$(inkey$)
until ans="Y" or ans="N"
if ans="Y" then
cls
PRINT
title
PRINT
color 1
PRINT "This is an adaptation of a BASIC program which appeared in"
PRINT "Astronomy magazine, December 1988."
PRINT
PRINT "The purpose of the program is to show the large scale effects of"
PRINT "one galaxy (here refered to as the INTRUDER galaxy) passing nearby"
PRINT "or through another (TARGET) galaxy."
PRINT
PRINT "This is a task which until recent times has been the province of"
PRINT "of the supercomputer due to the sheer processing power required to"
PRINT "accurately model the gravitational effects of two galaxies - each"
PRINT "containing tens or hundreds of billions of stars - upon one ";
PRINT "another."
PRINT
PRINT "However, if the number of stars in the target galaxy is limited and"
PRINT "the intruder galaxy is considered to be a point gravitational"
PRINT "source, the problem becomes manageable on a microcomputer."
PRINT
PRINT "In this simulation the target galaxy consists of concentric rings"
PRINT "of stars."
await_CR
cls
PRINT
title
PRINT
color 1
PRINT "Before a simulation begins, you will be asked to enter a number of"
PRINT "parameters. Here is some background information:"
PRINT
PRINT " - 1 parsec = 3.26 light years = approx 30 million million kms"
PRINT " - 1 solar mass = the mass of our sun = 1990 thousand million"
PRINT " million million million kilograms"
PRINT " - Each time step represents 1.2 million years"
PRINT " - Each integer X, Y or Z step represents 500 parsecs"
PRINT " - Vx, Vy and Vz represent the velocities in the 3 axes"
PRINT " - The mass of the target galaxy equals 20 billion solar masses"
PRINT " - The mass of the intruder galaxy is entered as a fraction of"
PRINT " the target galaxy (eg: 0.25 x 20 billion = 5 billion)."
await_CR
cls
PRINT
title
PRINT
color 1
PRINT "The following are some sample initial conditions and their results:"
PRINT
PRINT "Result Intruder Mass X Y Z Vx Vy Vz Time Steps"
PRINT
PRINT "Ring Galaxy 1 7.5 0 35 0 0 -1 65"
PRINT "Bridge Galaxy 0.25 40 10 10 -1 0 0 120"
PRINT "Whirlpool Galaxy 0.25 -30 30 0 0 -0.5 0.5 175"
PRINT
PRINT "For best results, use about 10 concentric rings and 20 stars per"
PRINT "ring. This shows enough detail without slowing the simulation down"
PRINT "too much."
PRINT
PRINT "In what follows, you will also be given the opportunity to choose"
PRINT "one of the above 3 resultant galaxies rather than entering initial"
PRINT "condition values."
PRINT
PRINT "This program may also be run from the shell/CLI, with the following"
PRINT "syntax:"
PRINT
PRINT " GalColSim [ring | bridge | whirlpool]"
await_CR
end if
END SUB
SUB entry_method
string ans
cls
color 1
PRINT:PRINT
PRINT "Enter [P]arameters or [N]ame of simulation?"
repeat
ans=ucase$(inkey$)
until ans="P" or ans="N"
case
ans="P" : entry_method=PARAMS
ans="N" : entry_method=SIM
end case
END SUB
SUB set_parameters(opt)
shared NRR,NRS,NS,DR
shared M2
shared X2,Y2,Z2
shared VX2,VY2,VZ2
shared NTSPR
'..initialise parameters
if opt=1 then
'..ring
M2=1
X2=7.5 : Y2=0 : Z2=35
VX2=0 : VY2=0 : VZ2=-1
NTSPR=65
else
if opt=2 then
'..bridge
M2=0.25
X2=40 : Y2=10 : Z2=10
VX2=-1 : VY2=0 : VZ2=0
NTSPR=120
else
'..whirlpool
M2=0.25
X2=-30 : Y2=30 : Z2=0
VX2=0 : VY2=-0.5 : VZ2=0.5
NTSPR=175
end if
end if
'..number of rings and stars per ring
NRR=10
NRS=20
NS=NRR*NRS
if NRR<2 then NRR=2
DR=20 \ (NRR-1)
END SUB
SUB args_present
string end_state
if argcount<>1 then
args_present=false
exit sub
else
args_present=true
end_state=ucase$(arg$(1))
case
end_state="RING" : opt=1
end_state="BRIDGE" : opt=2
end_state="WHIRLPOOL" : opt=3
end case
set_parameters(opt)
end if
END SUB
SUB get_simulation
shortint opt
'..ask for simulation end-state
PRINT
PRINT "Which end-state?"
PRINT
PRINT "1. Ring Galaxy"
PRINT "2. Bridge Galaxy"
PRINT "3. Whirlpool Galaxy"
repeat
opt=val(inkey$)
until opt>=1 and opt<=3
set_parameters(opt)
END SUB
SUB get_parameters
{The stars are distributed in the
TARGET galaxy in rings. The total number
of stars is the product of the # of rings and
the # of stars per ring.}
shared NRR,NRS,NS,DR
shared M2
shared X2,Y2,Z2
shared VX2,VY2,VZ2
shared NTSPR
string ANS
repeat
cls
PRINT
PRINT "Enter the initial conditions..."
PRINT
PRINT "Input the number of rings of stars in the TARGET galaxy (try 8-20):"
input NRR
PRINT
PRINT "Input the number of stars per ring in the TARGET galaxy (try 15-30):"
input NRS
PRINT
NS=NRR*NRS
if NRR<2 then NRR=2
DR=20 \ (NRR-1)
PRINT "Input the mass fraction of the INTRUDER galaxy"
PRINT "in units of the TARGET galaxy mass (try 0.25-1):"
input M2
PRINT
PRINT "Input the initial X Y Z co-ordinates of the INTRUDER galaxy"
PRINT "(eg: 40 10 10):"
PRINT "The TARGET galaxy is located at 0 0 0."
PRINT "X: ";
input X2
PRINT "Y: ";
input Y2
PRINT "Z: ";
input Z2
PRINT
PRINT "Input the initial X Y Z velocities"
PRINT "of the INTRUDER galaxy (eg: -1 0 0):"
PRINT "The TARGET galaxy is initially at rest."
PRINT "X: ";
input VX2
PRINT "Y: ";
input VY2
PRINT "Z: ";
input VZ2
{not too small (0 is ok) - system may crash at around +- .34 or so...}
if VX2<0.5 then VX2=VX2*2;
if VY2<0.5 then VY2=VY2*2;
if VZ2<0.5 then VZ2=VZ2*2;
PRINT
{the position of the TARGET galaxy
is assigned by the computer}
PRINT "Input number of time steps for this run (try 50-200)"
input NTSPR
PRINT
PRINT "Are these inputs correct? (y/n) "
repeat
ANS = ucase$(inkey$)
until ANS="Y" or ANS="N"
until ANS="Y"
END SUB
SUB update_display
{update screen display}
shared X,Y,VX,VY,Z,VZ
shared NRR,NRS,NS,DR
shared M1,M2
shared X1,Y1,Z1
shared X2,Y2,Z2
shared VX1,VY1,VZ1
shared VX2,VY2,VZ2
shared NTSPR,sim_time
single XC,YC,ZC,XX1,YY1,ZZ1,XX2,YY2,ZZ2
longint I,J
single XP,YP,ZP
string ch
{calculate centre of mass of system
for use as centre of output display}
XC=(M1*X1+M2*X2)/(M1+M2)
YC=(M1*Y1+M2*Y2)/(M1+M2)
ZC=(M1*Z1+M2*Z2)/(M1+M2)
{set up output display - clear text & graphics}
cls
{print out display headings}
color 3
locate 2
PRINT " Polar Edge-on"
color 3
locate 22
PRINT " Step:";sim_time
color 5
locat