Skip to content

-nan in GiantBranch::CalculateCoreMassAtBGB()  #1256

@jeffriley

Description

@jeffriley

Running COMPAS with:

./compas -n1 --random-seed 0

results in -nan in GiantBranch::CalculateCoreMassAtBGB() in the following statement:

return std::min((0.95 * gbParams(McBAGB)), std::sqrt(std::sqrt(c + (MC_L_C1 * PPOW(p_Mass, MC_L_C2)))));      // sqrt is much faster than PPOW()

because the value of c is negative enough to cause the parameter to sqrt() to be negative

double GiantBranch::CalculateCoreMassAtBGB(const double p_Mass, const DBL_VECTOR &p_GBParams) {
#define gbParams(x) p_GBParams[static_cast<int>(GBP::x)]                // for convenience and readability - undefined at end of function
#define massCutoffs(x) m_MassCutoffs[static_cast<int>(MASS_CUTOFF::x)]  // for convenience and readability - undefined at end of function
   
    double luminosity = GiantBranch::CalculateLuminosityAtPhaseBase_Static(massCutoffs(MHeF), m_AnCoefficients);
    double Mc_MHeF    = BaseStar::CalculateCoreMassGivenLuminosity_Static(luminosity, p_GBParams);
    double c          = (Mc_MHeF * Mc_MHeF * Mc_MHeF * Mc_MHeF) - (MC_L_C1 * PPOW(massCutoffs(MHeF), MC_L_C2));         // pow() is slow - use multiplication

    return std::min((0.95 * gbParams(McBAGB)), std::sqrt(std::sqrt(c + (MC_L_C1 * PPOW(p_Mass, MC_L_C2)))));            // sqrt is much faster than PPOW()

#undef massCutoffs
#undef gbParams
}

To Reproduce
Run COMPAS with:

./compas -n1 --random-seed 0

Expected behavior
Production code does not cause -nan

**Versioning

OS: Ubuntu 22.04
COMPAS v03.07.01

EDIT: at first I thought this only occurs when p_Mass is 0.0, but that is not the case - the problem is evident for other values of p_Mass (e.g. 0.87)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingseverity_majorThis is a severe bugurgency_moderateThis is a moderately urgent issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions