|
3 | 3 | import numpy as np
|
4 | 4 | import pytest
|
5 | 5 |
|
6 |
| -# Custom |
7 |
| -from gala.potential import ( |
8 |
| - NullPotential, |
9 |
| - NFWPotential, |
10 |
| - HernquistPotential, |
11 |
| - ConstantRotatingFrame, |
12 |
| - StaticFrame, |
13 |
| -) |
14 | 6 | from gala.dynamics import PhaseSpacePosition, combine
|
15 |
| -from gala.units import UnitSystem, galactic |
16 | 7 | from gala.integrate import (
|
17 | 8 | DOPRI853Integrator,
|
18 | 9 | LeapfrogIntegrator,
|
19 | 10 | Ruth4Integrator,
|
20 | 11 | )
|
21 | 12 |
|
| 13 | +# Custom |
| 14 | +from gala.potential import ( |
| 15 | + ConstantRotatingFrame, |
| 16 | + HernquistPotential, |
| 17 | + NFWPotential, |
| 18 | + NullPotential, |
| 19 | + StaticFrame, |
| 20 | +) |
| 21 | +from gala.units import UnitSystem, galactic |
| 22 | + |
22 | 23 | # Project
|
23 | 24 | from ..core import DirectNBody
|
24 | 25 |
|
@@ -220,3 +221,28 @@ def test_directnbody_integrate_rotframe(self, Integrator):
|
220 | 221 |
|
221 | 222 | assert u.allclose(orbits_static.xyz, orbits_static.xyz)
|
222 | 223 | assert u.allclose(orbits2.v_xyz, orbits2.v_xyz)
|
| 224 | + |
| 225 | + @pytest.mark.parametrize("Integrator", [DOPRI853Integrator]) |
| 226 | + def test_nbody_reorder(self, Integrator): |
| 227 | + N = 16 |
| 228 | + rng = np.random.default_rng(seed=42) |
| 229 | + w0 = PhaseSpacePosition( |
| 230 | + pos=rng.normal(0, 5, size=(3, N)) * u.kpc, |
| 231 | + vel=rng.normal(0, 50, size=(3, N)) * u.km / u.s, |
| 232 | + ) |
| 233 | + pots = [ |
| 234 | + ( |
| 235 | + HernquistPotential(1e9 * u.Msun, 1.0 * u.pc, units=galactic) |
| 236 | + if rng.uniform() > 0.5 |
| 237 | + else None |
| 238 | + ) |
| 239 | + for _ in range(N) |
| 240 | + ] |
| 241 | + sim = DirectNBody( |
| 242 | + w0, |
| 243 | + pots, |
| 244 | + external_potential=HernquistPotential(1e12, 10, units=galactic), |
| 245 | + units=galactic, |
| 246 | + ) |
| 247 | + orbits = sim.integrate_orbit(dt=1.0 * u.Myr, t1=0, t2=100 * u.Myr) |
| 248 | + assert np.allclose(orbits.pos[0].xyz, w0.pos.xyz) |
0 commit comments