-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·107 lines (82 loc) · 2.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
# Import all needed packages
from modules.time import Time
from modules.cluster import Cluster
from modules.galaxy import Galaxy
from modules.system import System
from modules.integrator import *
from modules.analysis import Analysis
from modules.plot import Plotter
from modules.model import *
import numpy as np
##########################################################################
# PARAMETERS
##########################################################################
# Simulation parameters
model_name = "kepler" # The name of the model
dt = 0.01 # The step size
output_dt = 0.01 # The output timestep to save data
tmax = 10 # The max timestep
output = "body.dat" # The output filename to store the data
use_analysis = True # A flag for using the analysis tool
plot_data = True # A flag for plotting data
##########################################################################
# INITIAL CONDITIONS
##########################################################################
# Store the current model
if model_name.lower() == "kepler":
model = KeplerModel(
a = 1.0,
e = 0.6,
v_mul = 1.0,
)
elif model_name.lower() == "isochrone":
model = IsochroneModel(
b = 0.1,
v_esc = 0.5,
)
elif model_name.lower() == "oscillator":
model = OscillatorModel(
rho = 0.5,
)
elif model_name.lower() == "logarithmic":
model = LogarithmicModel(
v0 = 1.0,
Rc = 0.2,
q = 0.8,
v_mul = 0.5,
)
else:
raise Exception("Invalid model name used.")
# Create a cluster
cluster = Cluster(
model,
n_bodies = 1,
radius = 1.0,
use_background = True,
masses = [1],
vel_vec=Vector(0, 1, 0)
)
# Create the system
system = System(
cluster
)
# Create the time
time = Time(0, tmax, dt)
##########################################################################
# INTEGRATOR
##########################################################################
integrator = LeapFrogIntegrator()
integrator.execute(system, time, output, output_timestep = output_dt)
# If using the analysis tool
if use_analysis:
analysis = Analysis("output/body_00000.dat", True)
analysis.output()
##########################################################################
# CREATES PLOT
##########################################################################
# If plotting data
if plot_data:
# Creates a plotter with the outputs
plotter = Plotter()
plotter.ask_plot()