PLaSK library

Loading...
Searching...
No Matches
bessel.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 sys
15 import unittest
16
17 from numpy import *
18
19 from plask import *
20 from plask import material, geometry, mesh
21
22 from optical.modal import BesselCyl
23 from optical.effective import EffectiveFrequencyCyl
24
25
26@material.simple()
27 class Core(material.Material):
28 Nr = 3.5
29
30
31 class Disk(unittest.TestCase):
32
33 def setUp(self):
34
35 R = 9.
36 N = 7
37
38 self.f = f = 1
39
40 disk = geometry.Rectangle(5./f, 0.5/f, 'Core')
41 side = geometry.Rectangle(R-5./f, 0.5/f, 'air')
42 layer = geometry.Shelf()
43 layer.append(disk)
44 layer.append(side)
45 above = geometry.Rectangle(R/f, 2.0/f, 'air')
46 stack = geometry.Stack2D()
47 stack.prepend(above)
48 stack.prepend(layer)
49 stack.prepend(above)
50 self.geometry = geometry.Cylindrical(stack)
51
52 #self.solver = EffectiveFrequencyCyl('EFM')
53 #self.solver.geometry = self.geometry
54 #self.solver.lam0 = 1500./f
55 #self.solver.vat = 0.
56
57 self.solver = BesselCyl('Bessel')
58 self.solver.geometry = self.geometry
59 self.solver.set_interface(stack)
60 self.solver.size = N
61
62 self.solver.pml.dist = 10./f - R
63 self.solver.pml.size = 2.
64 self.solver.pml.factor = 1.-2.j
65 self.solver.pml.shape = 0
66
67 self.solver.pml.dist = 10./f - R + 2.
68 self.solver.pml.size = 0.
69 self.solver.pml.factor = 1.
70
71 self.solver.lam0 = 1550/f
72
73 #self.solver.domain = 'infinite'
74
75 self.layer = 0
76
77 def plot_geometry(self):
78 plot_geometry(self.geometry, fill=True, margin=0.1)
79
80 def print_integrals(self):
81 try:
82 self.solver.wavelength = 1500/self.f
83 self.solver.m = 1
84 set_printoptions(precision=6, linewidth=180, suppress=True)
85 epsVmm = self.solver.epsVmm(self.layer)
86 print("\nepsVmm =")
87 print(real(epsVmm))
88 print("\nepsVpp =")
89 print(real(self.solver.epsVpp(self.layer)))
90 print("\nepsTmm =")
91 print(real(self.solver.epsTmm(self.layer)))
92 print("\nepsTpp =")
93 print(real(self.solver.epsTpp(self.layer)))
94 print("\nepsTmp =")
95 print(real(self.solver.epsTmp(self.layer)))
96 print("\nepsTpm =")
97 print(real(self.solver.epsTpm(self.layer)))
98 print("\nepsDm =")
99 print(real(self.solver.epsDm(self.layer)))
100 print("\nepsDp =")
101 print(real(self.solver.epsDp(self.layer)))
102 print
103 #print("\nmuVmm =")
104 #print(real(self.solver.muVmm()))
105 #print("\nmuVpp =")
106 #print(real(self.solver.muVpp()))
107 #print("\nmuTmm =")
108 #print(real(self.solver.muTmm()))
109 #print("\nmuTpp =")
110 #print(real(self.solver.muTpp()))
111 #print("\nmuTmp =")
112 #print(real(self.solver.muTmp()))
113 #print("\nmuTpm =")
114 #print(real(self.solver.muTpm()))
115 #print("\nmuDm =")
116 #print(real(self.solver.muDm()))
117 #print("\nmuDp =")
118 #print(real(self.solver.muDp()))
119 #print
120 except AttributeError:
121 import traceback
122 traceback.print_exc()
123
124 def print_matrices(self):
125 try:
126 self.solver.wavelength = 1500/self.f
127 self.solver.m = 1
128 RE, RH = self.solver.get_matrices(self.layer)
129 except AttributeError:
130 pass
131 else:
132 set_printoptions(precision=2, linewidth=240, suppress=True)
133 print("\nRH = ")
134 print(abs(RH))
135 print("\nRE = ")
136 print(abs(RE))
137 print("\nQE = ")
138 print(abs(dot(RH,RE)))
139 print
140
141 def plot_determinant(self):
142 lams = linspace(1000/self.f, 5000/self.f, 700)
143 try:
144 dets = self.solver.get_determinant(lam=lams, m=1, dispersive=False)
145 except TypeError:
146 dets = self.solver.get_determinant(lam=lams)
147 figure()
148 plot(lams, abs(dets))
149 yscale('log')
150
151
152 if __name__ == "__main__":
153
154 try:
155 function = sys.argv[1]
156 except IndexError:
157 function = 'setUp'
158
159 disk = Disk(function)
160 disk.setUp()
161
162 if function != 'setUp':
163 getattr(disk, function)()
164 else:
165 disk.print_integrals()
166 disk.print_matrices()
167 disk.plot_geometry()
168 disk.plot_determinant()
169 #disk.plot_field()
170 show()