|
2 | 2 | // it under the terms of the GNU General Public License as published by |
3 | 3 | // the Free Software Foundation, either version 3 of the License, or |
4 | 4 | // (at your option) any later version. |
5 | | - |
6 | 5 | // This program is distributed in the hope that it will be useful, |
7 | 6 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
8 | 7 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9 | 8 | // GNU General Public License for more details. |
10 | | - |
11 | 9 | // You should have received a copy of the GNU General Public License |
12 | 10 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
13 | 11 |
|
14 | 12 | #pragma once |
15 | | -#include <cmath> |
16 | | -#include "floatdef.h" |
17 | 13 | #include "dt/softening.h" |
| 14 | +#include "floatdef.h" |
| 15 | +#include <cmath> |
18 | 16 |
|
19 | 17 | struct alignas(32) Particle { |
20 | | - real x, y, z; |
21 | | - real vx, vy, vz; |
22 | | - real m; |
23 | | - int type; |
| 18 | + real x, y, z; |
| 19 | + real vx, vy, vz; |
| 20 | + real m; |
| 21 | + int type; |
24 | 22 | }; |
25 | 23 |
|
26 | | -inline void Gravity(Particle& a, Particle& b, real dt) |
27 | | -{ |
28 | | - constexpr real G = real(1.0); |
| 24 | +inline void Gravity(Particle &a, Particle &b, real dt) { |
| 25 | + constexpr real G = real(1.0); |
29 | 26 |
|
30 | | - real eps = pairSoftening(a.m, b.m); |
| 27 | + real eps = pairSoftening(a.m, b.m); |
31 | 28 |
|
32 | | - real dx = b.x - a.x; |
33 | | - real dy = b.y - a.y; |
34 | | - real dz = b.z - a.z; |
| 29 | + real dx = b.x - a.x; |
| 30 | + real dy = b.y - a.y; |
| 31 | + real dz = b.z - a.z; |
35 | 32 |
|
36 | | - real r2 = dx*dx + dy*dy + dz*dz + eps*eps; |
| 33 | + real r2 = dx * dx + dy * dy + dz * dz + eps * eps; |
37 | 34 |
|
38 | | - real invR2 = real(1.0) / r2; |
39 | | - real invR = std::sqrt(invR2); |
40 | | - real invR3 = invR * invR2; |
| 35 | + real invR2 = real(1.0) / r2; |
| 36 | + real invR = std::sqrt(invR2); |
| 37 | + real invR3 = invR * invR2; |
41 | 38 |
|
42 | | - real ax = G * b.m * dx * invR3; |
43 | | - real ay = G * b.m * dy * invR3; |
44 | | - real az = G * b.m * dz * invR3; |
| 39 | + real ax = G * b.m * dx * invR3; |
| 40 | + real ay = G * b.m * dy * invR3; |
| 41 | + real az = G * b.m * dz * invR3; |
45 | 42 |
|
46 | | - real bx = -G * a.m * dx * invR3; |
47 | | - real by = -G * a.m * dy * invR3; |
48 | | - real bz = -G * a.m * dz * invR3; |
| 43 | + real bx = -G * a.m * dx * invR3; |
| 44 | + real by = -G * a.m * dy * invR3; |
| 45 | + real bz = -G * a.m * dz * invR3; |
49 | 46 |
|
50 | | - a.vx += ax * dt; |
51 | | - a.vy += ay * dt; |
52 | | - a.vz += az * dt; |
| 47 | + a.vx += ax * dt; |
| 48 | + a.vy += ay * dt; |
| 49 | + a.vz += az * dt; |
53 | 50 |
|
54 | | - b.vx += bx * dt; |
55 | | - b.vy += by * dt; |
56 | | - b.vz += bz * dt; |
| 51 | + b.vx += bx * dt; |
| 52 | + b.vy += by * dt; |
| 53 | + b.vz += bz * dt; |
57 | 54 | } |
0 commit comments