This README file aim to explain the code of the simulation of the Solar System
Note: Keep in mind that in this explenation the term 'vector' may be used in a mathematical context, as well as the object type.
The Solar System consits of the star named 'Sun' and planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. The physics behind the motion of planets and stars are described by graviataional forces:
Where
Moreover, the motion of each planet can be discribed by its position and velocity vectors whose values can be calulated based on these equations:
Begining with
- $\Delta t = 10 $ days - Time increasement, note that this time is converted to seconds (SI units) in the simpulation code
-
$t_{max} = dt$ Maximal time of simulation -
$m_s = 1.9891 \cdot 10^{30}$ Mass of the Sun -
$G = 6.6743 \cdot 10^{-11}$ Gravitational constant -
$x_0 = 0$ Initial x-position -
$y_0 = 1432 \cdot 10^{10}$ Initial y-position -
$v_{x_0} = 9.7 \cdot 10^{3}$ Initial x-component of velocity -
$v_{y_0} = 0$ Initial y-component of velocity
-
main.h- This file imports libraries and definition of physical constants and initial conditions -
man.cpp- The main program of the simulation -
matplotlibcpp.h- matplotlib library implemented in C++ -
Vec2D.h- vector class definition -
Vec2D.cpp- vector class methods -
Planet.h- Class definition of planet object -
Planet.cpp- planet class methods -
Solar_System.h- solar_system class difinition -
Solar_System.cpp- solar_system methods -
planets.txt- Contains names, initial position and velocities of planets. The layout of the columns is as follows: name, initial x-position$x_0$ , initial y-position$y_0$ , initial x comonent of velocity$v_{x_0}$ , initial y-component of velocity$v_{y_0}$
-
data- this folder cointains files named after each planet. Each file contains information about planet's position in a given time. The layout of the files is as folows: time$t$ , x-cooridnate$x(t)$ , y-coordinate$y(t)$ -
plots- this folder contains plots of the current and past positions of the planets in a given time (in days) given as a title of the plot
x- x-coordinate of a vector, Type doubley- y-coordinate of a vector, Type double
planet()- Constructor taking no argumantsplanet(vec2d a, vec2d b)- Constructor taking x and y arguments respectively~planet()- Destructorget_x()- Returns x-coordinateget_y()- Returns y-coordinateset_x(double a)- Sets x-coordinate, takes a double as an argumentset_y(double b)- sets y_coordinate, takes double as an argumentadd(vec2d vec)- Addition of a vector, takes a vector as a argumentsub(vec2d vec)- Subtration of a vector. Vector in the argument is subtracted from the vector that the method is applied toscale(double a)- Multilpication by a scalar. Takes a double as an argument
+- addition operator, the x-coordinate and y-coordinate are added seperately'-'- subtraction operator, the Vec2D vector on the right of the operator is subtracted from the vector on the left of the operator\*- multiplication by a scalar operator, the vector must stand on the left of the operator, while scalar on the right, scalar must be a double type
pos- Position vector of a planet, type vec2dvel- Velocity vector of a planet, type vec2dname- Name of the planet, type string
planet()- Constructor taking no argumentsplanet(vec2d a, vec2d b)- constructor taking position vector (vec2d) and velocity vector (vec2d) as arguments respectively~planet()- Destructorget_pos()- Returns position vector, returns vector typeget_vel()- Returns velocity vector, returns vector typeget_name()- Returns a name of a planet as a stringset_pos(vec2d a)- Sets a position vector, takes vector vec2d as an argumentset_vel(vec 2d b)- Sets a velocity vecor, takes vector vec2d as an argumentset_name(string n)- Sets a name of a planet, takes a string as an argumentdelta_t()- Changes the position vector and velocity vector of a planet based on time increasement. The change is based on the equations included in the introduction as well as model parameters. Note the timedtmust be converted to seconds
-
planets- this is a vector containing elements of classplanet -
current_timeis the double type variable encoding current time of the simulation, in days -
time_step- time difference$\Delta t$ of a simulation in days, double type
solar_system(double d_t)- constructor taking time simpulaton time step as an argument, which is assigned totime_stepprivate variable. Setscurrent_timeto zeto~solar_system()- destructordraw()- this method uses matplotlib to draw each planet of a solar system in a given time stamp. The title of the plot is a simulation day. The method reads the time and position of a planet from a planet's file indatafolder and plots a smaller point for each time stamp. The latest position of a planet is drawn as a bigger dot. This function uses the time in dayssystem_evolve()method used to update the position of the planets based on the model and to update current time of a simulation. This method usesto_file()method to write updated data to each planet's file indatafolder.to_file- writes the current time of the simultion, x-position and y-position to a file named after the name of a planet.from_file()- reads theplanets.txtfile to exctract the name of each planet, it's initial position and velocity vector (Vec2D). Then writes the data to aplanetsvector.
- Krzysztof Kuba - author of the code
- Michał Suchorowski - originator of the project