Skip to content

Commit 5ff8957

Browse files
authored
Merge pull request #205 from lcpp-org/dev
Update RustBCA to 2.0.0: Improvements to Python bindings, code cleanup, simplify Mesh2D input, update examples
2 parents 204e1c0 + 6722cf6 commit 5ff8957

17 files changed

+1027
-595
lines changed

.github/workflows/rustbca_compile_check.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
python3 -m pip install setuptools_rust testresources setuptools wheel
4545
python3 -m pip install --upgrade pip setuptools wheel
4646
python3 -m pip install .
47-
python3 -c "from libRustBCA.pybca import *;"
47+
python3 -c "from libRustBCA import *;"
4848
python3 examples/test_rustbca.py
4949
- name: Test Fortran and C bindings
5050
run : |
@@ -65,9 +65,9 @@ jobs:
6565
./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml
6666
./target/release/RustBCA 1D examples/layered_geometry_1D.toml
6767
cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output
68-
./target/release/RustBCA examples/boron_nitride.toml
6968
./target/release/RustBCA examples/layered_geometry.toml
7069
cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output
7170
./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml
7271
cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml
72+
./target/release/RustBCA examples/boron_nitride_wire.toml
7373

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "RustBCA"
3-
version = "1.3.0"
3+
version = "2.0.0"
44
default-run = "RustBCA"
55
authors = ["Jon Drobny <[email protected]>", "Jon Drobny <[email protected]>"]
66
edition = "2018"
@@ -12,7 +12,7 @@ path = "src/main.rs"
1212
[lib]
1313
name = "libRustBCA"
1414
path = "src/lib.rs"
15-
crate-type = ["cdylib"]
15+
crate-type = ["cdylib", "lib"]
1616

1717
[dependencies]
1818
rand = "0.8.3"
@@ -30,7 +30,7 @@ netlib-src = {version = "0.8", optional = true}
3030
intel-mkl-src = {version = "0.6.0", optional = true}
3131
rcpr = { git = "https://github.com/drobnyjt/rcpr", optional = true}
3232
ndarray = {version = "0.14.0", features = ["serde"], optional = true}
33-
parry3d-f64 = {version = "0.2.0", optional = true}
33+
parry3d-f64 = {optional = true, version="0.2.0"}
3434
egui = {version = "0.15.0", optional = true}
3535

3636
[dependencies.pyo3]

README.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and Fortran.
1010
By discretizing the collision cascade into a sequence of binary collisions,
1111
[BCA] codes can accurately and efficiently model the prompt interaction
1212
between an energetic ion and a target material. This includes reflection,
13-
implantation, and transmission of the incident ion, s well as sputtering
13+
implantation, and transmission of the incident ion, as well as sputtering
1414
and displacement damage of the target. Generally, [BCA] codes can be
1515
valid for incident ion energies between approximately ~1 eV/nucleon
1616
to <1 GeV/nucleon.
@@ -23,16 +23,17 @@ Journal of Open Source Software by clicking the badge below:
2323

2424
## Getting started
2525

26-
The easiest way to get started is with the ergonomic Python functions currently on the development branch. Follow these steps to install, build, and run simple RustBCA simulations for sputtering yields and reflection coefficients:
26+
The easiest way to get started is with the ergonomic Python functions.
27+
Follow these steps to install, build, and run simple RustBCA simulations
28+
for sputtering yields and reflection coefficients:
2729
```
2830
git clone https://github.com/lcpp-org/rustbca
2931
cd rustbca
30-
git checkout dev
3132
python -m pip install .
3233
python
3334
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
3435
Type "help", "copyright", "credits" or "license" for more information.
35-
>>> from libRustBCA.pybca import *; from scripts.materials import *
36+
>>> from libRustBCA import *; from scripts.materials import *
3637
>>> angle = 0.0 # deg
3738
>>> energy = 1000.0 # eV
3839
>>> num_samples = 10000
@@ -44,7 +45,8 @@ Type "help", "copyright", "credits" or "license" for more information.
4445
```
4546

