-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_compute_inventory.py
238 lines (195 loc) · 7.12 KB
/
test_compute_inventory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import time
import pytest
import numpy as np
import divHretention
def test_fecth_inventory_and_error():
"""Checks that fetch_inventory_and_error adds entries to database_inv_sig
and that the execution time is smaller when fetching an already existing
entry
"""
# build
for key in divHretention.database_inv_sig:
# ensuring an empty database
del divHretention.database_inv_sig[key]
# test
test_time = 1e3
start_time = time.time()
inv, sig = divHretention.fetch_inventory_and_error(test_time)
long_time = time.time() - start_time
start_time = time.time()
inv, sig = divHretention.fetch_inventory_and_error(test_time)
short_time = time.time() - start_time
assert test_time in divHretention.database_inv_sig
assert short_time < long_time
def test_compute_inventory():
"""Checks that compute_inventory runs correctly
"""
T = [1000]
c_max = [1e20]
time = 1e3
inv, sig = divHretention.compute_inventory(T, c_max, time)
assert len(inv) == len(sig)
assert len(inv) == len(T)
def test_compute_inventory_float():
"""Checks that compute_inventory raises a TypeError when a float is given
"""
T = 1000
c_max = 1e20
time = 1e3
with pytest.raises(TypeError):
inv, sig = divHretention.compute_inventory(T, c_max, time)
def test_compute_c_max_h():
"""Runs compute_c_max with isotope H and checks that the correct value is
produced
"""
# build
T = np.array([600, 500])
E_ion = np.array([20, 10])
E_atom = np.array([30, 40])
angles_ion = np.array([60, 60])
angles_atom = np.array([60, 60])
ion_flux = np.array([1e21, 1e20])
atom_flux = np.array([2e21, 2e20])
# run
c_max = divHretention.compute_c_max(
T, E_ion, E_atom, angles_ion, angles_atom,
ion_flux, atom_flux, full_export=False, isotope="H")
# test
D_0_W = 1.9e-7
E_D_W = 0.2
k_B = 8.617e-5
D = D_0_W*np.exp(-E_D_W/k_B/T)
# implantation ranges
implantation_range_ions = [
float(divHretention.implantation_range(energy, angle))
for energy, angle in zip(E_ion, angles_ion)]
implantation_range_atoms = [
float(divHretention.implantation_range(energy, angle))
for energy, angle in zip(E_atom, angles_atom)]
# reflection coefficients
reflection_coeff_ions = [
float(divHretention.reflection_coeff(energy, angle))
for energy, angle in zip(E_ion, angles_ion)]
reflection_coeff_atoms = [
float(divHretention.reflection_coeff(energy, angle))
for energy, angle in zip(E_atom, angles_atom)]
reflection_coeff_ions = np.array(reflection_coeff_ions)
reflection_coeff_atoms = np.array(reflection_coeff_atoms)
c_max_ions = (1 - reflection_coeff_ions) * \
ion_flux*implantation_range_ions/D
c_max_atoms = (1 - reflection_coeff_atoms) * \
atom_flux*implantation_range_atoms/D
c_max_expected = c_max_ions + c_max_atoms
assert c_max.all() == c_max_expected.all()
def test_compute_c_max_D():
"""Runs compute_c_max with isotope D and checks that the correct value is
produced
"""
# build
T = np.array([600, 500])
E_ion = np.array([20, 10])
E_atom = np.array([30, 40])
angles_ion = np.array([60, 60])
angles_atom = np.array([60, 60])
ion_flux = np.array([1e21, 1e20])
atom_flux = np.array([2e21, 2e20])
# run
c_max = divHretention.compute_c_max(
T, E_ion, E_atom, angles_ion, angles_atom,
ion_flux, atom_flux, full_export=False, isotope="D")
# test
D_0_W = 1.9e-7
E_D_W = 0.2
k_B = 8.617e-5
D = D_0_W*np.exp(-E_D_W/k_B/T)
D *= 1/2**0.5
# implantation ranges
implantation_range_ions = [
float(divHretention.implantation_range(energy, angle))
for energy, angle in zip(E_ion, angles_ion)]
implantation_range_atoms = [
float(divHretention.implantation_range(energy, angle))
for energy, angle in zip(E_atom, angles_atom)]
# reflection coefficients
reflection_coeff_ions = [
float(divHretention.reflection_coeff(energy, angle))
for energy, angle in zip(E_ion, angles_ion)]
reflection_coeff_atoms = [
float(divHretention.reflection_coeff(energy, angle))
for energy, angle in zip(E_atom, angles_atom)]
reflection_coeff_ions = np.array(reflection_coeff_ions)
reflection_coeff_atoms = np.array(reflection_coeff_atoms)
c_max_ions = (1 - reflection_coeff_ions) * \
ion_flux*implantation_range_ions/D
c_max_atoms = (1 - reflection_coeff_atoms) * \
atom_flux*implantation_range_atoms/D
c_max_expected = c_max_ions + c_max_atoms
assert c_max.all() == c_max_expected.all()
def test_compute_c_max_D():
"""Runs compute_c_max with isotope T and checks that the correct value is
produced
"""
# build
T = np.array([600, 500])
E_ion = np.array([20, 10])
E_atom = np.array([30, 40])
angles_ion = np.array([60, 60])
angles_atom = np.array([60, 60])
ion_flux = np.array([1e21, 1e20])
atom_flux = np.array([2e21, 2e20])
# run
c_max = divHretention.compute_c_max(
T, E_ion, E_atom, angles_ion, angles_atom,
ion_flux, atom_flux, full_export=False, isotope="T")
# test
D_0_W = 1.9e-7
E_D_W = 0.2
k_B = 8.617e-5
D = D_0_W*np.exp(-E_D_W/k_B/T)
D *= 1/3**0.5
# implantation ranges
implantation_range_ions = [
float(divHretention.implantation_range(energy, angle))
for energy, angle in zip(E_ion, angles_ion)]
implantation_range_atoms = [
float(divHretention.implantation_range(energy, angle))
for energy, angle in zip(E_atom, angles_atom)]
# reflection coefficients
reflection_coeff_ions = [
float(divHretention.reflection_coeff(energy, angle))
for energy, angle in zip(E_ion, angles_ion)]
reflection_coeff_atoms = [
float(divHretention.reflection_coeff(energy, angle))
for energy, angle in zip(E_atom, angles_atom)]
reflection_coeff_ions = np.array(reflection_coeff_ions)
reflection_coeff_atoms = np.array(reflection_coeff_atoms)
c_max_ions = (1 - reflection_coeff_ions) * \
ion_flux*implantation_range_ions/D
c_max_atoms = (1 - reflection_coeff_atoms) * \
atom_flux*implantation_range_atoms/D
c_max_expected = c_max_ions + c_max_atoms
assert c_max.all() == c_max_expected.all()
assert c_max.all() == c_max_expected.all()
def test_compute_c_max_output():
"""Runs compute_c_max and checks that the correct output
"""
# build
T = np.array([600, 500])
E_ion = np.array([20, 10])
E_atom = np.array([30, 40])
angles_ion = np.array([60, 60])
angles_atom = np.array([60, 60])
ion_flux = np.array([1e21, 1e20])
atom_flux = np.array([2e21, 2e20])
# run
output = divHretention.compute_c_max(
T, E_ion, E_atom, angles_ion, angles_atom,
ion_flux, atom_flux, full_export=True)
# test
assert len(output) == 3
# run
output = divHretention.compute_c_max(
T, E_ion, E_atom, angles_ion, angles_atom,
ion_flux, atom_flux, full_export=False)
# test
assert len(output) == 2