-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_ideal_cases.py
102 lines (71 loc) · 3.2 KB
/
test_ideal_cases.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
import numpy as np
from pytest import approx
def test_lambertian_scattering():
from rayflare.matrix_formalism.ideal_cases import lambertian_matrix
from rayflare.angles import make_angle_vector
theta_intv, _, angle_vector = make_angle_vector(20, np.pi / 2, 0.25)
mat, _ = lambertian_matrix(angle_vector, theta_intv, "test", "test", "front", False)
R_ind = int(len(angle_vector) / 2)
assert np.sum(mat, 0).todense() == approx(1)
assert np.sum(mat, 1)[R_ind:].todense() == approx(0)
def test_perfect_mirror():
from rayflare.matrix_formalism.ideal_cases import mirror_matrix
from rayflare.angles import make_angle_vector
options = {"phi_symmetry": np.pi / 4}
theta_intv, phi_intv, angle_vector = make_angle_vector(
20, options["phi_symmetry"], 0.25
)
R_ind = int(len(angle_vector) / 2)
mat, _ = mirror_matrix(
angle_vector, theta_intv, phi_intv, "test", options, "test", "front", False
)
assert np.sum(mat, 0).todense() == approx(1)
assert np.sum(mat, 1)[:R_ind].todense() == approx(1)
assert np.sum(mat, 1)[R_ind:].todense() == approx(0)
mat, _ = mirror_matrix(
angle_vector, theta_intv, phi_intv, "test", options, "test", "rear", False
)
assert np.sum(mat, 0).todense() == approx(1)
assert np.sum(mat, 1)[:R_ind].todense() == approx(0)
assert np.sum(mat, 1)[R_ind:].todense() == approx(1)
def test_lambertian_process():
from solcore.structure import Layer
from solcore import material
# rayflare imports
from rayflare.structure import Interface, BulkLayer, Structure
from rayflare.matrix_formalism import process_structure, calculate_RAT
from rayflare.options import default_options
# Thickness of bulk Ge layer
bulkthick = 200e-9
wavelengths = np.linspace(640, 1700, 6) * 1e-9
# set options
options = default_options()
options.wavelengths = wavelengths
options.n_theta_bins = 6
options.c_azimuth = 0.25
options.project_name = "Lambertian"
Al2O3 = material("Al2O3")()
Ge = material("Ge")()
Air = material("Air")()
front_materials = [Layer(100e-9, Al2O3)]
front_surf = Interface("TMM", layers=front_materials, name="TMM", coherent=True)
back_surf = Interface("Lambertian", name="lambert")
back_surf_2 = Interface("Mirror", name="mirror")
bulk_Ge = BulkLayer(bulkthick, Ge, name="Ge_bulk") # bulk thickness in m
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ge)
SC_mirror = Structure(
[front_surf, bulk_Ge, back_surf_2], incidence=Air, transmission=Ge
)
process_structure(SC, options)
process_structure(SC_mirror, options)
RAT = calculate_RAT(SC, options)
RAT_mirror = calculate_RAT(SC_mirror, options)
assert RAT[0]["T"].data == approx(0)
assert RAT_mirror[0]["T"].data == approx(0)
assert np.all(RAT_mirror[0]["A_bulk"][0].data < RAT[0]["A_bulk"][0].data)
# repeat to check if loading works correctly
RAT = calculate_RAT(SC, options)
RAT_mirror = calculate_RAT(SC_mirror, options)
assert RAT[0]["T"].data == approx(0)
assert RAT_mirror[0]["T"].data == approx(0)
assert np.all(RAT_mirror[0]["A_bulk"][0].data < RAT[0]["A_bulk"][0].data)