Skip to content

Instantly share code, notes, and snippets.

@syrte
Created March 26, 2022 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syrte/27079054c1aeb59744fd2b57eda87d51 to your computer and use it in GitHub Desktop.
Save syrte/27079054c1aeb59744fd2b57eda87d51 to your computer and use it in GitHub Desktop.
Interp orbit using agama between snapshots
def interp_orbit(ix, snap_list, npts=51, rtol=1e-5):
ns = len(snap_list) - 1
ts = np.array([si.t for si in snap_list.values()])
t_list = np.empty((ns, npts))
xv_list = np.empty((len(ix), ns, npts, 6))
for i, si in enumerate(snap_list.values()):
print(i, end=',', flush=True)
pot = si.pot_t
ic = si.xv[ix]
if i < ns:
res = agama.orbit(potential=pot, ic=ic, timestart=ts[i], time=ts[i + 1] - ts[i],
trajsize=npts, accuracy=rtol)
for j, (t, xv) in enumerate(res):
assert len(t) == npts
xv_list[j, i] = xv
t_list[i] = t
if i > 0:
res = agama.orbit(potential=pot, ic=ic, timestart=ts[i], time=ts[i - 1] - ts[i],
trajsize=npts, accuracy=rtol)
for j, (t, xv) in enumerate(res):
assert len(t) == npts
fac = (t[::-1] - ts[i - 1]).reshape(-1, 1) / (ts[i] - ts[i - 1])
xv_list[j, i - 1] = xv_list[j, i - 1] * (1 - fac) + xv[::-1] * fac
t_list = t_list.reshape(-1)
xv_list = xv_list.reshape(len(ix), -1, 6)
return ts, t_list, xv_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment