POSYDON-code / POSYDON

POSYDON is a next-generation single and binary-star population synthesis code incorporating full stellar structure and evolution modeling with the use of MESA.
BSD 3-Clause "New" or "Revised" License
29 stars 19 forks source link

`binary.evolve()` crash due to separation not present when giving the orbital_period on initialisation #387

Open maxbriel opened 3 weeks ago

maxbriel commented 3 weeks ago

When running the following binary, it crashes due to the "separation" not being available for the RLO calculation. Even though the orbital_period and masses are given, it feels counterintuitive that the separation is not automatically calculated.

Similarly, there are some other properties that are not initialised when creating your own binary, which are by default initialised for a POSYDON ZAMS binary. Should this be done as well when initiating a binary manually at ZAMS?

STAR1 = SingleStar(**{'mass': 150,
                      'state': 'H-rich_Core_H_burning',
                      'metallicity':1e-3})
STAR2 = SingleStar(**{'mass': 90,
                      'state': 'H-rich_Core_H_burning',
                      'metallicity':1e-3})

BINARY = BinaryStar(STAR1, STAR2,  
                    **{'time': 0.0,
                       'state': 'detached',
                       'event': 'ZAMS',
                       'orbital_period':12000, 
                       'eccentricity': 0.0},
                    properties = sim_pop)
Traceback TypeError Traceback (most recent call last) Cell In[22], line 1 ----> 1 BINARY.evolve() File ~/Documents/POSYDON_versions/POSYDON_PISN/posydon/binary_evol/binarystar.py:210, in BinaryStar.evolve(self) 206 while (self.event != 'END' and self.event != 'FAILED' 207 and self.event not in self.properties.end_events 208 and self.state not in self.properties.end_states): 209 signal.alarm(MAXIMUM_STEP_TIME) --> 210 self.run_step() 212 n_steps += 1 213 if max_n_steps is not None: File ~/Documents/POSYDON_versions/POSYDON_PISN/posydon/binary_evol/binarystar.py:239, in BinaryStar.run_step(self) 234 raise ValueError( 235 "Next step name '{}' does not correspond to a function in " 236 "SimulationProperties.".format(next_step_name)) 238 self.properties.pre_step(self, next_step_name) --> 239 next_step(self) 240 finally: 241 self.append_state() File ~/Documents/POSYDON_versions/POSYDON_PISN/posydon/binary_evol/DT/step_detached.py:1392, in detached_step.__call__(self, binary) 1389 print("initial omega_in_rad_per_year", omega_in_rad_per_year) 1390 return omega_in_rad_per_year -> 1392 if (ev_rlo1(binary.time, [binary.separation, binary.eccentricity]) >= 0 1393 or ev_rlo2(binary.time, [binary.separation, binary.eccentricity]) >= 0): 1394 binary.state = "initial_RLOF" 1395 return File ~/Documents/POSYDON_versions/POSYDON_PISN/posydon/binary_evol/DT/step_detached.py:1220, in detached_step.__call__..ev_rlo1(t, y) 1217 sep = y[0] 1218 ecc = y[1] -> 1220 RL = roche_lobe_radius(sec_mass, pri_mass, (1 - ecc) * sep) 1222 # 95% filling of the RL is enough to assume beginning of RLO, 1223 # as we do in CO-HMS_RLO grid 1224 return interp1d_sec["R"](t - t_offset_sec) - 0.95*RL TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
mkruckow commented 3 weeks ago

Yes, the __init__ of each class should always create and initialize all the element of an object of that class, which are called without being checked for their existence.