Skip to content

Commit f1ded67

Browse files
authored
Merge pull request #294 from lcpp-org/krc_morse_speedup
Replace sigmoid with smootherstep in Kr-C-Morse.
2 parents 5b01319 + 1c3f4ac commit f1ded67

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/interactions.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ pub fn crossing_point_doca(interaction_potential: InteractionPotential) -> f64 {
1212

1313
}
1414

15-
fn sigmoid(x: f64, k: f64, x0: f64) -> f64 {
16-
1./(1. + (-k*(x - x0)).exp())
15+
fn smootherstep(x: f64, k: f64, x0: f64) -> f64 {
16+
let x_transformed = x*k/8.0; //Constant to match sigmoid, determined by eye
17+
let x0_transformed = x0*k/8.0;
18+
19+
if x_transformed <= x0_transformed - 0.5 {
20+
0.
21+
} else if x_transformed >= 0.5 + x0_transformed {
22+
1.
23+
} else {
24+
let x1 = x_transformed - x0_transformed + 0.5;
25+
return x1 * x1 * x1 * (x1 * (6. * x1 - 15.) + 10.);
26+
}
1727
}
1828

1929
/// Interaction potential between two particles a and b at a distance `r`.
@@ -346,9 +356,9 @@ pub fn morse(r: f64, D: f64, alpha: f64, r0: f64) -> f64 {
346356
D*((-2.*alpha*(r - r0)).exp() - 2.*(-alpha*(r - r0)).exp())
347357
}
348358

349-
/// Kr-C + Morse potential with sigmoid interpolation at crossing point of two potentials
359+
/// Kr-C + Morse potential with smootherstep interpolation at crossing point of two potentials
350360
pub fn krc_morse(r: f64, a: f64, Za: f64, Zb: f64, D: f64, alpha: f64, r0: f64, k: f64, x0: f64) -> f64 {
351-
sigmoid(r, k, x0)*morse(r, D, alpha, r0) + sigmoid(r, -k, x0)*screened_coulomb(r, a, Za, Zb, InteractionPotential::KR_C)
361+
smootherstep(r, k, x0)*morse(r, D, alpha, r0) + smootherstep(r, -k, x0)*screened_coulomb(r, a, Za, Zb, InteractionPotential::KR_C)
352362
}
353363

354364
/// Distance of closest approach function for four-eight potential (Born repulsion)

0 commit comments

Comments
 (0)