@@ -82,14 +82,6 @@ pub fn single_ion_bca<T: Geometry>(particle: particle::Particle, material: &mate
8282 //Choose impact parameters and azimuthal angles for all collisions, and determine mean free path
8383 let binary_collision_geometries = bca:: determine_mfp_phi_impact_parameter ( & mut particle_1, material, options, rng) ;
8484
85- #[ cfg( feature = "accelerated_ions" ) ]
86- let distance_to_target = if !material. inside ( particle_1. pos . x , particle_1. pos . y , particle_1. pos . z ) {
87- let ( x, y, z) = material. geometry . closest_point ( particle_1. pos . x , particle_1. pos . y , particle_1. pos . z ) ;
88- ( ( x - particle_1. pos . x ) . powi ( 2 ) + ( y - particle_1. pos . y ) . powi ( 2 ) + ( z - particle_1. pos . z ) . powi ( 2 ) ) . sqrt ( )
89- } else {
90- 0.
91- } ;
92-
9385 let mut total_energy_lost_to_recoils = 0. ;
9486 let mut total_asymptotic_deflection = 0. ;
9587 let mut normalized_distance_of_closest_approach = 0. ;
@@ -159,7 +151,7 @@ pub fn single_ion_bca<T: Geometry>(particle: particle::Particle, material: &mate
159151
160152 let n = material. total_number_density ( particle_2. pos . x , particle_2. pos . y , particle_2. pos . z ) ;
161153 //We just need the lindhard screening length here, so the particular potential is not important
162- let a: f64 = interactions:: screening_length ( Za , Zb , InteractionPotential :: MOLIERE ) ;
154+ let a: f64 = interactions:: lindhard_screening_length_lookup ( Za as u64 , Zb as u64 ) ;
163155 let reduced_energy: f64 = LINDHARD_REDUCED_ENERGY_PREFACTOR * a* Mb /( Ma +Mb ) /Za /Zb * E ;
164156 let estimated_range_of_recoils = ( reduced_energy. powf ( 0.3 ) + 0.1 ) . powi ( 3 ) /n/a/a;
165157
@@ -181,14 +173,9 @@ pub fn single_ion_bca<T: Geometry>(particle: particle::Particle, material: &mate
181173 }
182174
183175 //Advance particle in space and track total distance traveled
184- #[ cfg( not( feature = "accelerated_ions" ) ) ]
185176 let distance_traveled = particle_1. advance (
186177 binary_collision_geometries[ 0 ] . mfp , total_asymptotic_deflection) ;
187178
188- #[ cfg( feature = "accelerated_ions" ) ]
189- let distance_traveled = particle_1. advance (
190- binary_collision_geometries[ 0 ] . mfp + distance_to_target - material. geometry . get_energy_barrier_thickness ( ) , total_asymptotic_deflection) ;
191-
192179 //Subtract total energy from all simultaneous collisions and electronic stopping
193180 let energy_lost_to_electronic_stopping = bca:: subtract_electronic_stopping_energy ( & mut particle_1, material, distance_traveled,
194181 normalized_distance_of_closest_approach, strong_collision_Z,
@@ -235,7 +222,8 @@ pub fn determine_mfp_phi_impact_parameter<T: Geometry>(particle_1: &mut particle
235222 let E : f64 = particle_1. E ;
236223 let Ec : f64 = particle_1. Ec ;
237224 //We just need the Lindhard screening length here, so the particular potential is not important
238- let a: f64 = interactions:: screening_length ( Za , Zb , InteractionPotential :: MOLIERE ) ;
225+ let a: f64 = interactions:: lindhard_screening_length_lookup ( Za as u64 , Zb as u64 ) ;
226+
239227 let reduced_energy: f64 = LINDHARD_REDUCED_ENERGY_PREFACTOR * a* Mb /( Ma +Mb ) /Za /Zb * E ;
240228
241229 //Minimum energy transfer for generating scattering event set to cutoff energy
@@ -510,8 +498,8 @@ pub fn calculate_binary_collision(particle_1: &particle::Particle, particle_2: &
510498 _ => x0* a* ( theta/2. ) . sin ( )
511499 } ;
512500
513- let psi = theta. sin ( ) . atan2 ( Ma /Mb + theta. cos ( ) ) ; //.abs();
514- let psi_recoil = theta. sin ( ) . atan2 ( 1. - theta. cos ( ) ) ; //.abs();
501+ let psi = theta. sin ( ) . atan2 ( Ma /Mb + theta. cos ( ) ) ;
502+ let psi_recoil = theta. sin ( ) . atan2 ( 1. - theta. cos ( ) ) ;
515503 let recoil_energy = 4. * ( Ma * Mb ) /( Ma + Mb ) . powi ( 2 ) * E0 * ( theta/2. ) . sin ( ) . powi ( 2 ) ;
516504
517505 Ok ( BinaryCollisionResult :: new ( theta, psi, psi_recoil, recoil_energy, asymptotic_deflection, x0) )
@@ -525,7 +513,9 @@ fn scattering_integral_mw(x: f64, beta: f64, reduced_energy: f64, interaction_po
525513}
526514
527515/// Gauss-Legendre scattering integrand.
528- fn scattering_function_gl ( u : f64 , impact_parameter : f64 , r0 : f64 , relative_energy : f64 , interaction_potential : & dyn Fn ( f64 ) -> f64 ) -> Result < f64 , anyhow:: Error > {
516+ fn scattering_function_gl < F > ( u : f64 , impact_parameter : f64 , r0 : f64 , relative_energy : f64 , interaction_potential : F ) -> Result < f64 , anyhow:: Error >
517+ where F : Fn ( f64 ) -> f64
518+ {
529519 let result = 4. * impact_parameter* u/( r0* ( 1. - interaction_potential ( r0/( 1. - u* u) ) /relative_energy - impact_parameter* impact_parameter* ( 1. - u* u) . powi ( 2 ) /r0/r0) . sqrt ( ) ) ;
530520
531521 if result. is_nan ( ) {
@@ -537,7 +527,9 @@ fn scattering_function_gl(u: f64, impact_parameter: f64, r0: f64, relative_energ
537527}
538528
539529/// Gauss-Mehler scattering integrand.
540- fn scattering_function_gm ( u : f64 , impact_parameter : f64 , r0 : f64 , relative_energy : f64 , interaction_potential : & dyn Fn ( f64 ) -> f64 ) -> Result < f64 , anyhow:: Error > {
530+ fn scattering_function_gm < F > ( u : f64 , impact_parameter : f64 , r0 : f64 , relative_energy : f64 , interaction_potential : F ) -> Result < f64 , anyhow:: Error >
531+ where F : Fn ( f64 ) -> f64
532+ {
541533 let result = impact_parameter/r0/( 1. - interaction_potential ( r0/u) /relative_energy - ( impact_parameter* u/r0) . powi ( 2 ) ) . sqrt ( ) ;
542534
543535 if result. is_nan ( ) {
@@ -549,23 +541,27 @@ fn scattering_function_gm(u: f64, impact_parameter: f64, r0: f64, relative_energ
549541}
550542
551543/// Compute the scattering integral for a given relative energy, distance of closest approach `r0`, and interaction potential using a Gauss-Mehler, n-point quadrature.
552- fn scattering_integral_gauss_mehler ( impact_parameter : f64 , relative_energy : f64 , r0 : f64 , interaction_potential : & dyn Fn ( f64 ) -> f64 , n_points : usize ) -> f64 {
544+ fn scattering_integral_gauss_mehler < F > ( impact_parameter : f64 , relative_energy : f64 , r0 : f64 , interaction_potential : F , n_points : usize ) -> f64
545+ where F : Fn ( f64 ) -> f64 + Clone
546+ {
553547 let x: Vec < f64 > = ( 1 ..=n_points) . map ( |i| ( ( 2. * i as f64 - 1. ) /4. /n_points as f64 * PI ) . cos ( ) ) . collect ( ) ;
554548 let w: Vec < f64 > = ( 1 ..=n_points) . map ( |i| PI /n_points as f64 * ( ( 2. * i as f64 - 1. ) /4. /n_points as f64 * PI ) . sin ( ) ) . collect ( ) ;
555549
556550 PI - x. iter ( ) . zip ( w)
557- . map ( |( & x, w) | w* scattering_function_gm ( x, impact_parameter, r0, relative_energy, interaction_potential)
551+ . map ( |( & x, w) | w* scattering_function_gm ( x, impact_parameter, r0, relative_energy, interaction_potential. clone ( ) )
558552 . with_context ( || format ! ( "Numerical error: NaN in Gauss-Mehler scattering integral at x = {} with Er = {} eV and p = {} A." , x, relative_energy/EV , impact_parameter/ANGSTROM ) )
559553 . unwrap ( ) ) . sum :: < f64 > ( )
560554}
561555
562556/// Compute the scattering integral for a given relative energy, distance of closest approach `r0`, and interaction potential using a Gauss-Legendre, 5-point quadrature.
563- fn scattering_integral_gauss_legendre ( impact_parameter : f64 , relative_energy : f64 , r0 : f64 , interaction_potential : & dyn Fn ( f64 ) -> f64 ) -> f64 {
557+ fn scattering_integral_gauss_legendre < F > ( impact_parameter : f64 , relative_energy : f64 , r0 : f64 , interaction_potential : F ) -> f64
558+ where F : Fn ( f64 ) -> f64 + Clone
559+ {
564560 let x: Vec < f64 > = [ 0. , -0.538469 , 0.538469 , -0.90618 , 0.90618 ] . iter ( ) . map ( |x| x/2. + 1. /2. ) . collect ( ) ;
565561 let w: Vec < f64 > = [ 0.568889 , 0.478629 , 0.478629 , 0.236927 , 0.236927 ] . iter ( ) . map ( |w| w/2. ) . collect ( ) ;
566562
567563 PI - x. iter ( ) . zip ( w)
568- . map ( |( & x, w) | w* scattering_function_gl ( x, impact_parameter, r0, relative_energy, interaction_potential)
564+ . map ( |( & x, w) | w* scattering_function_gl ( x, impact_parameter, r0, relative_energy, interaction_potential. clone ( ) )
569565 . with_context ( || format ! ( "Numerical error: NaN in Gauss-Legendre scattering integral at x = {} with Er = {} eV and p = {} A." , x, relative_energy/EV , impact_parameter/ANGSTROM ) )
570566 . unwrap ( ) ) . sum :: < f64 > ( )
571567}
@@ -583,18 +579,6 @@ pub fn polynomial_rootfinder(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact
583579 let coefficients = interactions:: polynomial_coefficients ( relative_energy, impact_parameter, interaction_potential) ;
584580 let roots = real_polynomial_roots ( coefficients. clone ( ) , polynom_complex_threshold) . unwrap ( ) ;
585581
586- /*
587- println!("p={}", impact_parameter/ANGSTROM);
588-
589- for coefficient in &coefficients {
590- println!("{}", {coefficient});
591- }
592-
593- for root in &roots {
594- println!("{} A", {root});
595- }
596- */
597-
598582 let max_root = roots. iter ( ) . cloned ( ) . fold ( f64:: NAN , f64:: max) ;
599583
600584 let inverse_transformed_root = interactions:: inverse_transform ( max_root, interaction_potential) ;
@@ -642,8 +626,6 @@ pub fn cpr_rootfinder(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact_parame
642626 let g = |r : f64 | -> f64 { interactions:: distance_of_closest_approach_function_singularity_free ( r, a, Za , Zb , relative_energy, impact_parameter, interaction_potential) *
643627 interactions:: scaling_function ( r, impact_parameter, interaction_potential) } ;
644628
645- //Using upper bound const, ~10, construct upper bound as a plateau near 0 and linear increase away from that
646- //let upper_bound = f64::max(upper_bound_const*p, upper_bound_const*a);
647629 let upper_bound = impact_parameter + interactions:: crossing_point_doca ( interaction_potential) ;
648630
649631 let roots = match derivative_free {
@@ -683,14 +665,16 @@ pub fn newton_rootfinder(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact_par
683665 let f = |r : f64 | -> f64 { interactions:: distance_of_closest_approach_function ( r, a, Za , Zb , relative_energy, impact_parameter, interaction_potential) } ;
684666 let df = |r : f64 | -> f64 { interactions:: diff_distance_of_closest_approach_function ( r, a, Za , Zb , relative_energy, impact_parameter, interaction_potential) } ;
685667
686- //Guess for large reduced energy from Mendenhall and Weller 1991
687- //For small energies, use pure Newton-Raphson with arbitrary guess of 1
688- let mut x0 = beta;
689668 let mut xn: f64 ;
690- if reduced_energy > 5. {
669+
670+ //Guess for large reduced energy from Mendenhall and Weller 1991
671+ //For small energies, use pure Newton-Raphson with arbitrary guess of beta
672+ let mut x0 = if reduced_energy > 5. {
691673 let inv_er_2 = 0.5 /reduced_energy;
692- x0 = inv_er_2 + ( inv_er_2* inv_er_2 + beta* beta) . sqrt ( ) ;
693- }
674+ inv_er_2 + ( inv_er_2* inv_er_2 + beta* beta) . sqrt ( )
675+ } else {
676+ beta
677+ } ;
694678
695679 //Newton-Raphson to determine distance of closest approach
696680 let mut err: f64 = tolerance + 1. ;
0 commit comments