11use super :: * ;
22use std:: sync:: LazyLock ;
33
4+ const Z_MAX : usize = 120 ;
5+
46/// Analytic solutions to outermost root of the interaction potential.
57pub 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.
236256pub 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.
241261pub 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 ;
288307static 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