Skip to content

Commit 34ecb17

Browse files
committed
Trying a static lookup table for Lindhard screening lengths.
1 parent 1ed27e0 commit 34ecb17

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

‎src/interactions.rs‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
use cached::macros::cached;
2+
use std::sync::LazyLock;
33

44
/// Analytic solutions to outermost root of the interaction potential.
55
pub fn crossing_point_doca(interaction_potential: InteractionPotential) -> f64 {
@@ -274,24 +274,39 @@ pub fn screening_length(Za: f64, Zb: f64, interaction_potential: InteractionPote
274274
//ZBL screening length, Eckstein (4.1.8)
275275
InteractionPotential::ZBL => zbl_screening_length(Za as u64, Zb as u64),
276276
//Lindhard/Firsov screening length, Eckstein (4.1.5)
277-
InteractionPotential::MOLIERE | InteractionPotential::KR_C | InteractionPotential::LENZ_JENSEN | InteractionPotential::TRIDYN | InteractionPotential::WW => lindhard_screening_length(Za as u64, Zb as u64),
278-
InteractionPotential::LENNARD_JONES_12_6{..} | InteractionPotential::LENNARD_JONES_65_6{..} => lindhard_screening_length(Za as u64, Zb as u64),
277+
InteractionPotential::MOLIERE | InteractionPotential::KR_C | InteractionPotential::LENZ_JENSEN | InteractionPotential::TRIDYN | InteractionPotential::WW => lindhard_screening_length_lookup(Za as u64, Zb as u64),
278+
InteractionPotential::LENNARD_JONES_12_6{..} | InteractionPotential::LENNARD_JONES_65_6{..} => lindhard_screening_length_lookup(Za as u64, Zb as u64),
279279
InteractionPotential::MORSE{D, alpha, r0} => alpha,
280280
InteractionPotential::COULOMB{Za: Z1, Zb: Z2} => zbl_screening_length(Za as u64, Zb as u64),
281-
InteractionPotential::KRC_MORSE{..} => 0.8853*A0*(Za.sqrt() + Zb.sqrt()).powf(-2./3.),
282-
InteractionPotential::FOUR_EIGHT{..} =>0.8853*A0*(Za.sqrt() + Zb.sqrt()).powf(-2./3.),
281+
InteractionPotential::KRC_MORSE{..} => lindhard_screening_length_lookup(Za as u64, Zb as u64),
282+
InteractionPotential::FOUR_EIGHT{..} => lindhard_screening_length_lookup(Za as u64, Zb as u64),
283283
}
284284
}
285285

286-
#[cached]
287-
fn zbl_screening_length(Za: u64, Zb: u64) -> f64{
286+
const Z_MAX: usize = 120;
287+
static LINDHARD_SCREENING_LENGTH_TABLE: LazyLock<[f64; Z_MAX*Z_MAX]> = LazyLock::new(
288+
||
289+
std::array::from_fn(
290+
|i| {
291+
let Za = i / Z_MAX;
292+
let Zb = i % Z_MAX;
293+
lindhard_screening_length(Za as u64, Zb as u64)
294+
}
295+
)
296+
);
297+
298+
pub fn zbl_screening_length(Za: u64, Zb: u64) -> f64{
288299
0.88534*A0/((Za as f64).powf(0.23) + (Zb as f64).powf(0.23))
289300
}
290-
#[cached]
291-
fn lindhard_screening_length(Za: u64, Zb: u64) -> f64 {
301+
302+
pub fn lindhard_screening_length(Za: u64, Zb: u64) -> f64 {
292303
0.8853*A0*((Za as f64).sqrt() + (Zb as f64).sqrt()).powf(-2./3.)
293304
}
294305

306+
pub fn lindhard_screening_length_lookup(Za: u64, Zb: u64) -> f64 {
307+
LINDHARD_SCREENING_LENGTH_TABLE[Za as usize * Z_MAX + Zb as usize]
308+
}
309+
295310
/// Coefficients of inverse-polynomial interaction potentials.
296311
/// Note: these go in order of decreasing orders of r, e.g., [r^n, r^n-1, r^n-2, ... r, 1].
297312
pub fn polynomial_coefficients(relative_energy: f64, impact_parameter: f64, interaction_potential: InteractionPotential) -> Vec<f64> {

0 commit comments

Comments
 (0)