forked from lruhlen/Code_for_Kozai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_for_kozai.f
More file actions
3672 lines (3453 loc) · 116 KB
/
code_for_kozai.f
File metadata and controls
3672 lines (3453 loc) · 116 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 STELLAR
include 'parm.h'
include 'var.h'
save
c
call start
imod=0
konv=0
mode=0
do i=1,100000
imod=imod+1
TIME=TIME+DTIME
MODEL=MODEL+1
C
C Store old values of time dependent variables in arrays with names
C beginning with a "v".
C
do j=1,N
do k=1,NG
vx(j,k)=x(j,k)
enddo
vhydrogen(j)=hydrogen(j)
vhelium4(j)=helium4(j)
vhelium3(j)=helium3(j)
vdeuterium(j)=deuterium(j)
vcarbon(j)=carbon(j)
vtrogen(j)=trogen(j)
voxygen(j)=oxygen(j)
enddo
C
C End of storing old values of time dependent variables
C
konv=max(0,konv-1)
call massflux(TIME,Zflux)
if(konv.gt.0. or. MODEL.eq.1) then
mode=999
else
mode=0
call gridmov
endif
dTAUmx= taufactor*taujk
c call elatim('NOPRINT')
call henyey(mode)
if(mode.ne.0) then
konv=konv+3
c goto 99
C
C NO CONVERGENCE IN HENYEY. TRY AGAIN
C
TIME=TIME-DTIME
MODEL=MODEL-1
imod=imod-1
if(abs(DTIME/DTMIN-1.).lt.0.01) stop 'NO CONVERGENCE'
DTIME=DTIME/float(konv)
DTIME=max(DTIME,DTMIN)
write(6,*) "NEW DTIME value = ",DTIME
C
C Reset time dependent variables with old values.
C
do j=1,N
do k=1,NG
x(j,k)=vx(j,k)
enddo
hydrogen(j)=vhydrogen(j)
helium4(j)=vhelium4(j)
helium3(j)=vhelium3(j)
deuterium(j)=vdeuterium(j)
carbon(j)=vcarbon(j)
trogen(j)=vtrogen(j)
oxygen(j)=voxygen(j)
enddo
C
C End of variable reset.
C
else
C
C CONVERGENCE IN HENYEY. ADVANCE THE COMPOSITION
C
call compchange
call addmass
c if(konv.lt.2) call addsub
call printm(imod)
C
C OPTIMIZE THE TIME STEP, TAKING INTO ACCOUNT THE PREVIOUS CONVERGENCE
C BEHAVIOR AND THE NET CHANGES.
C
if(CHANGE.lt.CHGMIN .and. ITER.lt.9 .and. konv.eq.0)
* DTIME=DTIME*1.1
if(CHANGE.gt.CHGMAX) DTIME=DTIME*0.8
if(CHANGE.gt.2.*CHGMAX) DTIME=DTIME*0.8
DTIME=max(DTIME,DTMIN)
DTIME=min(DTIME,DTMAX)
endif
c. if((nmod.gt.0 .and. imod.ge.nmod) .or. konv.ge.7) goto 99
c. write(6,*) "konv = ",konv
if((nmod.gt.0 .and. imod.ge.nmod) .or. konv.ge.18) goto 99
enddo
99 call printm(-1)
c. 99 continue
stop
end
SUBROUTINE PRINTM(imod)
C+
C THE SUBROUTINE PRINTM WRITES OUT MODEL INFORMATION
C
C AUTHOR: H.W. YORKE 30-AUG-02 (JPL / CALTECH)
C-
include 'parm.h'
include 'var.h'
CHARACTER*1 CS(2)
DATA MODWRT/-1/
DATA CS/'*',' '/
save
C
if(mod(IMOD,NRIT).ne.0 .and. mod(MODEL,JRIT).ne.0) return
if(IMOD.gt.0) then
te4 = X(N,3)/7.125e-4/X(N,2)/X(N,2)
tee=sqrt(sqrt(te4))
c Znet=1.d0-hydrogen(1)-helium4(1)-helium3(1)-deuterium(1) &
c & -carbon(1)-trogen(1)-oxygen(1)
if(iter.lt.abs(itmax/2)) then
write (6,200) MODEL,TIME,DTIME,CHANGE, &
& X(1,1),X(1,4),X(N,2),X(N,3),tee,Zmass,Zflux
c & hydrogen(1),helium4(1),helium3(1),deuterium(1), &
c & carbon(1),oxygen(1),Znet, &
200 format(' MODEL:',i6,' TIME:',1p,D11.4,' DTIME:',D11.4, &
& ' NET CHANGE: ',D9.2, &
& /,' Pc,Tc,R,L,TE,M:',6D10.3,D11.3 &
& /,1x,83("*"))
c & /,' H,He4,He3,D,C,O:',0p,7f8.5,1p, &
else
write (6,300) MODEL,TIME,DTIME,CHANGE, &
& X(1,1),X(1,4),X(N,2),X(N,3),tee,Zmass,Zflux
300 format(' MODEL:',i6,' TIME:',1p,D11.4,' DTIME:',D11.4, &
& ' NET CHANGE: ',D9.2, &
& /,' XXXXXXXXXXXXXX:',6D10.3,D11.3 &
& /,1x,83("*"))
endif
endif
if((mod(IMOD,nrit).eq.0 .or. IMOD.lt.0) .and. MODEL.ne.MODWRT) &
& then
MODWRT=MODEL
if(deuterium(1).lt.1.d-37) then
if(helium3(1).lt.1.d-37) then
write(6,*) "Start of model ",MODEL
write (6,401) MODEL,TIME
else
write(6,*) "Start of model ",MODEL
write (6,301) MODEL,TIME
endif
else
write(6,*) "Start of model ",MODEL
write (6,201) MODEL,TIME
endif
401 format(/,' MODEL:',i6,' TIME:',1p,D12.4,/ &
& ' J dM M P R ', &
& ' L T RHO 1-BETA HYDR ', &
& ' HE4 C N O')
301 format(/,' MODEL:',i6,' TIME:',1p,D12.4,/ &
& ' J dM M P R ', &
& ' L T RHO 1-BETA HYDR ', &
& ' HE4 HE3 N O')
201 format(/,' MODEL:',i6,' TIME:',1p,G25.15,/ &
& ' J dM M P R ', &
& ' L T RHO 1-BETA HYDR ', &
& ' HE4 D N O')
do j=1,N
call invstate(91,x(j,1),x(j,4),hydrogen(j),helium4(j),Crad, &
& RHO,cP,alpha,beta,delta)
if(deuterium(1).lt.1.d-37) then
if(helium3(1).lt.1.d-37) then
write (6,202) J,CS(1+ICONVECT(j)),dM(j),zM(j), &
& (X(j,k),k=1,NG),rho,beta, &
& hydrogen(j),helium4(j),carbon(j), &
& trogen(j),oxygen(j)
else
write (6,202) J,CS(1+ICONVECT(j)),dM(J),zM(J), &
& (X(j,k),k=1,NG),rho,beta, &
& hydrogen(j),helium4(j),helium3(j), &
& trogen(j),oxygen(j)
endif
else
write (6,202) J,CS(1+ICONVECT(j)),dM(J),zM(J), &
& (X(j,k),k=1,NG),rho,beta, &
& hydrogen(j),helium4(j),deuterium(j), &
& trogen(j),oxygen(j)
endif
C202 format(I5,1x,a1,0p,F9.6,1p,12D9.2)
c202 format(I5,1x,a1,1p,D9.2,D13.6,D10.3,D9.2,D13.5,2D10.3,6D9.2)
202 format(I5,1x,a1,1p,13G25.15)
enddo
write(6,*) "End of model ",MODEL
write(6,*) "Start of atmos ",MODEL
if(NATM.gt.0 .and. IMOD.ne.0) then
call atmos(Tatm,RHOatm,Ratm,Patm,X(N,2),X(N,3),NATM)
else
call atmos(Tatm,RHOatm,Ratm,Patm,X(N,2),X(N,3),0)
endif
write(6,*) "End of atmos ",MODEL
if(MODEL.ne.0) then
write (JUNIT) MODEL,N,TIME,dTIME,taujk, &
& ((x(j,k),k=1,4),dM(j), &
& hydrogen(j),helium3(j),helium4(j),deuterium(j), &
& carbon(j),trogen(j),oxygen(j), &
& j=1,N)
c backspace JUNIT
c read (JUNIT)
NREC=NREC+1
write (6,204) MODEL,TIME,NREC,JUNIT
204 format(' MODEL:',i6,' TIME:',1p,D12.4,' STORED AS RECORD', &
& i5,' ON UNIT',i3)
endif
endif
return
end
SUBROUTINE START
C+
C THE SUBROUTINE START PREPARES FOR THE FIRST RUNNUNG OF HYDRO.
C
C AUTHOR: H.W. YORKE 30-JAN-02 (JPL / CALTECH)
C-
include 'parm.h'
include 'var.h'
character*50 SFILE,OFILE
character*1 why(3)
dimension ZH(14)
dimension dens(MJ),temp(MJ), xl(MJ), r(MJ) ,pres(MJ)
equivalence (X(1,1),pres) , (X(1,4),temp)
equivalence (X(1,2),r) , (X(1,3),xl)
COMMON/ABUND/XBA(14),H1(14),AH(14)
COMMON/TIDALINTS/sigma,efactor,xmass
COMMON/TIDALDBLS/frequency
DATA ZH /1.0081451,4.003874,12.0038156,23.,24.32, &
& 26.97,28.06,32.07,39.102,40.08,55.85,14.0075257,16.,19.99/
DATA RSUN/6.96d10/
DATA PI /3.14159265359d0/
save
c
do i=1,14
ah(i)=zh(i)
enddo
c
call comrd
READ (5,200) IUNIT,SFILE
c WRITE(6,200) IUNIT,SFILE
call comrd
READ (5,200) JUNIT,OFILE
c WRITE(6,200) JUNIT,OFILE
c
if(IUNIT.eq.1) then
open(unit=IUNIT,file=SFILE, form='formatted' , status='old' )
else
open(unit=IUNIT,file=SFILE, form='unformatted' , status='old' )
endif
if(IUNIT.ne.JUNIT) &
& open(unit=JUNIT,file=OFILE, form='unformatted' , &
& status='unknown' )
C
200 FORMAT(20X,i3,1X,a)
201 FORMAT(5(6X,I6))
202 FORMAT(1P,4(6X,D9.2))
203 FORMAT(4(6X,D9.2))
C
call comrd
READ (5,201) NREC,NMOD,NRIT,ITMIN,ITMAX
c WRITE(6,201) NREC,NMOD,NRIT,ITMIN,ITMAX
call comrd
READ (5,201) JADD,JSUB,NATM
c WRITE(6,201) JADD,JSUB,NATM
call comrd
READ (5,203) Atmx,Atmn,dTAUmx,RLH
c WRITE(6,202) Atmx,Atmn,dTAUmx,RLH
taufactor=dTAUmx
call comrd
READ (5,203) dLmx,dLmn,dXmx,dXmn
c WRITE(6,202) dLmx,dLmn,dXmx,dXmn
call comrd
READ (5,203) dPmx,dPmn,Crad,Cwrk
c WRITE(6,202) dPmx,dPmn,Crad,Cwrk
call comrd
READ (5,203) dZmax,dZmin,dZdt
dZmax=dZmax*1.00001
c WRITE(6,202) dZmax,dZmin,dZdt
call comrd
READ (5,203) EPS
c WRITE(6,202) EPS
call comrd
READ (5,203) SMIN
c WRITE(6,202) SMIN
call comrd
READ (5,203) SMAX
c WRITE(6,202) SMAX
C
call comrd
READ (5,203) DTIME,FACTIM,DTMIN,DTMAX
c WRITE(6,202) DTIME,FACTIM,DTMIN,DTMAX
call comrd
READ (5,203) CHGMIN,CHGMAX
c WRITE(6,202) CHGMIN,CHGMAX
call comrd
READ (5,203) x1,x2,x3
xmass = x1
sigma = x2
efactor = x3
call comrd
READ(5,203) xperiod
xperiod = 3.1536E+7 * xperiod
frequency = 2.0*PI / xperiod
c write(6,*) "********"
c write(6,*) "Kozai frequency = ", frequency
c write(6,*) "********"
c,sigmasquared,efactor
call comrd
READ (5,*) (H1(J), J = 1,4)
call comrd
READ (5,*) (H1(J), J = 5,8)
call comrd
READ (5,*) (H1(J), J = 9,12)
call comrd
READ (5,*) (H1(J), J = 13,14)
call comrd
NG=MH
JRIT = max(1,NRIT/10)
C
XH2=H1(2)
H1(2)=abs(H1(2))
SUM = 1.
DO J = 1,14
SUM = SUM - H1(J)
END DO
XX=H1(1)
YY=SUM
C H1(2) is temporarily used as the primordial deuterium abundance and
C then replaced by the initial helium abundance.
H1(2)=YY
DO J = 1,14
XBA(J) = H1(J) / AH(J)
END DO
ZZ= 1. - XX - YY
IF(IUNIT.EQ.1) THEN
NREC=0
MODEL=0
C SETUP STARTING MODEL
do j=1,MJ
read(IUNIT,*,end=34) zM(j),r(j),temp(j),xl(j),dens(j)
if(r(j).le.0.d0) goto 35
enddo
J=MJ+1
GOTO 35
34 backspace(IUNIT)
35 N=min(J-1,MJ)
close(IUNIT)
Zmass=zM(N+1)
C**************
amu = 2.*XX + 0.75*YY + 0.57*ZZ
Rglog=log10(83145100.d0*amu)
do i = 1,N
r(i) = RSUN*r(i)
tlog = log10(temp(i))
hydrogen(i) = XX
helium4(i) = YY
helium3(i) = 1.d-5
deuterium(i)=abs(XH2)
carbon(i)=H1(3)
trogen(i)=H1(12)
oxygen(i)=H1(13)
denlog = log10(dens(i))
xl(i) = xl(i)*3.85d33
Plog = Rglog + denlog + Tlog
pres(i)=10.d0**Plog
zM(i)=zM(i)*zMass
end do
dM (1)=zM(1)
do i=2,N
dM (i)=zM(i)-zM(i-1)
enddo
TIME=0.
taujk=1.D11
dTAUmx=taujk*taufactor
call printm(MODEL)
ELSE
if(NREC.lt.0) NREC=99999
nn=max(1,NREC)
do imod=1,nn
read(IUNIT,end=301) MODEL,N,TIME,dTIM,taujk, &
& ((x(j,k),k=1,4),dM(j), &
& hydrogen(j),helium3(j),helium4(j),deuterium(j), &
& carbon(j),trogen(j),oxygen(j), &
& j=1,N)
enddo
IMOD=NREC+1
goto 302
301 backspace(IUNIT)
302 NREC=IMOD-1
zM(1)=dM(1)
do i=2,N
zM(i)=zM(i-1)+dM(i)
enddo
if(NREC.eq.0) then
TIME=0.d0
MODEL=0
endif
write(6,209) NREC,MODEL,N,TIME,dTIM
209 format(' RECORD',i4,' MODEL:',i6,' N:',i4,' TIME:', &
& 1p,D11.4,' DTIME:',D11.4)
if(JUNIT.ne.IUNIT) NREC=0
if(DTIME.lt.0.0d0) DTIME=dTIM
write(6,*) '... continuing calculations with MODEL=',MODEL
Zmass=zM(N)
write(*,*) 'Zmass=', Zmass
if(Jadd.gt.0) then
why(1)='I'
call add(Jadd,why)
endif
if(Jsub.gt.0) call sub(Jsub)
if(FACTIM.lt.0.d0) TIME=0.
ENDIF
c. Following lines were added for the kozai energy input modifications to the code:
TIME=0.0
DTIME = min(dtim, (xperiod / 20.0))
DTMAX = xperiod/20.0
xmass= xmass*zMass
sigma = sigma*zMass
RETURN
END
subroutine comrd
character*1 line(1)
character*80 lin
equivalence (lin,line)
save
c
1 read (5,203,end=999) lin
if(line(1).eq.' ') then
write(6,203) lin
backspace 5
return
else
if(line(1).ne.'c' .and. line(1).ne.'C') &
& write(6,203) lin
c202 format(1x,a)
endif
goto 1
999 write(6,203) 'COMRD: END OF INPUT DATA'
203 format(a)
return
end
subroutine opacity(j,tlog,rholog,bkap)
include 'parm.h'
include 'var.h'
parameter(NTVAL=60,NRVAL=14)
DIMENSION TVAL(NTVAL),RVAL(NRVAL)
DATA TVAL/
+2.000,2.097,2.176,2.243,2.301,2.352,2.398,2.439,
+2.477,2.512,2.544,2.574,2.602,2.628,2.653,2.677,
+2.699,2.740,2.778,2.813,2.845,2.875,2.903,2.929,
+2.954,2.978,3.000,3.021,3.041,3.061,3.079,3.097,
+3.114,3.130,3.146,3.161,3.176,3.204,3.230,3.255,
+3.279,3.301,3.350,3.400,3.450,3.500,3.550,3.600,
+3.650,3.700,3.800,3.900,4.000,4.079,4.176,4.301,
+4.477,4.699,4.845,5.000/
DATA RVAL/-12.,-11.,-10.,-9.,-8.,-7.,-6.,-5.,-4.,-3.,-2.,-1.,0.,1.
1/
data ifirst/0/
save
c if(j.lt.100) write(6,*) 'opacity: j,tlog,rhol=',j,tlog,rhol
if(ifirst.eq.0) then
ifirst=1
C....read in the low temperature opacity
open(unit=52, file='opac.cool', status='old')
do itemp=1,60
READ(52,46) (ZKAP(idense,itemp), idense=1,7)
c WRITE(6,46) (ZKAP(idense,itemp), idense=1,7)
READ(52,46) (ZKAP(idense,itemp),idense=8,14)
c WRITE(6,46) (ZKAP(idense,itemp),idense=8,14)
46 FORMAT(7F7.3)
end do
close(52)
open(unit=50,file='hyd.cond',status='old')
open(unit=51,file='hel.cond',status='old')
c.....read in hydrogen conductive opacities
read(50,*) (rhyr(i),i=1,23)
read(50,*) (thyr(i),i=1,28)
do i=1,28
read(50,*) (auxchyop(k,i),k=1,23)
end do
c.....read in helium conductive opacities
read(51,*) (rhel(i),i=1,25)
read(51,*) (thel(i),i=1,32)
do i=1,28
read(51,*) (auxcheop(k,i),k=1,25)
end do
close(50)
close(51)
endif
YY=helium4(j)+helium3(j)
c.....Start here with logT,logRho, Rference logTs logRhos, Table,
c.. log Opacity is Bkap.
RHOL=rholog
IF(TLOG .GE. TVAL(NTVAL)) GO TO 206
call bracket(TVAL,TLOG,NTVAL,mode,it1,it,iterx)
RHOL=max( RVAL(1) , RHOL )
RHOL=min( RVAL(NRVAL)-1.E-9 , RHOL )
WS1 = TVAL(IT1) - TLOG 1900
WS = TVAL(IT1) - TVAL(IT) 2000
WS1 = WS1 / WS 2100
WS = 1. - WS1 2200
call bracket(RVAL,RHOL,NRVAL,mode,iw1,iw,iterx)
WS2 = RHOL - RVAL(IW1) 2800
WS3 = RVAL(IW) - RVAL(IW1) 2900
WS2 = WS2 / WS3 3000
WS3 = 1. - WS2 3100
Z00 = ZKAP(IW,IT) 3200
Z10 = ZKAP(IW1,IT) 3300
Z11 = ZKAP(IW1,IT1) 3400
Z01 = ZKAP(IW,IT1) 3500
IF(Z00.EQ.0..OR.Z01.EQ.0..OR.Z11.EQ.0..OR.Z10.EQ.0.) GO TO 200 3600
WS4 = WS2*(WS1*Z00 + WS*Z01) 3700
WS5 = WS3*(WS1*Z10 + WS*Z11) 3800
BKAP= (WS4+WS5)
C Slowly transition into OPAL opacities
if(Tlog.gt.TVAL(NTVAL)-.1) then
W1=(TVAL(NTVAL)-Tlog)*10.
W2=1.d0-W1
call opaltab(Tlog,RHOlog,hydrogen(j),YY,bkap2,ierror)
if(ierror.eq.0) BKAP=W1*BKAP+W2*bkap2
endif
GO TO 205
206 continue
call opaltab(Tlog,RHOlog,hydrogen(j),YY,bkap,ierror)
c if(ierror.ne.0) Bkap= 4.7
c.....add in conductive opacity:
if(rhol.gt.0. .and. tlog.gt.5.0)then
if(hydrogen(j) .le. 1.e-5) then
hyckap=1.
else
call chyopacity(tlog,rhol,hyckap)
end if
call cheopacity(tlog,rhol,heckap)
ckap=hydrogen(j)*hyckap+(1.-hydrogen(j))*heckap
ckap=10**ckap
realbkap = 10.**bkap
realbkap=1./(1./realbkap+1./Ckap)
bkap=log10(realbkap)
end if
205 continue
RETURN
200 write(6,201) TLOG,RHOL
201 FORMAT(' OUTSIDE TABLE, T = ', 1PE12.3, ' RHO= ',E12.3)
STOP 'opacity'
END
Subroutine opacityhy(T,rho,realk)
include 'parm.h'
COMMON/AUXhyOPACITY/RHOREF(18),TREF(15),rkapparef(18,15)
c..........This subroutine computes the opacity for a specified temperature
c..........and pressure by linearly interpolating between the proper points
c..........of a pure hydrogen opacity table.
data its,irhs /15,18/
save
if ((T.le.Tref(1)).or.(T.ge.Tref(its)).or.(Rho.le.Rhoref(1))
+ .or.(RhO.ge.Rhoref(irhs))) then
write(6,*) 'Temperature: ',T,' Density: ',Rho
write(6,*) 'Out of Bounds.'
realk=1.
C goto 2104
stop 'opacityhy'
endif
c..........Determine which of the reference points bracket the temperature.
call bracket(Tref,T,its,mode,icool,ihot,iterx)
call bracket(Rhoref,Rho,irhs,mode,jrare,jdense,iterx)
c..........Determine Krare and Kdense by a linear interpolation in temperature.
rare = rkapparef(jrare,icool)
+ +((rkapparef(jrare,ihot)-rkapparef(jrare,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
dense = rkapparef (jdense,icool)
+ +((rkapparef(jdense,ihot)-rkapparef(jdense,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
c.........Determine kappa by a linear interpolation in the density
realk=rare+((dense-rare)/(rhoref(jdense)-rhoref(jrare)))
+ *(rho - rhoref(jrare))
c.........We have thus determined k.
2104 continue
c write(*,*) ihot,icool,jdense,jrare,krare,kdense,k
c write(*,*) 'rkapp(jr,ic),rk(jr,ih),rk(jd,ic),rk(jd,ih)'
c write(*,*) rkapparef(jrare,icool),rkapparef(jrare,ihot)
c write(*,*) rkapparef(jdense,icool),rkapparef(jdense,ihot)
c write(*,*) 'tref(ihot),tref(icool),rhoref(jdense),rhoref(jrare)'
c write(*,*) tref(ihot),tref(icool),rhoref(jdense),rhoref(jrare)
return
end
Subroutine opacityhe(T,rho,realk)
c..........This subroutine computes the opacity for a specified temperature
c..........and pressure by linearly interpolating between the proper points
c..........of a pure helium opacity table.
include 'parm.h'
COMMON/AUXheOPACITY/RHOREF(18),TREF(15),rkapparef(18,15)
data its,irhs /15,18/
save
if ((T.le.Tref(1)).or.(T.ge.Tref(its)).or.(Rho.le.Rhoref(1))
+ .or.(RhO.ge.Rhoref(irhs))) then
write(6,*) 'Temperature: ',T,' Density: ',Rho
write(6,*) 'Out of Bounds.'
realk=1.
C goto 2104
stop 'opacityhe'
endif
c..........Determine which of the reference points bracket the temperature.
call bracket(Tref,T,its,mode,icool,ihot,iterx)
call bracket(Rhoref,Rho,irhs,mode,jrare,jdense,iterx)
c..........Determine Krare and Kdense by a linear interpolation in temperature.
rare = rkapparef(jrare,icool)
+ +((rkapparef(jrare,ihot)-rkapparef(jrare,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
dense = rkapparef (jdense,icool)
+ +((rkapparef(jdense,ihot)-rkapparef(jdense,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
c.........Determine kappa by a linear interpolation in the density
realk=rare+((dense-rare)/(rhoref(jdense)-rhoref(jrare)))
+ *(rho - rhoref(jrare))
c.........We have thus determined k.
2104 continue
c write(*,*) ihot,icool,jdense,jrare,krare,kdense,k
c write(*,*) 'rkapp(jr,ic),rk(jr,ih),rk(jd,ic),rk(jd,ih)'
c write(*,*) rkapparef(jrare,icool),rkapparef(jrare,ihot)
c write(*,*) rkapparef(jdense,icool),rkapparef(jdense,ihot)
c write(*,*) 'tref(ihot),tref(icool),rhoref(jdense),rhoref(jrare)'
c write(*,*) tref(ihot),tref(icool),rhoref(jdense),rhoref(jrare)
return
end
Subroutine chyopacity(T,rho,realk)
c..........This subroutine computes the opacity for a specified temperature
c..........and pressure by linearlly interpolating between the proper points
c..........of the Hubbard-Lampe (gL-padded) hydrogen conductive opacity table
include 'parm.h'
common /ahycopacity/ Rhoref(23),Tref(28),rkapparef(23,28)
data its,irhs /28,23/
save
condmin=rkapparef(1,its)
c write(*,*) 'chyopacity: Temperature: ',T,' Density: ',Rho
if (T.le.Tref(1).or.Rho.le.Rhoref(1)) then
write(*,*) 'Temperature: ',T,' Density: ',Rho
write(*,*) 'Out of Bounds in conductive hydrogen O-table.'
stop 'chyopacity'
endif
c..........Determine which of the reference points bracket the temperature.
call bracket(Tref,T,its,mode,icool,ihot,iterx)
call bracket(Rhoref,Rho,irhs,mode,jrare,jdense,iterx)
c..........Determine Krare and Kdense by a linear interpolation in temperature
rare = rkapparef(jrare,icool)
+ +((rkapparef(jrare,ihot)-rkapparef(jrare,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
dense = rkapparef (jdense,icool)
+ +((rkapparef(jdense,ihot)-rkapparef(jdense,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
c.........Determine kappa by a linear interpolation in the density
realk=rare+((dense-rare)/(rhoref(jdense)-rhoref(jrare)))
+ *(rho - rhoref(jrare))
realk=min(realk,condmin)
c.........We have thus determined k.
return
end
Subroutine cheopacity(T,rho,realk)
c..........This subroutine computes the opacity for a specified temperature
c..........and pressure by linearlly interpolating between the proper points
c..........of the Hubbard-Lampe (gL-padded) helium conductive opacity table
include 'parm.h'
common /ahecopacity/ Rhoref(25),Tref(32),rkapparef(25,32)
data its,irhs /32,25/
save
c
condmin=rkapparef(1,its)
if(T.le.Tref(1).or.Rho.le.Rhoref(1)) then
write(*,*) 'Temperature: ',T,' Density: ',Rho
write(*,*) 'Out of Bounds in conductive helium O-table.'
stop 'cheopacity'
endif
c..........Determine which of the reference points bracket the temperature.
call bracket(Tref,T,its,mode,icool,ihot,iterx)
call bracket(Rhoref,Rho,irhs,mode,jrare,jdense,iterx)
c..........Determine Krare and Kdense by a linear interpolation in temperature
rare = rkapparef(jrare,icool)
+ +((rkapparef(jrare,ihot)-rkapparef(jrare,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
dense = rkapparef (jdense,icool)
+ +((rkapparef(jdense,ihot)-rkapparef(jdense,icool))/
+ (Tref(ihot)-Tref(icool)))*(T-Tref(icool))
c.........Determine kappa by a linear interpolation in the density
realk=rare+((dense-rare)/(rhoref(jdense)-rhoref(jrare)))
+ *(rho - rhoref(jrare))
realk=max(realk,condmin)
c.........We have thus determined k.
return
end
C+
C NAME: bracket (Version 1.0)
C AUTHOR: H.W. Yorke (JPL)
C DATE: 24-Feb-05 V1.0
C UPDATES:
C
C The subroutine bracket finds the upper and lower indices of the
C members of a monotonic increasing table which bracket a given number.
C
C *** NOTE: bracket does not check whether the table is monotonically
C increasing.
C
C USAGE: call bracket (Xarray , Xval, Narray , mode , I1 , I2 , ITER )
C
C WHERE Xarray is the given monotonically increasing table (INPUT)
C Xval is the given number to be bracketed (INPUT)
C Narray is the length of the table (INPUT)
C mode = -1, 0 , 1 depending on whether Xval is OUTPUT
C less than the smallest value in the table
C (mode=-1), greater than the maximum value
C (mode=1) or lies within the table (mode=0)
C I1 is the lower index of bracketing OUTPUT
C I2 is the upper index of bracketing OUTPUT
C ITER is the number of iterations OUTPUT
C
C PROGRAMS USED: none
C-
subroutine bracket(Xarray,Xval,Narray,mode,I1,I2,iter)
include 'parm.h'
dimension Xarray(Narray)
save
c
i=0
mode=0
if(Xval.lt.Xarray(1)) then
I1=1
I2=2
mode=-1
return
endif
if(Xval.gt.Xarray(Narray)) then
I1=Narray-1
I2=Narray
mode=1
return
endif
I1=1
I2=Narray
do i=1,Narray
ID=(I1+I2)/2
if(Xarray(ID).lt.Xval) then
I1=ID
else
I2=ID
endif
if(I2-I1.eq.1) goto 90
enddo
stop 'bracket: Unable to find position in table'
90 iter=i
continue
return
end
subroutine opaltab(Tlog,RHOlog,XH,Y,opac,ierror)
include 'parm.h'
include 'var.h'
parameter (MX=14,MR=19,MT=70)
character*5 TABLE
dimension OPACTB(MX,MR,MT),XX(MX),RR(MR),TT(MT)
COMMON/ABUND/XBA(14),H1(14),AH(14)
data ifirst/0/
data Z0,Z1/0.,1./
save
ierror=0
if(ifirst.eq.0) then
ifirst=1
open(51,file='GN93hz',form='formatted',status='old',err=99)
do i=1,239
read(51,*)
enddo
do ix=1,MX
read(51,*)
201 format(a5,31x,f6.4,12x,f6.4,2(5x,f6.4))
read(51,201,err=98) TABLE,XX(ix),ZZ,XC,XO
c write(6,201) TABLE,XX(ix),ZZ,XC,XO
if(TABLE.ne.'TABLE') goto 98
C
C XX(ix) is normally used to store the hydrogen mass content used to
C generate the table. However, for X=0 (no hydrogen) then -XX(ix) is
C used to store the amount of additional oxygen and carbon.
C
if(XC+XO.gt.0.0001) then
XX(ix)=-(XC+XO)
else
ZZtab = ZZ
endif
read(51,*)
read(51,*)
read(51,*)
202 format(4x,f6.1,18f7.1)
read(51,202,err=98) RR
c write(6,202) RR
read(51,*)
do it=1,MT
203 format(f4.2,19f7.3)
read(51,203,err=98) TT(it),(OPACTB(ix,ir,it),ir=1,MR)
c write(6,203) TT(it),(OPACTB(ix,ir,it),ir=1,MR)
enddo
c write(6,203) TT
enddo
close(51)
dr=(RR(MR)-RR(1))/float(MR-1)
IXmax=1
XXmax=XX(1)
do ix=1,MX
if(XX(ix).gt.XXmax) then
IXmax=ix
XXmax=XX(ix)
endif
enddo
Znorm = Z1-H1(1)-H1(2)
endif
if(XH.lt.XX(1) .or. XH.gt.XXmax) ierror=1
dZZ=((Z1-XH-Y)-Znorm) * (Z1-ZZtab)/(Z1-Znorm)
if(dZZ.le.0.0014d0) then
IX1=IXmax-1
IX2=IXmax
if(XH.lt.XX(IX1)) then
IX1=1
IX2=2
if(XH.gt.XX(IX2)) then
IUP=IXmax-1
IDN=2
do i=1,2
IX1=(IUP+IDN)/2
if(XH.gt.XX(IX1)) then
IDN=IX1
else
IUP=IX1
endif
enddo
IX1=IDN
IX2=IUP
endif
endif
DX2=(XH-XX(IX1))/(XX(IX2)-XX(IX1))
DX1=Z1-DX2
else
if(XH.gt.1.d-20) then
ierror=99
write(6,*) 'You have no business being in this part of the', &
& ' opacity table ZZtab,dZZ=',ZZtab,dZZ
write(6,*) 'X,Y,Znorm=',XH,Y,Znorm
write(6,'(a,1p,14E11.3)') 'Abundances:',H1
do j=1,N
if(abs(XH-hydrogen(j)).lt.1.d-10) then
write(6,'(a,i4,9F8.5)') 'J,lnT,X,Y4,Y3,D,C,N,O=',j,Tlog, &
& XH,helium4(j),helium3(j),deuterium(j),carbon(j), &
& trogen(j),oxygen(j),1.d0-XH-helium4(j)-helium3(j)- &
& deuterium(j)-carbon(j)-trogen(j)-oxygen(j)
endif
enddo
stop 'opaltab'
endif
IX1=MX-1
IX2=MX
if(dZZ.lt.-XX(IX1)) then
IX1=1
IX2=IXmax+1
if(dZZ.gt.-XX(IX2)) then
IUP=MX-1
IDN=IXmax+1
do i=1,2
IX1=(IUP+IDN)/2
if(dZZ.gt.-XX(IX1)) then
IDN=IX1
else
IUP=IX1
endif
enddo
IX1=IDN
IX2=IUP
endif
endif
DX2=(dZZ+XX(IX1))/(-XX(IX2)+XX(IX1))
DX1=Z1-DX2
endif
c write(6,204) 'X:',XH,XX(ix1),XX(ix2),ix1,ix2,dx1,dx2
204 format(a,1p,3E12.4,2i10,2E12.4,i3)
Rlog=RHOlog-3.*(Tlog-6.)
if(Rlog.lt.RR(1) .or. Rlog.gt.RR(MR)) ierror=ierror+2
DR2=(Rlog-RR(1))/dr
IR1=max(DR2,Z0)
IR2=min(IR1+2,MR)
IR1=IR2-1
DR2=DR2-float(IR1-1)
DR1=Z1-DR2
c write(6,204) 'R:',Rlog,RR(ir1),RR(ir2),ir1,ir2,dr1,dr2
if(Tlog.lt.TT(1) .or. Tlog.gt.TT(MT)) ierror=ierror+4
call bracket(TT,Tlog,MT,mode,IT1,IT2,iterx)
DT2=(Tlog-TT(IT1))/(TT(IT2)-TT(IT1))
DT1=Z1-DT2
c write(6,204) 'T:',Tlog,TT(it1),TT(it2),it1,it2,dt1,dt2,iterx
opac=dx1*(dr1*(dt1*OPACTB(ix1,ir1,it1)+dt2*OPACTB(ix1,ir1,it2))
& + dr2*(dt1*OPACTB(ix1,ir2,it1)+dt2*OPACTB(ix1,ir2,it2)))
& +dx2*(dr1*(dt1*OPACTB(ix2,ir1,it1)+dt2*OPACTB(ix2,ir1,it2))
& + dr2*(dt1*OPACTB(ix2,ir2,it1)+dt2*OPACTB(ix2,ir2,it2)))
return
98 write(6,*) 'Error reading opacity tables'
stop 'opaltab'
99 write(6,*) 'Error opening opacity tables'