Skip to content

Commit 9376106

Browse files
committed
updated comprad for METISSE
1 parent 766f2e5 commit 9376106

File tree

6 files changed

+55
-229
lines changed

6 files changed

+55
-229
lines changed

.gitignore

-104
This file was deleted.

meson.build

-109
This file was deleted.

src/cosmic/evolve.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
246246
# check the initial conditions of the system and warn user if
247247
# anything is weird about them, such as the star starts
248248
# in Roche Lobe overflow
249-
utils.check_initial_conditions(initialbinarytable)
249+
utils.check_initial_conditions(initialbinarytable,SSEDict)
250250

251251
# assign some columns based on keyword arguments but that
252252
# can be overwritten by the params or BSEDict
@@ -486,6 +486,8 @@ def _evolve_single_system(f):
486486
_evolvebin.se_flags.using_sse = False
487487
path_to_tracks = f["path_to_tracks"]
488488
path_to_he_tracks = f["path_to_he_tracks"]
489+
else:
490+
raise ValueError("Use either 'sse' or 'metisse' as stellar engine")
489491

490492
[bpp_index, bcm_index, kick_info] = _evolvebin.evolv2([f["kstar_1"], f["kstar_2"]],
491493
[f["mass_1"], f["mass_2"]],

src/cosmic/sample/sampler/independent.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def get_independent_sampler(
4545
SF_duration,
4646
binfrac_model,
4747
met,
48+
SSEDict=None,
4849
size=None,
4950
total_mass=np.inf,
5051
sampling_target="size",
@@ -159,6 +160,8 @@ def get_independent_sampler(
159160
n_binaries : `int`
160161
Number of binaries needed to generate a population
161162
"""
163+
164+
162165
if sampling_target == "total_mass" and (total_mass is None or total_mass == np.inf):
163166
raise ValueError("If `sampling_target == 'total mass'` then `total_mass` must be supplied")
164167
if size is None and (total_mass is None or total_mass == np.inf):
@@ -284,8 +287,8 @@ def get_independent_sampler(
284287

285288
zsun = kwargs.pop("zsun", 0.02)
286289

287-
rad1 = initconditions.set_reff(mass1_binary, metallicity=met, zsun=zsun)
288-
rad2 = initconditions.set_reff(mass2_binary, metallicity=met, zsun=zsun)
290+
rad1 = initconditions.set_reff(SSEDict, mass1_binary, metallicity=met, zsun=zsun)
291+
rad2 = initconditions.set_reff(SSEDict, mass2_binary, metallicity=met, zsun=zsun)
289292

290293
# sample periods and eccentricities
291294
# if the porb_model is moe19, the metallicity needs to be supplied
@@ -1072,7 +1075,7 @@ def set_kstar(self, mass):
10721075

10731076
return kstar
10741077

1075-
def set_reff(self, mass, metallicity, zsun=0.02):
1078+
def set_reff(self, SSEDict ,mass, metallicity, zsun=0.02):
10761079
"""
10771080
Better way to set the radii from BSE, by calling it directly
10781081
@@ -1092,12 +1095,25 @@ def set_reff(self, mass, metallicity, zsun=0.02):
10921095

10931096
_evolvebin.metvars.zsun = zsun
10941097

1098+
if (SSEDict == None) or (SSEDict["stellar_engine"] == "sse"):
1099+
_evolvebin.se_flags.using_sse = True
1100+
_evolvebin.se_flags.using_metisse = False
1101+
path_to_tracks = ""
1102+
path_to_he_tracks = ""
1103+
elif SSEDict["stellar_engine"] == "metisse":
1104+
_evolvebin.se_flags.using_metisse = True
1105+
_evolvebin.se_flags.using_sse = False
1106+
path_to_tracks = SSEDict["path_to_tracks"]
1107+
path_to_he_tracks = SSEDict["path_to_he_tracks"]
1108+
else:
1109+
raise ValueError("Use either 'sse' or 'metisse' as stellar engine")
1110+
10951111
idx = 0
10961112
while total_length > max_array_size:
10971113
## cycle through the masses max_array_size number at a time
10981114
temp_mass = mass[idx*max_array_size:(idx+1)*max_array_size]
10991115

1100-
temp_radii = _evolvebin.compute_r(temp_mass,metallicity,max_array_size)
1116+
temp_radii = _evolvebin.compute_r(temp_mass,metallicity,max_array_size,path_to_tracks,path_to_he_tracks)
11011117

11021118
## put these in the radii array
11031119
radii[idx*max_array_size:(idx+1)*max_array_size] = temp_radii
@@ -1111,7 +1127,7 @@ def set_reff(self, mass, metallicity, zsun=0.02):
11111127
temp_mass = np.zeros(max_array_size)
11121128
temp_mass[:length_remaining] = mass[-length_remaining:]
11131129

1114-
temp_radii = _evolvebin.compute_r(temp_mass,metallicity,length_remaining)
1130+
temp_radii = _evolvebin.compute_r(temp_mass,metallicity,length_remaining,path_to_tracks,path_to_he_tracks)
11151131

11161132
#finish up the array
11171133
radii[-length_remaining:] = temp_radii[:length_remaining]

src/cosmic/src/comprad.f

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
***
2-
SUBROUTINE compute_r(mass,z,num,rad)
2+
SUBROUTINE compute_r(mass,z,num,rad,
3+
& path_to_tracks,path_to_he_tracks)
34
IMPLICIT NONE
45
INCLUDE 'const_bse.h'
56

@@ -17,8 +18,9 @@ SUBROUTINE compute_r(mass,z,num,rad)
1718
PARAMETER(loop=100000)
1819
real*8 mass(loop),rad(loop),z
1920
integer k,kstar,num
20-
real*8 mt,tm,tn,mass0,age,lum,mc,rc,me,re
21+
real*8 mt,tm,tn,mass0,age,lum,mc,rc,me,re,dtm
2122
REAL*8 tscls(20),lums(10),GB(10),zpars(20),k2,bhspin
23+
CHARACTER*256 path_to_tracks,path_to_he_tracks
2224

2325
***
2426
* f2py directives go here; we'll return the radii as a 10^5 array
@@ -29,7 +31,11 @@ SUBROUTINE compute_r(mass,z,num,rad)
2931
Cf2py intent(in) num
3032
Cf2py intent(out) rad
3133

32-
CALL zcnsts(z,zpars)
34+
if(using_METISSE) CALL initialize_front_end('cosmic')
35+
CALL zcnsts(z,zpars,path_to_tracks,path_to_he_tracks)
36+
37+
if(using_METISSE) call allocate_track(num,mass)
38+
3339

3440
***
3541
* Then just loop through everything
@@ -46,11 +52,15 @@ SUBROUTINE compute_r(mass,z,num,rad)
4652
kstar = 0
4753
if(mt.ge.0.7) kstar = 1
4854
bhspin = 0.d0
49-
rc = 0.d0
50-
CALL star(kstar,mass0,mt,tm,tn,tscls,lums,GB,zpars)
55+
rc = 0.d0
56+
dtm = 0.d0
57+
CALL star(kstar,mass0,mt,tm,tn,tscls,lums,GB,zpars,dtm,k)
5158
CALL hrdiag(mass0,age,mt,tm,tn,tscls,lums,GB,zpars,
5259
& rad(k),lum,kstar,mc,rc,me,re,k2,bhspin,k)
53-
60+
5461
10 continue
62+
63+
64+
if (using_METISSE) call dealloc_track()
5565

5666
END SUBROUTINE compute_r

src/cosmic/utils.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1602,13 +1602,14 @@ def error_check(BSEDict, SSEDict, filters=None, convergence=None, sampling=None)
16021602
return
16031603

16041604

1605-
def check_initial_conditions(full_initial_binary_table):
1605+
def check_initial_conditions(full_initial_binary_table, SSEDict):
16061606
"""Checks initial conditions and reports warnings
16071607
16081608
Only warning provided right now is if star begins in Roche lobe
16091609
overflow
16101610
"""
1611-
1611+
from cosmic import _evolvebin
1612+
16121613
def rzamsf(m):
16131614
"""A function to evaluate Rzams
16141615
( from Tout et al., 1996, MNRAS, 281, 257 ).
@@ -1635,10 +1636,20 @@ def rzamsf(m):
16351636

16361637
if np.all(mass2 == 0.0):
16371638
return
1638-
else:
1639+
elif (SSEDict["stellar_engine"] == "sse"):
16391640
rzams1 = rzamsf(mass1)
16401641
rzams2 = rzamsf(mass2)
1641-
1642+
1643+
# TODO: the following section with METISSE is incomplete
1644+
# elif (SSEDict["stellar_engine"] == "metisse"):
1645+
# _evolvebin.se_flags.using_sse = False
1646+
# _evolvebin.se_flags.using_metisse = True
1647+
# path_to_tracks = SSEDict["path_to_tracks"]
1648+
# path_to_he_tracks = SSEDict["path_to_he_tracks"]
1649+
1650+
# rzams1 = _evolvebin.compute_r(mass1,z,len(mass1),path_to_tracks,path_to_he_tracks)
1651+
# rzams1 = _evolvebin.compute_r(mass2,z,len(mass2),path_to_tracks,path_to_he_tracks)
1652+
16421653
# assume some time step in order to calculate sep
16431654
yeardy = 365.24
16441655
aursun = 214.95

0 commit comments

Comments
 (0)