Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
# 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
def jacobi_com(self):
clibrebound.reb_get_jacobi_com.restype = Particle
return clibrebound.reb_get_jacobi_com(byref(self))
@property