How to use the rebound.clibrebound.reb_get_jacobi_com function in rebound

To help you get started, we’ve selected a few rebound examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hannorein / rebound / rebound / particle.py View on Github external
if primary is None:
                raise ValueError("Particle does not belong to any simulation and no primary given. Cannot calculate orbit.")
            if G is None:
                raise ValueError("Particle does not belong to any simulation and G not given. Cannot calculate orbit.")
            else:
                G = c_double(G)
        else:
            # First check whether this is particles[0]
            clibrebound.reb_get_particle_index.restype = c_int
            index = clibrebound.reb_get_particle_index(byref(self)) # first check this isn't particles[0]
            if index == 0 and primary is None:
                raise ValueError("Orbital elements for particle[0] not implemented unless primary is provided")

            if primary is None:    # Use default, i.e., Jacobi coordinates
                clibrebound.reb_get_jacobi_com.restype = Particle   # now return jacobi center of mass
                primary = clibrebound.reb_get_jacobi_com(byref(self))
            G = c_double(self._sim.contents.G)
        
        err = c_int()
        clibrebound.reb_tools_particle_to_orbit_err.restype = rebound.Orbit
        o = clibrebound.reb_tools_particle_to_orbit_err(G, self, primary, byref(err))

        if err.value == 1:
            raise ValueError("Primary has no mass.")
        if err.value == 2:
            raise ValueError("Particle and primary positions are the same.")

        return o
github hannorein / rebound / rebound / simulation.py View on Github external
first ``last`` particles in the array (i.e., indices up to i-1, as used 
            in Jacobi coordinates).

        Examples
        --------
        >>> sim = rebound.Simulation()
        >>> sim.add(m=1, x=0)
        >>> sim.add(m=1, x=1)
        >>> com = sim.calculate_com()
        >>> com.x
        0.5

        """
        if last is not None:
            last = min(last, self.N_real-1)
            clibrebound.reb_get_jacobi_com.restype = Particle
            com = clibrebound.reb_get_jacobi_com(byref(self.particles[last]))
            return com
        else:
            clibrebound.reb_get_com.restype = Particle
            com = clibrebound.reb_get_com(byref(self))
            return com
github hannorein / rebound / rebound / simulation.py View on Github external
in Jacobi coordinates).

        Examples
        --------
        >>> sim = rebound.Simulation()
        >>> sim.add(m=1, x=0)
        >>> sim.add(m=1, x=1)
        >>> com = sim.calculate_com()
        >>> com.x
        0.5

        """
        if last is not None:
            last = min(last, self.N_real-1)
            clibrebound.reb_get_jacobi_com.restype = Particle
            com = clibrebound.reb_get_jacobi_com(byref(self.particles[last]))
            return com
        else:
            clibrebound.reb_get_com.restype = Particle
            com = clibrebound.reb_get_com(byref(self))
            return com
github hannorein / rebound / rebound / particle.py View on Github external
# Particle not in a simulation
            if primary is None:
                raise ValueError("Particle does not belong to any simulation and no primary given. Cannot calculate orbit.")
            if G is None:
                raise ValueError("Particle does not belong to any simulation and G not given. Cannot calculate orbit.")
            else:
                G = c_double(G)
        else:
            # First check whether this is particles[0]
            clibrebound.reb_get_particle_index.restype = c_int
            index = clibrebound.reb_get_particle_index(byref(self)) # first check this isn't particles[0]
            if index == 0 and primary is None:
                raise ValueError("Orbital elements for particle[0] not implemented unless primary is provided")

            if primary is None:    # Use default, i.e., Jacobi coordinates
                clibrebound.reb_get_jacobi_com.restype = Particle   # now return jacobi center of mass
                primary = clibrebound.reb_get_jacobi_com(byref(self))
            G = c_double(self._sim.contents.G)
        
        err = c_int()
        clibrebound.reb_tools_particle_to_orbit_err.restype = rebound.Orbit
        o = clibrebound.reb_tools_particle_to_orbit_err(G, self, primary, byref(err))

        if err.value == 1:
            raise ValueError("Primary has no mass.")
        if err.value == 2:
            raise ValueError("Particle and primary positions are the same.")

        return o
github hannorein / rebound / rebound / particle.py View on Github external
def jacobi_com(self):
        clibrebound.reb_get_jacobi_com.restype = Particle
        return clibrebound.reb_get_jacobi_com(byref(self))
    @property