Skip to content

Commit 52dc705

Browse files
authored
Merge pull request #317 from lcpp-org/electronic_stopping_fixes
Electronic stopping fixes and improvements
2 parents f384630 + 5987950 commit 52dc705

7 files changed

Lines changed: 272 additions & 41 deletions

File tree

‎.github/workflows/rustbca_compile_check.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install HDF5 Libraries
3636
run: |
3737
sudo apt install libhdf5-dev
38-
- name: test Python Bindings
38+
- name: test Python Bindings and run testing scripts
3939
run: |
4040
python3 -m pip install setuptools_rust testresources setuptools wheel
4141
python3 -m pip install --upgrade pip setuptools wheel
@@ -44,6 +44,7 @@ jobs:
4444
python3 examples/test_rustbca.py
4545
python3 examples/test_cube.py
4646
python3 examples/make_input_file_and_run.py
47+
python3 examples/test_electronic_stopping.py
4748
- name: Test Fortran and C bindings
4849
run : |
4950
cargo build --release --lib --features parry3d

‎examples/H_Al_PSTAR.dat‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
1.000E-03 9.238E+01
2+
1.500E-03 1.131E+02
3+
2.000E-03 1.306E+02
4+
2.500E-03 1.461E+02
5+
3.000E-03 1.600E+02
6+
4.000E-03 1.848E+02
7+
5.000E-03 2.066E+02
8+
6.000E-03 2.263E+02
9+
7.000E-03 2.444E+02
10+
8.000E-03 2.613E+02
11+
9.000E-03 2.771E+02
12+
1.000E-02 2.921E+02
13+
1.250E-02 3.206E+02
14+
1.500E-02 3.448E+02
15+
1.750E-02 3.657E+02
16+
2.000E-02 3.838E+02
17+
2.250E-02 3.996E+02
18+
2.500E-02 4.132E+02
19+
2.750E-02 4.250E+02
20+
3.000E-02 4.351E+02
21+
3.500E-02 4.510E+02
22+
4.000E-02 4.620E+02
23+
4.500E-02 4.692E+02
24+
5.000E-02 4.734E+02
25+
5.500E-02 4.752E+02
26+
6.000E-02 4.751E+02
27+
6.500E-02 4.737E+02
28+
7.000E-02 4.712E+02
29+
7.500E-02 4.680E+02
30+
8.000E-02 4.642E+02
31+
8.500E-02 4.601E+02
32+
9.000E-02 4.558E+02
33+
9.500E-02 4.513E+02
34+
1.000E-01 4.468E+02
35+
1.250E-01 4.245E+02
36+
1.500E-01 4.045E+02
37+
1.750E-01 3.867E+02
38+
2.000E-01 3.710E+02
39+
2.250E-01 3.568E+02
40+
2.500E-01 3.440E+02
41+
2.750E-01 3.323E+02
42+
3.000E-01 3.215E+02
43+
3.500E-01 3.017E+02
44+
4.000E-01 2.842E+02
45+
4.500E-01 2.686E+02
46+
5.000E-01 2.548E+02
47+
5.500E-01 2.425E+02
48+
6.000E-01 2.314E+02
49+
6.500E-01 2.215E+02
50+
7.000E-01 2.124E+02
51+
7.500E-01 2.042E+02
52+
8.000E-01 1.966E+02
53+
8.500E-01 1.897E+02
54+
9.000E-01 1.833E+02
55+
9.500E-01 1.774E+02
56+
1.000E+00 1.719E+02
57+
1.250E+00 1.494E+02
58+
1.500E+00 1.327E+02
59+
1.750E+00 1.198E+02
60+
2.000E+00 1.094E+02
61+
2.250E+00 1.009E+02
62+
2.500E+00 9.377E+01
63+
2.750E+00 8.769E+01
64+
3.000E+00 8.245E+01
65+
3.500E+00 7.383E+01
66+
4.000E+00 6.703E+01
67+
4.500E+00 6.151E+01
68+
5.000E+00 5.691E+01
69+
5.500E+00 5.303E+01
70+
6.000E+00 4.970E+01
71+
6.500E+00 4.681E+01
72+
7.000E+00 4.428E+01
73+
7.500E+00 4.203E+01
74+
8.000E+00 4.002E+01
75+
8.500E+00 3.822E+01
76+
9.000E+00 3.658E+01
77+
9.500E+00 3.510E+01
78+
1.000E+01 3.375E+01
79+
1.250E+01 2.841E+01
80+
1.500E+01 2.465E+01
81+
1.750E+01 2.185E+01
82+
2.000E+01 1.968E+01
83+
2.500E+01 1.651E+01
84+
2.750E+01 1.532E+01
85+
3.000E+01 1.430E+01
86+
3.500E+01 1.267E+01
87+
4.000E+01 1.141E+01
88+
4.500E+01 1.041E+01
89+
5.000E+01 9.590E+00
90+
5.500E+01 8.908E+00
91+
6.000E+01 8.330E+00
92+
6.500E+01 7.835E+00
93+
7.000E+01 7.405E+00
94+
7.500E+01 7.029E+00
95+
8.000E+01 6.696E+00
96+
8.500E+01 6.399E+00
97+
9.000E+01 6.133E+00
98+
9.500E+01 5.893E+00
99+
1.000E+02 5.676E+00
100+
1.250E+02 4.835E+00
101+
1.500E+02 4.261E+00
102+
1.750E+02 3.843E+00
103+
2.000E+02 3.525E+00
104+
2.250E+02 3.276E+00
105+
2.500E+02 3.075E+00
106+
2.750E+02 2.910E+00
107+
3.000E+02 2.772E+00
108+
3.500E+02 2.555E+00
109+
4.000E+02 2.392E+00
110+
4.500E+02 2.266E+00
111+
5.000E+02 2.166E+00
112+
5.500E+02 2.086E+00
113+
6.000E+02 2.019E+00
114+
6.500E+02 1.964E+00
115+
7.000E+02 1.918E+00
116+
7.500E+02 1.878E+00
117+
8.000E+02 1.845E+00
118+
8.500E+02 1.816E+00
119+
9.000E+02 1.790E+00
120+
9.500E+02 1.768E+00
121+
1.000E+03 1.749E+00
122+
1.500E+03 1.647E+00
123+
2.000E+03 1.617E+00
124+
2.500E+03 1.613E+00
125+
3.000E+03 1.619E+00
126+
4.000E+03 1.642E+00
127+
5.000E+03 1.668E+00
128+
6.000E+03 1.692E+00
129+
7.000E+03 1.714E+00
130+
8.000E+03 1.734E+00
131+
9.000E+03 1.752E+00
132+
1.000E+04 1.768E+00
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from libRustBCA import electronic_stopping_cross_sections
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
Ma = 1.008
6+
Za = 1.0
7+
Zb = 13.0
8+
n_Al = 6.026e28
9+
ck = 1.4
10+
ci = 0.8171 # found via scipy.optimize minimization of SSE
11+
12+
# load PSTAR data for H on Al
13+
# PSTAR data is in MeV cm^2/g
14+
# to convert to eV/m, multiply by 2.7 [g/cm^3] * 100 [cm/m] * 1E-6 [eV/MeV]
15+
PSTAR = np.genfromtxt('examples/H_Al_PSTAR.dat')
16+
energies = PSTAR[:, 0]*1e6
17+
S_PSTAR = PSTAR[:, 1]*270.*1e6
18+
plt.loglog(energies, S_PSTAR, label='PSTAR')
19+
20+
num_energies = len(energies)
21+
22+
lindhard_scharff = np.zeros(num_energies)
23+
bethe_bloch = np.zeros(num_energies)
24+
biersack_varelas = np.zeros(num_energies)
25+
bv_custom = np.zeros(num_energies)
26+
27+
for index, energy in enumerate(energies):
28+
lindhard_scharff[index], bethe_bloch[index], biersack_varelas[index], bv_custom[index] = electronic_stopping_cross_sections(Za, Zb, energy, Ma, ck, ci)
29+
30+
plt.loglog(energies, lindhard_scharff*n_Al, label=f'Lindhard-Scharff (ck={ck}[Eckstein 1991 Tab. 5.1])')
31+
plt.loglog(energies, bethe_bloch*n_Al, label=f'Bethe-Bloch (ck={ck})')
32+
plt.loglog(energies, biersack_varelas*n_Al, label=f'Biersack-Varelas (ck={ck})')
33+
plt.loglog(energies, bv_custom*n_Al, label=f'Biersack-Varelas (ck={ck}, ci={ci})', linestyle='--')
34+
35+
plt.legend(loc='lower left')
36+
plt.title('Nonlocal Electronic Stopping Modes in RustBCA (H -> Al)')
37+
plt.xlabel('E [eV]')
38+
plt.ylabel('S [eV/m]')
39+
plt.gca().set_ylim([3e8, 1e12])
40+
plt.savefig('electronic_stopping_cross_sections.png')
41+
42+
plt.figure()
43+
index_valid = np.argmax(energies > 1e9)
44+
residual = np.sqrt((biersack_varelas[:index_valid]*n_Al - S_PSTAR[:index_valid])**2)/S_PSTAR[:index_valid]
45+
residual_custom = np.sqrt((bv_custom[:index_valid]*n_Al - S_PSTAR[:index_valid])**2)/S_PSTAR[:index_valid]
46+
# Biersack-Varelas interpolation misses the peak with ~19.9% error, but has ~1% error in LS region and max 3% error in B-B region below 1e8 ev
47+
np.testing.assert_allclose(residual, 0.0, atol=0.2)
48+
49+
50+
plt.loglog(energies[:index_valid], residual, label='Original Biersack-Varelas')
51+
plt.loglog(energies[:index_valid], residual_custom, label=f'BV with custom interp. weight ci={ci}')
52+
plt.title(f'Biersack-Varelas residual against PSTAR (H->Al, ck={ck})')
53+
plt.xlabel('E [eV]')
54+
plt.ylabel('Error in BV vs PSTAR')
55+
plt.legend()
56+
plt.savefig('biersack_varelas_residual.png')
57+
58+
plt.show()