4647
For those eager to get started with the standalone code, try running one of the examples in the
47-
`RustBCA/examples` directory. Note that to automatically manipulate input files and reproduce the plots located on the [Wiki], these require several optional, but common,
48+
`RustBCA/examples` directory. Note that to automatically manipulate input files and reproduce
49+
the plots located on the [Wiki], these require several optional, but common,
4850
[Python] packages (`matplotlib`, `numpy`, `scipy`, `shapely`, and `toml`).
4951

5052
### H trajectories and collision cascades in a boron nitride dust grain
@@ -94,17 +96,17 @@ plt.show()
9496
The following features are implemented in `rustBCA`:
9597

9698
* Ion-material interactions for all combinations of incident ion and target species.
97-
* Infinite, homogeneous targets (Mesh0D), Layered, finite-depth inhomogeneous targets (Mesh1D), arbitrary 2D geometry composition through a triangular mesh (Mesh2D), homogeneous spherical geometry (Sphere) and homogeneous, arbitrary triangular mesh geometry (TriMesh).
99+
* Infinite, homogeneous targets (Mesh0D), Layered, finite-depth inhomogeneous targets (Mesh1D), arbitrary 2D composition through a triangular mesh (Mesh2D), homogeneous spherical geometry (Sphere) and homogeneous 3D triangular mesh geometry (TriMesh).
98100
* Amorphous Solid/Liquid targets, Gaseous targets, and targets with both solid/liquid and gaseous elements
99101
* Low energy (< 25 keV/nucleon) electronic stopping modes including:
100102
* local (Oen-Robinson),
101103
* nonlocal (Lindhard-Scharff),
102-
* and equipartition forms.
104+
* and equipartition
103105
* Biersack-Varelas interpolation is also included for electronic stopping up to ~1 GeV/nucleon. Note that high energy physics beyond electronic stopping are not included.
104106
* Optionally, the Biersack-Haggmark treatment of high-energy free-flight paths between collisions can be included to greatly speed up high-energy simulations (i.e., by neglecting very small angle scattering).
105107
* A wide range of interaction potentials are provided, including:
106108
* the Kr-C, ZBL, Lenz-Jensen, and Moliere universal, screened-Coulomb potentials.
107-
* the Lennard-Jones 12-6, Lennard-Jones 6.5-6, and Morse attractive-repulsive potentials.
109+
* the Lennard-Jones 12-6 and Morse attractive-repulsive potentials.
108110
* Solving the distance-of-closest-approach problem is achieved using:
109111
* the Newton-Raphson method for simple root-finding,
110112
* or, for attractive-repulsive potentials, an Adaptive Chebyshev Proxy Rootfinder with Automatic Subdivision algorithm and a Polynomial root-finding algorithm are provided through the [rcpr] crate.
@@ -249,7 +251,7 @@ automatically during the build.
249251

250252
## Usage
251253

252-
To use `RustBCA`, modify the `input.toml` file, which is used to configure each
254+
To use `RustBCA`, modify an `input.toml` file, which is used to configure each
253255
simulation.
254256
To run a simulation, execute:
255257

@@ -279,4 +281,4 @@ Also have a look at the examples on the [Wiki] for writing `.toml` input files.
279281
[rustup]: https://rustup.rs
280282
[Rust]: https://en.wikipedia.org/wiki/Rust_(programming_language)
281283
[TOML]: https://en.wikipedia.org/wiki/TOML
282-
[Wiki]: https://github.com/lcpp-org/RustBCA/wiki
284+
[Wiki]: https://github.com/lcpp-org/RustBCA/wiki

