Skip to content

Commit

Permalink
Merge pull request gdsfactory#2409 from gdsfactory/use_cross_section_…
Browse files Browse the repository at this point in the history
…functions

use cross_section factories instead of copy
  • Loading branch information
joamatab authored Dec 23, 2023
2 parents 2d500ea + b359835 commit c06af8b
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 39 deletions.
5 changes: 2 additions & 3 deletions gdsfactory/components/coupler_straight_asymmetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def coupler_straight_asymmetric(
"""
component = Component()

xs = gf.get_cross_section(cross_section)
xs_top = xs.copy(width=width_top)
xs_bot = xs.copy(width=width_bot)
xs_top = gf.get_cross_section(cross_section, width=width_top)
xs_bot = gf.get_cross_section(cross_section, width=width_bot)

top = component << straight(length=length, cross_section=xs_top)
bot = component << straight(length=length, cross_section=xs_bot)
Expand Down
18 changes: 6 additions & 12 deletions gdsfactory/components/dbr_tapered.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,17 @@ def dbr_tapered(
c = gf.Component()

xs = gf.get_cross_section(cross_section=cross_section, width=w2, **kwargs)
xs1 = gf.get_cross_section(cross_section=cross_section, width=xs.width, **kwargs)
xs2 = gf.get_cross_section(cross_section=cross_section, width=w1, **kwargs)

input_taper = c << gf.components.taper(
length=taper_length,
width1=xs.width,
width2=w1,
cross_section=xs.copy(width=xs.width),
length=taper_length, width1=xs.width, width2=w1, cross_section=xs1
)

straight = c << gf.components.straight(
length=length, cross_section=xs.copy(width=w1)
)
straight = c << gf.components.straight(length=length, cross_section=xs2)

output_taper = c << gf.components.taper(
length=taper_length,
width1=w1,
width2=xs.width,
cross_section=xs.copy(width=xs.width),
length=taper_length, width1=w1, width2=xs.width, cross_section=xs1
)

input_taper.connect("o2", straight.ports["o1"])
Expand Down Expand Up @@ -150,5 +144,5 @@ def dbr_tapered(

if __name__ == "__main__":
# c = dbr_tapered(length=10, period=0.85, dc=0.5, w2=1, w1=0.4, taper_length=20, fins=True)
c = dbr_tapered()
c = dbr_tapered(cross_section=gf.cross_section.rib)
c.show(show_ports=True)
2 changes: 1 addition & 1 deletion gdsfactory/components/mmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def mmi(
w_mmi = width_mmi
w_taper = width_taper
x = gf.get_cross_section(cross_section)
xs_mmi = x.copy(width=w_mmi)
xs_mmi = gf.get_cross_section(cross_section, width=w_mmi)
width = width or x.width

_taper = taper(
Expand Down
2 changes: 1 addition & 1 deletion gdsfactory/components/mmi1x2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def mmi1x2(
c = Component()
gap_mmi = gf.snap.snap_to_grid(gap_mmi, grid_factor=2)
x = gf.get_cross_section(cross_section, **kwargs)
xs_mmi = x.copy(width=width_mmi)
xs_mmi = gf.get_cross_section(cross_section, width=width_mmi)
width = width or x.width

_taper = taper(
Expand Down
2 changes: 1 addition & 1 deletion gdsfactory/components/mmi2x2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def mmi2x2(
gap_mmi = gf.snap.snap_to_grid(gap_mmi, grid_factor=2)
w_taper = width_taper
x = gf.get_cross_section(cross_section, **kwargs)
xs_mmi = x.copy(width=width_mmi)
xs_mmi = gf.get_cross_section(cross_section, width=width_mmi)
width = width or x.width

_taper = taper(
Expand Down
4 changes: 2 additions & 2 deletions gdsfactory/components/mzit.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def mzit(
c = gf.Component()

xs = gf.get_cross_section(cross_section)
xs1 = xs.copy(width=w1)
xs2 = xs.copy(width=w2)
xs1 = gf.get_cross_section(cross_section, width=w1)
xs2 = gf.get_cross_section(cross_section, width=w2)

cp2 = c << coupler2(
length=coupler_length2,
Expand Down
7 changes: 2 additions & 5 deletions gdsfactory/components/taper_adiabatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def taper_adiabatic(
npoints: number of points for sampling
"""
xs = gf.get_cross_section(cross_section)
xs1 = gf.get_cross_section(cross_section, width=width1)
xs2 = gf.get_cross_section(cross_section, width=width2)
layer = xs.layer

# Obtain optimal curve
Expand All @@ -88,11 +90,6 @@ def taper_adiabatic(
c.add_polygon(
list(zip(x_array, y_array)) + list(zip(x_array, -y_array))[::-1], layer=layer
)

# Define ports
xs1 = xs.copy(width=width1)
xs2 = xs.copy(width=width2)

c.add_port(
name="o1",
center=(0, 0),
Expand Down
3 changes: 1 addition & 2 deletions gdsfactory/routing/get_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ def test_north_to_south():
xs_list = []
for element in cross_section:
xs, angles = element
xs = gf.get_cross_section(xs)
xs = xs.copy(**kwargs) # Shallow copy
xs = gf.get_cross_section(xs, **kwargs)
xs_list.append((xs, angles))
cross_section = xs_list

Expand Down
6 changes: 2 additions & 4 deletions gdsfactory/routing/get_bundle_from_waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ def get_bundle_from_waypoints(
xs_list = []
for element in cross_section:
xs, angles = element
xs = gf.get_cross_section(xs)
xs = xs.copy(**kwargs) # Shallow copy
xs = gf.get_cross_section(xs, **kwargs)
xs_list.append((xs, angles))
cross_section = xs_list

else:
cross_section = gf.get_cross_section(cross_section)
xs = cross_section = cross_section.copy(**kwargs)
xs = cross_section = gf.get_cross_section(cross_section, **kwargs)

waypoints = [ports1[0].center] + list(waypoints) + [ports2[0].center]
for p in ports1:
Expand Down
6 changes: 2 additions & 4 deletions gdsfactory/routing/get_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ def get_route(
xs_list = []
for element in cross_section:
xs, angles = element
xs = gf.get_cross_section(xs)
xs = xs.copy(**kwargs) # Shallow copy
xs = gf.get_cross_section(xs, **kwargs)
xs_list.append((xs, angles))
cross_section = xs_list

elif cross_section:
cross_section = gf.get_cross_section(cross_section)
x = cross_section = cross_section.copy(**kwargs)
x = cross_section = gf.get_cross_section(cross_section, **kwargs)

else:
x = cross_section = None
Expand Down
7 changes: 3 additions & 4 deletions gdsfactory/routing/get_route_from_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ def get_route_from_steps(
for element in cross_section:
xs, angles = element
xs = gf.get_cross_section(xs)
xs = xs.copy(**kwargs) # Shallow copy
xs = gf.get_cross_section(xs, **kwargs)
xs_list.append((xs, angles))
cross_section = xs_list

else:
cross_section = gf.get_cross_section(cross_section)
x = cross_section = cross_section.copy(**kwargs)
auto_widen = x.auto_widen
cross_section = gf.get_cross_section(cross_section, **kwargs)
auto_widen = cross_section.auto_widen

if auto_widen:
taper = gf.get_component(
Expand Down

0 comments on commit c06af8b

Please sign in to comment.