Repository navigation
Expand file tree
/
Copy pathtwo_body.py
More file actions
49 lines (42 loc) · 2.06 KB
/
Copy pathtwo_body.py
File metadata and controls
49 lines (42 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Compare the nine core methods with an analytic spatial two-body solution.
Assembles initial conditions, integration, analytic reference, error and cost
in one script. All stepping formulas are imported from ``astrosimbench``.
Usage
-----
python -m examples.two_body
python -m examples.two_body --eccentricity 0.8 --inclination 0.0
Defaults
--------
Eccentricity 0.6, inclination 0.4 rad, one quarter period, eleven output
times, initial or fixed dt = T/200.
Notes
-----
The printed error is the largest absolute barycentric position difference over
bodies and samples, not the scaled phase-space norm used in the lessons.
Force, jerk, Kepler and Newton counters measure different kinds of work.
Identical input settings do not make this an equal-accuracy comparison. Pure
two-body WH errors sit at a Kepler-solver/round-off floor and cannot measure
splitting order (see Lessons 1E and 2B). Prints a table; writes no files.
Requires NumPy only.
"""
import argparse
import numpy as np
from astrosimbench import integrate,METHODS
from astrosimbench.systems import eccentric_two_body,exact_two_body_states
def main():
parser=argparse.ArgumentParser()
parser.add_argument('--eccentricity',type=float,default=.6)
parser.add_argument('--inclination',type=float,default=.4,help='radians; 0 gives planar states with z=vz=0')
args=parser.parse_args()
r,v,m,T=eccentric_two_body(eccentricity=args.eccentricity,inclination=args.inclination)
end=.25*T
times=np.linspace(0,end,11)
ref,refv=exact_two_body_states(r,v,m,times)
print('method max position error force jerk Kepler Newton')
for name in METHODS:
out=integrate(name,r,v,m,t_span=(0,end),dt=T/200,sample_times=times)
error=np.max(np.linalg.norm(out.positions-ref,axis=-1))
c=out.cost
print(f'{out.method:12s} {error:18.6e} {c.force_evaluations:8d} {c.jerk_evaluations:9d} {c.kepler_solves:9d} {c.newton_iterations:9d}')
print('WH two-body errors are a solver/roundoff floor; measure WH order on perturbed three-body systems.')
if __name__=='__main__': main()