‎src/bca.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ pub fn subtract_electronic_stopping_energy<T: Geometry>(particle_1: &mut particl
454454
let n = material.number_densities(x, y, z);
455455

456456
let delta_energy_electronic = match options.electronic_stopping_mode {
457-
ElectronicStoppingMode::INTERPOLATED => electronic_stopping_powers.iter().zip(n).map(|(se, number_density)| se*number_density).collect::<Vec<f64>>().iter().sum::<f64>()*distance_traveled,
458-
ElectronicStoppingMode::LOW_ENERGY_NONLOCAL => electronic_stopping_powers.iter().zip(n).map(|(se, number_density)| se*number_density).collect::<Vec<f64>>().iter().sum::<f64>()*distance_traveled,
457+
ElectronicStoppingMode::INTERPOLATED | ElectronicStoppingMode::LOW_ENERGY_NONLOCAL | ElectronicStoppingMode::INTERPOLATEDPLUS{..} => electronic_stopping_powers.iter().zip(n).map(|(se, number_density)| se*number_density).collect::<Vec<f64>>().iter().sum::<f64>()*distance_traveled,
458+
//ElectronicStoppingMode::LOW_ENERGY_NONLOCAL => electronic_stopping_powers.iter().zip(n).map(|(se, number_density)| se*number_density).collect::<Vec<f64>>().iter().sum::<f64>()*distance_traveled,
459459
ElectronicStoppingMode::LOW_ENERGY_LOCAL => oen_robinson_loss(particle_1.Z, strong_collision_Z, electronic_stopping_powers[strong_collision_index], x0, interaction_potential),
460460
ElectronicStoppingMode::LOW_ENERGY_EQUIPARTITION => {
461461

‎src/enums.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub enum ElectronicStoppingMode {
4444
LOW_ENERGY_NONLOCAL,
4545
/// Equipartition between Oen-Robinson and Lindhard-Scharff electronic stopping formulas.
4646
LOW_ENERGY_EQUIPARTITION,
47+
/// Biersack-Varelas interpolated electronic stopping with custom interpolation weight. Valid for ~eV/nucleon to ~GeV/nucleon.
48+
INTERPOLATEDPLUS{ci: f64}
4749
}
4850

4951
impl fmt::Display for ElectronicStoppingMode {
@@ -53,6 +55,7 @@ impl fmt::Display for ElectronicStoppingMode {
5355
ElectronicStoppingMode::LOW_ENERGY_NONLOCAL => write!(f, "Lindhard-Scharff electronic stopping"),
5456
ElectronicStoppingMode::LOW_ENERGY_LOCAL => write!(f, "Oen-Robinson electronic stopping"),
5557
ElectronicStoppingMode::LOW_ENERGY_EQUIPARTITION => write!(f, "Equipartition with Lindhard-Scharff and Oen-Robinson"),
58+
ElectronicStoppingMode::INTERPOLATEDPLUS{ci} => write!(f, "Biersack-Varelas interpolation with custom weight ci={}.", ci)
5659
}
5760
}
5861
}

‎src/lib.rs‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub use crate::output::{OutputUnits};
8282
pub use crate::geometry::{Geometry, GeometryElement, Mesh0D, Mesh1D, Mesh2D};
8383
pub use crate::sphere::{Sphere, SphereInput, InputSphere};
8484
pub use crate::math::*;
85+
pub use crate::material::*;
8586

8687
#[cfg(feature = "parry3d")]
8788
pub use crate::parry::{ParryBall, ParryBallInput, InputParryBall, ParryTriMesh, ParryTriMeshInput, InputParryTriMesh};
@@ -100,6 +101,8 @@ pub fn libRustBCA(py: Python, m: &PyModule) -> PyResult<()> {
100101
m.add_function(wrap_pyfunction!(reflection_coefficient, m)?)?;
101102
m.add_function(wrap_pyfunction!(compound_reflection_coefficient, m)?)?;
102103
m.add_function(wrap_pyfunction!(reflect_single_ion_py, m)?)?;
104+
m.add_function(wrap_pyfunction!(electronic_stopping_cross_sections, m)?)?;
105+
m.add_function(wrap_pyfunction!(reflect_single_ion_py, m)?)?;
103106
#[cfg(feature = "parry3d")]
104107
m.add_function(wrap_pyfunction!(rotate_given_surface_normal_py, m)?)?;
105108
#[cfg(feature = "parry3d")]
@@ -828,8 +831,29 @@ pub extern "C" fn simple_bca_c(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64
828831
}
829832
}
830833

834+
#[cfg(feature="python")]
835+
#[pyfunction]
836+
///electronic_stopping_cross_sections(Za, Zb, E, Ma, ck)
837+
/// uses RustBCA internal functions to calculate electronic stopping power cross-sections
838+
/// Args:
839+
/// Za (f64): atomic number of ion
840+
/// Zb (f64): atomic number of target
841+
/// E (f64): ion energy in eV
842+
/// Ma (f64): ion mass in AMU
843+
/// ck (f64): LS correction factor
844+
/// ci (f64): BV custom interp. weight
845+
/// Returns:
846+
/// (Lindhard-Scharff [eV m^2], Bethe-Bloch [eV m^2], Biersack-Varelas [eV m^2], Biersack-Varelas with custom interp. weight [eV m^2])
847+
pub fn electronic_stopping_cross_sections(Za: f64, Zb: f64, E: f64, Ma: f64, ck: f64, ci: f64) -> (f64, f64, f64, f64) {
848+
849+
let S_low = lindhard_scharff_stopping_power_cross_section(Za, Zb, E*EV, Ma*AMU);
850+
let S_high = bethe_bloch_stopping_power_cross_section(Za, Zb, E*EV, Ma*AMU);
851+
852+
(S_low*ck/EV, S_high/EV, 1./(1./(S_high) + 1./(S_low*ck))/EV, (S_high.powf(-ci) + (S_low*ck).powf(-ci)).powf(-1./ci)/EV)
853+
}
854+
831855
#[cfg(feature = "python")]
832-
///compound_\\\\\\_bca_list_py(ux, uy, uz, energy, Z1, m1, Ec1, Es1, Z2, m2, Ec2, Es2, n2, Eb2)
856+
///compound_bca_list_py(ux, uy, uz, energy, Z1, m1, Ec1, Es1, Z2, m2, Ec2, Es2, n2, Eb2)
833857
/// runs a BCA simulation for a list of particles and outputs a list of sputtered, reflected, and implanted particles.
834858
/// Args:
835859
/// energies (list(f64)): initial ion energies in eV.

0 commit comments

Comments
 (0)