Skip to content

Commit 20b3269

Browse files
author
Jon Drobny
committed
LUT
1 parent 258dc22 commit 20b3269

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

‎src/bca.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,10 @@ pub fn magic(Za: f64, Zb: f64, Ma: f64, Mb: f64, E0: f64, impact_parameter: f64,
713713
//MAGIC algorithm
714714
//Since this is legacy code I don't think I will clean this up
715715
let C_ = match interaction_potential {
716-
InteractionPotential::MOLIERE => vec![ 0.6743, 0.009611, 0.005175, 6.314, 10.0 ],
717-
InteractionPotential::KR_C => vec![ 0.7887, 0.01166, 0.006913, 17.16, 10.79 ],
718-
InteractionPotential::ZBL => vec![ 0.99229, 0.011615, 0.0071222, 9.3066, 14.813 ],
719-
InteractionPotential::TRIDYN => vec![1.0144, 0.235809, 0.126, 69350., 83550.], //Undocumented Tridyn constants
716+
InteractionPotential::MOLIERE => [ 0.6743, 0.009611, 0.005175, 6.314, 10.0 ],
717+
InteractionPotential::KR_C => [ 0.7887, 0.01166, 0.006913, 17.16, 10.79 ],
718+
InteractionPotential::ZBL => [ 0.99229, 0.011615, 0.0071222, 9.3066, 14.813 ],
719+
InteractionPotential::TRIDYN => [1.0144, 0.235809, 0.126, 69350., 83550.], //Undocumented Tridyn constants
720720
_ => panic!("Input error: unimplemented interaction potential {} for MAGIC algorithm. Use a screened Coulomb potential.", interaction_potential)
721721
};
722722
let a: f64 = interactions::screening_length(Za, Zb, interaction_potential);

‎src/interactions.rs‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use super::*;
22
use std::sync::LazyLock;
33

4+
const Z_MAX: usize = 120;
5+
46
/// Analytic solutions to outermost root of the interaction potential.
57
pub fn crossing_point_doca(interaction_potential: InteractionPotential) -> f64 {
68

@@ -232,14 +234,32 @@ pub fn diff_distance_of_closest_approach_function_singularity_free(r: f64, a: f6
232234
}
233235
}
234236

237+
static COULOMB_CONSTANT_TABLE: LazyLock<[f64; Z_MAX*Z_MAX]> = LazyLock::new(
238+
||
239+
std::array::from_fn(
240+
|i| {
241+
// standard 2D to 1D array indexing
242+
// I always have to look this up; copied from here
243+
// (e.g. https://stackoverflow.com/questions/5494974/convert-1d-array-index-to-2d-array-index)
244+
let Za = i / Z_MAX;
245+
let Zb = i % Z_MAX;
246+
coulomb_constant(Za as f64, Zb as f64)
247+
}
248+
)
249+
);
250+
251+
fn coulomb_constant(Za: f64, Zb: f64) -> f64 {
252+
Za*Zb*Q*Q/4./PI/EPS0
253+
}
254+
235255
/// Screened coulomb interaction potential.
236256
pub fn screened_coulomb(r: f64, a: f64, Za: f64, Zb: f64, interaction_potential: InteractionPotential) -> f64 {
237-
Za*Zb*Q*Q/4./PI/EPS0/r*phi(r/a, interaction_potential)
257+
COULOMB_CONSTANT_TABLE[Za as usize * Z_MAX + Zb as usize]/r*phi(r/a, interaction_potential)
238258
}
239259

240260
/// Coulombic interaction potential.
241261
pub fn coulomb(r: f64, Za: f64, Zb: f64) -> f64 {
242-
Za*Zb*Q*Q/4./PI/EPS0/r
262+
COULOMB_CONSTANT_TABLE[Za as usize * Z_MAX + Zb as usize]/r
243263
}
244264

245265
/// Screening functions for screened-coulomb interaction potentials.
@@ -284,7 +304,6 @@ pub fn screening_length(Za: f64, Zb: f64, interaction_potential: InteractionPote
284304
// It turns out it's faster (~10% speedup) to just generate every possible screening length as a lookup table
285305
// LazyLock is a thread-safe value that is initialized whenever it is first accessed
286306
// It will block other threads while it runs, but it should run extremely quickly and only once
287-
const Z_MAX: usize = 120;
288307
static LINDHARD_SCREENING_LENGTH_TABLE: LazyLock<[f64; Z_MAX*Z_MAX]> = LazyLock::new(
289308
||
290309
std::array::from_fn(
@@ -468,7 +487,7 @@ pub fn tungsten_tungsten_cubic_spline(r: f64) -> f64 {
468487

469488
} else {
470489

471-
let a = vec![
490+
let a = [
472491
-0.1036435865158945,
473492
-0.2912948318493851,
474493
-2.096765499656263,
@@ -480,7 +499,7 @@ pub fn tungsten_tungsten_cubic_spline(r: f64) -> f64 {
480499
14.12806259323987,
481500
];
482501

483-
let delta = vec![
502+
let delta = [
484503
4.268_9,
485504
3.985_68,
486505
3.702_46,

0 commit comments

Comments
 (0)