Skip to content

Commit db0a527

Browse files
committed
Updated L to 2.5
1 parent 2c7cbc9 commit db0a527

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

‎src/bca.rs‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
use super::*;
22
use rand::RngExt;
3-
use anyhow::ensure;
43

54
#[cfg(feature = "cpr_rootfinder")]
65
const CPR_ROOTFINDER_LOWER_BOUND: f64 = 1e-4;
76

7+
8+
#[cfg(feature = "cpr_rootfinder")]
9+
// Boyd suggests that the CPR is insensitive to this parameter
10+
// Empirical testing with rcpr suggests best convergence for Morse
11+
// potential at ~3; other potentials, ~2; 2.5 seems a good compromise.
12+
const L: f64 = 2.5;
13+
814
#[cfg(feature = "cpr_rootfinder")]
915
use rcpr::rootfinders::{
1016
find_roots,
@@ -597,12 +603,7 @@ pub fn polynomial_rootfinder(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact
597603

598604
#[cfg(feature = "cpr_rootfinder")]
599605
fn transform(x: f64) -> f64 {
600-
2.0/(x*PI/2.).tan().powi(2)
601-
}
602-
603-
#[cfg(feature = "cpr_rootfinder")]
604-
fn inverse_transform(x: f64) -> f64 {
605-
2./PI*((2.0/x).sqrt()).atan()
606+
L/(x*PI/2.).tan().powi(2)
606607
}
607608

608609
#[cfg(feature = "cpr_rootfinder")]
@@ -638,7 +639,7 @@ pub fn cpr_rootfinder(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact_parame
638639
interactions::distance_of_closest_approach_function_singularity_free(transform(r)*a, a, Za, Zb, relative_energy, impact_parameter, interaction_potential)*
639640
interactions::scaling_function(transform(r)*a, a, interaction_potential)
640641
};
641-
642+
642643
let lower_bound = CPR_ROOTFINDER_LOWER_BOUND;
643644
let upper_bound = 1.0_f64;
644645

@@ -658,7 +659,10 @@ pub fn cpr_rootfinder(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact_parame
658659

659660
// Since above the arg to doca is transform(r)*a, this is already scaled as output
660661
//let max_root = roots.iter().map(|&x| transform(x)).fold(f64::NAN, f64::max);
661-
let max_root = roots.iter().map(|&x| transform(x)).max_by(f64::total_cmp).expect("Numerical error: failed to find maximum root.");
662+
let max_root = roots.iter()
663+
.map(|&x| transform(x))
664+
.max_by(f64::total_cmp)
665+
.ok_or_else(|| {anyhow!("Numerical error: failed to find maximum root. F(a): {}, F(b): {}", g(lower_bound), g(upper_bound))})?;
662666

663667
if roots.is_empty() || max_root.is_nan() {
664668
return Err(anyhow!("Numerical error: CPR rootfinder failed to find root. x0: {}, F(a): {}, F(b): {};", max_root, g(lower_bound), g(upper_bound)));

0 commit comments

Comments
 (0)