Nbody6
 All Files Functions Variables
comenv.f
Go to the documentation of this file.
1 ***
2  SUBROUTINE comenv(M01,M1,MC1,AJ1,JSPIN1,KW1,
3  & m02,m2,mc2,aj2,jspin2,kw2,ecc,sep,coel)
4 *
5 * Common Envelope Evolution.
6 *
7  include 'common6.h'
8 *
9  INTEGER kw1,kw2,kw
10 * INTEGER IDUM
11 *
12  REAL*8 m01,m1,mc1,aj1,jspin1,r1,l1
13  REAL*8 m02,m2,mc2,aj2,jspin2,r2,l2,mc22
14  REAL*8 tscls1(20),tscls2(20),lums(10),gb(10),tm1,tm2,tn
15  REAL*8 ebindi,ebindf,eorbi,eorbf,ecirc
16  REAL*8 aa,bb,cc,efac
17  REAL*8 ecc,sep,sepf,sepl,mf,xx
18  REAL*8 const,dely,deri,delmf,mc3,fage1,fage2
19  REAL*8 tb,oorb,ospin1,ospin2
20  REAL*8 rc1,rc2,q1,q2,rl1,rl2
21  REAL*8 menv,renv,menvd,rzams
22  REAL*8 lamb1,lamb2,k21,k22
23  REAL*8 aursun,k3,lambda,alpha1,mch
24  parameter(aursun = 214.95d0,k3 = 0.21d0)
25  parameter(lambda = 0.d0,alpha1 = 3.d0)
26  parameter(mch = 1.44d0)
27  LOGICAL coel,eccflg
28  REAL*8 celamf,rl,rzamsf
29  EXTERNAL celamf,rl,rzamsf
30 *
31 * Common envelope evolution - entered only when KW1 = 2, 3, 4, 5, 6, 8 or 9.
32 *
33 * For simplicity energies are divided by -G.
34 *
35  coel = .false.
36  eccflg = .true.
37 *
38 * Obtain the core masses and radii.
39 *
40  kw = kw1
41  CALL star(kw1,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
42  IF(aj1.GT.tn) aj1 = tn
43  CALL hrdiag(m01,aj1,m1,tm1,tn,tscls1,lums,gb,zpars,
44  & r1,l1,kw1,mc1,rc1,menv,renv,k21)
45  ospin1 = jspin1/(k21*r1*r1*(m1-mc1)+k3*rc1*rc1*mc1)
46  IF(m1.GT.mc1)THEN
47  menvd = menv/(m1-mc1)
48  rzams = rzamsf(m01)
49  lamb1 = celamf(kw,m01,l1,r1,rzams,menvd,lambda)
50  ELSE
51  lamb1 = 0.5d0
52  ENDIF
53  IF(kw.NE.kw1) WRITE(38,*)' COMENV TYPE CHANGE *1'
54 *
55  kw = kw2
56  CALL star(kw2,m02,m2,tm2,tn,tscls2,lums,gb,zpars)
57  IF(aj2.GT.tn) aj2 = tn
58  CALL hrdiag(m02,aj2,m2,tm2,tn,tscls2,lums,gb,zpars,
59  & r2,l2,kw2,mc2,rc2,menv,renv,k22)
60  ospin2 = jspin2/(k22*r2*r2*(m2-mc2)+k3*rc2*rc2*mc2)
61  IF(kw.NE.kw2) WRITE(38,*)' COMENV TYPE CHANGE *2'
62 *
63  IF(sep.GT.0.d0)THEN
64  tb = (sep/aursun)*sqrt(sep/(aursun*(m1+m2)))
65  oorb = twopi/tb
66  ENDIF
67 *
68  WRITE(38,66)kw1,m01,m1,mc1,aj1,sep
69  66 FORMAT(' COMENV OLD *1:',i4,3f7.2,f9.2,f12.4)
70  WRITE(38,67)kw2,m02,m2,mc2,aj2
71  67 FORMAT(' COMENV OLD *2:',i4,3f7.2,f9.2)
72 *
73 * Calculate the binding energy of the giant envelope (multiplied by lambda).
74 *
75  ebindi = m1*(m1-mc1)/(lamb1*r1)
76 *
77 * Calculate the initial orbital energy
78 *
79  eorbi = mc1*m2/(2.d0*sep)
80 *
81 * Allow for an eccentric orbit.
82 *
83 * ECIRC = EORBI/(1.D0 - ECC*ECC)
84 *
85  IF(eccflg.AND.ecc.GT.0.01d0)THEN
86 *
87 * Assume 10% of the binding energy is lost on the first orbit and determine
88 * whether the star just passes through. For the moment put all the
89 * secondary's envelope with the primary's.
90 *
91 * DE = MIN(EBINDI/10.D0,(ECIRC-EORBI)*ALPHA1)
92 *
93 * Adopt new procedure based on a cubic fitting (May 2003).
94 * (Oct 2005: YP is maximum for a head-on collision and would reduce
95 * to zero for a grazing encounter, i.e. QP=1. However,
96 * in order to be consistent with Kochanek collision detection
97 * which allows QP values up to 1.7 on entry to expel/comenv
98 * we set a non-zero YP for QP > 1. This is a temporary fix
99 * until a better collision detection scheme comes along sometime
100 * in the near future, we hope.)
101 *
102  qp = sep*(1.d0 - ecc)/(r1 + r2)
103  yp = 0.5d0*(qp - 0.5d0)**3 - 0.375d0*(qp - 0.5d0) + 0.125d0
104  yp = max(yp,0.05d0)
105  yp = min(yp,0.5d0)
106  de = yp*ebindi
107 * Remove all envelope mass if below 0.05 m_sun.
108  IF (m1-mc1.LT.0.05) de = ebindi
109  ebindf = ebindi - de
110  mf = 0.5d0*(mc1 + sqrt(mc1*mc1 + 4.d0*lamb1*r1*ebindf))
111  eorbi = mf*m2/(2.d0*sep)
112  ecirc = eorbi/(1.d0 - ecc*ecc)
113  eorbf = eorbi + de/alpha1
114  IF(eorbf.LT.ecirc)THEN
115  m1 = mf
116  ecc = sqrt(1.d0 - eorbf/ecirc)
117  ELSE
118 * EFAC = 1.d0 - 1.d0/(ECC*ECC)
119  efac = ecc*ecc/(1.d0 - ecc*ecc)
120  aa = 1.d0/(lamb1*r1)
121 * BB = (2.d0*M1-MC1)/(LAMB1*R1) + ALPHA1*M2/(SEP*EFAC)
122  bb = (2.d0*m1-mc1)/(lamb1*r1) + alpha1*efac*m2/(2.d0*sep)
123 * CC = M1*MC1/(LAMB1*R1) + ALPHA1*M1*M2/(SEP*EFAC)
124  cc = alpha1*efac*m1*m2/(2.d0*sep)
125  dm = (bb - sqrt(bb*bb - 4.d0*aa*cc))/(2.d0*aa)
126  IF(dm.LE.0.0.OR.dm.GT.(m1-mc1))THEN
127  WRITE(*,*)' WARNING: CE DM ',dm,m1,mc1
128  ENDIF
129  m1 = max(m1-dm,mc1)
130  ebindf = m1*(m1-mc1)/(lamb1*r1)
131  de = ebindi - ebindf
132  eorbf = eorbi + de/alpha1
133  ecc = 0.001d0
134  ENDIF
135  sepf = m1*m2/(2.d0*eorbf)
136  IF((m1-mc1).LT.1.0d-07)THEN
137  m1 = mc1
138  CALL star(kw1,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
139  CALL hrdiag(m01,aj1,m1,tm1,tn,tscls1,lums,gb,zpars,
140  & r1,l1,kw1,mc1,rc1,menv,renv,k21)
141  ELSEIF(kw1.EQ.4)THEN
142  aj1 = (aj1 - tscls1(2))/tscls1(3)
143  CALL gntage(mc1,m1,kw1,zpars,m01,aj1)
144  ENDIF
145  goto 30
146  ENDIF
147 *
148 * If the secondary star is also giant-like add its envelopes's energy.
149 *
150  IF(kw2.GE.2.AND.kw2.LE.9.AND.kw2.NE.7)THEN
151  IF(m2.GT.mc2)THEN
152  menvd = menv/(m2-mc2)
153  rzams = rzamsf(m02)
154  lamb2 = celamf(kw,m02,l2,r2,rzams,menvd,lambda)
155  ELSE
156  lamb2 = 0.5d0
157  ENDIF
158  ebindi = ebindi + m2*(m2-mc2)/(lamb2*r2)
159 *
160 * Re-calculate the initial orbital energy
161 *
162  eorbi = mc1*mc2/(2.d0*sep)
163  ENDIF
164 *
165 *
166 * Calculate the final orbital energy without coalescence.
167 *
168  eorbf = eorbi + ebindi/alpha1
169 *
170 * If the secondary is on the main sequence see if it fills its Roche lobe.
171 *
172  IF(kw2.LE.1.OR.kw2.EQ.7)THEN
173  sepf = mc1*m2/(2.d0*eorbf)
174 ***
175 * Assume the energy generated by forcing the secondary to
176 * co-rotate goes into the envelope (experimental).
177 * TB = (SEPF/AURSUN)*SQRT(SEPF/(AURSUN*(MC1+M2)))
178 * OORB = TWOPI/TB
179 * DELY = 0.5D0*M2*R2*R2*(OSPIN2*OSPIN2 - OORB*OORB)/3.91D+08
180 * DELY = K22*DELY
181 * EBINDI = MAX(0.D0,EBINDI - DELY)
182 * EORBF = EORBI + EBINDI/ALPHA1
183 * SEPF = MC1*M2/(2.D0*EORBF)
184 ***
185  q1 = mc1/m2
186  q2 = 1.d0/q1
187  rl1 = rl(q1)
188  rl2 = rl(q2)
189  IF(rc1/rl1.GE.r2/rl2)THEN
190 *
191 * The helium core of a very massive star of type 4 may actually fill
192 * its Roche lobe in a wider orbit with a very low-mass secondary.
193 *
194  IF(rc1.GT.rl1*sepf)THEN
195  coel = .true.
196  sepl = rc1/rl1
197  ENDIF
198  ELSE
199  IF(r2.GT.rl2*sepf)THEN
200  coel = .true.
201  sepl = r2/rl2
202  ENDIF
203  ENDIF
204  IF(coel)THEN
205 *
206  kw = ktype(kw1,kw2) - 100
207  mc3 = mc1
208  IF(kw2.EQ.7.AND.kw.EQ.4) mc3 = mc3 + m2
209 *
210 * Coalescence - calculate final binding energy.
211 *
212  eorbf = max(mc1*m2/(2.d0*sepl),eorbi)
213  ebindf = ebindi - alpha1*(eorbf - eorbi)
214  ELSE
215 *
216 * Primary becomes a black hole, neutron star, white dwarf or helium star.
217 *
218  mf = m1
219  m1 = mc1
220  CALL star(kw1,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
221  CALL hrdiag(m01,aj1,m1,tm1,tn,tscls1,lums,gb,zpars,
222  & r1,l1,kw1,mc1,rc1,menv,renv,k21)
223  ENDIF
224  ELSE
225 *
226 * Degenerate or giant secondary. Check if the least massive core fills its
227 * Roche lobe.
228 *
229  sepf = mc1*mc2/(2.d0*eorbf)
230 ***
231 * Assume the energy generated by forcing the secondary to
232 * co-rotate goes into the envelope (experimental).
233 * IF(KW2.GE.10.AND.KW2.LE.14)THEN
234 * TB = (SEPF/AURSUN)*SQRT(SEPF/(AURSUN*(MC1+MC2)))
235 * OORB = TWOPI/TB
236 * DELY = 0.5D0*M2*R2*R2*(OSPIN2*OSPIN2 - OORB*OORB)/3.91D+08
237 * DELY = K3*DELY
238 * EBINDI = MAX(0.D0,EBINDI - DELY)
239 * EORBF = EORBI + EBINDI/ALPHA1
240 * SEPF = MC1*MC2/(2.D0*EORBF)
241 * ENDIF
242 ***
243  q1 = mc1/mc2
244  q2 = 1.d0/q1
245  rl1 = rl(q1)
246  rl2 = rl(q2)
247  IF(rc1/rl1.GE.rc2/rl2)THEN
248  IF(rc1.GT.rl1*sepf)THEN
249  coel = .true.
250  sepl = rc1/rl1
251  ENDIF
252  ELSE
253  IF(rc2.GT.rl2*sepf)THEN
254  coel = .true.
255  sepl = rc2/rl2
256  ENDIF
257  ENDIF
258 *
259  IF(coel)THEN
260 *
261 * If the secondary was a neutron star or black hole the outcome
262 * is an unstable Thorne-Zytkow object that leaves only the core.
263 *
264  sepf = 0.d0
265  IF(kw2.GE.13)THEN
266  mc1 = mc2
267  m1 = mc1
268  mc2 = 0.d0
269  m2 = 0.d0
270  kw1 = kw2
271  kw2 = 15
272  aj1 = 0.d0
273 *
274 * The envelope mass is not required in this case.
275 *
276  goto 30
277  ENDIF
278 *
279  kw = ktype(kw1,kw2) - 100
280  mc3 = mc1 + mc2
281 *
282 * Calculate the final envelope binding energy.
283 *
284  eorbf = max(mc1*mc2/(2.d0*sepl),eorbi)
285  ebindf = ebindi - alpha1*(eorbf - eorbi)
286 *
287 * Check if we have the merging of two degenerate cores and if so
288 * then see if the resulting core will survive or change form.
289 *
290  IF(kw1.EQ.6.AND.(kw2.EQ.6.OR.kw2.GE.11))THEN
291  CALL dgcore(kw1,kw2,kw,mc1,mc2,mc3,ebindf)
292  ENDIF
293  IF(kw1.LE.3.AND.m01.LE.zpars(2))THEN
294  IF((kw2.GE.2.AND.kw2.LE.3.AND.m02.LE.zpars(2)).OR.
295  & kw2.EQ.10)THEN
296  CALL dgcore(kw1,kw2,kw,mc1,mc2,mc3,ebindf)
297  IF(kw.GE.10)THEN
298  kw1 = kw
299  m1 = mc3
300  mc1 = mc3
301  IF(kw.LT.15) m01 = mc3
302  aj1 = 0.d0
303  mc2 = 0.d0
304  m2 = 0.d0
305  kw2 = 15
306  goto 30
307  ENDIF
308  ENDIF
309  ENDIF
310 *
311  ELSE
312 *
313 * The cores do not coalesce - assign the correct masses and ages.
314 *
315  mf = m1
316  m1 = mc1
317  CALL star(kw1,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
318  CALL hrdiag(m01,aj1,m1,tm1,tn,tscls1,lums,gb,zpars,
319  & r1,l1,kw1,mc1,rc1,menv,renv,k21)
320  mf = m2
321  kw = kw2
322  m2 = mc2
323  CALL star(kw2,m02,m2,tm2,tn,tscls2,lums,gb,zpars)
324  CALL hrdiag(m02,aj2,m2,tm2,tn,tscls2,lums,gb,zpars,
325  & r2,l2,kw2,mc2,rc2,menv,renv,k22)
326  ENDIF
327  ENDIF
328 *
329  IF(coel)THEN
330  mc22 = mc2
331  IF(kw.EQ.4.OR.kw.EQ.7)THEN
332 * If making a helium burning star calculate the fractional age
333 * depending on the amount of helium that has burnt.
334  IF(kw1.LE.3)THEN
335  fage1 = 0.d0
336  ELSEIF(kw1.GE.6)THEN
337  fage1 = 1.d0
338  ELSE
339  fage1 = (aj1 - tscls1(2))/(tscls1(13) - tscls1(2))
340  ENDIF
341  IF(kw2.LE.3.OR.kw2.EQ.10)THEN
342  fage2 = 0.d0
343  ELSEIF(kw2.EQ.7)THEN
344  fage2 = aj2/tm2
345  mc22 = m2
346  ELSEIF(kw2.GE.6)THEN
347  fage2 = 1.d0
348  ELSE
349  fage2 = (aj2 - tscls2(2))/(tscls2(13) - tscls2(2))
350  ENDIF
351  ENDIF
352  ENDIF
353 *
354 * Now calculate the final mass following coelescence. This requires a
355 * Newton-Raphson iteration.
356 *
357  IF(coel)THEN
358 *
359 * Calculate the orbital spin just before coalescence.
360 *
361  tb = (sepl/aursun)*sqrt(sepl/(aursun*(mc1+mc2)))
362  oorb = twopi/tb
363 *
364  xx = 1.d0 + zpars(7)
365  IF(ebindf.LE.0.d0)THEN
366  mf = mc3
367  goto 20
368  ELSE
369  const = ((m1+m2)**xx)*(m1-mc1+m2-mc22)*ebindf/ebindi
370  ENDIF
371 *
372 * Initial Guess.
373 *
374  mf = max(mc1 + mc22,(m1 + m2)*(ebindf/ebindi)**(1.d0/xx))
375  10 dely = (mf**xx)*(mf - mc1 - mc22) - const
376 * IF(ABS(DELY/MF**(1.D0+XX)).LE.1.0D-02) GOTO 20
377  IF(abs(dely/mf).LE.1.0d-03) goto 20
378  deri = mf**zpars(7)*((1.d0+xx)*mf - xx*(mc1 + mc22))
379  delmf = dely/deri
380  mf = mf - delmf
381  goto 10
382 *
383 * Set the masses and separation.
384 *
385  20 IF(mc22.EQ.0.d0) mf = max(mf,mc1+m2)
386  m2 = 0.d0
387  m1 = mf
388  kw2 = 15
389 *
390 * Combine the core masses.
391 *
392  IF(kw.EQ.2)THEN
393  CALL star(kw,m1,m1,tm2,tn,tscls2,lums,gb,zpars)
394  IF(gb(9).GE.mc1)THEN
395  m01 = m1
396  aj1 = tm2 + (tscls2(1) - tm2)*(aj1-tm1)/(tscls1(1) - tm1)
397  CALL star(kw,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
398  ENDIF
399  ELSEIF(kw.EQ.7)THEN
400  m01 = m1
401  CALL star(kw,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
402  aj1 = tm1*(fage1*mc1 + fage2*mc22)/(mc1 + mc22)
403  ELSEIF(kw.EQ.4.OR.mc2.GT.0.d0.OR.kw.NE.kw1)THEN
404  IF(kw.EQ.4) aj1 = (fage1*mc1 + fage2*mc22)/(mc1 + mc22)
405  mc1 = mc1 + mc2
406  mc2 = 0.d0
407 *
408 * Obtain a new age for the giant.
409 *
410  CALL gntage(mc1,m1,kw,zpars,m01,aj1)
411  CALL star(kw,m01,m1,tm1,tn,tscls1,lums,gb,zpars)
412  ENDIF
413  CALL hrdiag(m01,aj1,m1,tm1,tn,tscls1,lums,gb,zpars,
414  & r1,l1,kw,mc1,rc1,menv,renv,k21)
415  jspin1 = oorb*(k21*r1*r1*(m1-mc1)+k3*rc1*rc1*mc1)
416  jspin2 = 0.d0
417  kw1 = kw
418  ecc = 0.001d0
419  ELSE
420 *
421 * Determine if any eccentricity remains in the orbit.
422 *
423 * IF(ECCFLG.AND.EORBF.LT.ECIRC)THEN
424 * ECC = SQRT(1.D0 - EORBF/ECIRC)
425 * ELSE
426 * ECC = 0.001D0
427 * ENDIF
428 *
429 * Set both cores in co-rotation with the orbit on exit of CE,
430 *
431  tb = (sepf/aursun)*sqrt(sepf/(aursun*(m1+m2)))
432  oorb = twopi/tb
433 * JSPIN1 = OORB*(K21*R1*R1*(M1-MC1)+K3*RC1*RC1*MC1)
434 * JSPIN2 = OORB*(K22*R2*R2*(M2-MC2)+K3*RC2*RC2*MC2)
435 *
436 * or, leave the spins of the cores as they were on entry.
437 * Tides will deal with any synchronization later.
438 *
439  jspin1 = ospin1*(k21*r1*r1*(m1-mc1)+k3*rc1*rc1*mc1)
440  jspin2 = ospin2*(k22*r2*r2*(m2-mc2)+k3*rc2*rc2*mc2)
441  ENDIF
442  30 sep = sepf
443  aj1 = max(aj1,1.0d-10)
444  aj2 = max(aj2,1.0d-10)
445 * AJ1 = MAX(AJ1,1.0D-10*TM1)
446 * AJ2 = MAX(AJ2,1.0D-10*TM2)
447 *
448  WRITE(38,68)kw1,m01,m1,mc1,aj1
449  68 FORMAT(' COMENV NEW *1:',i4,3f7.2,f9.2)
450  WRITE(38,69)kw2,m02,m2,mc2,aj2
451  69 FORMAT(' COMENV NEW *2:',i4,3f7.2,f9.2)
452 *
453  RETURN
454  END
455 ***