Skip to main content

libassist_sys/
ffi.rs

1//! Raw FFI bindings to the ASSIST C library.
2//!
3//! `assist_ephem` and `assist_extras` are treated as opaque types. Field
4//! access goes through thin C helpers compiled in `helpers.c`. REBOUND types
5//! (`reb_simulation`, `reb_particle`) come from [`librebound_sys::ffi`] and
6//! are re-exported here so ASSIST FFI signatures resolve transparently.
7
8use libc::{c_char, c_double, c_int};
9
10// Re-export every REBOUND FFI item (types, constants, extern fns, accessor
11// helpers) so consumers can use a single `libassist_sys::ffi::*` namespace
12// for both REBOUND and ASSIST symbols.
13pub use librebound_sys::ffi::*;
14
15// ---------------------------------------------------------------------------
16// Opaque ASSIST types
17// ---------------------------------------------------------------------------
18
19/// Opaque ASSIST ephemeris data.
20#[repr(C)]
21pub struct assist_ephem {
22    _opaque: [u8; 0],
23}
24
25/// Opaque ASSIST extras (attaches ASSIST forces to a REBOUND simulation).
26#[repr(C)]
27pub struct assist_extras {
28    _opaque: [u8; 0],
29}
30
31// ---------------------------------------------------------------------------
32// Constants
33// ---------------------------------------------------------------------------
34
35// ASSIST body IDs
36pub const ASSIST_BODY_SUN: c_int = 0;
37pub const ASSIST_BODY_MERCURY: c_int = 1;
38pub const ASSIST_BODY_VENUS: c_int = 2;
39pub const ASSIST_BODY_EARTH: c_int = 3;
40pub const ASSIST_BODY_MOON: c_int = 4;
41pub const ASSIST_BODY_MARS: c_int = 5;
42pub const ASSIST_BODY_JUPITER: c_int = 6;
43pub const ASSIST_BODY_SATURN: c_int = 7;
44pub const ASSIST_BODY_URANUS: c_int = 8;
45pub const ASSIST_BODY_NEPTUNE: c_int = 9;
46pub const ASSIST_BODY_PLUTO: c_int = 10;
47pub const ASSIST_BODY_NPLANETS: c_int = 11;
48
49// ASSIST force flags
50pub const ASSIST_FORCE_SUN: c_int = 0x01;
51pub const ASSIST_FORCE_PLANETS: c_int = 0x02;
52pub const ASSIST_FORCE_ASTEROIDS: c_int = 0x04;
53pub const ASSIST_FORCE_NON_GRAVITATIONAL: c_int = 0x08;
54pub const ASSIST_FORCE_EARTH_HARMONICS: c_int = 0x10;
55pub const ASSIST_FORCE_SUN_HARMONICS: c_int = 0x20;
56pub const ASSIST_FORCE_GR_EIH: c_int = 0x40;
57pub const ASSIST_FORCE_GR_SIMPLE: c_int = 0x80;
58pub const ASSIST_FORCE_GR_POTENTIAL: c_int = 0x100;
59
60/// Default force flags: Sun + planets + asteroids + Earth J2/J3/J4 + Sun J2 + GR (EIH).
61pub const ASSIST_FORCES_DEFAULT: c_int = ASSIST_FORCE_SUN
62    | ASSIST_FORCE_PLANETS
63    | ASSIST_FORCE_ASTEROIDS
64    | ASSIST_FORCE_EARTH_HARMONICS
65    | ASSIST_FORCE_SUN_HARMONICS
66    | ASSIST_FORCE_GR_EIH;
67
68// ASSIST status codes
69pub const ASSIST_SUCCESS: c_int = 0;
70pub const ASSIST_ERROR_EPHEM_FILE: c_int = 1;
71pub const ASSIST_ERROR_AST_FILE: c_int = 2;
72
73// ---------------------------------------------------------------------------
74// ASSIST functions
75// ---------------------------------------------------------------------------
76
77unsafe extern "C" {
78    pub fn assist_ephem_create(
79        planets_path: *const c_char,
80        asteroids_path: *const c_char,
81    ) -> *mut assist_ephem;
82    pub fn assist_ephem_free(ephem: *mut assist_ephem);
83
84    pub fn assist_attach(sim: *mut reb_simulation, ephem: *mut assist_ephem) -> *mut assist_extras;
85    pub fn assist_free(ax: *mut assist_extras);
86    pub fn assist_detach(sim: *mut reb_simulation, ax: *mut assist_extras);
87
88    pub fn assist_get_particle(
89        ephem: *const assist_ephem,
90        particle_id: c_int,
91        t: c_double,
92    ) -> reb_particle;
93    pub fn assist_get_particle_with_error(
94        ephem: *const assist_ephem,
95        particle_id: c_int,
96        t: c_double,
97        error: *mut c_int,
98    ) -> reb_particle;
99
100    pub fn assist_integrate_or_interpolate(ax: *mut assist_extras, t: c_double);
101}
102
103// ---------------------------------------------------------------------------
104// C helper functions (from src/helpers.c)
105// ---------------------------------------------------------------------------
106
107unsafe extern "C" {
108    // Ephem cache reset (between propagations sharing the same simulation).
109    pub fn assist_rs_ephem_cache_reset(ax: *mut assist_extras);
110
111    // assist_extras field accessors
112    pub fn assist_rs_extras_get_forces(ax: *const assist_extras) -> c_int;
113    pub fn assist_rs_extras_set_forces(ax: *mut assist_extras, f: c_int);
114    pub fn assist_rs_extras_get_geocentric(ax: *const assist_extras) -> c_int;
115    pub fn assist_rs_extras_set_geocentric(ax: *mut assist_extras, g: c_int);
116    pub fn assist_rs_extras_get_particle_params(ax: *const assist_extras) -> *mut c_double;
117    pub fn assist_rs_extras_set_particle_params(ax: *mut assist_extras, p: *mut c_double);
118
119    // Non-gravitational force model parameters
120    pub fn assist_rs_extras_get_alpha(ax: *const assist_extras) -> c_double;
121    pub fn assist_rs_extras_set_alpha(ax: *mut assist_extras, v: c_double);
122    pub fn assist_rs_extras_get_nk(ax: *const assist_extras) -> c_double;
123    pub fn assist_rs_extras_set_nk(ax: *mut assist_extras, v: c_double);
124    pub fn assist_rs_extras_get_nm(ax: *const assist_extras) -> c_double;
125    pub fn assist_rs_extras_set_nm(ax: *mut assist_extras, v: c_double);
126    pub fn assist_rs_extras_get_nn(ax: *const assist_extras) -> c_double;
127    pub fn assist_rs_extras_set_nn(ax: *mut assist_extras, v: c_double);
128    pub fn assist_rs_extras_get_r0(ax: *const assist_extras) -> c_double;
129    pub fn assist_rs_extras_set_r0(ax: *mut assist_extras, v: c_double);
130
131    // assist_ephem field accessors
132    pub fn assist_rs_ephem_get_jd_ref(ephem: *const assist_ephem) -> c_double;
133    pub fn assist_rs_ephem_set_jd_ref(ephem: *mut assist_ephem, jd: c_double);
134    pub fn assist_rs_ephem_get_au(ephem: *const assist_ephem) -> c_double;
135    pub fn assist_rs_ephem_get_clight(ephem: *const assist_ephem) -> c_double;
136    pub fn assist_rs_ephem_get_c_au_per_day(ephem: *const assist_ephem) -> c_double;
137    pub fn assist_rs_ephem_get_re(ephem: *const assist_ephem) -> c_double;
138    pub fn assist_rs_ephem_get_re_eq(ephem: *const assist_ephem) -> c_double;
139    pub fn assist_rs_ephem_get_emrat(ephem: *const assist_ephem) -> c_double;
140}