From a8516a6ed2fc6e525cb50ef2f2b2ec3d2891bdd5 Mon Sep 17 00:00:00 2001 From: Jeff Riley Date: Mon, 11 Dec 2023 15:36:37 +1100 Subject: [PATCH 1/2] Fix for issue #1022 --- src/BaseStar.cpp | 12 ++++++------ src/changelog.h | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/BaseStar.cpp b/src/BaseStar.cpp index a30c2fdac..f5fcaf27a 100755 --- a/src/BaseStar.cpp +++ b/src/BaseStar.cpp @@ -1384,8 +1384,8 @@ double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescript upperMassInd = 0; } else if (upperMassInd == -1) { - lowerMassInd = massesFromGe20.size(); - upperMassInd = massesFromGe20.size(); + lowerMassInd = massesFromGe20.size() - 1; + upperMassInd = massesFromGe20.size() - 1; } // Get vector of radii from GE20_QCRIT_AND_ZETA for the lower and upper mass indices @@ -1416,8 +1416,8 @@ double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescript upperRadiusLowerMassInd = 0; } else if (upperRadiusLowerMassInd == -1) { - lowerRadiusLowerMassInd = logRadiusVectorLowerMass.size(); - upperRadiusLowerMassInd = logRadiusVectorLowerMass.size(); + lowerRadiusLowerMassInd = logRadiusVectorLowerMass.size() - 1; + upperRadiusLowerMassInd = logRadiusVectorLowerMass.size() - 1; } std::vector indR1 = utils::binarySearch(logRadiusVectorUpperMass, log10(m_Radius)); @@ -1429,8 +1429,8 @@ double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescript upperRadiusUpperMassInd = 0; } else if (upperRadiusUpperMassInd == -1) { - lowerRadiusUpperMassInd = logRadiusVectorUpperMass.size(); - upperRadiusUpperMassInd = logRadiusVectorUpperMass.size(); + lowerRadiusUpperMassInd = logRadiusVectorUpperMass.size() - 1; + upperRadiusUpperMassInd = logRadiusVectorUpperMass.size() - 1; } // Set the 4 boundary points for the 2D interpolation diff --git a/src/changelog.h b/src/changelog.h index e7ccc0694..52f25feca 100644 --- a/src/changelog.h +++ b/src/changelog.h @@ -1071,8 +1071,10 @@ // - Fixed CalculateOrbitalAngularMomentum() (now uses eccentricity) // - Added links to online documentation to splash string // - Constants 'G1' and 'G_SN' renamed to 'G_AU_Msol_yr' and 'G_km_Msol_s' respectively +// 02.41.01 JR - Dec 11, 2023 - Defect repair: +// - Fix for issue #1022 - incorrect index used for last array entry. -const std::string VERSION_STRING = "02.41.00"; +const std::string VERSION_STRING = "02.41.01"; # endif // __changelog_h__ From 501ae24ae47a75865842bee745036e7dce0496fa Mon Sep 17 00:00:00 2001 From: Jeff Riley Date: Mon, 11 Dec 2023 15:42:41 +1100 Subject: [PATCH 2/2] Code cleanup --- src/BaseBinaryStar.cpp | 2 +- src/BaseStar.cpp | 26 +++++++++++++------------- src/changelog.h | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/BaseBinaryStar.cpp b/src/BaseBinaryStar.cpp index f428bdb87..518c587f7 100644 --- a/src/BaseBinaryStar.cpp +++ b/src/BaseBinaryStar.cpp @@ -1893,7 +1893,7 @@ void BaseBinaryStar::CalculateMassTransfer(const double p_Dt) { // NOTE: Critical mass ratio is defined as mAccretor/mDonor double qCrit = m_Donor->CalculateCriticalMassRatio(m_Accretor->IsDegenerate()); - isUnstable = (m_Accretor->Mass()/m_Donor->Mass()) < qCrit; + isUnstable = (m_Accretor->Mass() / m_Donor->Mass()) < qCrit; m_FractionAccreted = 1.0; // Accretion is assumed fully conservative for qCrit calculations } else { // Determine stability based on zetas diff --git a/src/BaseStar.cpp b/src/BaseStar.cpp index f5fcaf27a..f461218ce 100755 --- a/src/BaseStar.cpp +++ b/src/BaseStar.cpp @@ -1364,11 +1364,11 @@ double BaseStar::CalculateCriticalMassRatio(const bool p_AccretorIsDegenerate) { * from Ge et al. (2020), GE20 or GE20_IC. The first is the full adiabatic response, the second assumes * artificially isentropic envelopes. * - * double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescription) + * double BaseStar::InterpolateGe20QCrit(const QCRIT_PRESCRIPTION p_qCritPrescription) * * @return Interpolated value of either the critical mass ratio or zeta for given stellar mass / radius */ -double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescription) { +double BaseStar::InterpolateGe20QCrit(const QCRIT_PRESCRIPTION p_qCritPrescription) { // Get vector of masses from GE20_QCRIT_AND_ZETA std::vector massesFromGe20 = std::get<0>(GE20_QCRIT_AND_ZETA); @@ -1398,12 +1398,12 @@ double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescript // One of the following must be set if (p_qCritPrescription == QCRIT_PRESCRIPTION::GE20) { - qCritVectorLowerMass = std::get<1>(radiiQCritsZetasFromGe20[lowerMassInd]); - qCritVectorUpperMass = std::get<1>(radiiQCritsZetasFromGe20[upperMassInd]); + qCritVectorLowerMass = std::get<1>(radiiQCritsZetasFromGe20[lowerMassInd]); + qCritVectorUpperMass = std::get<1>(radiiQCritsZetasFromGe20[upperMassInd]); } else if (p_qCritPrescription == QCRIT_PRESCRIPTION::GE20_IC) { - qCritVectorLowerMass = std::get<2>(radiiQCritsZetasFromGe20[lowerMassInd]); - qCritVectorUpperMass = std::get<2>(radiiQCritsZetasFromGe20[upperMassInd]); + qCritVectorLowerMass = std::get<2>(radiiQCritsZetasFromGe20[lowerMassInd]); + qCritVectorUpperMass = std::get<2>(radiiQCritsZetasFromGe20[upperMassInd]); } // Get vector of radii from GE20_QCRIT_AND_ZETA for both lower and upper masses @@ -1441,18 +1441,18 @@ double BaseStar::InterpolateGe20QCrit( const QCRIT_PRESCRIPTION p_qCritPrescript double lowerMass = massesFromGe20[lowerMassInd]; double upperMass = massesFromGe20[upperMassInd]; - double lowerRadiusLowerMass = pow(10, logRadiusVectorLowerMass[lowerRadiusLowerMassInd]); - double upperRadiusLowerMass = pow(10, logRadiusVectorLowerMass[upperRadiusLowerMassInd]); - double lowerRadiusUpperMass = pow(10, logRadiusVectorUpperMass[lowerRadiusUpperMassInd]); - double upperRadiusUpperMass = pow(10, logRadiusVectorUpperMass[upperRadiusUpperMassInd]); + + double lowerRadiusLowerMass = PPOW(10.0, logRadiusVectorLowerMass[lowerRadiusLowerMassInd]); + double upperRadiusLowerMass = PPOW(10.0, logRadiusVectorLowerMass[upperRadiusLowerMassInd]); + double lowerRadiusUpperMass = PPOW(10.0, logRadiusVectorUpperMass[lowerRadiusUpperMassInd]); + double upperRadiusUpperMass = PPOW(10.0, logRadiusVectorUpperMass[upperRadiusUpperMassInd]); // Interpolate on the radii first, then the masses - double qCritLowerMass = qLowLow + (upperRadiusLowerMass - m_Radius)/(upperRadiusLowerMass - lowerRadiusLowerMass) * (qLowUpp - qLowLow); - double qCritUpperMass = qUppLow + (upperRadiusUpperMass - m_Radius)/(upperRadiusUpperMass - lowerRadiusUpperMass) * (qUppUpp - qUppLow); + double qCritLowerMass = qLowLow + (upperRadiusLowerMass - m_Radius) / (upperRadiusLowerMass - lowerRadiusLowerMass) * (qLowUpp - qLowLow); + double qCritUpperMass = qUppLow + (upperRadiusUpperMass - m_Radius) / (upperRadiusUpperMass - lowerRadiusUpperMass) * (qUppUpp - qUppLow); double interpolatedQCrit = qCritLowerMass + (upperMass - m_Mass)/(upperMass - lowerMass) * (qCritUpperMass - qCritLowerMass); return interpolatedQCrit; - } diff --git a/src/changelog.h b/src/changelog.h index 52f25feca..0439a3521 100644 --- a/src/changelog.h +++ b/src/changelog.h @@ -1071,8 +1071,9 @@ // - Fixed CalculateOrbitalAngularMomentum() (now uses eccentricity) // - Added links to online documentation to splash string // - Constants 'G1' and 'G_SN' renamed to 'G_AU_Msol_yr' and 'G_km_Msol_s' respectively -// 02.41.01 JR - Dec 11, 2023 - Defect repair: +// 02.41.01 JR - Dec 11, 2023 - Defect repair, a little code cleanup: // - Fix for issue #1022 - incorrect index used for last array entry. +// - A little code cleanup const std::string VERSION_STRING = "02.41.01";