PLaSK library
Loading...
Searching...
No Matches
grating.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3
# Copyright (c) 2022 Lodz University of Technology
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, version 3.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
13
14
import
unittest
15
16
from
numpy
import
*
17
18
from
plask
import
*
19
from
plask
import
material, geometry, mesh
20
from
optical.modal
import
Fourier2D
21
22
plask.config.axes
=
'xy'
23
24
ns = 3.48
25
nh = 3.48
26
nl = 1.00
27
L = 1.00
28
tg = 0.20
29
tl = 0.83
30
fill = 0.4
31
N = 12
32
33
34
@material.simple()
35
class
Subs
(
material.Material
):
36
nr = ns
37
38
@material.simple()
39
class
Hi
(
material.Material
):
40
#nr = nh
41
def
nr
(self, lam, temp, conc):
42
return
nh
43
44
@material.simple()
45
class
Lo
(
material.Material
):
46
nr = nl
47
48
49
class
GratingTest
(
unittest.TestCase
):
50
51
def
setUp
(self):
52
self.
stack
=
geometry.Stack2D
()
53
bar =
geometry.Block2D
(fill*L, tg,
'Hi'
); self.
stack
.
prepend
(bar)
54
self.
stack
.
prepend
(
geometry.Block2D
(L, tl,
'Lo'
))
55
geom =
geometry.Cartesian2D
(self.
stack
, bottom=
'Subs'
, left=
'periodic'
, right=
'periodic'
)
56
self.
solver
= Fourier2D(
'solver'
)
57
self.
solver
.geometry = geom
58
self.
solver
.
set_interface
(bar)
59
self.
solver
.size = N
60
self.
solver
.smooth = 0.
61
62
def
testComputations
(self):
63
l_te = array([1500., 1600.])
64
self.
solver
.lam0 = 1500.
65
r_te = self.
solver
.
compute_reflectivity
(l_te,
'top'
,
'El'
)
66
self.assertAlmostEqual(r_te[0], 99.934, 2)
67
self.assertAlmostEqual(r_te[1], 98.886, 2)
68
69
l_tm = array([1298., 1344.])
70
self.
solver
.lam0 = 1300.
71
r_tm = self.
solver
.
compute_reflectivity
(l_tm,
'top'
,
'Et'
)
72
self.assertAlmostEqual(r_tm[0], 98.529, 2)
73
self.assertAlmostEqual(r_tm[1], 28.296, 2)
74
75
def
testIntegrals
(self):
76
self.
solver
.lam = self.
solver
.lam0 = 1500.
77
scattering = self.
solver
.
scattering
(
'top'
,
'El'
)
78
79
box = self.
solver
.
geometry.get_object_bboxes
(self.
stack
)[0]
80
msh =
mesh.Rectangular2D
(
mesh.Regular
(0.,
box.right
, 501),
81
mesh.Regular
(
box.bottom
,
box.top
, 201))
82
dx =
msh.axis0
[1] -
msh.axis0
[0]
83
dy =
msh.axis1
[1] -
msh.axis1
[0]
84
integral_mesh =
msh.elements.mesh
85
86
E =
scattering.outLightE
(integral_mesh).array
87
EE0 = 0.5 *
sum
(real(E*
conj
(E))) * dx * dy
88
EE1 =
scattering.integrateEE
(
box.bottom
,
box.top
)
89
ratio = EE1 / EE0
90
print_log
(
'result'
,
"E ratio:"
, ratio)
91
self.assertAlmostEqual(ratio, 1.0, delta=0.1)
92
93
H =
scattering.outLightH
(integral_mesh).array
94
HH0 = 0.5 *
sum
(real(H*
conj
(H))) * dx * dy
95
HH1 =
scattering.integrateHH
(
box.bottom
,
box.top
)
96
ratio = HH1 / HH0
97
print_log
(
'result'
,
"H ratio:"
, ratio)
98
self.assertAlmostEqual(ratio, 1.00, delta=0.15)
99
100
101
if
__name__ ==
'__main__'
:
102
unittest.main
()
solvers
optical
modal
tests
grating.py
Generated by
1.9.8