Conversation
…ey only come from the core of the postMS star
…s (with changes) and the star_base (the HMS, star 1 probably) becomes massless remnant
for more information, see https://pre-commit.ci
| try: | ||
| mass_weighted_avg_value=(A1*M1+A2*M2)/(M1+M2) | ||
| except TypeError: | ||
| mass_weighted_avg_value= np.nan |
There was a problem hiding this comment.
Is setting the mass weighted average to np.nan going to cause issues later down the pipeline?
There was a problem hiding this comment.
Is it possible to avoid a try/except?
Is it instead possible to verify the type of the values used?
There was a problem hiding this comment.
-
@astro-abhishek the np.nan may cause issues later, but I think is the most pythonic way of saying "the function was called byt physically there are issues at the calculation so we have no computed result, we don't know the value". If the question is whether it will make it crash, I am not sure, I think not, as np.nan is accepted as a value in calculations, it will just produce more "unknown" np.nan quantities wherever it is used in a calcualation.
-
@maxbriel The following is a different way more exact checking, instead of try-except loop. Is this what you are thinking? If did not add it yet, but if you agree, please just add it as a commit directly.
den = M1 + M2
if not (np.isfinite(A1) and np.isfinite(A2) and np.isfinite(M1) and np.isfinite(M2)):
mass_weighted_avg_value = np.nan
elif den == 0:
mass_weighted_avg_value = np.nan
else:
mass_weighted_avg_value = (A1M1 + A2M2) / den
In both cases, if you have better coding ideas for this part (or any other) feel free to add them directly.
| "log_R", | ||
| "center_c12" | ||
| "center_c12", | ||
| "co_core_mass" |
There was a problem hiding this comment.
what if the co_core_mass doesn't exist? (there's a comment about something similar right above this)
There was a problem hiding this comment.
Hmm, this list assumes that the single star models and the respective EEPs have this column. If a user uses their one sinlge star and EEPs, not run with POSYDON, so not calculating a co_core (having only a c_core or an o_core for example), there may be a mismatch. For our POSYDON runs this is ok for now. If we want to generalize it so much, I think much of the structure should change anyway. I would leave it for now, keeping the above comment there for future reference.
|
There are two testing binaries in the suite that change with this PR.
|
|
|
||
| # weighted central abundances if merging cores. Else only from star_base | ||
| if (comp.co_core_mass > 0 and star_base.co_core_mass == 0): # comp with CO core and the star_base has not | ||
| if (comp.co_core_mass is not None and star_base.co_core_mass == 0): # comp with CO core and the star_base has not |
There was a problem hiding this comment.
Why is there this change from values to None? It happens later too.
Are there specific binaries that crash because the co_core_mass is undefined when reaching this stage?
Same n line 575.
There was a problem hiding this comment.
Hmm, I don' remember exactly the reasoning. I think I thought that instead of raising a TypeError in case of comp.co_core_mass = None and crashing, I preferred it to go to the else: Pwarn("weird compbination of CO core masses during merging", "EvolutionWarning").
But again, if you think of a better handling it , feel free to directly change it back
| #these stellar attributes change value | ||
| merged_star.mass = (star_base.mass + comp.mass) * (1.-self.rel_mass_lost_HMS_HMS) | ||
|
|
||
| #TODO for key in ["center_h1", "center_he4", "center_c12", "center_n14","center_o16"]: |
There was a problem hiding this comment.
is this TODO still needed?
There was a problem hiding this comment.
No, you are right, I took the line out
| for key in ["mass", "he_core_mass", "c_core_mass", "o_core_mass", "co_core_mass"]: | ||
| current = getattr(star_base, key) + getattr(comp, key) | ||
| setattr(merged_star, key,current) | ||
| merged_star = comp |
There was a problem hiding this comment.
Why are we changing what the merged star is here?
This is different than the definition of which one starts the RLO. This will make the companion the remaining star.
There was a problem hiding this comment.
Hmm, actually this occurs even at line 256. Indeed, it "violates" the engulfind star (that starts the RLO) is our base of the merger, making the base to be the star with the most layers. So for example in a postMS+HMS merger, the postMS star becomes the base always. Same between postMS+HeMS. Even if it is not the postMS that engulfs. This is because the final merged star with have a more complex layering (envelope, core, etc). Of course in most cases it will indeed be the postMS star that is also initiating the RLO and the engulfing, but we allow for the other case too, giving the same outcome.
If needed we can restructure the code to remake the calculation using the engulfing always as the base, but this is only for the sake of clarity. It will not change the merged outcome in the end.
summary: The outcome in the end should not depend on which star engulfs (unless omeone argues otherwise). it is just easier to start the merger construction from that star in most cases, as it usually is the more "complex" star in the perspective of layers, i.e. it is a giant star
|
@astro-abhishek @maxbriel Thanks for the detailed comments. I tried to answer all of them and address whichever where doable. Feel free to directly change the coding way if you think a better option exists. Note as soon as this PR is accepted, it is better to be pulled by the #788 before that PR is evaluated and merged. |
|
Here's the output of the branch currently: The diff: https://www.diffchecker.com/7IurVLUA/ |
|
|
||
| if self.verbose: | ||
| print(abundance_name, mass_weight1, mass_weight2) | ||
| print("A_base, M_base_abundance, A_comp, M_comp_abundance", A1, M1, A2, M2) |
There was a problem hiding this comment.
Should we say *_base or e.g., *_1 or *_pri? I think other parts of the code use one of the latter. Also, should M_*_abundance be something like M_*_mass because M1/M2 hold masses?
| # companion with the envelope of star_base | ||
| parameters_to_mix = ["surface_h1", "surface_he4", "surface_c12", "surface_n14", "surface_o16"] | ||
| for abundance_name in parameters_to_mix: | ||
| setattr(merged_star, abundance_name, self.mass_weighted_avg(star_base, | ||
| comp, | ||
| abundance_name=abundance_name, | ||
| mass_weight1="H-rich_envelope_mass", | ||
| mass_weight2="mass")) | ||
|
|
||
| # The change of masses occurs after the calculation of weighted averages | ||
| # Note that the he core mass is unchanged, which means that | ||
| # adding the mass changes the envelope mass only. | ||
| merged_star.mass = star_base.mass + comp.mass | ||
|
|
||
| for key in STARPROPERTIES: | ||
| # these stellar attributes become np.nan | ||
| for substring in ["log_", "lg_", "surf_", "conv_", "lambda", "profile"]: | ||
| if (substring in key) : | ||
| setattr(merged_star, key, np.nan) | ||
| if key in [ "c12_c12", "center_gamma", | ||
| "avg_c_in_c_core", "total_moment_of_inertia", "spin"]: | ||
| setattr(merged_star, key, np.nan) | ||
| # Set parameters that are not expected to be meaningful after a merger to np.nan | ||
| self._apply_nan_attributes(merged_star) |
There was a problem hiding this comment.
Some of this is repeated code in this if chain. I suggest generalizing this and creating a helper function for clarity/brevity that is called here and elsewhere, as appropriate.
There was a problem hiding this comment.
working on this here: sg_merger_copiedattributes
There was a problem hiding this comment.
This line (binary.event = None) means that the print statements based on binary.event (e.g., if binary.event == 'oMerging1':) below never fire when self.verbose = True. Should this be set to None after the verbose print? Is this line needed?
There was a problem hiding this comment.
I commented the binary.event = None line for now.
| "avg_c_in_c_core", "total_moment_of_inertia", "spin"]: | ||
| if key in [ "c12_c12", "total_moment_of_inertia", "spin"]: | ||
| setattr(merged_star, key, np.nan) | ||
| merged_star.state = check_state_of_star(merged_star, star_CO=False) # TODO for sure this needs testing! |
There was a problem hiding this comment.
The comment says that this for sure needs to be tested -- has it been?
|
I was working on generalizing the logic and creating functions to apply these merging rules and noticed something. For post-HMS mergers, we have this logic (in whereas for HMS-HMS mergers, we do not apply the same rule. Should we? The following binary evolution from our test suite contains an HMS-HMS merger where the base star has a non-zero CO core mass while the companion has no CO core. (The branch that I'm working on the logic in is |
This is strange. A HMS-HMS merger should not have a CO core or He core defined in either component, so the same rule shouldn't be applied. |
@maxbriel this is the debugging output prior to merging: Star 1 is classed as In the grids, this system may lie near a boundary between unstable MT and unstable reverse MT. While the unstable MT models have no CO core, the unstable reverse MT models do. These should be in different interpolation classes though? I noticed that it seems we only have an At q = 0.95, the closest neighbors to this system are in the red boxed region:
and at q = 0.99:
(The axes in the plot are showing you the linear values of Porb and mass, not log10 values). |




Implementing and solving issues already discussed in a previous PR version #311 which is now deprecated.
Reminder : The resulting merger product is continuing as a singlestar instance at the place of the engulfing star (i.e. if oMerging1, then star_1 would be the merged product) UNLESS a NS/BH is involved, where the latter is the only one surviving (potential Thorne-Zytkov object).