Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transition also tapers cladding_layers and cladding offsets #1082

Merged
merged 2 commits into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
113 changes: 64 additions & 49 deletions gdsfactory/path.py
Expand Up @@ -616,57 +616,72 @@ def transition(
)

sections = []
for alias in X1.aliases.keys():
if alias in X2.aliases:
section1 = X1.aliases[alias]
section2 = X2.aliases[alias]

offset1 = section1.offset
offset2 = section2.offset
width1 = section1.width
width2 = section2.width

if callable(offset1):
offset1 = offset1(1)
if callable(offset2):
offset2 = offset2(0)
if callable(width1):
width1 = width1(1)
if callable(width2):
width2 = width2(0)

offset_fun = _sinusoidal_transition(offset1, offset2)

if width_type == "linear":
width_fun = _linear_transition(width1, width2)
elif width_type == "sine":
width_fun = _sinusoidal_transition(width1, width2)
elif width_type == "parabolic":
width_fun = _parabolic_transition(width1, width2)
else:
raise ValueError(
f"width_type={width_type!r} must be {'sine','linear','parabolic'}"
)

if section1.layer != section2.layer:
hidden = True
layer1 = get_layer(section1.layer)
layer2 = get_layer(section2.layer)
layer = (layer1, layer2)
else:
hidden = False
layer = get_layer(section1.layer)

s = Section(
width=width_fun,
offset=offset_fun,
layer=layer,
port_names=(section2.port_names[0], section1.port_names[1]),
port_types=(section2.port_types[0], section1.port_types[1]),
name=alias,
hidden=hidden,
sections1 = [
X1.aliases[alias] for alias in X1.aliases.keys() if alias in X2.aliases
]
sections2 = [
X2.aliases[alias] for alias in X2.aliases.keys() if alias in X1.aliases
]

if X1.cladding_layers:
sections1 += [
Section(width=X1.width + offset, layer=layer)
for offset, layer in zip(X1.cladding_offsets, X2.cladding_layers)
]
if X2.cladding_layers:
sections2 += [
Section(width=X2.width + offset, layer=layer)
for offset, layer in zip(X2.cladding_offsets, X2.cladding_layers)
]

for section1, section2 in zip(sections1, sections2):
offset1 = section1.offset
offset2 = section2.offset
width1 = section1.width
width2 = section2.width

if callable(offset1):
offset1 = offset1(1)
if callable(offset2):
offset2 = offset2(0)
if callable(width1):
width1 = width1(1)
if callable(width2):
width2 = width2(0)

offset_fun = _sinusoidal_transition(offset1, offset2)

if width_type == "linear":
width_fun = _linear_transition(width1, width2)
elif width_type == "sine":
width_fun = _sinusoidal_transition(width1, width2)
elif width_type == "parabolic":
width_fun = _parabolic_transition(width1, width2)
else:
raise ValueError(
f"width_type={width_type!r} must be {'sine','linear','parabolic'}"
)
sections.append(s)

if section1.layer != section2.layer:
hidden = True
layer1 = get_layer(section1.layer)
layer2 = get_layer(section2.layer)
layer = (layer1, layer2)
else:
hidden = False
layer = get_layer(section1.layer)

s = Section(
width=width_fun,
offset=offset_fun,
layer=layer,
port_names=(section2.port_names[0], section1.port_names[1]),
port_types=(section2.port_types[0], section1.port_types[1]),
name=section1.name,
hidden=hidden,
)
sections.append(s)

return Transition(
cross_section1=X1,
Expand Down
49 changes: 49 additions & 0 deletions gdsfactory/tests/test_taper_cladding_offsets.py
@@ -0,0 +1,49 @@
from functools import partial

import gdsfactory as gf

xc_sin = partial(
gf.cross_section.cross_section,
width=1.0,
layer=(0, 1),
cladding_layers=[(0, 2), (0, 3)],
cladding_offsets=[5, 10],
)

xc_sin_ec = partial(xc_sin, width=0.2)


@gf.cell
def demo_taper_cladding_offsets():
taper_length = 10

in_stub_length = 10
out_stub_length = 10

c = gf.Component()

wg_in = c << gf.components.straight(length=in_stub_length, cross_section=xc_sin_ec)

taper = c << gf.components.taper_cross_section_linear(
length=taper_length, cross_section1=xc_sin_ec, cross_section2=xc_sin
)

wg_out = c << gf.components.straight(length=out_stub_length, cross_section=xc_sin)

taper.connect("o1", wg_in.ports["o2"])
wg_out.connect("o1", taper.ports["o2"])

c.add_port("o1", port=wg_in.ports["o1"])
c.add_port("o2", port=wg_out.ports["o2"])
return c


def test_taper_cladding_offets():
c = demo_taper_cladding_offsets()
assert len(c.get_polygons()) == 9


if __name__ == "__main__":
test_taper_cladding_offets()
c = demo_taper_cladding_offsets()
c.show()