/
disk.py
372 lines (333 loc) · 13.4 KB
/
disk.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import gdspy
import picwriter.toolkit as tk
class Disk(tk.Component):
""" Disk Resonator Cell class.
Args:
* **wgt** (WaveguideTemplate): WaveguideTemplate object
* **radius** (float): Radius of the disk resonator
* **coupling_gap** (float): Distance between the bus waveguide and resonator
Keyword Args:
* **wrap_angle** (float): Angle in *radians* between 0 and pi (defaults to 0) that determines how much the bus waveguide wraps along the resonator. 0 corresponds to a straight bus waveguide, and pi corresponds to a bus waveguide wrapped around half of the resonator.
* **parity** (1 or -1): If 1, resonator to left of bus waveguide, if -1 resonator to the right
* **port** (tuple): Cartesian coordinate of the input port (x1, y1)
* **direction** (string): Direction that the component will point *towards*, can be of type `'NORTH'`, `'WEST'`, `'SOUTH'`, `'EAST'`, OR an angle (float, in radians)
Members:
* **portlist** (dict): Dictionary with the relevant port information
Portlist format:
* portlist['input'] = {'port': (x1,y1), 'direction': 'dir1'}
* portlist['output'] = {'port': (x2, y2), 'direction': 'dir2'}
Where in the above (x1,y1) is the same as the 'port' input, (x2, y2) is the end of the component, and 'dir1', 'dir2' are of type `'NORTH'`, `'WEST'`, `'SOUTH'`, `'EAST'`, *or* an angle in *radians*.
'Direction' points *towards* the waveguide that will connect to it.
"""
def __init__(
self,
wgt,
radius,
coupling_gap,
wrap_angle=0,
parity=1,
port=(0, 0),
direction="EAST",
):
tk.Component.__init__(self, "Disk", locals())
self.portlist = {}
self.port = port
# self.trace=[port, tk.translate_point(port, 2*radius, direction)]
self.direction = direction
self.radius = radius
self.coupling_gap = coupling_gap
self.wrap_angle = wrap_angle
if (wrap_angle > np.pi) or (wrap_angle < 0):
raise ValueError(
"Warning! Wrap_angle is nor a valid angle between 0 and pi."
)
self.parity = parity
self.resist = wgt.resist
self.wgt = wgt
self.wg_spec = {"layer": wgt.wg_layer, "datatype": wgt.wg_datatype}
self.clad_spec = {"layer": wgt.clad_layer, "datatype": wgt.clad_datatype}
self.__build_cell()
self.__build_ports()
""" Translate & rotate the ports corresponding to this specific component object
"""
self._auto_transform_()
def __build_cell(self):
# Sequentially build all the geometric shapes using gdspy path functions
# for waveguide, then add it to the Cell
if self.wrap_angle == 0:
bus_length = 2 * self.radius
# Add bus waveguide with cladding
path = gdspy.Path(self.wgt.wg_width, (0, 0))
path.segment(2 * self.radius, direction="+x", **self.wg_spec)
clad = gdspy.Path(2 * self.wgt.clad_width + self.wgt.wg_width, (0, 0))
clad.segment(2 * self.radius, direction="+x", **self.clad_spec)
# Disk resonator
if self.parity == 1:
ring = gdspy.Round(
(
self.radius,
self.radius + self.wgt.wg_width / 2.0 + self.coupling_gap,
),
self.radius,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius
),
**self.wg_spec
)
clad_ring = gdspy.Round(
(
self.radius,
self.radius + self.wgt.wg_width / 2.0 + self.coupling_gap,
),
self.radius + self.wgt.clad_width,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius + self.wgt.clad_width
),
**self.clad_spec
)
elif self.parity == -1:
ring = gdspy.Round(
(
self.radius,
-self.radius - self.wgt.wg_width / 2.0 - self.coupling_gap,
),
self.radius,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius
),
**self.wg_spec
)
clad_ring = gdspy.Round(
(
self.radius,
-self.radius - self.wgt.wg_width / 2.0 - self.coupling_gap,
),
self.radius + self.wgt.clad_width,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius + self.wgt.clad_width
),
**self.clad_spec
)
else:
raise ValueError(
"Warning! Parity value is not an acceptable value (must be +1 or -1)."
)
elif self.wrap_angle > 0:
theta = self.wrap_angle / 2.0
rp = self.radius + self.wgt.wg_width / 2.0 + self.coupling_gap
dx, dy = rp * np.sin(theta), rp - rp * np.cos(theta)
bus_length = 2 * self.radius if (4 * dx < 2 * self.radius) else 4 * dx
# Add bus waveguide with cladding that wraps
path = gdspy.Path(self.wgt.wg_width, (0, 0))
clad = gdspy.Path(2 * self.wgt.clad_width + self.wgt.wg_width, (0, 0))
if 4 * dx < bus_length:
path.segment(
(bus_length - 4 * dx) / 2.0, direction="+x", **self.wg_spec
)
clad.segment(
(bus_length - 4 * dx) / 2.0, direction="+x", **self.clad_spec
)
xcenter = self.radius
else:
xcenter = 2 * dx
if self.parity == 1:
path.arc(
rp,
np.pi / 2.0,
np.pi / 2.0 - theta,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.wg_spec
)
path.arc(
rp,
-np.pi / 2.0 - theta,
-np.pi / 2.0 + theta,
number_of_points=2 * self.wgt.get_num_points_curve(2 * theta, rp),
**self.wg_spec
)
path.arc(
rp,
np.pi / 2.0 + theta,
np.pi / 2.0,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.wg_spec
)
clad.arc(
rp,
np.pi / 2.0,
np.pi / 2.0 - theta,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.clad_spec
)
clad.arc(
rp,
-np.pi / 2.0 - theta,
-np.pi / 2.0 + theta,
number_of_points=2 * self.wgt.get_num_points_curve(2 * theta, rp),
**self.clad_spec
)
clad.arc(
rp,
np.pi / 2.0 + theta,
np.pi / 2.0,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.clad_spec
)
# Make the disk resonator
ring = gdspy.Round(
(
xcenter,
self.radius
+ self.wgt.wg_width / 2.0
+ self.coupling_gap
- 2 * dy,
),
self.radius,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius
),
**self.wg_spec
)
clad_ring = gdspy.Round(
(
xcenter,
self.radius
+ self.wgt.wg_width / 2.0
+ self.coupling_gap
- 2 * dy,
),
self.radius + self.wgt.clad_width,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius + self.wgt.clad_width
),
**self.clad_spec
)
elif self.parity == -1:
path.arc(
rp,
-np.pi / 2.0,
-np.pi / 2.0 + theta,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.wg_spec
)
path.arc(
rp,
np.pi / 2.0 + theta,
np.pi / 2.0 - theta,
number_of_points=2 * self.wgt.get_num_points_curve(2 * theta, rp),
**self.wg_spec
)
path.arc(
rp,
-np.pi / 2.0 - theta,
-np.pi / 2.0,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.wg_spec
)
clad.arc(
rp,
-np.pi / 2.0,
-np.pi / 2.0 + theta,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.clad_spec
)
clad.arc(
rp,
np.pi / 2.0 + theta,
np.pi / 2.0 - theta,
number_of_points=2 * self.wgt.get_num_points_curve(2 * theta, rp),
**self.clad_spec
)
clad.arc(
rp,
-np.pi / 2.0 - theta,
-np.pi / 2.0,
number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
**self.clad_spec
)
# Make the disk resonator
ring = gdspy.Round(
(
xcenter,
-self.radius
- self.wgt.wg_width / 2.0
- self.coupling_gap
+ 2 * dy,
),
self.radius,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius
),
**self.wg_spec
)
clad_ring = gdspy.Round(
(
xcenter,
-self.radius
- self.wgt.wg_width / 2.0
- self.coupling_gap
+ 2 * dy,
),
self.radius + self.wgt.clad_width,
number_of_points=self.wgt.get_num_points_curve(
2 * np.pi, self.radius + self.wgt.clad_width
),
**self.clad_spec
)
if 4 * dx < bus_length:
path.segment((bus_length - 4 * dx) / 2.0, **self.wg_spec)
clad.segment((bus_length - 4 * dx) / 2.0, **self.clad_spec)
self.port_input = (0, 0)
self.port_output = (bus_length, 0)
self.add(ring)
self.add(clad_ring)
self.add(path)
self.add(clad)
def __build_ports(self):
# Portlist format:
# example: example: {'port':(x_position, y_position), 'direction': 'NORTH'}
self.portlist["input"] = {"port": self.port_input, "direction": "WEST"}
self.portlist["output"] = {"port": self.port_output, "direction": "EAST"}
if __name__ == "__main__":
from . import *
top = gdspy.Cell("top")
wgt = WaveguideTemplate(bend_radius=50, resist="+")
wg1 = Waveguide([(0, 0), (100, 0)], wgt)
tk.add(top, wg1)
r1 = Disk(
wgt, 60.0, 1.0, wrap_angle=np.pi / 2.0, parity=1, **wg1.portlist["output"]
)
wg2 = Waveguide(
[
r1.portlist["output"]["port"],
(r1.portlist["output"]["port"][0] + 100, r1.portlist["output"]["port"][1]),
],
wgt,
)
tk.add(top, wg2)
r2 = Disk(wgt, 50.0, 0.8, wrap_angle=np.pi, parity=-1, **wg2.portlist["output"])
wg3 = Waveguide(
[
r2.portlist["output"]["port"],
(r2.portlist["output"]["port"][0] + 100, r2.portlist["output"]["port"][1]),
],
wgt,
)
tk.add(top, wg3)
r3 = Disk(wgt, 40.0, 0.6, parity=1, **wg3.portlist["output"])
wg4 = Waveguide(
[
r3.portlist["output"]["port"],
(r3.portlist["output"]["port"][0] + 100, r3.portlist["output"]["port"][1]),
],
wgt,
)
tk.add(top, wg4)
tk.add(top, r1)
tk.add(top, r2)
tk.add(top, r3)
# gdspy.LayoutViewer()
# gdspy.write_gds('disk.gds', unit=1.0e-6, precision=1.0e-9)