| 1 |
/* Poincare.mac is a set of routines for the computation |
| 2 |
of Poincare surfaces of sections of Hamiltonian systems */ |
| 3 |
|
| 4 |
/* Author: Jose A Vallejo |
| 5 |
Universidad Autonoma de San Luis Potosi (Mexico) |
| 6 |
[email protected] */ |
| 7 |
|
| 8 |
/* To avoid messages when loading draw, execute |
| 9 |
with_stdout("/dev/null",load(draw))$ (in Linux) |
| 10 |
with_stdout("NUL",load(draw))$ (in Windows) */ |
| 11 |
|
| 12 |
/* Poincare.mac requires a compiled version of |
| 13 |
rkfun.lisp, a LISP implementation of the RK4 |
| 14 |
algorithm due to Richard Fateman. The original |
| 15 |
code can be downloaded from |
| 16 |
https://people.eecs.berkeley.edu/~fateman/lisp/rkfun.lisp */ |
| 17 |
|
| 18 |
/*load("rkfun.fasl");*/ |
| 19 |
/*load("rkfun.lisp");*/ |
| 20 |
|
| 21 |
|
| 22 |
hameqs(H,name):=block( |
| 23 |
[vv,t,tvv,n,Q,P,eqq,eqp,eqs], |
| 24 |
vv:args(lhs(apply(fundef,[H]))), |
| 25 |
tvv:cons(t,vv), |
| 26 |
n:length(vv)/2, |
| 27 |
Q:makelist(vv[2*j-1],j,1,n), |
| 28 |
P:makelist(vv[2*k],k,1,n), |
| 29 |
eqq:makelist(float(diff(apply(H,vv),P[j])),j,1,n), |
| 30 |
eqp:makelist(float(-diff(apply(H,vv),Q[j])),j,1,n), |
| 31 |
eqs:join(eqq,eqp), |
| 32 |
for j:1 thru 2*n do define(funmake(concat(name,j),tvv),block([],mode_identity(float,vv),eqs[j])), |
| 33 |
apply(compile,makelist(concat(name,j),j,1,2*n)), |
| 34 |
[makelist(apply(concat(name,j),tvv),j,1,2*n),vv,makelist(concat(name,j),j,1,2*n)] |
| 35 |
)$ |
| 36 |
|
| 37 |
lextract(ll,n):=block([l,a,b], |
| 38 |
l:length(ll), |
| 39 |
a:rest(ll,n), |
| 40 |
b:rest(ll,n-l-1), |
| 41 |
append(b,a) |
| 42 |
)$ |
| 43 |
|
| 44 |
poincare3d(H,name,inicond,timestep,coord):=block( |
| 45 |
[heq,vars,tvars,hfuns,c,sol], |
| 46 |
heq:hameqs(H,name), |
| 47 |
vars:heq[2], |
| 48 |
tvars:cons(t,vars), |
| 49 |
hfuns:heq[3], |
| 50 |
c:first(sublist_indices(vars,lambda([x],x=coord))), |
| 51 |
sol:rkfun(hfuns,tvars,float(inicond),timestep), |
| 52 |
map(lambda([x],lextract(x,c)),map(lambda([x],rest(x)),sol)) |
| 53 |
)$ |
| 54 |
|
| 55 |
poincare2d(H,name,inicond,timestep,scene):=block( |
| 56 |
[heq,vars,tvars,hfuns,solu,c,soluc,sola,solb,subind,sol,e,f], |
| 57 |
heq:hameqs(H,name), |
| 58 |
vars:heq[2], |
| 59 |
tvars:cons(t,vars), |
| 60 |
hfuns:heq[3], |
| 61 |
solu:rkfun(hfuns,tvars,float(inicond),timestep), |
| 62 |
c:first(sublist_indices(vars,lambda([x],x=first(scene)))), |
| 63 |
soluc:map(lambda([x],x[c+1]),solu), |
| 64 |
sola:rest(soluc,-1)-second(scene), |
| 65 |
solb:rest(soluc)-second(scene), |
| 66 |
subind:sublist_indices(sola*solb,lambda([x],is(x < 0))), |
| 67 |
sol:makelist(solu[k],k,subind), |
| 68 |
e:first(sublist_indices(vars,lambda([x],x=third(scene))))+1, |
| 69 |
f:first(sublist_indices(vars,lambda([x],x=fourth(scene))))+1, |
| 70 |
makelist([j[e],j[f]],j,sol) |
| 71 |
)$ |