From 37d1fafa2d30849b6a4770a29328500b3bdd18a6 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Sun, 29 Nov 2026 07:43:24 -0800 Subject: [PATCH 1/4] Fixed minor bugs; direction update post-refraction, interaction indices for single-element particle params, and weak collision asymptotic path length calculation. --- src/input.rs | 2 +- src/material.rs | 2 ++ src/particle.rs | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/input.rs b/src/input.rs index 9f09883..c4eb3a9 100644 --- a/src/input.rs +++ b/src/input.rs @@ -513,7 +513,7 @@ pub fn process_input_file(input: ::InputFileFormat) "Input error: particle input arrays of unequal length."); if particle_parameters.interaction_index.len() <= 1 { - particle_parameters.interaction_index = vec![0; particle_parameters.Z.len()]; + particle_parameters.interaction_index = vec![particle_parameters.interaction_index[0]; particle_parameters.Z.len()]; } //Check that interaction indices are all within interaction matrices diff --git a/src/material.rs b/src/material.rs index 26610ac..3a93467 100644 --- a/src/material.rs +++ b/src/material.rs @@ -412,7 +412,9 @@ pub fn surface_binding_energy(particle_1: &mut particle::Particle, particle_1.dir.y = -2.*(costheta)*dy/mag + cosy; particle_1.dir.z = -2.*(costheta)*dz/mag + cosz; particle_1.backreflected = true; + } + particle_1.dir_old = particle_1.dir; } } } diff --git a/src/particle.rs b/src/particle.rs index f64f3b2..239c9b4 100644 --- a/src/particle.rs +++ b/src/particle.rs @@ -236,7 +236,11 @@ impl Particle { self.pos_old.z = self.pos.z; //In order to keep average denisty constant, must add back previous asymptotic deflection - let distance_traveled = mfp + self.asymptotic_deflection - asymptotic_deflection; + let distance_traveled = if mfp + self.asymptotic_deflection - asymptotic_deflection > 0. { + mfp + self.asymptotic_deflection - asymptotic_deflection + } else { + 0. + }; //dir has been updated, so use previous direction to advance in space self.pos.x += self.dir_old.x*distance_traveled; From 36cd9de28f341dc4d2c45e085e0791e90c165ce8 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Sun, 29 Nov 2026 08:04:44 -0800 Subject: [PATCH 2/4] Update tests for new values. --- README.md | 2 +- examples/test_rustbca.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f0168c0..1b0c976 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ materials.py is intended to provide example input values only; all input values >>> angle = 0.0 # deg >>> energy = 1000.0 # eV >>> num_samples = 10000 ->>> sputtering_yield(argon, tungsten, energy, angle, num_samples) == 1.0291 +>>> sputtering_yield(argon, tungsten, energy, angle, num_samples) == 1.0447 True >>> R_N, R_E = reflection_coefficient(argon, tungsten, energy, angle, num_samples) >>> R_N == 0.3297 diff --git a/examples/test_rustbca.py b/examples/test_rustbca.py index 6df8d35..78375dc 100644 --- a/examples/test_rustbca.py +++ b/examples/test_rustbca.py @@ -108,7 +108,7 @@ def main(): Y = sputtering_yield(ion, target, energy, angle, num_samples) print(f'Sputtering yield for {ion["symbol"]} on {target["symbol"]} at {energy} eV is {Y} at/ion. Yamamura predicts { np.round(yamamura(ion, target, energy),3)} at/ion.') - np.testing.assert_approx_equal(Y, 0.044) + np.testing.assert_approx_equal(Y, 0.045) R_N, R_E = reflection_coefficient(ion, target, energy, angle, num_samples) print(f'Particle reflection coefficient for {ion["symbol"]} on {target["symbol"]} at {energy} eV is {R_N}. Thomas predicts {np.round(thomas_reflection(ion, target, energy), 3)}.') @@ -132,7 +132,7 @@ def main(): Y = sputtering_yield(ion, target, energy, angle, num_samples) R_N, R_E = reflection_coefficient(ion, target, energy, angle, num_samples) - np.testing.assert_approx_equal(Y, 3.3481) + np.testing.assert_approx_equal(Y, 3.3154) np.testing.assert_approx_equal(R_N, 0.0878) np.testing.assert_approx_equal(R_E, 0.013734709021659743) @@ -140,7 +140,7 @@ def main(): Y = sputtering_yield(ion, target, energy, angle, num_samples) R_N, R_E = reflection_coefficient(ion, target, energy, angle, num_samples) - np.testing.assert_approx_equal(Y, 4.9431) + np.testing.assert_approx_equal(Y, 4.9043) np.testing.assert_approx_equal(R_N, 0.0066) np.testing.assert_approx_equal(R_E, 0.000298720196409247) @@ -273,7 +273,7 @@ def main(): plt.plot([50.0, 50.0], [0.0, np.max(heights)*1.1]) plt.gca().set_ylim([0.0, np.max(heights)*1.1]) - np.testing.assert_approx_equal(np.mean(x), 10.424570485829282) + np.testing.assert_approx_equal(np.mean(x), 9.844300403767717) number_ions = 10000 @@ -343,8 +343,8 @@ def main(): print(f'RustBCA R: {len(reflected[:, 0])/number_ions} Thomas R: {thomas}') print(f'Time per ion: {delta_time/number_ions} s/{ion["symbol"]}') - np.testing.assert_approx_equal(len(sputtered[:, 0])/number_ions, 0.027) - np.testing.assert_approx_equal(len(reflected[:, 0])/number_ions, 0.5155) + np.testing.assert_approx_equal(len(sputtered[:, 0])/number_ions, 0.0269) + np.testing.assert_approx_equal(len(reflected[:, 0])/number_ions, 0.5152) plt.figure() plt.plot(incident_index) From a20243bf3a489965c20b819348041034a363e8a2 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Sun, 29 Nov 2026 10:39:27 -0800 Subject: [PATCH 3/4] updated assertion values. --- examples/test_different_options.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/test_different_options.py b/examples/test_different_options.py index f3ca629..c93ef13 100644 --- a/examples/test_different_options.py +++ b/examples/test_different_options.py @@ -308,17 +308,17 @@ def run_test( sim_times = [] Y_test = np.array([ - 0.02593, 0.02104, 0.02467, 0.02731, 0.02593, 0.0218, 0.02211, 0.02288, - 0.03577, 0.02593, 0.02587, 0.0296, 0.0255, 0.02593, 0.02587, 0.02593, - 0.02905, 0.02593, 0.02593, 0.02593, 0.02593, 0.02593, 0.02593, 0.02593, - 0.02593 + 0.02812, 0.02328, 0.02656, 0.02973, 0.02812, 0.02568, 0.02524, 0.02679, + 0.03886, 0.02812, 0.02817, 0.03208, 0.02825, 0.02812, 0.02815, 0.02812, + 0.03194, 0.02812, 0.02812, 0.02812, 0.02812, 0.02812, 0.02812, 0.02812, + 0.02812 ]) R_N_test = np.array([ - 0.17442, 0.17032, 0.16802, 0.18216, 0.17442, 0.17437, 0.17449, 0.17777, - 0.28801, 0.17442, 0.17452, 0.22074, 0.17506, 0.17442, 0.17445, 0.17442, - 0.17722, 0.17442, 0.17442, 0.17442, 0.17442, 0.17442, 0.17442, 0.17442, - 0.17442 + 0.17688, 0.17252, 0.16998, 0.18417, 0.17688, 0.17672, 0.17642, 0.1799, + 0.29106, 0.17688, 0.17688, 0.2229, 0.17705, 0.17688, 0.17695, 0.17688, + 0.1798, 0.17688, 0.17688, 0.17688, 0.17688, 0.17688, 0.17688, 0.17688, + 0.17688 ]) Y = np.zeros_like(Y_test) From c90de83d7bbbfa78e4cd140c596d3210edf9fe7d Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Mon, 30 Nov 2026 08:31:19 -0800 Subject: [PATCH 4/4] updates --- src/geometry.rs | 2 +- src/interactions.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geometry.rs b/src/geometry.rs index f7f31f9..697ada5 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -198,7 +198,7 @@ impl Geometry for Mesh1D { } } panic!("Geometry error: method inside() is returning true for points outside all layers. Check geometry.") - } else if x < self.top { + } else if x <= self.top { &self.layers[0].densities } else { &self.layers[self.layers.len() - 1].densities diff --git a/src/interactions.rs b/src/interactions.rs index 5ffb125..96c1c9e 100644 --- a/src/interactions.rs +++ b/src/interactions.rs @@ -164,7 +164,7 @@ pub fn scaling_function(r: f64, a: f64, interaction_potential: InteractionPotent 1./(1. + (r/a).powi(2)) }, InteractionPotential::LENNARD_JONES_12_6{sigma, ..} => { - 1./(1. + (r/sigma).powi(11)) + 1./(1. + (r/sigma).powi(12)) }, InteractionPotential::LENNARD_JONES_65_6{sigma, ..} => { 1./(1. + (r/sigma).powi(6))