-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhscf.f
executable file
·1867 lines (1583 loc) · 49.5 KB
/
hscf.f
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
c****************************************************************************
c computes the hydrostatic equilibrium structures of rigidly
c rotating polytropes and white dwarfs - 2d.
c to build tori, kout should be a negative integer.
c to build spheroids, kout should be a positive integer.
c when building polytropes, the output appears in polyout.
c the units in polyout are the dimesionless units given in
c hachisu, i. 1986, apjsuppl., 61, 479. the output for white
c dwarf models is in wdout, where the units are cgs and are
c akin to the normalizations in table 4 of hachisu, 1986.
c*****************************************************************************
c
c compile double precision on workstations!!!
c
c
c last edited: sept 9, 1993
c adding j(m) option
c oct 5, 1993
c adding subs for n' options and n'=infinity
c oct 11,1993
c adding conversion to polytrope units
c
c nov 15,1993
c by taking a weighted average of the density array from one step to
c the next we can exceed the performance of the bo code. del = 0.75
c seems to be the optimum for the more spherical models.
c may need to go as high as .90 or .95 for the flatter ones
c
c nov 19,1993
c creating output file for hydro code called fort.2
c as written, minor changes in hydro code are required in order to
c read the input file. they are:
c 1.) change the dimensions of the denny and anggy arrays in hydro
c to denny(jmax2,kmax2) and anngy(jmax1,kmax1). both
c parameters are currently included in the param.h file.
c 2.) the input data are written from indices starting from
c j,k=1, not 2 as in the hydro code.
c 3.) note that anngy and denny are both already cell centered.
c
program scf
implicit double precision (a-h,o-z)
include "param.h"
parameter (delta=1.0e-8, rho0=1.0d0,
1 maxit=5000, jmax1=jmax+1, kmax1=kmax+1,
2 jmax2=jmax+2, kmax2=kmax+2, g=6.674e-8,
3 a=6.0e22, b=1.964e6)
integer case,rinit
dimension phi(jmax2,kmax2), phi_star(jmax2,kmax2),
& psi(jmax1),toomr(jmax2),rhosurf(jmax2),
1 rhf(jmax1),rho(jmax2,kmax2), h(jmax2,kmax2),
2 c(maxit), h0sq(maxit), hmax(maxit), f(jmax2,kmax2),
3 fmax(maxit),x(jmax2,kmax2),
4 xmas(jmax1),omega(jmax1),r(jmax1),epic(jmax2)
double precision jr(jmax1),lgrhomax,np
dimension rho1(jmax2,kmax2),rho2(jmax2,kmax2)
dimension omegac(jmax1)
dimension omegap(jmax1)
double precision jtot,jtotp,jtotc,jfac,jxa,jxb,jxc
double precision ixa,ixb,ixc,ifac
dimension anngy(jmax1,kmax1),cen_pot(jmax1)
dimension angmo(jmax1)
dimension avquad(jmax1)
dimension sumi(jmax1),sums(jmax1),
1 rhfpoly(jmax1)
common /vec/ phi, rho, rhf, pi, dr
common /jofm/ hp(2,1000)
dimension denny(jmax2,jmax2)
c open output files
open(unit=19,file='rho.dat',form='unformatted')
open(unit=94,file='anal.dat',form='formatted')
open(unit=9,file='fact')
open(unit=10,file='fact1')
open(unit=13,file='wdout',form='formatted')
open(unit=12,file='polyout',form='formatted')
open(unit=17,file='outfile',form='formatted')
open(unit=95,file='eta',form='formatted')
c
write(6,*) 'enter 1 to construct a polytrope or'
write(6,*) 'enter 2 to construct a white dwarf:'
read(5,*) case
c
c it is not known whether the white dwarf option works. it's not likely
c
c
c to start building models start with a fairly spherical model
c and use a density array with all 1's. it turns out it really doesn't
c matter. we tried initial arrays with 1/r^2 and others and the code
c still convereges pretty quickly. after you have a rho.dat file you can
c use successive files to build the flatter models. if you want to save
c the density arrays you need to rename rho.dat each time.
c
write(*,*)'enter 1 to read old rho.dat'
write(*,*)'enter 0 to use all 1.0'
read(*,*)rinit
if (case.eq.1) then
write(6,*) 'enter polytropic index, np,jold,kmax,jout,kout'
write(6,*) 'and log maximum density (in cgs units),del: '
read(5,*) pin,np,jold,kold,jout,kout,lgrhomax,del,starnot
starm = starnot
rhomax = 10.0**lgrhomax
c
c np is nprime (for infinity, enter a value .gt. 3.0);
c jold is the previous jout;
c jout and kout set the axis ratio. note that the ratio is
c (kout-2)/(jout-2);
c the log max dens we use 0;
c del is the percentage of the previous iteration to keep. The flatter
c flatter you get the closer to 1.o del needs to be. Typically, 0.8
c or 0.9 works well.
c
else
write(6,*) 'enter jout, kout and '
write(6,*) 'log maximum density (in cgs units):'
read(5,*) jout,kout,lgrhomax
rhomax = 10.0**lgrhomax
xmax = (rhomax/b)**(1.0/3.0)
end if
koutk = kout
do j_model = 1 , 1
if(j_model.le.5) then
kout = kout - (j_model-1) * 8
else
kout = kout - (j_model-1) * 2
end if
rb = (kout/abs(kout))*float(abs(kout)-2)/float(jout-2)
pi = acos(-1.0)
koutest = kout
kin = 2
if (koutest.gt.0) then
jin = 2
else
jin = -kout
kout = (jout-jin)
end if
c dr is the grid spacing
dr = 1.0/(float(jout)-2.0)
c rhf is the radial coordinate at the grid center
rhf(1) = -0.5*dr
do j=2,jmax1
rhf(j) = rhf(j-1) + dr
end do
r(2) = 0.d0
do j = 2,jout-1
r(j+1) = r(j) + dr
end do
rminus = rhf(koutk-2)
rplus = rhf(jout-2)
if(j_model.eq.1) then
c zeros out the density on the entire grid
do 20 k=2,kmax2
do 20 j=2,jmax2
rho(j,k) = 0.0
20 continue
cff = 4.0*pi*dr*dr
if(rinit .eq. 0) then
c sets the density of the model to the initial guess
c and calculates the total mass, tmss
tmss = 0.0
do 40 k=kin,kmax
rhoz = rho0
do 40 j=jin,jout
rho(j,k) = rhoz*(rhf(j)/rhf(jout))**2
tmss = tmss + rhf(j)*rho(j,k)
write(15,41) j,k,rho(j,k)
40 continue
tmss = cff*tmss
else
tmss = 0.d0
do j = 2,jold
do k = 2,kold
read(19,end=1112) rho(j,k)
tmss = tmss + rhf(j)*rho(j,k)
write(16,41) j,k,rho(j,k)
end do
end do
tmss = cff*tmss
41 format(2i5,1p1e12.4)
1111 format(1x,e14.8)
1112 continue
end if
end if
c the big iteration loop begins here
c construct model based on specific angular momentum j(m)
c psi is the effective centrifugal potential
do 30 n=1,maxit
do j = 2,jmax2
do k = 2,kmax2
rho1(j,k) = rho(j,k)
end do
end do
42 format(2i5,1p1e12.4)
write(*,*)'iter loop =',n
c the subroutines called here determine the gravitational
c potential phi by solving poisson's equation
jout1=jout-1
jin1=jin-1
kout1=kout-1
call jhelp(jout,kout,jin,rho,rhf,dr,psi,cen_pot,xmas,
& jr,omega,psia,psib,r,pi,tmss,
& jmax2,jmax1,kmax2,np)
dpsiold = dpsi
dpsi = psia - psib
call bndry
call pot2d
c
cc starm = 2.0**(j_model-1)*0.1*tmss
cc starm = 0.0
c
starm = starnot*tmss
do j = 2,jout
do k = 2,kmax1
rad = sqrt(rhf(j)**2 + rhf(k)**2)
phi_star(j,k) = -starm/rad
phi(j,k) = phi(j,k) + phi_star(j,k)
end do
end do
c phia and phib are the boundary values of phi
phia = 0.5*(phi(jout,2) + phi(jout1,2))
if (koutest.gt.0) then
phib = 0.5*(phi(2,kout) + phi(2,kout1))
else
phib = 0.5*(phi(jin,2) + phi(jin1,2))
end if
dphiold = dphi
dphi = phia - phib
c for rigid rotation, h0sq is the square of the angular velocity
h0sq(n) = -dphi/dpsi
if(n.gt.10000) then
h0sqold = -dphiold/dpsiold
h0sq(n) = h0sqold + 0.1*rand(n)*(h0sq(n)-h0sqold)
end if
c c is the equilibrium integration constant
if (case.eq.1) then
c(n) = phia + h0sq(n)*psia
else
do 43 k=kin,kmax1
do 43 j=jin,jout
f(j,k) = -phi(j,k) - h0sq(n)*psi(j)
43 continue
fmax(n) = f(jin,kin)
do 45 k=kin,kmax1
do 45 j=jin,jout
if (fmax(n).lt.f(j,k)) fmax(n) = f(j,k)
45 continue
c(n) = (fmax(n) - ((1.0 + xmax**2.0)**0.5)
1 *f(jout,2))/((1.0 + xmax**2.0)**0.5
2 -1.0)
end if
c calculates the enthalpy h and updates the density and the
c total mass
do 50 k=kin,kmax2
do 50 j=jin,jout
h(j,k) = c(n) - phi(j,k) - h0sq(n)*psi(j)
50 continue
c finds the maximum value of the enthalpy
hmax(n) = h(jin,kin)
do 60 k=kin,kmax1
do 60 j=jin,jout
if (hmax(n).lt.h(j,k)) hmax(n) = h(j,k)
60 continue
tmss = 0.0
do 65 k=kin,kmax1
do 65 j=jin,jout
if (h(j,k).gt.0.0) then
if (case.eq.1) then
rho(j,k) = (h(j,k)/hmax(n))**pin
else
x(j,k) = (1.0 + xmax**2.0)*
1 ((h(j,k)/hmax(n))**2.0) - 1.0
if (x(j,k).lt.0.0) then
x(j,k) = 0.0
else
x(j,k) = x(j,k)**0.5
endif
rho(j,k) = (x(j,k)/xmax)**3.0
endif
tmss = tmss + rhf(j)*rho(j,k)
else
rho(j,k) = 0.0
endif
65 continue
tmss = cff*tmss
do j = 2,jmax2
do k = 2,kmax2
rho2(j,k) = rho(j,k)
end do
end do
do j = 2,jmax2
do k =2,kmax2
rho(j,k) = rho1(j,k) + (1.0-del)*(rho2(j,k) - rho1(j,k))
end do
end do
if (n.eq.1) goto 30
c checks for convergence of hmax, h0sq, and c
hmaxd = abs((hmax(n) - hmax(n-1))/hmax(n))
h0sqd = abs((h0sq(n) - h0sq(n-1))/h0sq(n))
cd = abs((c(n) - c(n-1) )/c(n))
write(*,*)'hmax(n) =',hmax(n)
write(*,*)'h0sq(n) =',h0sq(n)
write(*,*)'c(n) =',c(n)
write(*,*)' '
write(*,*)'dh =',hmaxd
write(*,*)'dh02 =',h0sqd
write(*,*)'cd =',cd
write(*,*)' '
if (hmaxd.le.delta) then
if (h0sqd.le.delta) then
if (cd.le.delta) then
write(6,*) 'converged after ',n,' iterations'
nfin = n
goto 35
end if
end if
else
if (n.eq.maxit) write(6,*) 'iteration did'
1 ,' not converge'
nfin = maxit
end if
30 continue
c ss is the thermal energy, tt is the rotational kinetic
c energy, and ww is the gravitational energy
35 ss = 0.0
tt = 0.0
ww = 0.0
ws = 0.0
if ((case.eq.1).and.(pin.ne.0.0)) then
re = ((1.0+pin)*(1.0/g)
1 *(rhomax**(-1.0+1.0/pin))/hmax(nfin))**0.5
else
re = (8.0*a*(1.0 + xmax**2.0)**0.5/(b*g*rhomax*
1 hmax(nfin)))**0.5
end if
do 70 k=kin,kmax
do 70 j=jin,jout
dm = rho(j,k)
if (dm.gt.0.0) then
dm = dm*rhf(j)
if (case.eq.1) then
ss = ss + dm*h(j,k)
else
ss = ss + (x(j,k)*((2.0*x(j,k)**2.0)-3.0)
1 *((x(j,k)**2.0+1.0)**0.5)+3.0*log(x(j,k)+
2 sqrt(1.0+x(j,k)**2.0)))*rhf(j)
end if
tt = tt + dm*(omega(j)*rhf(j))**2.d0
ww = ww + dm*(phi(j,k)-phi_star(j,k))
ws = ws + dm*phi_star(j,k)
end if
70 continue
oc = 1.0/(1.0+pin)
enrm = g*(re/1.0e10)**5.0*rhomax**2.0
if (case.eq.1) then
ss = cff*ss*oc
else
ss = cff*ss*a/(g*re**2.0*rhomax**2.0)
end if
starm = starm/tmss
tt = 0.5*cff*h0sq(nfin)*tt
ww = 0.5*cff*ww
ws = cff*ws
aww = -1.0/(ww+ws)
sow = 1.5*ss*aww
tow = tt*aww
c vc is the virial correction, a measure of the numerical
c accuracy of the solution
vc = -1.0/(ww+ws)*abs(2.0*tt + (ww+ws) + 3.0*ss)
c write converged model to fort.71
rewind(71)
do j = 2,jold
do k = 2,kold
write(71) rho(j,k)
end do
end do
c rewind (72)
c do j = 2,jmax2
c do k = 2,kmax2
c write(72,73) j,k,rho(j,k)
c end do
c end do
73 format(2i5,1p1e12.5)
c converts to cgs units
hmax(nfin) = hmax(nfin)*g*(re**2.0)*rhomax
do 80 k=kin,kmax2
do 80 j=jin,jout
rho(j,k) = rhomax*rho(j,k)
phi(j,k) = phi(j,k)*g*(re**2.0)*rhomax
phi_star(j,k) = phi_star(j,k)*g*(re**2.0)*rhomax
h(j,k) = h(j,k)*g*(re**2.0)*rhomax
80 continue
if (case.eq.2) then
tmss = tmss*((re/1.258e11)**3.0)*rhomax
ww = ww*enrm
ws = ws*enrm
tt = tt*enrm
ss = ss*enrm
end if
if (case.eq.1) then
write(12,101) pin
write(12,103) np
write(12,*) 'converged after ', nfin,' iterations'
write(12,100) hmaxd,h0sqd,cd,
1 sow,tow,vc
write(12,110) rb,h0sq(nfin),tmss,tt,-ww,-ws,3.0*ss,
& starm
do j=2,jmax1
write(17,99)j,rhf(j),jr(j),omega(j),xmas(j),rho(j,2)
end do
else
write(13,*)
write(13,102) lgrhomax
write(13,*) ' converged after ', nfin,' iterations'
write(13,*)
write(13,100) hmaxd,h0sqd,cd,sow,tow,vc
write(13,111) rb,tmss,tt,-ww,-ws,3.*ss,re/1.0e8
end if
99 format(1x,i3,1x,e10.4,1x,e10.4,1x,e10.4,1x,e10.4,1x,
& e10.4,1x,e10.4)
100 format(1x,'relative diff. in hmax : ',e10.4,/,
1 1x, 'relative diff. in h0sq : ',e10.4,/,
2 1x, 'relative diff. in c : ',e10.4,/,
3 1x, '1.5*s/|w| : ',e10.4,/,
4 1x, 't/|w| : ',e10.4,/,
5 1x, 'virial error : ',e10.4)
101 format(1x,'polytropic index : ',f3.1,/)
103 format(1x,'n prime : ',f8.1,/)
102 format(1x,'rhomax: 10^',f3.1,/)
110 format(1x,'axis ratio: ',f6.3,/,
1 1x,'omega0^2: ',1pe12.4,/,
2 1x,'mass: ',1pe12.4,/,
3 1x,'t: ',1pe12.4,/,
4 1x,'-w: ',1pe12.4,/,
4 1x,'-ws ',1pe12.4,/,
5 1x,'3.0*s: ',1pe12.4,/,
6 1x,'star/disk: ',1pe12.4)
111 format(1x,'axis ratio : ',f5.3,/,
1 1x,'mass: ',1pe12.4,/,
2 1x,'t : ',1pe12.4,/,
3 1x,'-w : ',1pe12.4,/,
4 1x,'3*s : ',1pe12.4,/,
5 1x,'re : ',1pe12.4)
c rewind(18)
c do j = 2,jold
c do k =2,kold
c_18 write(18) rho(j,k)
c end do
c end do
c 1113 format(1x,e14.8)
c*************************************************************************
c output in polytrope units (k=1,m=1,g=1) *
c*************************************************************************
c xk is polytropic constant
gamma = 1.d0 + 1.d0/pin
rhomax = (hmax(nfin)/(1+pin))**(1.d0/(gamma-1.d0))
xk = (1.d0/(1.d0+pin))*h(jin,kin)*(rho(jin,kin)**(-1.d0/pin))
xnum = (3.d0 * gamma) - 4.d0
c rotational inertia and total angular momentum
do j =2,jmax1
dum = 0.d0
do k =2,kmax1
dum = dum + rho(j,k)*(rhf(j)**3.d0)
end do
sumi(j) = dum
sums(j) = dum*omega(j)*sqrt(h0sq(nfin))
end do
dummy1 = 0.d0
dummy2 = 0.d0
do j= 2,jmax1
dummy1 = dummy1 + sumi(j)
dummy2 = dummy2 + sums(j)
end do
roti = cff*dummy1
jtot = cff*dummy2
c*************************************************************************
c convert quantites to cgs units. h, rho, phi already done
c*************************************************************************
tmcgs = tmss*(re**3.d0)*rhomax
dummy = h0sq(nfin)
do j=2,jmax1
omegac(j) = sqrt(dummy)*omega(j)*(g**0.5d0)*(rhomax**0.5d0)
enddo
do j =2,jmax1
r(j) = r(j)*re
enddo
ttcgs = tt * g * (re**5.d0) * (rhomax**2.d0)
wwcgs = ww * g * (re**5.d0) * (rhomax**2.d0)
sscgs = ss * g * (re**5.d0) * (rhomax**2.d0)
recgs = r(jout)*re
drcgs = dr*re
rotic = roti *(re**5.d0)*(rhomax)
h0sqc = h0sq(nfin) * g * (re**5.d0) * (rhomax**2.d0)
jtotc = jtot * (g**0.5d0) * (re**5.d0) * (rhomax**(3.d0/2.d0))
c factor for rho, h
rfac = (tmcgs**2.d0*g**3.d0*xk**-3.d0)**(1.d0/xnum)
hfac = g*(re**2.d0)*rhomax
do j=2,jmax2
do k=2,kmax2
rho(j,k) = rho(j,k)/rfac
h(j,k) = h(j,k)/hfac
enddo
enddo
c interpolate to get rhocen
rslope = (rho(3,2) - rho(2,2))/(rhf(3) - rhf(2))
br = rho(2,2) - rslope*rhf(2)
c zero out rho's not considered in hydro code
rhocut = 0.0
do j = 2,jmax2
if(rho(j,2).ge.rhocut) rhocut = rho(j,2)
end do
do j = 2,jmax2
do k = 2,kmax2
if(rho(j,k) .lt. (rhocut*1.e-06)) rho(j,k) = 0.d0
c_poly if(rho(j,k) .lt. (br*1.e-06)) rho(j,k) = br*1.0e-06
end do
end do
c do j = 2,jmax2,15
c do k = 2,kmax2
c_29 write(29,*) j,k,rho(j,k)
c end do
c end do
c factor for omega
opxa = 1.d0/xnum
opxb = (3.d0*gamma-1.d0)/(2.d0*xnum)
opxc = (-3.d0/2.d0)/xnum
ofac = (tmcgs**opxa)*(g**opxb)*(xk**opxc)
omegap(1) = 0.d0
do j=2,jmax1
omegap(j) = omegac(j)/ofac
if(omegap(j) .gt. omegap(j-1)) then
omax = omegap(j)
omaxj = j
endif
enddo
c interpolate to get omegacen
c should really set to zero for protostars
oslope = (omegap(3) - omegap(2))/(rhf(3) - rhf(2))
ob = omegap(2) - oslope*rhf(2)
c factor for phi
pxa = (2.d0*(gamma-1.d0))/xnum
pxb = (3.d0*(gamma-1.d0))/xnum
pxc = -1.d0/xnum
pfac = (tmcgs**pxa)*(g**pxb)*(xk**pxc)
do j =2,jmax1
phi(j,2) = phi(j,2)/pfac
phi_star(j,2) = phi_star(j,2)/pfac
enddo
c factor for ww,tt,ss,h0sq
wxa = (5.d0*gamma-6.d0)/xnum
wxb = (3.d0*gamma-3.d0)/xnum
wxc = -1.d0/xnum
wfac = (tmcgs**wxa)*(g**wxb)*(xk**wxc)
ttpoly = ttcgs/wfac
wwpoly = wwcgs/wfac
sspoly = sscgs/wfac
upoly = 1.5d0*sspoly
c etot = 0.5d0*wwpoly
etot = ttpoly+wwpoly+upoly
h0sqp = h0sqc/wfac
c factor for radius
rxa = (gamma-2.d0)/xnum
rxb = -1.d0/xnum
rxc = 1.d0/xnum
radfac = (tmcgs**rxa)*(g**rxb)*(xk**rxc)
repoly = recgs/radfac
drpoly = drcgs/radfac
do j = 2,jmax
rhfpoly(j) = drpoly*(j-1.5d0)
r(j) = r(j)/radfac
enddo
c factor for roti
ixa = (5.d0*gamma-8.d0)/xnum
ixb = -2.d0/xnum
ixc = 2.d0/xnum
ifac = (tmcgs**ixa)*(g**ixb)*(xk**ixc)
rotip = rotic/ifac
c factor for jtot
jxa = (5.d0*gamma-7.d0)/xnum
jxb = (3.d0*gamma-5.d0)/(2.d0*xnum)
jxc = 1.d0/(2.d0*xnum)
jfac = (tmcgs**jxa)*(g**jxb)*(xk**jxc)
jtotp = jtotc/jfac
rat = upoly/abs(wwpoly)
write(9,12)'its =',nfin !# of iterations
write(9,11)'pin =',pin !polytropic index
write(9,11)'nprime =',np !n'
write(9,12)'jmax =',jmax !max extent of hach grid in r
write(9,12)'kmax =',kmax !" " " " " " " " " z
write(9,12)'jout =',jout !jreq for hydro
write(9,12)'kout =',kout !kzpol for hydro
write(9,11)'omega max =',omax
write(9,11)'omaxj =',omaxj !where the max occurs in j
write(9,11)'omegacen =',ob
write(9,11)'rhocen =',br
write(9,11)'rhomax =',rhomax
write(9,11)'xk =',xk !polytropic constant k
write(9,11)'wwpoly =',wwpoly !w in pu's
write(9,11)'ttpoly =',ttpoly !t " "
write(9,11)'sspoly =',sspoly !s " "
write(9,11)'u/|w| =',rat
write(9,11)'t/|w| =',tow
write(9,11)'etot =',etot !total energy
write(9,11)'ve =',vc !virial test
write(9,11)'repoly =',r(jout) !r equatorial in pu's
write(9,11)'re/rp =',1.d0/rb
write(9,11)'jtotp =',jtotp !total spec ang mom in pu's
write(9,11)'jtoth =',jtot !" " " " " " in hach units
write(9,11)'rotip =',rotip !moment of inertia in pu's
write(9,11)'rotih =',roti !" " " " " " " " in hach units
write(9,11)'rhf(jout) =',rhf(jout)
write(9,11)'drpoly =',drpoly !rof3n
11 format(1x,a15,1x,e14.7)
12 format(1x,a15,1x,i8)
c calculate the anngy array
do j = 2,jmax1
do k = 2,kmax1
anngy(j,k) = omegap(j)*rhfpoly(j)**2
end do
end do
c% rewind(2)
c write(2,94) jout,kout
c write(2,185) r(jout),starm
write(2,*) jout,kout
write(2,*) r(jout),starm
write(2,96) ((rho(j,k),j=2,jmax1),k=2,kmax1)
write(2,96) (anngy(j,2),j=2,jmax1)
c do j = 2,jmax2
c do k = 2,kmax2
c write(18,1600) j,k,rho(j,k)
c end do
c end do
c 1600 format(2i5,1p1e12.4)
rewind(47)
do k = 2,jmax
do j = 2,kmax
write(47,499) j,k,rho(j,k)
end do
write(47,*)
end do
499 format(2i5,1p1e12.5)
rewind(30)
do j = 1,jmax2
do k = 1,kmax2
write(30,599) j,k,rho(j,k)
end do
end do
599 format(2i5,1p1e15.8)
rewind(31)
do j = 1,jmax2
write(31,899) j,anngy(j,2)
end do
899 format(1i5,1p1e12.5)
94 format(2i5)
95 format(1pe16.7)
96 format(1p6e13.5)
185 format(1p2e12.5)
c find jrhomax
rewind(93)
ainewz = 1.0 ! NOT USED ANYMORE
write(93,195) pin,jtotp,r(jout),omegap(2),rho(2,2),tow,
& drpoly,drpoly,AINEWZ,jout,kout
write(93,196) rho
write(93,196) anngy
195 FORMAT(3X,1p9e13.6,2I4)
196 FORMAT(8(1PE10.3,2X))
c output for equilibrium analysis
c we've used this data to locate linblad resonances, calculate
c toomre's q, keplerian rotation, etc. and to make plots of
c the equilibrium models. glen is working on a verison that
c incororates sm directly for automatic plotting.
do j = 2,jout
write(94,114)j,r(j),rho(j,2),xmas(j),phi(j,2),phi_star(j,2),
& omegap(j)
enddo
114 format(1x,i4,1x,e10.3,1x,e12.5,1x,e10.3,1x,e12.5,1x,e12.5,1x,
7 e10.3)
ckz calculate christodoulou and andlib parameters
grav = 1.0 !gravitational constant
rhom = 0.0
omegam = 0.0
cell = 0.0
rhotot = 0.0
toomrmin = 1.0e10
dz = 1.0/(float(kout)-2.0)
do j = 2,jmax1
epic(j) = 0.0
rhosurf(j) = 0.0
toomr(j) = 0.0
end do
do j = 2,jout
rin = rhfpoly(jin)
if(rho(j,2).gt.rhom) then
rhom = rho(j,2)
omegam = omegap(j)
rrhomax = rhfpoly(j)
jrhomax = j
end if
rout = rhfpoly(jout)
if(rho(j,2).gt.0.0) then
rhotot = rhotot + rho(j,2)
cell = cell + 1.0
end if
end do
c.......calculate epicyclic freq and locations where freq ratios
c pass through 1
omegaj = sqrt(4.0*pi*rhom) !jeans freq
omegakep = sqrt(starm/rrhomax**3.0) !kepler freq
c.....re-center angular momentum
do j=3,jmax1
angmo(j)=0.5*(anngy(j-1,2)+anngy(j,2))
end do
angmo(1)=angmo(3)
angmo(2)=angmo(3)
angmo(jmax1)=2.0*angmo(jmax)-angmo(jmax-1)
do j = 2,jmax1
avquad(j) = angmo(j)/r(j)**2
end do
c Toomre Q-parameter: Q = c(sound) kappa / ( pi G sigma )
c Jim says there is a mistake, should include 1/r
c do j=3,jmax-1
c if(rho(j,2).le.0.0) go to 2830
c vorticity=(avquad(j+1)*rhf(j+1)**2-avquad(j)*rhf(j)**2)/dr
c ep=(avquad(j)+avquad(j+1))*vorticity
c s1=0.0
c dz=rhf(3)-rhf(2)
c do k=2,kmax1
c if(rho(j,k).gt.0.0) then
c s1=s1+2.0*rho(j,k)*dz
c end if
c end do
c if(s1.ne.0.0) then
c anot=sqrt(gamma*s1**(1.0/pin))
c toomr(j) =(sqrt(abs(ep))*anot)/(pi*s1)
c end if
c 2830 continue
c end do
c......calculate surface density, vortensity and toomre parameter
do j = 2,jmax2
rhosurf(j) = 0.0
end do
do j = jin,jout
delr = rhfpoly(j) - rhfpoly(j-1)
do k = 2,kmax1
rhosurf(j) = rhosurf(j) + 2*rho(j,k)*delr
end do
end do
vortmin = 1.0e+30
vortmax = -1.0e+30
do j = jin,jout-4
vorten = rhosurf(j)/((2.0 - np)*omegap(j))
if(vorten.le.vortmin) then
vortmin = vorten
rvortmin = rhfpoly(j)/rrhomax
end if
if(vorten.ge.vortmax) then
vortmax = vorten
rvortmax = rhfpoly(j)/rrhomax
end if
write(57,571) rhfpoly(j)/rrhomax,vorten
end do
571 format(1p2e14.5)
c use epicyclic freq squared = 2(2-q)*omega squared where np = -q
c use column density for sound speed
qminus = 0.0
qplus = 0.0
do j = jin,jout-2
cspeed = sqrt(gamma*rhosurf(j)**(gamma-1.0))
epic(j) = sqrt(4.0 + 2.0*np)*omegap(j)
toomr(j) = cspeed*epic(j)/(pi*rhosurf(j))
if(toomr(j-1).gt.1) then
if(toomr(j).lt.1) then
qminus = rhfpoly(j-1)/rrhomax
end if
end if
if(toomr(j-1).lt.1) then
if(toomr(j).gt.1) then
qplus = rhfpoly(j-1)/rrhomax
end if
end if
write(55,815) rhfpoly(j)/rrhomax,toomr(j)
end do
write(56,*) qminus, qplus
815 format(1p2e12.5)
gamma = 1.0+1.0/pin
rhoavg = rhotot/cell
avgc = sqrt(gamma*rhoavg**(gamma-1.0)) !avg sound speed
tjeans = sqrt(pi/rhoavg) !jeans time
tsound = avgc*(rout-rin) !sound crossing time
tratio = tjeans/tsound
omegas = sqrt(gamma*rhom**(gamma - 1.0)/rrhomax)
czero = sqrt(gamma*rhom**(gamma - 1.0))
zeromach = omegam*rrhomax/czero
oratio1 = omegaj/omegam
amirp = 2.0*acos(-1.0)/omegam
c......see christodoulou '92
pee = sqrt(2.0*pi)*rrhomax
eta = (omegakep/omegam)**2.0
eps = (rout - rin)/(2.0*rrhomax)
gee = pee*eps
tauzero = 4.0*pi*rhom/(omegam**2.0)
rratio = rin/rrhomax
rratio1 = rout/rrhomax
rratio2 = rrhomax/rout
rratio3 = rin/rout
rratio4 = 1.0 - rratio
oratio2 = eta*(omegaj/omegam)**2.0
c do j = 2,jmax2
c do k = 2,kmax2
c write(96,955) j,k,rho(j,k)
c end do
c end do
c 955 format(2i5,1p1e12.5)
write(12,515) rratio,rratio1,rratio2,rratio3,rratio4,jrhomax,rout,
1 rin,rrhomax,rhom,amirp,rvortmin,rvortmax,qminus,qplus,
2 eta,pee,tauzero
write(12,516) omegam,omegaj,omegas,omegakep
write(9,517) avgc,tjeans,tsound,rhoavg,zeromach,czero
c macho,oratio1,oratio2,epicj,epick,epico
write(10,521)tow,rhom,amirp,rrhomax,rvortmin,jtotp,rout
515 format(1x,' r-/ro: ',1pe12.4,/,
1 1x,' r+/r0: ',1pe12.4,/,