Skip to content

Commit 079c8a2

Browse files
authored
Merge pull request #301 from lcpp-org/add_example
Add compound_bca_list_1d_py example.
2 parents e01474c + b82d0a0 commit 079c8a2

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
from libRustBCA import *
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import sys, os
5+
sys.path.append(os.path.dirname(__file__)+'/../scripts')
6+
sys.path.append('scripts')
7+
from materials import *
8+
from formulas import *
9+
10+
11+
'''
12+
This script is intended to serve as an example of using the Python
13+
interface for a multi-layer, multi-species simulation.
14+
15+
In this simulation, 50 He and 50 H ions are incident on a target
16+
of two layers, one titanium boride and one aluminum:
17+
18+
_____________
19+
| |
20+
| TiB2 | dx = 100 A
21+
_____________
22+
| |
23+
| Al | dx = 1 um
24+
| |
25+
26+
'''
27+
number_ions = 10000
28+
angle = 45.0 # angles in BCA codes are typically measured from the surface normal.
29+
energy = 1000.0 # eV
30+
31+
ux = [np.cos(angle*np.pi/180.0)]*number_ions
32+
uy = [np.sin(angle*np.pi/180.0)]*number_ions
33+
uz = [0.0]*number_ions
34+
35+
energies = [energy]*number_ions
36+
ion1 = hydrogen
37+
ion2 = helium
38+
39+
# Ion properties are per-ion; so we have a list of number_ions/2 of each:
40+
Z1 = [ion1["Z"]]*(number_ions//2) + [ion2["Z"]]*(number_ions//2)
41+
m1 = [ion1["m"]]*(number_ions//2) + [ion2["m"]]*(number_ions//2)
42+
Ec1 = [ion1["Ec"]]*(number_ions//2) + [ion2["Ec"]]*(number_ions//2)
43+
Es1 = [ion1["Es"]]*(number_ions//2) + [ion2["Es"]]*(number_ions//2)
44+
45+
# Material properties are per species; so we have a list of 3 species:
46+
Z2 = [titanium["Z"], boron["Z"], aluminum["Z"]]
47+
m2 = [titanium["m"], boron["m"], aluminum["m"]]
48+
Ec2 = [titanium["Ec"], boron["Ec"], aluminum["Ec"]]
49+
Es2 = [titanium["Es"], boron["Es"], aluminum["Es"]]
50+
Eb2 = [titanium["Eb"], boron["Eb"], aluminum["Eb"]]
51+
52+
# Densities (n2) are specified as a list of layers,
53+
# each of which has a list of the densities per-species:
54+
55+
#top layer, titanium diboride:
56+
# n_i calculated from ni = rho_TiB2 / (m_Ti + 2 * m_B)
57+
ni = 3.8e28 # 1/m3
58+
59+
nTi1 = ni/10**30 # 1/A^3
60+
nB1 = 2 * ni/10**30 # 1/A^3
61+
nAl1 = 0.0
62+
63+
# bottom layer, pure aluminum:
64+
nTi2 = 0.0
65+
nB2 = 0.0
66+
nAl2 = aluminum["n"]/10**30 # 1/A^3
67+
68+
n2 = [
69+
[nTi1, nB1, nAl1], # top layer
70+
[nTi2, nB2, nAl2] # bottom layer
71+
]
72+
73+
dx = [
74+
100.0, # Angstrom, top layer
75+
1.0*1e-6/1e-10 # Angstrom; bottom layer
76+
]
77+
78+
# compound_bca_list_py provides three return values
79+
output, incident, stopped = compound_bca_list_1D_py(
80+
ux,
81+
uy,
82+
uz,
83+
energies,
84+
Z1,
85+
m1,
86+
Ec1,
87+
Es1,
88+
Z2,
89+
m2,
90+
Ec2,
91+
Es2,
92+
Eb2,
93+
n2,
94+
dx
95+
)
96+
97+
# output columns = [Z, m (amu), E (eV), x, y, z, (angstrom), ux, uy, uz]
98+
output = np.array(output)
99+
Z = output[:, 0]
100+
E = output[:, 0]
101+
102+
# implanted ions can be selected using the stopped value
103+
x_He = output[np.logical_and(Z == helium["Z"], stopped), 3]
104+
x_H = output[np.logical_and(Z == hydrogen["Z"], stopped), 3]
105+
106+
num_bins = 50
107+
bins = np.linspace(0.0, 400.0, num_bins)
108+
plt.hist(x_He, bins=bins, histtype='step', label='He')
109+
plt.hist(x_H, bins=bins, histtype='step', label='H')
110+
plt.plot([dx[0], dx[0]], [0.0, number_ions], linestyle='--', color='gray')
111+
plt.ylim([0.0, 375])
112+
plt.xlabel('x [A]')
113+
plt.ylabel('f(x) [counts]')
114+
plt.title('H/He implantation in TiB2 on Al')
115+
plt.legend()
116+
plt.show()

0 commit comments

Comments
 (0)