Skip to content

Commit 1db6143

Browse files
committed
Added LUTs for LS stopping, BV mean ionization pot. Seems to gain another ~5-10% speedup...
1 parent c277a71 commit 1db6143

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

‎src/material.rs‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ impl <T: Geometry> Material<T> {
301301
}
302302

303303
const Z_MAX: usize = 120;
304+
// Generating lookup tables for all possibilities turns out to be faster than calculating on the fly
304305
static LS_STOPPING_CONSTANT_TABLE: LazyLock<[f64; Z_MAX*Z_MAX]> = LazyLock::new(
305306
||
306307
std::array::from_fn(
@@ -320,26 +321,35 @@ pub fn lindhard_scharff_stopping_power_cross_section(Za: f64, Zb: f64, E: f64, M
320321
LS_STOPPING_CONSTANT_TABLE[Za as usize * Z_MAX + Zb as usize]*(E/Ma).sqrt()
321322
}
322323

324+
static BV_EMPIRICAL_MEAN_IONIZATON_POT: LazyLock<[f64; Z_MAX]> = LazyLock::new(
325+
||
326+
std::array::from_fn(
327+
|Zb| {
328+
let I0 = if (Zb as f64) < 13. {
329+
12. + 7./ Zb as f64
330+
} else {
331+
9.76 + 58.5*(Zb as f64).powf(-1.19)
332+
};
333+
(Zb as f64)*I0*Q
334+
}
335+
)
336+
);
337+
323338
pub fn bethe_bloch_stopping_power_cross_section(Za: f64, Zb: f64, E: f64, Ma: f64) -> f64 {
324339
let beta = (1. - 1./(1. + E/Ma/C.powi(2)).powi(2)).sqrt();
325340
let v = beta*C;
326341

327-
// This term is an empirical fit to the mean ionization potential
328-
let I0 = match Zb < 13. {
329-
true => 12. + 7./Zb,
330-
false => 9.76 + 58.5*Zb.powf(-1.19),
331-
};
332-
let I = Zb*I0*Q;
342+
let I = BV_EMPIRICAL_MEAN_IONIZATON_POT[Zb as usize];
333343

334344
//See Biersack and Haggmark - this looks like an empirical shell correction
335-
let B = match Zb < 3. {
336-
true => 100.*Za/Zb,
337-
false => 5.
345+
let B = if Zb < 3. {
346+
100.*Za/Zb
347+
} else {
348+
5.
338349
};
339350

340351
let prefactor = BETHE_BLOCH_PREFACTOR*Zb*Za*Za/beta/beta;
341352
let eb = 2.*ME*v*v/I;
342-
343353
prefactor*(eb + 1. + B/eb).ln()
344354
}
345355

0 commit comments

Comments
 (0)