forked from ahwkuepper/mcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comenv.f
353 lines (353 loc) · 10.6 KB
/
comenv.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
***
SUBROUTINE COMENV(M01,M1,MC1,AJ1,JSPIN1,KW1,
& M02,M2,MC2,AJ2,JSPIN2,KW2,
& ZPARS,ECC,SEP,JORB,COEL)
*
* Common Envelope Evolution.
*
* Author : C. A. Tout
* Date : 18th September 1996
*
* Redone : J. R. Hurley
* Date : 7th July 1998
*
IMPLICIT NONE
*
INTEGER KW1,KW2,KW
INTEGER KTYPE(0:14,0:14)
COMMON /TYPES/ KTYPE
INTEGER ceflag,tflag,ifflag,nsflag,wdflag
COMMON /FLAGS/ ceflag,tflag,ifflag,nsflag,wdflag
*
REAL*8 M01,M1,MC1,AJ1,JSPIN1,R1,L1,K21
REAL*8 M02,M2,MC2,AJ2,JSPIN2,R2,L2,K22,MC22
REAL*8 TSCLS1(20),TSCLS2(20),LUMS(10),GB(10),TM1,TM2,TN,ZPARS(20)
REAL*8 EBINDI,EBINDF,EORBI,EORBF,ECIRC,SEPF,SEPL,MF,XX
REAL*8 CONST,DELY,DERI,DELMF,MC3,FAGE1,FAGE2
REAL*8 ECC,SEP,JORB,TB,OORB,OSPIN1,OSPIN2,TWOPI
REAL*8 RC1,RC2,Q1,Q2,RL1,RL2,LAMB1,LAMB2
REAL*8 MENV,RENV,MENVD,RZAMS,VS(3)
REAL*8 AURSUN,K3,ALPHA1,LAMBDA
PARAMETER (AURSUN = 214.95D0,K3 = 0.21D0)
COMMON /VALUE2/ ALPHA1,LAMBDA
LOGICAL COEL
REAL*8 CELAMF,RL,RZAMSF
EXTERNAL CELAMF,RL,RZAMSF
*
* Common envelope evolution - entered only when KW1 = 2, 3, 4, 5, 6, 8 or 9.
*
* For simplicity energies are divided by -G.
*
TWOPI = 2.D0*ACOS(-1.D0)
COEL = .FALSE.
*
* Obtain the core masses and radii.
*
KW = KW1
CALL star(KW1,M01,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS)
CALL hrdiag(M01,AJ1,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS,
& R1,L1,KW1,MC1,RC1,MENV,RENV,K21)
OSPIN1 = JSPIN1/(K21*R1*R1*(M1-MC1)+K3*RC1*RC1*MC1)
MENVD = MENV/(M1-MC1)
RZAMS = RZAMSF(M01)
LAMB1 = CELAMF(KW,M01,L1,R1,RZAMS,MENVD,LAMBDA)
KW = KW2
CALL star(KW2,M02,M2,TM2,TN,TSCLS2,LUMS,GB,ZPARS)
CALL hrdiag(M02,AJ2,M2,TM2,TN,TSCLS2,LUMS,GB,ZPARS,
& R2,L2,KW2,MC2,RC2,MENV,RENV,K22)
OSPIN2 = JSPIN2/(K22*R2*R2*(M2-MC2)+K3*RC2*RC2*MC2)
*
* Calculate the binding energy of the giant envelope (multiplied by lambda).
*
EBINDI = M1*(M1-MC1)/(LAMB1*R1)
*
* If the secondary star is also giant-like add its envelopes's energy.
*
EORBI = M1*M2/(2.D0*SEP)
IF(KW2.GE.2.AND.KW2.LE.9.AND.KW2.NE.7)THEN
MENVD = MENV/(M2-MC2)
RZAMS = RZAMSF(M02)
LAMB2 = CELAMF(KW,M02,L2,R2,RZAMS,MENVD,LAMBDA)
EBINDI = EBINDI + M2*(M2-MC2)/(LAMB2*R2)
*
* Calculate the initial orbital energy
*
IF(CEFLAG.NE.3) EORBI = MC1*MC2/(2.D0*SEP)
ELSE
IF(CEFLAG.NE.3) EORBI = MC1*M2/(2.D0*SEP)
ENDIF
*
* Allow for an eccentric orbit.
*
ECIRC = EORBI/(1.D0 - ECC*ECC)
*
* Calculate the final orbital energy without coalescence.
*
EORBF = EORBI + EBINDI/ALPHA1
*
* If the secondary is on the main sequence see if it fills its Roche lobe.
*
IF(KW2.LE.1.OR.KW2.EQ.7)THEN
SEPF = MC1*M2/(2.D0*EORBF)
Q1 = MC1/M2
Q2 = 1.D0/Q1
RL1 = RL(Q1)
RL2 = RL(Q2)
IF(RC1/RL1.GE.R2/RL2)THEN
*
* The helium core of a very massive star of type 4 may actually fill
* its Roche lobe in a wider orbit with a very low-mass secondary.
*
IF(RC1.GT.RL1*SEPF)THEN
COEL = .TRUE.
SEPL = RC1/RL1
ENDIF
ELSE
IF(R2.GT.RL2*SEPF)THEN
COEL = .TRUE.
SEPL = R2/RL2
ENDIF
ENDIF
IF(COEL)THEN
*
KW = KTYPE(KW1,KW2) - 100
MC3 = MC1
IF(KW2.EQ.7.AND.KW.EQ.4) MC3 = MC3 + M2
*
* Coalescence - calculate final binding energy.
*
EORBF = MAX(MC1*M2/(2.D0*SEPL),EORBI)
EBINDF = EBINDI - ALPHA1*(EORBF - EORBI)
ELSE
*
* Primary becomes a black hole, neutron star, white dwarf or helium star.
*
MF = M1
M1 = MC1
CALL star(KW1,M01,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS)
CALL hrdiag(M01,AJ1,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS,
& R1,L1,KW1,MC1,RC1,MENV,RENV,K21)
IF(KW1.GE.13)THEN
CALL kick(KW1,MF,M1,M2,ECC,SEPF,JORB,VS)
IF(ECC.GT.1.D0) GOTO 30
ENDIF
ENDIF
ELSE
*
* Degenerate or giant secondary. Check if the least massive core fills its
* Roche lobe.
*
SEPF = MC1*MC2/(2.D0*EORBF)
Q1 = MC1/MC2
Q2 = 1.D0/Q1
RL1 = RL(Q1)
RL2 = RL(Q2)
IF(RC1/RL1.GE.RC2/RL2)THEN
IF(RC1.GT.RL1*SEPF)THEN
COEL = .TRUE.
SEPL = RC1/RL1
ENDIF
ELSE
IF(RC2.GT.RL2*SEPF)THEN
COEL = .TRUE.
SEPL = RC2/RL2
ENDIF
ENDIF
*
IF(COEL)THEN
*
* If the secondary was a neutron star or black hole the outcome
* is an unstable Thorne-Zytkow object that leaves only the core.
*
SEPF = 0.D0
IF(KW2.GE.13)THEN
MC1 = MC2
M1 = MC1
MC2 = 0.D0
M2 = 0.D0
KW1 = KW2
KW2 = 15
AJ1 = 0.D0
*
* The envelope mass is not required in this case.
*
GOTO 30
ENDIF
*
KW = KTYPE(KW1,KW2) - 100
MC3 = MC1 + MC2
*
* Calculate the final envelope binding energy.
*
EORBF = MAX(MC1*MC2/(2.D0*SEPL),EORBI)
EBINDF = EBINDI - ALPHA1*(EORBF - EORBI)
*
* Check if we have the merging of two degenerate cores and if so
* then see if the resulting core will survive or change form.
*
IF(KW1.EQ.6.AND.(KW2.EQ.6.OR.KW2.GE.11))THEN
CALL dgcore(KW1,KW2,KW,MC1,MC2,MC3,EBINDF)
ENDIF
IF(KW1.LE.3.AND.M01.LE.ZPARS(2))THEN
IF((KW2.GE.2.AND.KW2.LE.3.AND.M02.LE.ZPARS(2)).OR.
& KW2.EQ.10)THEN
CALL dgcore(KW1,KW2,KW,MC1,MC2,MC3,EBINDF)
IF(KW.GE.10)THEN
KW1 = KW
M1 = MC3
MC1 = MC3
IF(KW.LT.15) M01 = MC3
AJ1 = 0.D0
MC2 = 0.D0
M2 = 0.D0
KW2 = 15
GOTO 30
ENDIF
ENDIF
ENDIF
*
ELSE
*
* The cores do not coalesce - assign the correct masses and ages.
*
MF = M1
M1 = MC1
CALL star(KW1,M01,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS)
CALL hrdiag(M01,AJ1,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS,
& R1,L1,KW1,MC1,RC1,MENV,RENV,K21)
IF(KW1.GE.13)THEN
CALL kick(KW1,MF,M1,M2,ECC,SEPF,JORB,VS)
IF(ECC.GT.1.D0) GOTO 30
ENDIF
MF = M2
KW = KW2
M2 = MC2
CALL star(KW2,M02,M2,TM2,TN,TSCLS2,LUMS,GB,ZPARS)
CALL hrdiag(M02,AJ2,M2,TM2,TN,TSCLS2,LUMS,GB,ZPARS,
& R2,L2,KW2,MC2,RC2,MENV,RENV,K22)
IF(KW2.GE.13.AND.KW.LT.13)THEN
CALL kick(KW2,MF,M2,M1,ECC,SEPF,JORB,VS)
IF(ECC.GT.1.D0) GOTO 30
ENDIF
ENDIF
ENDIF
*
IF(COEL)THEN
MC22 = MC2
IF(KW.EQ.4.OR.KW.EQ.7)THEN
* If making a helium burning star calculate the fractional age
* depending on the amount of helium that has burnt.
IF(KW1.LE.3)THEN
FAGE1 = 0.D0
ELSEIF(KW1.GE.6)THEN
FAGE1 = 1.D0
ELSE
FAGE1 = (AJ1 - TSCLS1(2))/(TSCLS1(13) - TSCLS1(2))
ENDIF
IF(KW2.LE.3.OR.KW2.EQ.10)THEN
FAGE2 = 0.D0
ELSEIF(KW2.EQ.7)THEN
FAGE2 = AJ2/TM2
MC22 = M2
ELSEIF(KW2.GE.6)THEN
FAGE2 = 1.D0
ELSE
FAGE2 = (AJ2 - TSCLS2(2))/(TSCLS2(13) - TSCLS2(2))
ENDIF
ENDIF
ENDIF
*
* Now calculate the final mass following coelescence. This requires a
* Newton-Raphson iteration.
*
IF(COEL)THEN
*
* Calculate the orbital spin just before coalescence.
*
TB = (SEPL/AURSUN)*SQRT(SEPL/(AURSUN*(MC1+MC2)))
OORB = TWOPI/TB
*
XX = 1.D0 + ZPARS(7)
IF(EBINDF.LE.0.D0)THEN
MF = MC3
GOTO 20
ELSE
CONST = ((M1+M2)**XX)*(M1-MC1+M2-MC22)*EBINDF/EBINDI
ENDIF
*
* Initial Guess.
*
MF = MAX(MC1 + MC22,(M1 + M2)*(EBINDF/EBINDI)**(1.D0/XX))
10 DELY = (MF**XX)*(MF - MC1 - MC22) - CONST
* IF(ABS(DELY/MF**(1.D0+XX)).LE.1.0D-02) GOTO 20
IF(ABS(DELY/MF).LE.1.0D-03) GOTO 20
DERI = MF**ZPARS(7)*((1.D0+XX)*MF - XX*(MC1 + MC22))
DELMF = DELY/DERI
MF = MF - DELMF
GOTO 10
*
* Set the masses and separation.
*
20 IF(MC22.EQ.0.D0) MF = MAX(MF,MC1+M2)
M2 = 0.D0
M1 = MF
KW2 = 15
*
* Combine the core masses.
*
IF(KW.EQ.2)THEN
CALL star(KW,M1,M1,TM2,TN,TSCLS2,LUMS,GB,ZPARS)
IF(GB(9).GE.MC1)THEN
M01 = M1
AJ1 = TM2 + (TSCLS2(1) - TM2)*(AJ1-TM1)/(TSCLS1(1) - TM1)
CALL star(KW,M01,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS)
ENDIF
ELSEIF(KW.EQ.7)THEN
M01 = M1
CALL star(KW,M01,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS)
AJ1 = TM1*(FAGE1*MC1 + FAGE2*MC22)/(MC1 + MC22)
ELSEIF(KW.EQ.4.OR.MC2.GT.0.D0.OR.KW.NE.KW1)THEN
IF(KW.EQ.4) AJ1 = (FAGE1*MC1 + FAGE2*MC22)/(MC1 + MC22)
MC1 = MC1 + MC2
MC2 = 0.D0
*
* Obtain a new age for the giant.
*
CALL gntage(MC1,M1,KW,ZPARS,M01,AJ1)
CALL star(KW,M01,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS)
ENDIF
CALL hrdiag(M01,AJ1,M1,TM1,TN,TSCLS1,LUMS,GB,ZPARS,
& R1,L1,KW,MC1,RC1,MENV,RENV,K21)
JSPIN1 = OORB*(K21*R1*R1*(M1-MC1)+K3*RC1*RC1*MC1)
KW1 = KW
ECC = 0.D0
ELSE
*
* Check if any eccentricity remains in the orbit by first using
* energy to circularise the orbit before removing angular momentum.
* (note this should not be done in case of CE SN ... fix).
*
IF(EORBF.LT.ECIRC)THEN
ECC = SQRT(1.D0 - EORBF/ECIRC)
ELSE
ECC = 0.D0
ENDIF
*
* Set both cores in co-rotation with the orbit on exit of CE,
*
TB = (SEPF/AURSUN)*SQRT(SEPF/(AURSUN*(M1+M2)))
OORB = TWOPI/TB
JORB = M1*M2/(M1+M2)*SQRT(1.D0-ECC*ECC)*SEPF*SEPF*OORB
* JSPIN1 = OORB*(K21*R1*R1*(M1-MC1)+K3*RC1*RC1*MC1)
* JSPIN2 = OORB*(K22*R2*R2*(M2-MC2)+K3*RC2*RC2*MC2)
*
* or, leave the spins of the cores as they were on entry.
* Tides will deal with any synchronization later.
*
JSPIN1 = OSPIN1*(K21*R1*R1*(M1-MC1)+K3*RC1*RC1*MC1)
JSPIN2 = OSPIN2*(K22*R2*R2*(M2-MC2)+K3*RC2*RC2*MC2)
ENDIF
30 SEP = SEPF
RETURN
END
***