-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (66 loc) · 2.57 KB
/
Copy pathmain.cpp
File metadata and controls
98 lines (66 loc) · 2.57 KB
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
/* Main file of Stellar Structure. */
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include "Initialize.h"
#include "SSFunctions.h"
using namespace std; //Mainly because YOLO
int main ( )
{
//Getting the boundary conditions and other constants from a file
//The numbers are stored in 'numberArray'
double numberArray[10] = { };
string fileName( "boundaryConditions.txt" );
initialize( fileName , numberArray );
//Outs
ofstream massOut, pressureOut, densityOut, salidaPotencial;
//Output files are stored in folder "data"
massOut.open ("./data/mass.dat");
pressureOut.open ("./data/pressure.dat");
densityOut.open ("./data/density.dat");
//Initial values
double density = numberArray[0];
double pressure = numberArray[1];
double totalRadius = numberArray[2];
double polytropicConstant = numberArray[3];
double radius = 0;
double mass = 0;
//Print initial values on screen
cout << "Initial Conditions" << endl;
cout << "Core Density" << "\t" << density << endl;
cout << "Core Pressure" << "\t" << pressure << endl;
cout << "Radius" << "\t" << totalRadius << endl;
int iterationCount = 0, outFilter = 10;
double stepSize = 1e5; //Step size for the RK4
while ( radius <= totalRadius )
{
/* Due to the huge amount of calculations this program does, only some calculations will be printed to file.
* The program prints data each 'outFilter' cycle */
if ( iterationCount % outFilter == 0 )
{
massOut << radius << "\t" << mass << endl;
densityOut << radius << "\t" << density << endl;
pressureOut << radius << "\t" << pressure << endl;
/* Since pressure will approach zero when the radius is near the total radius
* it is necessary to adjust the step size to make sure that it is still "small"
* compared to the pressure value. Since this chage will create more values
* the 'outFilter' gets an adjustment as well. */
if ( (stepSize / pressure) >= 1e-15 )
{
stepSize /= 10;
outFilter *= 10;
}
}
//Add the step size to the radius and update the counter
radius += stepSize;
iterationCount++;
//Calculate the new values
density = densityFunction( pressure , polytropicConstant );
mass = massFunction( radius , mass , density , stepSize );
pressure = pressureFunction( radius , pressure , mass , density , stepSize );
}
cout << "Iteration Count" << "\t" << iterationCount << endl;
cout << "Final Step Size" << "\t" << stepSize << endl; //Only mere curiosity
return 0;
}