Skip to main content

A small library for exploring the Circular Restricted 3-Body Problem (CR3BP)

Project description

build codecov

Intro

This is a small library meant to facilitate investigation of the Circular Restricted 3 Body Problem (CR3BP)

Usage

The library consists of a System dataclass representing a 3 body system, a couple of functions which encode the equations of motion of the CR3BP, and a function for setting initial conditions to get onto a periodic trajectory around the collinear Lagrange points. Below we'll explain the System class as well as the functions.

System class

You can either use one of the provided 3 body systems (Sun-Earth, Earth-Moon, Sun-Jupiter)

from cr3bp import EarthMoon

Or you can create your own system as follows:

from cr3bp import System
mass_primary = 2  # should be in kg
mass_secondary = 1  # should be in kg
distance = 100  # should be in m
MySystem = System(mass_primary, mass_secondary, distance)

System API

Properties

mass_primary - kg
mass_seconary - kg
l - m
G - 6.67408e-11 m^3 / (kg s^2) (this is constant across all Systems)
mu
theta_dot - radians/sec
total_mass - kg
seconds - number of seconds in a non-dimensional second (s*)
s - alias for seconds
conversion_vector - provides the vector [l, l, l, l/s, l/s, l/s] for converting dimensionless state to dimensional state
L1
L2
L3
L4
L5

All of the L* functions return dimensionless values. L1-3 return a float, L4 and L5 return a tuple with x and y values (but they just return (0.5, +/- sqrt(3)/2) for all systems). L1-3 perform a root-finding calculation so it's best not to use them in a performance sensitive loop - store the returned value and use that

Functions

convert_to_dimensional_state(state)

Accepts a dimensionless 6-element state vector and returns a 6-element state vector with dimensions added in

x_eqn

This is used for calculating the location of the collinear Lagrange points. It returns a function that bakes in the mu value of the system and which can then be used for plotting or root finding.

Other functions

  • DimensionalEOMs(t, X, system=EarthMoon)
    This function encodes the EOMs for the CR3BP using dimensional values (meters, seconds, etc.). It is meant to be used with a numerical integrator from scipy. For example: scipy.integrate.solve_ivp(cr3bp.DimensionalEOMs, [0, 3600*24], IC, args=[cr3bp.SunEarth], atol=1e-6, rtol=1e-12)
    In this case we are starting from some initial condition IC (a 6 element state vector) and integrating for 1 day using the SunEarth system with a tolerance down to the micrometer level (atol=1e-6)

  • EOMConstructor(mu, STM=False)
    This encodes the EOMs in dimensionless form but it's a little different from DimensionalEOMs in that it takes a mu value and returns a function that can be used with numerical integrators. This just makes it a little smoother to use the numerical integrators since you specify the system when creating the EOMs as opposed to passing it in every time the EOMs are evaluated. The returned function can either integrate the State Transition Matrix or not. If integrating the STM, the returned function will expected a 42-element state vector, if not it will expect a 6-element one. Use this function like this:

EM = cr3bp.EarthMoon
eoms = cr3bp.EOMConstructor(EM.mu)
# We set the absolute tolerance to be at the micrometer level and keep the rtol small enough so that the atol dominates. rtol cannot be set lower than machine precision, so there may be some precision issues.
solution = scipy.integrate.solve_ivp(eoms, [0, 3600*24 / EM.seconds], IC, atol=0.000001/EM.l, rtol=2.3e-14)
  • initial_velocity(initial_position: tuple[float, float], lpoint: float, mu: float) -> tuple[float, float]:
    This function takes a dimensionless initial position consisting of an x and y position relative to the system barycenter, the dimensionless value of the collinear Lagrange point around which one wants to oscillate, and the mu of the system and returns the necessary initial x and y velocity to get onto an oscillatory trajectory around the Lagrange point. Sample usage:
# IC (Initial Conditions) represents x, y, z, xdot, ydot, zdot
IC = [EM.L1 + 100/EM.l, 0, 0, 0, 0, 0]
IC[3:5] = cr3bp.initial_velocity(IC[:2], EM.L1, EM.mu)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cr3bp-0.2.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

cr3bp-0.2.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file cr3bp-0.2.1.tar.gz.

File metadata

  • Download URL: cr3bp-0.2.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for cr3bp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bf7484f38e7e9fb30510e92b496149389ab87a56a722b3409032e2ce0d9628aa
MD5 3a651d80e9f6e39210ae1e6eb2857a4d
BLAKE2b-256 5dfff154c5a9addbf776b7f9ae5ac03ed8045d9ad92ab385cd3f2594a1389314

See more details on using hashes here.

File details

Details for the file cr3bp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: cr3bp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for cr3bp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3cc8dcf14cc457c8a0cd429cc98fd0e570e77374cb0680b84c486843abc439ed
MD5 c47464954ec3d96ca3a53a896c6afa1f
BLAKE2b-256 15d766db9c82d705a403d410de9d497e12e1dd72d50c2ac2860685d9f517dc2a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page