examples/benchmark_eam.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from libRustBCA import *
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import sys
5+
import os
6+
#This should allow the script to find materials and formulas from anywhere
7+
sys.path.append(os.path.dirname(__file__)+'/../scripts')
8+
sys.path.append('scripts')
9+
from materials import *
10+
from formulas import *
11+
12+
#Data digitized from Fig. 1 of https://doi.org/10.1016/0022-3115(84)90433-1
13+
#Modeled reflection coefficients using EAM at 100 eV and below and experimentally at 100 eV and above
14+
#Used to show that TRIM breaks down at higher incident energies
15+
data = np.array(
16+
[[0.2962771, 0.18217821],
17+
[0.96344626, 0.4871287],
18+
[3.0372448, 0.8930693],
19+
[9.876638, 0.86534655],
20+
[30.184526, 0.7841584],
21+
[96.644066, 0.6217822], #note: this is the last EAM data point
22+
[102.83226, 0.4950495], #note: this is the first experimental data point
23+
[203.52855, 0.37623763],
24+
[516.34265, 0.3980198],
25+
[809.75903, 0.32277226],
26+
[1006.2257, 0.2990099],
27+
[2054.3218, 0.17821783],
28+
[4129.5522, 0.13069306],
29+
[6890.884, 0.0990099]]
30+
)
31+
32+
#Setting the cutoff low is necessary since the incident energies are also low.
33+
hydrogen['Ec'] = 0.001
34+
35+
#Plotting the EAM data points.
36+
energies = data[:6, 0]
37+
r_benchmark = data[:6, 1]
38+
plt.semilogx(energies, r_benchmark, marker='o', linestyle='', label='EAM')
39+
40+
#Plotting the experimental data points.
41+
energies = data[6:, 0]
42+
r_benchmark = data[6:, 1]
43+
plt.semilogx(energies, r_benchmark, marker='^', linestyle='', label='Exp.')
44+
45+
#Plotting RustBCA data points, using the ergonomic helper function reflection_coefficient().
46+
energies = np.logspace(-1, 4, 25)
47+
r_rustbca = [reflection_coefficient(hydrogen, nickel, energy, 0.0, 1000)[0] for energy in energies]
48+
plt.semilogx(energies, r_rustbca, label='RustBCA', color='black')
49+
50+
r_thomas = [thomas_reflection(hydrogen, nickel, energy) for energy in energies]
51+
plt.semilogx(energies, r_thomas, label='Thomas', color='red', linestyle='--')
52+
53+
plt.title('Reflection Coefficients of Normal Incidence H on Ni')
54+
plt.xlabel('E [eV]')
55+
plt.ylabel('R')
56+
plt.gca().set_ylim([0.0, 1.0])
57+
plt.legend(loc='upper right')
58+
59+
plt.show()
60+

