forked from lruhlen/Original_Peter_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoomre.f
More file actions
1497 lines (1271 loc) · 38.4 KB
/
toomre.f
File metadata and controls
1497 lines (1271 loc) · 38.4 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program toomre
c.. Computes galaxy encounters using the restricted three-body approximation
c.. Requires Numerical Recipes Routines: RAN2
c. BSSTEP (set nmax=2000)
c. PZEXTR (set nmax=2000)
c. MMID (set nmax=2000)
c...
c............................................................................
implicit real*8(a-h,o-z), integer*4(i-n)
parameter (nb=176,ngal=2,numrings=6)
parameter(n=6*nb,pi=3.14159265358979323846)
dimension nring(6)
dimension rring(6)
dimension y(n),dydx(n),yscal(n)
common /path2/ rm(ngal),vcx,vcy,vcz
data nring /14,20,26,32,38,44/
data rring /.14,.20,.26,.32,.38,.44/
external derivs
c.. Timestep accuracy for Bulirsch-Stoer
Acc=1.e-8
c.. number of phase space dimensions
nvar=n
c.. number of scattering trials
nloop=1
c.. initial timestep guess
htry=0.01
c.. integration timescale
x2=7.
c.. maximum timestep number
nstepmax=5000
c.. printout interval
printdt=1.
c.. starting time for the integration
x=0.
c.. initial snapshot number
nsnap=0
open(unit=1,file='gal1.pos',status='unknown')
open(unit=2,file='gal2.pos',status='unknown')
c.. Galaxy encounter initial conditions:
rm(1)=5.
rm(2)=1.
a=3.
e=0.6
rinc=pi/6.
p=pi/4.
rn=pi/2.
rl=1.7*pi
c.. euler angles for rotation of angular momentum vector of initial galaxy
ephi=pi/3.
ethe=pi/3.
epsi=0.
c.. transform orbital elements of galaxy pair into cartesian coordinates:
y(1)=0.
y(2)=0.
y(3)=0.
y(4)=0.
y(5)=0.
y(6)=0.
rmu=rm(1)+rm(2)
q=a*(1-e)
c.. this routine does the elements to cartesian conversion
call mco_el2x (rmu,q,e,rinc,p,rn,rl,rx,ry,rz,ru,rv,rw)
ib=6*(ngal-1)
y(ib+1)=rx
y(ib+3)=ry
y(ib+5)=rz
y(ib+2)=ru
y(ib+4)=rv
y(ib+6)=rw
c.. form the rotation matrix for the given euler angles:
s1 = sin(ephi)
c1 = cos(ephi)
s2 = sin(ethe)
c2 = cos(ethe)
s3 = sin(epsi)
c3 = cos(epsi)
a11 = c3*c1 - c2*s1*s3
a12 = -1.0*s3*c1 - c2*s1*c3
a13 = s2*s1
a21 = c3*s1 + c2*c1*s3
a22 = -1.0*s3*s1 + c2*c1*c3
a23 = -1.0*s2*c1
a31 = s3*s2
a32 = c3*s2
a33 = c2
c.. set up the test particles
ipart=ngal
do j=1,numrings
do i=1,nring(j)
ipart=ipart+1
ib=(ipart-1)*6
thet=(real(i)/real(nring(j)))*(2.*pi)
xp0=rring(j)*cos(thet)
yp0=rring(j)*sin(thet)
zp0=0.0
y(ib+1)=a11*xp0 + a12*yp0 + a13*zp0
y(ib+3)=a21*xp0 + a22*yp0 + a23*zp0
y(ib+5)=a31*xp0 + a32*yp0 + a33*zp0
vcirc= sqrt(rm(2)/rring(j))
vx0=-vcirc*sin(thet)
vy0= vcirc*cos(thet)
vz0=0.0
y(ib+2)=a11*vx0 + a12*vy0 + a13*vz0
y(ib+4)=a21*vx0 + a22*vy0 + a23*vz0
y(ib+6)=a31*vx0 + a32*vy0 + a33*vz0
end do
end do
c.. put them in orbit around the primary
do i=ngal+1,ipart
ib=(i-1)*6
kb=(ngal-1)*6
do jb=1,6
y(ib+jb)=y(ib+jb)+y(kb+jb)
end do
end do
c.. Compute center of mass velocity for the system and subtract it.
vcx=0.
vcy=0.
vcz=0.
rmtot=0.
do i=1,ngal
ib=(i-1)*6
rmtot=rmtot+rm(i)
vcx=vcx+rm(i)*y(ib+2)
vcy=vcy+rm(i)*y(ib+4)
vcz=vcz+rm(i)*y(ib+6)
end do
vcx=vcx/rmtot
vcy=vcy/rmtot
vcz=vcz/rmtot
do i=1,nb
ib=(i-1)*6
y(ib+2)=y(ib+2)-vcx
y(ib+4)=y(ib+4)-vcy
y(ib+6)=y(ib+6)-vcz
end do
c.. Compute center of mass position of system and subtract it.
pcx=0.
pcy=0.
pcz=0.
rmtot=0.
do i=1,ngal
ib=(i-1)*6
rmtot=rmtot+rm(i)
pcx=pcx+rm(i)*y(ib+1)
pcy=pcy+rm(i)*y(ib+3)
pcz=pcz+rm(i)*y(ib+5)
end do
pcx=pcx/rmtot
pcy=pcy/rmtot
pcz=pcz/rmtot
do i=1,nb
ib=(i-1)*6
y(ib+1)=y(ib+1)-pcx
y(ib+3)=y(ib+3)-pcy
y(ib+5)=y(ib+5)-pcz
end do
c.. Overall integration loop
iflag=0
2105 continue
iflag=iflag+1
call derivs(x,y,dydx)
do iscale=1,nvar
yscal(iscale)=abs(y(iscale))+abs(htry*dydx(iscale))+1.e-30
end do
call bsstep(y,dydx,nvar,x,htry,acc,yscal,hdid,hnext,derivs)
htry=hnext
c.. write out high-resolution orbit for the two test particles:
write(1,*) y(1),y(3),y(5)
write(2,*) y(7),y(9),y(11)
if(x.gt.(nsnap*printdt)) then
nsnap=nsnap+1
call printout(x,y,nsnap)
end if
if(iflag.gt.nstepmax.or.x.gt.x2) then
goto 2106
end if
c.. go do another step.
goto 2105
2106 continue
c.. End of overall integration loop for a particular experiment
end
subroutine derivs(x,y,dydx)
implicit real*8(a-h,o-z), integer*4(i-n)
parameter (nb=176,ngal=2)
parameter (eps2=0.0005)
parameter(n=6*nb,pi=3.14159265358979323846)
common /path2/ rm(ngal),vcx,vcy,vcz
real*8 x,y(n),dydx(n)
real*8 denom(ngal,ngal)
real*8 denom2(nb,ngal)
do i=2,n,2
dydx(i-1)=y(i)
end do
do i=1,ngal
do j=i+1,ngal
if (i.ne.j) then
jb=(j-1)*6
ib=(i-1)*6
denom(i,j)=(y(jb+1)-y(ib+1))*(y(jb+1)-y(ib+1)) +
+ (y(jb+3)-y(ib+3))*(y(jb+3)-y(ib+3)) +
+ (y(jb+5)-y(ib+5))*(y(jb+5)-y(ib+5)) +
+ eps2
denom(i,j)=denom(i,j)*sqrt(denom(i,j))
denom(j,i)=denom(i,j)
end if
end do
end do
do i=ngal +1,nb
do j=1,ngal
if (i.ne.j) then
jb=(j-1)*6
ib=(i-1)*6
denom2(i,j)=(y(jb+1)-y(ib+1))*(y(jb+1)-y(ib+1)) +
+ (y(jb+3)-y(ib+3))*(y(jb+3)-y(ib+3)) +
+ (y(jb+5)-y(ib+5))*(y(jb+5)-y(ib+5)) +
+ eps2
denom2(i,j)=denom2(i,j)*sqrt(denom2(i,j))
end if
end do
end do
2104 continue
c.. self-gravitating particles
do i=1,ngal
ib=(i-1)*6
do ic=1,3
dydx(ib+(2*ic))=0.
c.. contributions from the other massive particles:
do j=1,ngal
jb=(j-1)*6
if( i.ne.j) then
dydx(ib+(2*ic))=dydx(ib+(2*ic)) -
+ rm(j)*(y(ib+2*ic-1)-y(jb+2*ic-1))/denom(i,j)
end if
end do
end do
end do
c.. test particles
do i=ngal +1,nb
ib=(i-1)*6
do ic=1,3
dydx(ib+(2*ic))=0.
c.. contributions from the massive particles:
do j=1,ngal
jb=(j-1)*6
dydx(ib+(2*ic))=dydx(ib+(2*ic)) -
+ rm(j)*(y(ib+2*ic-1)-y(jb+2*ic-1))/denom2(i,j)
end do
end do
end do
return
end
c..................................................................
c
subroutine printout(x,y,nsnap)
c
c..................................................................
implicit real*8(a-h,o-z), integer*4(i-n)
parameter (nb=176,ngal=2)
parameter(n=6*nb,pi=3.14159265358979323846)
common /path2/ rm(ngal),vcx,vcy,vcz
real*8 y(6*nb)
character*3 sstring
character*4 filestem
character*10 nstring
character*7 target_out
data nstring/'0123456789'/
save
sstring(1:1)=nstring(1+nsnap/100:1+nsnap/100)
istring=1+mod(nsnap,100)/10
sstring(2:2)=nstring(istring:istring)
istring=1+mod(nsnap,10)
sstring(3:3)=nstring(istring:istring)
filestem='snap'
target_out=filestem(1:4)//sstring(1:3)
open(unit=10,file=target_out,status='unknown')
do i=1,nb
jb=(i-1)*6
write(10,2104) y(jb+1),y(jb+3),y(jb+5)
end do
2104 format(4e13.5)
close(10)
return
end
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_X2EL.FOR (ErikSoft 6 May 2000)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Calculates Keplerian orbital elements given relative coordinates and
c velocities, and MU = G times the sum of the masses.
c
c The elements are: q = perihelion distance
c e = eccentricity
c i = inclination
c p = longitude of perihelion (NOT argument of perihelion!!)
c n = longitude of ascending node
c l = mean anomaly (or mean longitude if e < 1.e-8)
c
c------------------------------------------------------------------------------
c
subroutine mco_x2el (mu,x,y,z,u,v,w,q,e,i,p,n,l)
c
implicit none
integer NMAX, CMAX, NMESS
real*8 HUGE
parameter (NMAX = 2000)
parameter (CMAX = 50)
parameter (NMESS = 200)
parameter (HUGE = 9.9d29)
c Constants:
c
c DR = conversion factor from degrees to radians
c K2 = Gaussian gravitational constant squared
c AU = astronomical unit in cm
c MSUN = mass of the Sun in g
c
real*8 PI,TWOPI,PIBY2,DR,K2,AU,MSUN
c
parameter (PI = 3.141592653589793d0)
parameter (TWOPI = PI * 2.d0)
parameter (PIBY2 = PI * .5d0)
parameter (DR = PI / 180.d0)
parameter (K2 = 2.959122082855911d-4)
parameter (AU = 1.4959787e13)
parameter (MSUN = 1.9891e33)
c
c Input/Output
real*8 mu,q,e,i,p,n,l,x,y,z,u,v,w
c
c Local
real*8 hx,hy,hz,h2,h,v2,r,rv,s,true
real*8 ci,to,temp,tmp2,bige,f,cf,ce
c
c------------------------------------------------------------------------------
c
hx = y * w - z * v
hy = z * u - x * w
hz = x * v - y * u
h2 = hx*hx + hy*hy + hz*hz
v2 = u * u + v * v + w * w
rv = x * u + y * v + z * w
r = sqrt(x*x + y*y + z*z)
h = sqrt(h2)
s = h2 / mu
c
c Inclination and node
ci = hz / h
if (abs(ci).lt.1) then
i = acos (ci)
n = atan2 (hx,-hy)
if (n.lt.0) n = n + TWOPI
else
if (ci.gt.0) i = 0.d0
if (ci.lt.0) i = PI
n = 0.d0
end if
c
c Eccentricity and perihelion distance
temp = 1.d0 + s*(v2/mu - 2.d0/r)
if (temp.le.0) then
e = 0.d0
else
e = sqrt (temp)
end if
q = s / (1.d0 + e)
c
c True longitude
if (hy.ne.0) then
to = -hx/hy
temp = (1.d0 - ci) * to
tmp2 = to * to
true = atan2((y*(1.d0+tmp2*ci)-x*temp),(x*(tmp2+ci)-y*temp))
else
true = atan2(y * ci, x)
end if
if (ci.lt.0) true = true + PI
c
if (e.lt.1.d-8) then
p = 0.d0
l = true
else
ce = (v2*r - mu) / (e*mu)
c
c Mean anomaly for ellipse
if (e.lt.1) then
if (abs(ce).gt.1) ce = sign(1.d0,ce)
bige = acos(ce)
if (rv.lt.0) bige = TWOPI - bige
l = bige - e*sin(bige)
else
c
c Mean anomaly for hyperbola
if (ce.lt.1) ce = 1.d0
bige = log( ce + sqrt(ce*ce-1.d0) )
if (rv.lt.0) bige = TWOPI - bige
l = e*sinh(bige) - bige
end if
c
c Longitude of perihelion
cf = (s - r) / (e*r)
if (abs(cf).gt.1) cf = sign(1.d0,cf)
f = acos(cf)
if (rv.lt.0) f = TWOPI - f
p = true - f
p = mod (p + TWOPI + TWOPI, TWOPI)
end if
c
if (l.lt.0) l = l + TWOPI
if (l.gt.TWOPI) l = mod (l, TWOPI)
c
c------------------------------------------------------------------------------
c
return
end
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_KEP.FOR (ErikSoft 7 July 1999)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Solves Kepler's equation for eccentricities less than one.
c Algorithm from A. Nijenhuis (1991) Cel. Mech. Dyn. Astron. 51, 319-330.
c
c e = eccentricity
c l = mean anomaly (radians)
c u = eccentric anomaly ( " )
c
c------------------------------------------------------------------------------
c
function mco_kep (e,oldl)
implicit none
c
c Input/Outout
real*8 oldl,e,mco_kep
c
c Local
real*8 l,pi,twopi,piby2,u1,u2,ome,sign
real*8 x,x2,sn,dsn,z1,z2,z3,f0,f1,f2,f3
real*8 p,q,p2,ss,cc
logical flag,big,bigg
c
c------------------------------------------------------------------------------
c
pi = 3.141592653589793d0
twopi = 2.d0 * pi
piby2 = .5d0 * pi
c
c Reduce mean anomaly to lie in the range 0 < l < pi
if (oldl.ge.0) then
l = mod(oldl, twopi)
else
l = mod(oldl, twopi) + twopi
end if
sign = 1.d0
if (l.gt.pi) then
l = twopi - l
sign = -1.d0
end if
c
ome = 1.d0 - e
c
if (l.ge..45d0.or.e.lt..55d0) then
c
c Regions A,B or C in Nijenhuis
c -----------------------------
c
c Rough starting value for eccentric anomaly
if (l.lt.ome) then
u1 = ome
else
if (l.gt.(pi-1.d0-e)) then
u1 = (l+e*pi)/(1.d0+e)
else
u1 = l + e
end if
end if
c
c Improved value using Halley's method
flag = u1.gt.piby2
if (flag) then
x = pi - u1
else
x = u1
end if
x2 = x*x
sn = x*(1.d0 + x2*(-.16605 + x2*.00761) )
dsn = 1.d0 + x2*(-.49815 + x2*.03805)
if (flag) dsn = -dsn
f2 = e*sn
f0 = u1 - f2 - l
f1 = 1.d0 - e*dsn
u2 = u1 - f0/(f1 - .5d0*f0*f2/f1)
else
c
c Region D in Nijenhuis
c ---------------------
c
c Rough starting value for eccentric anomaly
z1 = 4.d0*e + .5d0
p = ome / z1
q = .5d0 * l / z1
p2 = p*p
z2 = exp( log( dsqrt( p2*p + q*q ) + q )/1.5 )
u1 = 2.d0*q / ( z2 + p + p2/z2 )
c
c Improved value using Newton's method
z2 = u1*u1
z3 = z2*z2
u2 = u1 - .075d0*u1*z3 / (ome + z1*z2 + .375d0*z3)
u2 = l + e*u2*( 3.d0 - 4.d0*u2*u2 )
end if
c
c Accurate value using 3rd-order version of Newton's method
c N.B. Keep cos(u2) rather than sqrt( 1-sin^2(u2) ) to maintain accuracy!
c
c First get accurate values for u2 - sin(u2) and 1 - cos(u2)
bigg = (u2.gt.piby2)
if (bigg) then
z3 = pi - u2
else
z3 = u2
end if
c
big = (z3.gt.(.5d0*piby2))
if (big) then
x = piby2 - z3
else
x = z3
end if
c
x2 = x*x
ss = 1.d0
cc = 1.d0
c
ss = x*x2/6.*(1. - x2/20.*(1. - x2/42.*(1. - x2/72.*(1. -
% x2/110.*(1. - x2/156.*(1. - x2/210.*(1. - x2/272.)))))))
cc = x2/2.*(1. - x2/12.*(1. - x2/30.*(1. - x2/56.*(1. -
% x2/ 90.*(1. - x2/132.*(1. - x2/182.*(1. - x2/240.*(1. -
% x2/306.))))))))
c
if (big) then
z1 = cc + z3 - 1.d0
z2 = ss + z3 + 1.d0 - piby2
else
z1 = ss
z2 = cc
end if
c
if (bigg) then
z1 = 2.d0*u2 + z1 - pi
z2 = 2.d0 - z2
end if
c
f0 = l - u2*ome - e*z1
f1 = ome + e*z2
f2 = .5d0*e*(u2-z1)
f3 = e/6.d0*(1.d0-z2)
z1 = f0/f1
z2 = f0/(f2*z1+f1)
mco_kep = sign*( u2 + f0/((f3*z1+f2)*z2+f1) )
c
c------------------------------------------------------------------------------
c
return
end
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_SINE.FOR (ErikSoft 17 April 1997)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Calculates sin and cos of an angle X (in radians).
c
c------------------------------------------------------------------------------
c
subroutine mco_sine (x,sx,cx)
c
implicit none
c
c Input/Output
real*8 x,sx,cx
c
c Local
real*8 pi,twopi
c
c------------------------------------------------------------------------------
c
pi = 3.141592653589793d0
twopi = 2.d0 * pi
c
if (x.gt.0) then
x = mod(x,twopi)
else
x = mod(x,twopi) + twopi
end if
c
cx = cos(x)
c
if (x.gt.pi) then
sx = -sqrt(1.d0 - cx*cx)
else
sx = sqrt(1.d0 - cx*cx)
end if
c
c------------------------------------------------------------------------------
c
return
end
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_SINH.FOR (ErikSoft 12 June 1998)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Calculates sinh and cosh of an angle X (in radians)
c
c------------------------------------------------------------------------------
c
subroutine mco_sinh (x,sx,cx)
c
implicit none
c
c Input/Output
real*8 x,sx,cx
c
c------------------------------------------------------------------------------
c
sx = sinh(x)
cx = sqrt (1.d0 + sx*sx)
c
c------------------------------------------------------------------------------
c
return
end
***********************************************************************
c ORBEL_FGET.F
***********************************************************************
* PURPOSE: Solves Kepler's eqn. for hyperbola using hybrid approach.
*
* Input:
* e ==> eccentricity anomaly. (real scalar)
* capn ==> hyperbola mean anomaly. (real scalar)
* Returns:
* orbel_fget ==> eccentric anomaly. (real scalar)
*
* ALGORITHM: Based on pp. 70-72 of Fitzpatrick's book "Principles of
* Cel. Mech. ". Quartic convergence from Danby's book.
* REMARKS:
* AUTHOR: M. Duncan
* DATE WRITTEN: May 11, 1992.
* REVISIONS: 2/26/93 hfl
***********************************************************************
real*8 function orbel_fget(e,capn)
implicit NONE
c... Version of Swift
real*8 VER_NUM
parameter(VER_NUM=2.0d0)
c... Maximum array size
integer NPLMAX, NTPMAX
c parameter (NPLMAX = 21) ! max number of planets, including the Sun
parameter (NPLMAX = 51) ! max number of planets, including the Sun
parameter (NTPMAX = 1001) ! max number of test particles
c... Size of the test particle integer status flag
integer NSTATP ! Number of status parameters
parameter (NSTATP = 3)
integer NSTAT ! Number of status parameters
parameter (NSTAT = NSTATP + NPLMAX - 1) ! include one for @ planet
c... Size of the test particle integer status flag
integer NSTATR
parameter (NSTATR = NSTAT) ! io_init_tp assumes NSTAT==NSTATR
c... convergence criteria for danby
real*8 DANBYAC , DANBYB
parameter (DANBYAC= 1.0d-14, DANBYB = 1.0d-13)
c... loop limits in the Laguerre attempts
integer NLAG1, NLAG2
parameter(NLAG1 = 50, NLAG2 = 400)
c... A small number
real*8 TINY
PARAMETER(TINY=4.D-15)
c... trig stuff
real*8 PI,TWOPI,PIBY2,DEGRAD
parameter (PI = 3.14159265358979D0)
parameter (TWOPI = 2.0D0 * PI)
parameter (PIBY2 = PI/2.0D0)
parameter (DEGRAD = 180.0D0 / PI)
c... Inputs Only:
real*8 e,capn
c... Internals:
integer i,IMAX
real*8 tmp,x,shx,chx
real*8 esh,ech,f,fp,fpp,fppp,dx
PARAMETER (IMAX = 10)
c----
c... Executable code
c Function to solve "Kepler's eqn" for F (here called
c x) for given e and CAPN.
c begin with a guess proposed by Danby
if( capn .lt. 0.d0) then
tmp = -2.d0*capn/e + 1.8d0
x = -log(tmp)
else
tmp = +2.d0*capn/e + 1.8d0
x = log( tmp)
endif
orbel_fget = x
do i = 1,IMAX
call orbel_schget(x,shx,chx)
esh = e*shx
ech = e*chx
f = esh - x - capn
c write(6,*) 'i,x,f : ',i,x,f
fp = ech - 1.d0
fpp = esh
fppp = ech
dx = -f/fp
dx = -f/(fp + dx*fpp/2.d0)
dx = -f/(fp + dx*fpp/2.d0 + dx*dx*fppp/6.d0)
orbel_fget = x + dx
c If we have converged here there's no point in going on
if(abs(dx) .le. TINY) RETURN
x = orbel_fget
enddo
write(6,*) 'FGET : RETURNING WITHOUT COMPLETE CONVERGENCE'
return
end ! orbel_fget
c------------------------------------------------------------------
***********************************************************************
c ORBEL_FLON.F
***********************************************************************
* PURPOSE: Solves Kepler's eqn. for hyperbola using hybrid approach.
*
* Input:
* e ==> eccentricity anomaly. (real scalar)
* capn ==> hyperbola mean anomaly. (real scalar)
* Returns:
* orbel_flon ==> eccentric anomaly. (real scalar)
*
* ALGORITHM: Uses power series for N in terms of F and Newton,s method
* REMARKS: ONLY GOOD FOR LOW VALUES OF N (N < 0.636*e -0.6)
* AUTHOR: M. Duncan
* DATE WRITTEN: May 26, 1992.
* REVISIONS:
***********************************************************************
real*8 function orbel_flon(e,capn)
implicit NONE
c... Version of Swift
real*8 VER_NUM
parameter(VER_NUM=2.0d0)
c... Maximum array size
integer NPLMAX, NTPMAX
c parameter (NPLMAX = 21) ! max number of planets, including the Sun
parameter (NPLMAX = 51) ! max number of planets, including the Sun
parameter (NTPMAX = 1001) ! max number of test particles
c... Size of the test particle integer status flag
integer NSTATP ! Number of status parameters
parameter (NSTATP = 3)
integer NSTAT ! Number of status parameters
parameter (NSTAT = NSTATP + NPLMAX - 1) ! include one for @ planet
c... Size of the test particle integer status flag
integer NSTATR
parameter (NSTATR = NSTAT) ! io_init_tp assumes NSTAT==NSTATR
c... convergence criteria for danby
real*8 DANBYAC , DANBYB
parameter (DANBYAC= 1.0d-14, DANBYB = 1.0d-13)
c... loop limits in the Laguerre attempts
integer NLAG1, NLAG2
parameter(NLAG1 = 50, NLAG2 = 400)
c... A small number
real*8 TINY
PARAMETER(TINY=4.D-15)
c... trig stuff
real*8 PI,TWOPI,PIBY2,DEGRAD
parameter (PI = 3.14159265358979D0)
parameter (TWOPI = 2.0D0 * PI)
parameter (PIBY2 = PI/2.0D0)
parameter (DEGRAD = 180.0D0 / PI)
c... Inputs Only:
real*8 e,capn
c... Internals:
integer iflag,i,IMAX
real*8 a,b,sq,biga,bigb
real*8 x,x2
real*8 f,fp,dx
real*8 diff
real*8 a0,a1,a3,a5,a7,a9,a11
real*8 b1,b3,b5,b7,b9,b11
PARAMETER (IMAX = 10)
PARAMETER (a11 = 156.d0,a9 = 17160.d0,a7 = 1235520.d0)
PARAMETER (a5 = 51891840.d0,a3 = 1037836800.d0)
PARAMETER (b11 = 11.d0*a11,b9 = 9.d0*a9,b7 = 7.d0*a7)
PARAMETER (b5 = 5.d0*a5, b3 = 3.d0*a3)
c----
c... Executable code
c Function to solve "Kepler's eqn" for F (here called
c x) for given e and CAPN. Only good for smallish CAPN
iflag = 0
if( capn .lt. 0.d0) then
iflag = 1
capn = -capn
endif
a1 = 6227020800.d0 * (1.d0 - 1.d0/e)
a0 = -6227020800.d0*capn/e
b1 = a1
c Set iflag nonzero if capn < 0., in which case solve for -capn
c and change the sign of the final answer for F.
c Begin with a reasonable guess based on solving the cubic for small F
a = 6.d0*(e-1.d0)/e
b = -6.d0*capn/e
sq = sqrt(0.25*b*b +a*a*a/27.d0)
biga = (-0.5*b + sq)**0.3333333333333333d0
bigb = -(+0.5*b + sq)**0.3333333333333333d0
x = biga + bigb
c write(6,*) 'cubic = ',x**3 +a*x +b
orbel_flon = x
c If capn is tiny (or zero) no need to go further than cubic even for
c e =1.
if( capn .lt. TINY) go to 100
do i = 1,IMAX
x2 = x*x
f = a0 +x*(a1+x2*(a3+x2*(a5+x2*(a7+x2*(a9+x2*(a11+x2))))))
fp = b1 +x2*(b3+x2*(b5+x2*(b7+x2*(b9+x2*(b11 + 13.d0*x2)))))
dx = -f/fp
c write(6,*) 'i,dx,x,f : '
c write(6,432) i,dx,x,f
432 format(1x,i3,3(2x,1p1e22.15))
orbel_flon = x + dx
c If we have converged here there's no point in going on
if(abs(dx) .le. TINY) go to 100
x = orbel_flon
enddo
c Abnormal return here - we've gone thru the loop
c IMAX times without convergence
if(iflag .eq. 1) then
orbel_flon = -orbel_flon
capn = -capn
endif
write(6,*) 'FLON : RETURNING WITHOUT COMPLETE CONVERGENCE'
diff = e*sinh(orbel_flon) - orbel_flon - capn
write(6,*) 'N, F, ecc*sinh(F) - F - N : '
write(6,*) capn,orbel_flon,diff
return
c Normal return here, but check if capn was originally negative
100 if(iflag .eq. 1) then
orbel_flon = -orbel_flon
capn = -capn
endif