Skip to content

Commit

Permalink
Merge pull request #2293 from gdsfactory/extrude_transitions
Browse files Browse the repository at this point in the history
Components can extrude transitions
  • Loading branch information
joamatab committed Nov 8, 2023
2 parents abb64c6 + a1fa720 commit ab28d4a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 24 deletions.
42 changes: 35 additions & 7 deletions docs/notebooks/03_Path_CrossSection.py
Expand Up @@ -146,8 +146,9 @@
b.plot()

# %% [markdown]
# An arbitrary cross-section can also help place components along a path.
# This component can be useful for defining wiring vias.
# ### Option 3: CrossSection with ComponentAlongPath
#
# You can also place components along a path, which is useful for wiring vias.

# %%
import gdsfactory as gf
Expand Down Expand Up @@ -189,13 +190,12 @@
c.plot()

# %% [markdown]
# ## Building Paths quickly
# ## Path
#
# You can pass `append()` lists of path segments. This makes it easy to combine
# paths very quickly. Below we show 3 examples using this functionality:
# You can pass `append()` lists of path segments. This makes it easy to combine paths very quickly.
# Below we show 3 examples using this functionality:
#
# **Example 1:** Assemble a complex path by making a list of Paths and passing it
# to `append()`
# **Example 1:** Assemble a complex path by making a list of Paths and passing it to `append()`

# %%
P = gf.Path()
Expand Down Expand Up @@ -603,6 +603,34 @@ def looploop(num_pts=1000):
c.plot()


# %% [markdown]
# Since a Transition inherits from CrossSection you can also extrude an arbitrary Transition.
#
# 1. Extruding a Path

# %%
w1 = 1
w2 = 5
x1 = gf.get_cross_section("xs_sc", width=w1)
x2 = gf.get_cross_section("xs_sc", width=w2)
transition = gf.path.transition(x1, x2)
p = gf.path.arc(radius=10)
c = gf.path.extrude(p, transition)
c.plot()

# %% [markdown]
# 2. Or as a CrossSection for a component

# %%
w1 = 1
w2 = 5
length = 10
x1 = gf.get_cross_section("xs_sc", width=w1)
x2 = gf.get_cross_section("xs_sc", width=w2)
transition = gf.path.transition(x1, x2)
c = gf.components.bend_euler(radius=10, cross_section=transition)
c.plot()

# %% [markdown]
# ## Variable width / offset
#
Expand Down
11 changes: 11 additions & 0 deletions gdsfactory/cross_section.py
Expand Up @@ -373,6 +373,17 @@ class Transition(CrossSection):
cross_section2: CrossSectionSpec
width_type: WidthTypes = "sine"

@property
def width(self) -> tuple[float, float]:
return (
self.cross_section1.sections[0].width,
self.cross_section2.sections[0].width,
)

@property
def layer(self) -> LayerSpec:
return self.cross_section1.sections[0].layer


def cross_section(
width: float = 0.5,
Expand Down
36 changes: 20 additions & 16 deletions gdsfactory/path.py
Expand Up @@ -1576,20 +1576,24 @@ def smooth(
if __name__ == "__main__":
import gdsfactory as gf

P = gf.path.straight(length=10)

s0 = gf.Section(
width=0.415, offset=0, layer=(1, 0), name="core", port_names=("o1", "o2")
)
s1 = gf.Section(width=3, offset=0, layer=(3, 0), name="slab")
X1 = gf.CrossSection(sections=(s0, s1))

s2 = gf.Section(
width=0.5, offset=0, layer=(1, 0), name="core", port_names=("o1", "o2")
)
s3 = gf.Section(width=2.0, offset=0, layer=(3, 0), name="slab")
X2 = gf.CrossSection(sections=(s2, s3))
t = gf.path.transition(X1, X2, width_type="linear")
c = gf.path.extrude(P, t, shear_angle_start=10, shear_angle_end=45)

# P = gf.path.straight(length=10)
# s0 = gf.Section(
# width=0.415, offset=0, layer=(1, 0), name="core", port_names=("o1", "o2")
# )
# s1 = gf.Section(width=3, offset=0, layer=(3, 0), name="slab")
# X1 = gf.CrossSection(sections=(s0, s1))
# s2 = gf.Section(
# width=0.5, offset=0, layer=(1, 0), name="core", port_names=("o1", "o2")
# )
# s3 = gf.Section(width=2.0, offset=0, layer=(3, 0), name="slab")
# X2 = gf.CrossSection(sections=(s2, s3))
# t = gf.path.transition(X1, X2, width_type="linear")
# c = gf.path.extrude(P, t, shear_angle_start=10, shear_angle_end=45)

w1 = 1
w2 = 5
x1 = gf.get_cross_section("xs_sc", width=w1)
x2 = gf.get_cross_section("xs_sc", width=w2)
trans = gf.path.transition(x1, x2)
c = gf.components.bend_euler(radius=10, cross_section=trans)
c.show(show_ports=True)
14 changes: 13 additions & 1 deletion tests/test_cross_section.py
Expand Up @@ -137,6 +137,18 @@ def test_cross_section_mirror() -> None:
assert s1.offset == -s2.offset, f"{s1.offset} != {s2.offset}"


def test_extrude_transition_component():
w1 = 1
w2 = 5
x1 = gf.get_cross_section("xs_sc", width=w1)
x2 = gf.get_cross_section("xs_sc", width=w2)
trans = gf.path.transition(x1, x2)
c = gf.components.bend_euler(radius=10, cross_section=trans)
assert c["o1"].width == w1
assert c["o2"].width == w2


if __name__ == "__main__":
# test_transition_names()
test_copy()
# test_copy()
test_extrude_transition_component()

0 comments on commit ab28d4a

Please sign in to comment.