Skip to content

Commit a20b101

Browse files
authored
Merge pull request #1383 from TeamCOMPAS/BugFix
Ensure that Loveridge Lambdas are always positive; speed up Matlab post-processing
2 parents b39dec1 + b3a3546 commit a20b101

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

compas_matlab_utils/ComparisonPlots.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function ComparisonPlots(filename1, name1, filename2, name2)
6969
%Plot LMXBs/IMXBs
7070
figure(5); clf(5);
7171
[LMXBcount, NSLMXBcount]=LMXBplot(filename1, name1, 5, 'r', 40);
72-
fprintf('\nLMXBs:\t\t#LMXB\t#NS LMXB\n');
72+
fprintf('\nLMXBs:\t\t#LMXB\t\t#NS LMXB\n');
7373
fprintf('%s:\t%d\t\t%d\n', name1, LMXBcount, NSLMXBcount);
7474
if(nargin==4),
7575
[LMXBcount, NSLMXBcount]=LMXBplot(filename2, name2, 5, 'b', 20);
@@ -345,13 +345,18 @@ function DWDplot(file, name, fignumberDWD, colour, point)
345345
timeCE=h5read(file,'/BSE_Common_Envelopes/Time');
346346
seedAll=h5read(file, '/BSE_System_Parameters/SEED');
347347
[isCE,indexCE]=ismember(seedSN,seedCE);
348+
[isCE,lastindexCE]=ismember(seedSN,seedCE,'legacy'); %last index of CE seed matching given SN seed (for binaries with 2+ CE events)
348349
simultaneouswithCE = false(size(indexCE));
349-
for(i=1:length(isCE)), if(isCE(i)), simultaneouswithCE(i) = ~isempty(find(timeCE==timeSN(i) & seedCE==seedSN(i))); end; end;
350+
simultaneouswithCE(isCE) = (timeCE(indexCE(isCE)) == timeSN(isCE)) | (timeCE(lastindexCE(isCE)) == timeSN(isCE));
351+
%Note: could (very rarely) miss a coincidence if >2 CE events and only intermediate CE matches SN in time
350352
precedingCE = false(size(indexCE));
351-
for(i=1:length(isCE)), if(isCE(i)), precedingCE(i) = ~isempty(find(timeCE<timeSN(i) & seedCE==seedSN(i))); end; end;
353+
precedingCE(isCE) = (timeCE(indexCE(isCE)) < timeSN(isCE));
352354
[experiencedRLOF,indexRLOF]=ismember(seedSN,seedRLOF);
355+
[experiencedRLOF,lastindexRLOF]=ismember(seedSN,seedRLOF, 'legacy');
353356
simultaneouswithRLOF = false(size(indexRLOF));
354-
for(i=1:length(indexRLOF)), if(experiencedRLOF(i)), simultaneouswithRLOF(i) = ~isempty(find(timeRLOF==timeSN(i) & seedRLOF==seedSN(i))); end; end;
357+
simultaneouswithRLOF(experiencedRLOF) = (timeRLOF(indexRLOF(experiencedRLOF)) == timeSN(experiencedRLOF) ...
358+
| timeRLOF(lastindexRLOF(experiencedRLOF)) == timeSN(experiencedRLOF));
359+
%Note: could miss a coincidence if >2 RLOF events and only intermediate RLOF matches SN in time
355360
binariescount=length(seedAll);
356361
SNcount=length(seedSN);
357362
BHcompletecount=sum(starSNSN==14 & MpreSN==MSNSN);

src/HG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ double HG::CalculateLambdaLoveridge(const double p_EnvMass, const bool p_IsMassL
134134
logBindingEnergy += 33.29866; // + logBE0
135135
double bindingEnergy = PPOW(10.0, logBindingEnergy);
136136

137-
return utils::Compare(bindingEnergy, 0.0) > 0 && utils::Compare(1.0 / bindingEnergy, 0.0) > 0 && utils::Compare(p_EnvMass, 0.0) > 0
137+
double lambda = utils::Compare(bindingEnergy, 0.0) > 0 && utils::Compare(1.0 / bindingEnergy, 0.0) > 0 && utils::Compare(p_EnvMass, MAXIMUM_MASS_LOSS_FRACTION * m_Mass) > 0
138138
? (G_CGS * m_Mass * MSOL_TO_G * p_EnvMass * MSOL_TO_G) / (m_Radius * RSOL_TO_AU * AU_TO_CM * bindingEnergy)
139-
: 1.0; // default to 1.0 (usual lambda default) if binding energy is not sensible [sometimes can be infinite if logBindingEnergy is too high] or if envelope mass is not positive [can be zero]
139+
: 1.0; // default to 1.0 (usual lambda default) if binding energy is not sensible [sometimes can be infinite if logBindingEnergy is too high] or if envelope mass is too low to reliably evaluate lambda [can be zero]
140+
return utils::Compare(lambda, 0.0) > 0 ? lambda : 1.0; // final check to avoid returning zero lambda
140141
}
141142

142143

src/changelog.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,9 @@
15451545
// - Changed the default behaviour to use enhanced Nanjing lambdas (for common envelope calculations), interpolating in mass and metallicity
15461546
// 03.18.03 IM - May 2, 2025 - Defect repair:
15471547
// - Fix for issue #1380, which appears when the Loveridge binding energy is so high that lambda is rounded off to zero
1548+
// 03.18.04 IM - May 4, 2025 - Defect repair:
1549+
// - Added a check to avoid Loveridge lambda becoming zero when the envelope mass is positive but very small
15481550

1549-
const std::string VERSION_STRING = "03.18.03";
1551+
const std::string VERSION_STRING = "03.18.04";
15501552

15511553
# endif // __changelog_h__

0 commit comments

Comments
 (0)