File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414#pragma once
1515#include < cmath>
1616#include " floatdef.h"
17+ #include " dt/softening.h"
1718
1819struct alignas (32 ) Particle {
1920 real x, y, z;
@@ -23,22 +24,19 @@ struct alignas(32) Particle {
2324
2425inline void Gravity (Particle& a, Particle& b, real dt)
2526{
26- constexpr real G = real (1.0 );
27- constexpr real eps2 = real ( 1e-4 );
27+ constexpr real G = real (1.0 );
28+ real eps2 = pairSoftening (a. m , b. m ); // must be epsilon^2
2829
29- // Relative position
3030 real dx = b.x - a.x ;
3131 real dy = b.y - a.y ;
3232 real dz = b.z - a.z ;
3333
34- // Softened squared distance
3534 real r2 = dx*dx + dy*dy + dz*dz + eps2;
3635
37- // Inverse distance and inverse distance cubed
38- real invR = std::sqrt (real ( 1.0 ) / r2 );
39- real invR3 = invR * invR * invR ;
36+ real invR2 = real ( 1.0 ) / r2;
37+ real invR = std::sqrt (invR2 );
38+ real invR3 = invR * invR2 ;
4039
41- // Accelerations (pairwise, symmetric)
4240 real ax = G * b.m * dx * invR3;
4341 real ay = G * b.m * dy * invR3;
4442 real az = G * b.m * dz * invR3;
You can’t perform that action at this time.
0 commit comments