Esempio n. 1
0
    def test_modify_mass(self):
        name = 'modify_mass'
        try:
            rebbin = os.path.join(THIS_DIR, 'binaries/' + name + '.sa')
            rebxbin = os.path.join(THIS_DIR, 'binaries/' + name + '.rebx')
            sa = reboundx.SimulationArchive(rebbin, rebxbin)
        except:
            sim = rebound.Simulation('binaries/twoplanets.bin')
            sim.automateSimulationArchive('binaries/' + name + '.sa',
                                          interval=1e3,
                                          deletefile=True)
            rebx = reboundx.Extras(sim)
            mod = rebx.load_operator(name)
            rebx.add_operator(mod)
            ps = sim.particles
            ps[0].params['tau_mass'] = -1e4
            rebx.save('binaries/' + name + '.rebx')
            sim.integrate(1.e4)
            sa = reboundx.SimulationArchive('binaries/' + name + '.sa',
                                            'binaries/' + name + '.rebx')

        simf, rebx = sa[-1]
        sim, rebx = sa[0]
        sim.integrate(simf.t)
        self.assertEqual(sim.particles[0].x, simf.particles[0].x)
Esempio n. 2
0
    def test_gr(self):
        name = 'gr'
        try:
            rebbin = os.path.join(THIS_DIR, 'binaries/' + name + '.sa')
            rebxbin = os.path.join(THIS_DIR, 'binaries/' + name + '.rebx')
            sa = reboundx.SimulationArchive(rebbin, rebxbin)
        except:
            sim = rebound.Simulation('binaries/twoplanets.bin')
            sim.automateSimulationArchive('binaries/' + name + '.sa',
                                          interval=1e3,
                                          deletefile=True)
            rebx = reboundx.Extras(sim)
            force = rebx.load_force(name)
            rebx.add_force(force)
            force.params['c'] = 1.e4
            ps = sim.particles
            rebx.save('binaries/' + name + '.rebx')
            sim.integrate(1.e4)
            sa = reboundx.SimulationArchive('binaries/' + name + '.sa',
                                            'binaries/' + name + '.rebx')

        simf, rebx = sa[-1]
        sim, rebx = sa[0]
        sim.integrate(simf.t)
        self.assertEqual(sim.particles[0].x, simf.particles[0].x)
Esempio n. 3
0
    def test_modify_orbits_forces(self):
        name = "modify_orbits_forces"
        try:
            rebbin = os.path.join(THIS_DIR, 'binaries/' + name + '.sa')
            rebxbin = os.path.join(THIS_DIR, 'binaries/' + name + '.rebx')
            sa = reboundx.SimulationArchive(rebbin, rebxbin)
        except:
            try:
                sim = rebound.Simulation('binaries/twoplanets.bin')
            except:
                sim = rebound.Simulation()
                sim.add(m=1.)
                sim.add(m=1.e-4, a=1., e=0.1)
                sim.add(m=1.e-4, a=2, e=0.1, inc=0.2)
                sim.integrator = "whfast"
                sim.dt = sim.particles[1].P / 100
                sim.move_to_com()
                sim.save('binaries/twoplanets.bin')

            sim.automateSimulationArchive('binaries/modify_orbits_forces.sa',
                                          interval=1e3,
                                          deletefile=True)
            rebx = reboundx.Extras(sim)
            mod = rebx.load_force('binaries/modify_orbits_forces')
            rebx.add_force(mod)
            ps = sim.particles
            ps[1].params['tau_a'] = -1e4
            ps[1].params['tau_e'] = -1e3
            ps[2].params['tau_e'] = -1e3
            ps[2].params['tau_inc'] = -1e3
            rebx.save('binaries/modify_orbits_forces.rebx')
            sim.integrate(1.e4)
            sa = reboundx.SimulationArchive(
                'binaries/modify_orbits_forces.sa',
                'binaries/modify_orbits_forces.rebx')

        simf, rebx = sa[-1]
        sim, rebx = sa[0]
        sim.integrate(simf.t)
        self.assertEqual(sim.particles[0].x, simf.particles[0].x)
Esempio n. 4
0
    def test_pre(self):
        for integrator in integrators:
            for rebxintegrator in rebxintegrators:
                self.setUp()
                self.sim.integrator = integrator
                self.sim.ri_ias15.epsilon = 0  # use fixed timesteps for ias15 if used, no problem otherwise
                self.integforce = self.rebx.load_operator("integrate_force")
                self.integforce.params['force'] = self.gr
                self.rebx.add_operator(self.integforce,
                                       dtfraction=1.,
                                       timing="pre")

                self.sim.integrate(1000)
                E = self.rebx.gr_hamiltonian(self.gr)
                # Test effect is actually doing something to the pericenter
                self.assertGreater(
                    self.sim.particles[1].pomega,
                    0.1,
                    msg='REB integrator: {0}, REBX integrator: {1}'.format(
                        integrator, rebxintegrator))
                # test energy conservtaion
                self.assertLess(
                    np.abs((E - self.E0) / self.E0),
                    1.e-4,
                    msg='REB integrator: {0}, REBX integrator: {1}'.format(
                        integrator, rebxintegrator))

                # test bitwise reproducibility starting from an intermediate snapshot
                self.sim.simulationarchive_snapshot('test.sa', deletefile=True)
                self.rebx.save('test.rebx')
                self.sim.integrate(2000)
                self.sim.simulationarchive_snapshot('test.sa')

                sa = reboundx.SimulationArchive('test.sa', 'test.rebx')
                simf, rebxf = sa[-1]
                tmax = simf.t
                sim, rebx = sa[0]
                sim.integrate(tmax)
                self.assertEqual(
                    self.sim.particles[1].x,
                    sim.particles[1].x,
                    msg='REB integrator: {0}, REBX integrator: {1}'.format(
                        integrator, rebxintegrator))
Esempio n. 5
0
    def test_force(self):
        for integrator in integrators + ['mercurius']:
            for rebxintegrator in rebxintegrators:
                self.setUp()
                self.sim.integrator = integrator
                self.rebx.add_force(self.gr)

                self.sim.integrate(1000)
                E = self.rebx.gr_hamiltonian(self.gr)
                # Test effect is actually doing something to the pericenter
                self.assertGreater(
                    self.sim.particles[1].pomega,
                    0.1,
                    msg='REB integrator: {0}, REBX integrator: {1}'.format(
                        integrator, rebxintegrator))
                # test energy conservtaion
                self.assertLess(
                    np.abs((E - self.E0) / self.E0),
                    1.e-4,
                    msg='REB integrator: {0}, REBX integrator: {1}'.format(
                        integrator, rebxintegrator))

                # test bitwise reproducibility starting from an intermediate snapshot
                self.sim.simulationarchive_snapshot('test.sa', deletefile=True)
                self.rebx.save('test.rebx')
                self.sim.integrate(2000)
                self.sim.simulationarchive_snapshot('test.sa')

                sa = reboundx.SimulationArchive('test.sa', 'test.rebx')
                simf, rebxf = sa[-1]
                tmax = simf.t
                sim, rebx = sa[0]
                sim.integrate(tmax)
                self.assertEqual(
                    self.sim.particles[1].x,
                    sim.particles[1].x,
                    msg='REB integrator: {0}, REBX integrator: {1}'.format(
                        integrator, rebxintegrator))