-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGalacticPositions.cs
206 lines (167 loc) · 6.15 KB
/
GalacticPositions.cs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GalacticMotionsWithExpansion
{
class GalacticPositions
{
CosmologicalExpansion NewExpansion = new CosmologicalExpansion();
static Random random = new Random();
public static int galacticNumber = 250;
// galactic position
private float[] position = new float[3];
private float[] extraposition = new float[3];
// size
private float _size;
// lifetime
private float _lifeTime;
private float d = new float();
private float[] sum = new float[3];
// acceleration of the galaxy
private float[] acceleration = new float[3];
private float M, M_mid;
double Omega_M = 0.31;
double Omega_L = 0.69;
double dt = 0.0001;
// velocity
private float[] velocity = new float[3];
// Time interval for galaxy activation
private float LastTime = 0;
// class constructor
public GalacticPositions(float x, float y, float z, float size, float lifeTime, float start_time)
{
_size = size;
_lifeTime = lifeTime;
LastTime = start_time;
//coordinates randomly
position[0] = random.Next(-10, 10);
position[1] = random.Next(-10, 10);
position[2] = random.Next(-10, 10);
//velocities randomly
for(int i=0; i<3; i++)
{
int a = 0;
while(a == 0)
{
a = random.Next(-500, 500);
}
velocity[i] = a;
}
M = random.Next(400, 500);
extraposition[0] = position[0];
extraposition[1] = position[1];
extraposition[2] = position[2];
}
// Method for solving the equations
public void SystemOfEquations(double Omega_M, double Omega_L, double dt)
{
/* N - это количество частиц(max количество не должно превышать 1 000 000 000);
* x0, y0, z0 - это начальные значения точек (задается руками);
* vx0, vy0, vz0 - начальное значение скоростей (задается руками);
* ax0, ay0, az0 - непосредственно вычисляется;
* Sum - слогаемое в правых частях.
* l - размер окна*/
//a(t) and da/dt
double A = NewExpansion.Parameter_A(Omega_M, Omega_L, dt);
double At = NewExpansion.Parameter_At(Omega_M, Omega_L, dt);
extraposition[0] = position[0];
extraposition[1] = position[1];
extraposition[2] = position[2];
/* Find the initial acceleration to find velocities etc. and doing it with the next iteration method */
acceleration[0] = (float)(-(2 / A) * At * velocity[0] - 3 * Omega_M / (8 * Math.PI * Math.Pow(A, 3) * M_mid) * sum[0]);
acceleration[1] = (float)(-(2 / A) * At * velocity[1] - 3 * Omega_M / (8 * Math.PI * Math.Pow(A, 3) * M_mid) * sum[1]);
acceleration[2] = (float)(-(2 / A) * At * velocity[2] - 3 * Omega_M / (8 * Math.PI * Math.Pow(A, 3) * M_mid) * sum[2]);
/* Iteration method for finding coordinates and velocities */
position[0] += velocity[0] * (float)dt;
position[1] += velocity[1] * (float)dt;
position[2] += velocity[2] * (float)dt;
//velocities
velocity[0] += acceleration[0] * (float)dt;
velocity[1] += acceleration[1] * (float)dt;
velocity[2] += acceleration[2] * (float)dt;
}
// Function for setting acceleration acting on the galaxy
public void SetAcceleration(float x, float y, float z)
{
acceleration[0] = x;
acceleration[1] = y;
acceleration[2] = z;
}
public void SetD(float x)
{
d = x;
}
public void SetSum(float x, float y, float z)
{
sum[0] = x;
sum[1] = y;
sum[2] = z;
}
public float GetPosition(int i)
{
return position[i];
}
public float GetMass()
{
return M;
}
// getting the galaxy size
public float GetSize()
{
return _size;
}
//Set the average value of the mass
public void SetAverMass(float x)
{
M_mid = x;
}
// Update the position of the galaxy
public void UpdatePosition(float timeNow)
{
SystemOfEquations(Omega_M, Omega_L, dt);
/* define the time difference from the last update of
* the position of the galaxy. (Because the timer may not be fixed) */
float dTime = timeNow - LastTime;
_lifeTime -= dTime;
}
// Check if the galaxy lifetime has not finished yet
public bool isLife()
{
if (_lifeTime > 0)
{
return true;
}
else
{
return false;
}
}
// Obtaining the coordinates of a galaxy
public float GetPositionX()
{
return position[0];
}
public float GetPositionY()
{
return position[1];
}
public float GetPositionZ()
{
return position[2];
}
// Obtaining old coordinates of the galaxy
public float GetOldPositionX()
{
return extraposition[0];
}
public float GetOldPositionY()
{
return extraposition[1];
}
public float GetOldPositionZ()
{
return extraposition[2];
}
}
}