Fix ujl discontinuity in near-flat models (conservative approach)#185
Fix ujl discontinuity in near-flat models (conservative approach)#185
Conversation
…inuity fix - Change scalar miny1 from /(l+10) to /(l+max(0,30-l)) for better performance - Provides 12.3× improvement vs original (vs 4.6× for previous fix) - 2.7× better than previous PR #185 fix at L=8 (0.234% vs 0.63% discontinuity) - More computationally efficient: targeted strictness only where needed - Tensor miny1 unchanged (analysis shows tensor modification not needed) - Preserves accuracy for |Omega_k| > 1e-4 where already working well
Updated with Adaptive Solution 🚀I've updated this PR with a significantly improved adaptive solution based on comprehensive analysis: Key Changes
Performance Improvement
Why Adaptive is SuperiorThe
Comprehensive Testing Completed
The adaptive solution provides the best balance of accuracy, efficiency, and targeted improvement while maintaining excellent stability across all tested scenarios. |
018dadd to
d315091
Compare
- Change scalar miny1 to adaptive formula: /(l+max(0,30-l)) - Provides 12.3× improvement vs original (0.234% vs 2.89% at L=8) - 2.7× better than previous /(l+10) fix - More computationally efficient with targeted strictness - Tensor miny1 unchanged (analysis shows not needed) - Comprehensive testing shows excellent stability across ±Omega_k Fixes #184
4c40774 to
f18e32f
Compare
🎯 FINAL UPDATE: Adaptive Solution ImplementedCurrent Status: This PR now implements the adaptive scalar-only solution which provides superior performance compared to the original conservative approach. ✅ What's Actually ImplementedCode Changes (only 1 line modified): // Line ~1696: ONLY scalar miny1 modified
miny1= 0.5d-4/(l+max(0,30-l))/BessIntBoost ! Adaptive formula for Omega_k discontinuity fix, see https://github.com/cmbant/CAMB/pull/185
// Line ~1761: Tensor miny1 UNCHANGED (analysis showed not needed)
miny1= 1.d-6/l/BessIntBoost ! Original formula📊 Performance Achieved
🧪 Comprehensive Testing Completed
🎯 Why Adaptive is SuperiorThe
📈 Updated FigureShows dramatic improvement with adaptive solution: smooth transitions, minimal discontinuities, excellent performance across all tested scenarios. 🏆 Final RecommendationThe adaptive scalar-only solution is ready for merge:
This adaptive solution provides the optimal balance of accuracy, efficiency, and targeted improvement while maintaining excellent stability. |

Problem
Fixes discontinuity in lensing potential power spectrum for small |omk| values between 1e-4 and 5e-7. The discontinuity was caused by inadequate integration termination thresholds in ujl calculations for near-flat models.
Root Cause Analysis
Through systematic component isolation, the root cause was identified as:
Key Discovery: The primary bottleneck is line 1698 (
miny1scalar integration threshold). Component isolation showed:miny1fix alone: 0.733% discontinuity (99.5% of improvement)minujlfix alone: 18.938% discontinuity (makes things worse!)Conservative Solution
Implements conservative integration threshold adjustments that provide excellent balance:
Why Conservative Approach
The
(l+10)/(l+5)scaling provides:Results
Discontinuity Reduction
CMB Spectra Validation
Testing across omk = [-1e-6, 0, +1e-6] shows excellent preservation:
Validation Figure
The figure shows smooth fractional differences in the phi-phi spectrum after applying the conservative fix, demonstrating:
Comprehensive Testing
Component Isolation
Systematic testing of individual accuracy parameters confirmed:
Diagnostic Switch Tests
Universality
Technical Implementation
Files changed:
fortran/cmbmain.f90(4 lines)Backward compatibility: ✅ No API changes
Performance impact: ~1.2× computational cost
Accuracy preservation: ✅ All CMB spectra remain accurate
Alternative Approaches Tested
Recommendation
The conservative approach provides the optimal balance for general CAMB usage:
For users requiring maximum precision, the aggressive
(l+50)/(l+20)variant is also available.Fixes #184
Conservative solution providing 10× discontinuity improvement with minimal side effects