-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_ray_tracing.py
51 lines (40 loc) · 2.17 KB
/
test_ray_tracing.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
from pytest import approx
import numpy as np
def test_parallel():
from rayflare.ray_tracing import rt_structure
from rayflare.textures import regular_pyramids
from rayflare.options import default_options
from solcore import material
from solcore import si
Air = material('Air')()
Si = material('Si')()
GaAs = material('GaAs')()
Ge = material('Ge')()
triangle_surf = regular_pyramids(30)
options = default_options()
options.wavelengths = np.linspace(700, 1700, 5)*1e-9
options.theta_in = 45*np.pi/180
options.nx = 5
options.ny = 5
options.pol = 'p'
options.n_rays = 3000
options.depth_spacing = 1e-6
options.parallel = True
rtstr = rt_structure(textures=[triangle_surf, triangle_surf, triangle_surf, triangle_surf],
materials = [GaAs, Si, Ge],
widths=[si('100um'), si('70um'), si('50um')], incidence=Air, transmission=Air)
result_new = rtstr.calculate(options)
rtstr = rt_structure(textures=[triangle_surf, triangle_surf, triangle_surf, triangle_surf],
materials = [GaAs, Si, Ge],
widths=[si('100um'), si('70um'), si('50um')], incidence=Air, transmission=Air)
result_old = rtstr.calculate(options)
assert sorted(list(result_old.keys())) == sorted(list(result_new.keys()))
rel_error = 0.3 # Monte Carlo (random) simulations so will never be exactly equal)
assert result_new['R'] == approx(result_old['R'], rel=rel_error)
assert result_new['R0'] == approx(result_old['R0'], rel=rel_error)
assert result_new['A_per_layer'] == approx(result_old['A_per_layer'], rel=rel_error)
assert result_new['profile'] == approx(result_old['profile'], rel=rel_error)
assert np.nanmean(result_new['thetas'], 1) == approx(np.nanmean(result_old['thetas'], 1), rel=rel_error)
# assert np.nanmean(result_new['phis'], 1) == approx(np.nanmean(result_old['phis'], 1), rel=rel_error)
assert np.nanmean(result_new['n_interactions'], 1) == approx(np.nanmean(result_old['n_interactions'], 1), rel=rel_error)
assert np.nanmean(result_new['n_passes'], 1) == approx(np.nanmean(result_old['n_passes'], 1), rel=rel_error)