-
Notifications
You must be signed in to change notification settings - Fork 187
/
add_termination.py
58 lines (46 loc) · 1.73 KB
/
add_termination.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
from __future__ import annotations
from functools import partial
import gdsfactory as gf
from gdsfactory.component import Component
from gdsfactory.components.taper import taper as taper_function
from gdsfactory.port import Port
from gdsfactory.typings import ComponentSpec
terminator_function = partial(taper_function, width2=0.1)
@gf.cell_with_child
def add_termination(
component: Component,
ports: list[Port] | None = None,
terminator: ComponentSpec = terminator_function,
port_name: str | None = None,
port_type: str = "optical",
**kwargs,
) -> Component:
"""Returns component with terminator on some ports.
Args:
component: to add terminator.
ports: optional list of ports to terminate (defaults to all).
terminator: factory for the terminator.
port_name: for the terminator to connect to the component ports.
port_type: of the ports that you want to terminate.
kwargs: for the ports you want to terminate (orientation, width).
"""
terminator = gf.get_component(terminator)
port_name = port_name or terminator.get_ports_list()[0].name
c = Component()
c.add_ref(component)
c.component = component
ports_all = component.get_ports_list()
ports = ports or component.get_ports_list(port_type=port_type, **kwargs)
for port in ports_all:
if port in ports:
t_ref = c.add_ref(terminator)
t_ref.connect(port_name, port)
else:
c.add_port(port.name, port=port)
c.copy_child_info(component)
return c
if __name__ == "__main__":
c = gf.components.straight(length=50)
cc = add_termination(component=c)
# cc = add_termination(component=c, orientation=0)
cc.show(show_ports=True)