examples/benchmark_nnp.py

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
from libRustBCA import *
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import sys
5+
import os
6+
#This should allow the script to find materials and formulas from anywhere
7+
sys.path.append(os.path.dirname(__file__)+'/../scripts')
8+
sys.path.append('scripts')
9+
from materials import *
10+
from formulas import *
11+
12+
R_T_Be = np.array(
13+
[
14+
[9.67742, 0.016754618],
15+
[20.32258, 0.09511873],
16+
[30.0, 0.13153034],
17+
[49.677418, 0.102242745],
18+
[74.83871, 0.08403694],
19+
[100.32258, 0.031002639],
20+
]
21+
)
22+
23+
R_D_Be = np.array(
24+
[
25+
[10.32258, 0.11649077],
26+
[20.32258, 0.19168866],
27+
[30.32258, 0.19722955],
28+
[49.677418, 0.17269129],
29+
[75.16129, 0.11174142],
30+
[100.0, 0.044459105],
31+
]
32+
)
33+
34+
R_H_Be = np.array(
35+
[
36+
[9.67742, 0.19485489],
37+
[19.67742, 0.32150397],
38+
[30.0, 0.33575198],
39+
[50.322582, 0.25105542],
40+
[75.16129, 0.1378628],
41+
[100.645164, 0.044459105],
42+
]
43+
)
44+
45+
#Plotting the MD data points.
46+
energies = R_H_Be[:, 0]
47+
R = R_H_Be[:, 1]
48+
plt.plot(energies, R, marker='o', linestyle='', label='H on Be MD+NNP')
49+
50+
#Plotting the MD data points.
51+
energies = R_D_Be[:, 0]
52+
R = R_D_Be[:, 1]
53+
plt.plot(energies, R, marker='x', linestyle='', label='D on Be MD+NNP')
54+
55+
#Plotting the MD data points.
56+
energies = R_T_Be[:, 0]
57+
R = R_T_Be[:, 1]
58+
plt.plot(energies, R, marker='^', linestyle='', label='T on Be MD+NNP')
59+
60+
61+
for ion in [hydrogen, deuterium, tritium]:
62+
energies = np.logspace(1, 2, 25)
63+
r_rustbca = [reflection_coefficient(ion, beryllium, energy, 0.0, 10000)[0] for energy in energies]
64+
r_thomas = [thomas_reflection(ion, beryllium, energy) for energy in energies]
65+
line = plt.plot(energies, r_rustbca, label=f'{ion["symbol"]} on Be RustBCA')[0]
66+
plt.plot(energies, r_thomas, label=f'{ion["symbol"]} on Be Thomas', linestyle='--', color=line.get_color())
67+
68+
plt.xlabel('E [eV]')
69+
plt.ylabel('R_N')
70+
plt.title('Reflection Coefficients')
71+
plt.legend()
72+
plt.savefig('reflection_md_nnp_rustbca.png')
73+
74+
#Data digitized from https://doi.org/10.1088/1741-4326/ac592a
75+
#MD+NNP Sputtering Yields
76+
y_H_Be = np.array([
77+
[20.004726, 0.0029361406],
78+
[29.880848, 0.013341782],
79+
[49.791046, 0.024575423],
80+
[75.00529, 0.016207783],
81+
[99.68844, 0.017530797],
82+
])
83+
84+
y_D_Be = np.array([
85+
[19.9699, 0.005002439],
86+
[29.601622, 0.021064475],
87+
[49.76866, 0.03461476],
88+
[74.71549, 0.030082114],
89+
[99.954605, 0.013559438],
90+
])
91+
92+
y_T_Be = np.array([
93+
[20.013433, 0.0025699555],
94+
[29.85846, 0.01879205],
95+
[49.756844, 0.04147379],
96+
[74.707405, 0.034042966],
97+
[99.68098, 0.01965117],
98+
])
99+
100+
101+
plt.figure()
102+
103+
#Plotting the MD data points.
104+
energies = y_H_Be[:, 0]
105+
y = y_H_Be[:, 1]
106+
plt.semilogy(energies, y, marker='o', linestyle='', label='H on Be MD+NNP')
107+
108+
#Plotting the MD data points.
109+
energies = y_D_Be[:, 0]
110+
y = y_D_Be[:, 1]
111+
plt.semilogy(energies, y, marker='x', linestyle='', label='D on Be MD+NNP')
112+
113+
#Plotting the MD data points.
114+
energies = y_T_Be[:, 0]
115+
y = y_T_Be[:, 1]
116+
plt.semilogy(energies, y, marker='^', linestyle='', label='T on Be MD+NNP')
117+
118+
for ion in [hydrogen, deuterium, tritium]:
119+
energies = np.logspace(1, 2, 25)
120+
y_rustbca = [sputtering_yield(ion, beryllium, energy, 0.0, 100000) for energy in energies]
121+
plt.semilogy(energies, y_rustbca, label=f'{ion["symbol"]} on Be RustBCA')
122+
123+
yamamura_yield = [yamamura(hydrogen, beryllium, energy) for energy in energies]
124+
plt.semilogy(energies, yamamura_yield, label='Yamamura H on Be', linestyle='--')
125+
126+
plt.title('Sputtering Yields of Hydrogenic Species on Be')
127+
plt.xlabel('E [eV]')
128+
plt.ylabel('Y [at/ion]')
129+
plt.gca().set_ylim([1e-4, 1e-1])
130+
plt.legend(loc='lower right')
131+
132+
plt.savefig('sputtering_md_nnp_rustbca.png')

0 commit comments

Comments
 (0)