Moved from GSL Runge-Kutta to Boost Bulirsch-Stoer
This commit is contained in:
parent
9ec0633094
commit
c2051e9596
3 changed files with 90 additions and 43 deletions
20
plot.py
20
plot.py
|
|
@ -1,10 +1,13 @@
|
|||
#pylint: disable=W0401,W0614,W0622
|
||||
#All pylint codes: http://pylint.pycqa.org/en/latest/technical_reference/features.html
|
||||
|
||||
import numpy as np
|
||||
import ctypes, subprocess
|
||||
|
||||
recompile = True
|
||||
|
||||
if recompile:
|
||||
p = subprocess.Popen('g++ -shared -o libmain.so -fPIC loadtxt.cpp main.cpp -lgsl'.split())
|
||||
p = subprocess.Popen('g++ -I/home/meiron/boost_1_72_0 -shared -o libmain.so -fPIC loadtxt.cpp main.cpp -lgsl'.split())
|
||||
p.wait()
|
||||
if p.returncode != 0: raise RuntimeError(p.returncode)
|
||||
|
||||
|
|
@ -18,12 +21,21 @@ def integrate(y0, t_max, step_size=None):
|
|||
y = np.array(y).reshape(size,6)
|
||||
return np.array(y), status
|
||||
|
||||
gsl_success = libmain.gsl_success()
|
||||
def integrate_boost(y0, t_max, step_size=None):
|
||||
y0 = (ctypes.c_double*6)(*y0)
|
||||
if step_size is None: step_size = t_max
|
||||
size = int(t_max // step_size) + 1
|
||||
y = (ctypes.c_double*size*6)()
|
||||
libmain.integrate_boost(y0, ctypes.c_double(t_max), ctypes.c_double(step_size), y)
|
||||
y = np.array(y).reshape(size,6)
|
||||
return np.array(y), 0
|
||||
|
||||
#gsl_success = libmain.gsl_success()
|
||||
|
||||
from pylab import *
|
||||
t_max = 10
|
||||
ic = [80,0,0,0,80,0]
|
||||
res = integrate(ic, t_max, step_size=1/4096)
|
||||
res = integrate(ic, t_max, step_size=32/4096)
|
||||
x, y, z, vx, vy, vz = res[0].T
|
||||
zzz = x[-1]
|
||||
plot(x,y)
|
||||
|
|
@ -32,5 +44,5 @@ res = integrate(ic, t_max)
|
|||
x, y, z, vx, vy, vz = res[0].T
|
||||
plot(x,y,'o')
|
||||
print(zzz - x[-1])
|
||||
# gca().set_aspect('equal')
|
||||
gca().set_aspect('equal')
|
||||
show()
|
||||
Loading…
Add table
Add a link
Reference in a new issue