-
Notifications
You must be signed in to change notification settings - Fork 1
/
SSFunctions.cpp
73 lines (49 loc) · 1.88 KB
/
SSFunctions.cpp
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
/* Definition of the Stellar Structure derivatives and their integrations
* using RK4 */
#include <cmath>
#include "SSFunctions.h"
using namespace std; //Because YOLO
//Mass
double massDerivative(double radius, double mass, double density)
{
double derivative = 4 * ::pi * pow (radius , 2) * density ;
return derivative;
}
//RK4 integration
double massFunction( double radius, double mass, double density , double stepSize )
{
double k1,k2,k3,k4;
double newMass;
k1=massDerivative( radius , mass , density);
k2=massDerivative( radius+0.5 * stepSize , mass+0.5*stepSize*k1 , density);
k3=massDerivative( radius+ 0.5 * stepSize, mass + 0.5* stepSize *k2 , density);
k4=massDerivative( radius+ stepSize , mass + stepSize *k3 , density );
newMass = mass + (stepSize/6)*(k1+2*k2+2*k3+k4);
return newMass;
}
//Pressure
double pressureDerivative(double radius, double pressure , double mass, double density)
{
double derivative = -1 * ::gravitationalConstant * mass * ( 1 / pow( radius , 2 ) ) * density ;
return derivative;
}
//RK4 integration
double pressureFunction( double radius, double pressure, double mass, double density , double stepSize )
{
double k1,k2,k3,k4;
double newPressure;
k1=pressureDerivative( radius , pressure , mass , density);
k2=pressureDerivative(radius + 0.5*stepSize , pressure + 0.5*stepSize*k1 , mass, density);
k3=pressureDerivative(radius+ 0.5 * stepSize , pressure + 0.5* stepSize *k2 , mass , density);
k4=pressureDerivative(radius+ stepSize , pressure + stepSize *k3 , mass , density );
newPressure = pressure + (stepSize/6)*(k1+2*k2+2*k3+k4);
return newPressure;
}
//Density, polytropic fluid equation
double densityFunction( double pressure , double polytropicConstant )
{
double newValue, base;
base = ( pressure / polytropicConstant );
newValue = pow( base , polytropicIndex );
return newValue;
}