Exemple #1
0
def transition():
    c = gf.Component()
    X1 = gf.CrossSection()
    X1.add(width=1.2, offset=0, layer=2, name="wg", ports=("in1", "out1"))
    X1.add(width=2.2, offset=0, layer=3, name="etch")
    X1.add(width=1.1, offset=3, layer=1, name="wg2")

    # Create the second CrossSection that we want to transition to
    X2 = gf.CrossSection()
    X2.add(width=1, offset=0, layer=2, name="wg", ports=("in2", "out2"))
    X2.add(width=3.5, offset=0, layer=3, name="etch")
    X2.add(width=3, offset=5, layer=1, name="wg2")

    Xtrans = gf.path.transition(cross_section1=X1,
                                cross_section2=X2,
                                width_type="sine")

    P1 = gf.path.straight(length=5)
    P2 = gf.path.straight(length=5)
    wg1 = gf.path.extrude(P1, X1)
    wg2 = gf.path.extrude(P2, X2)

    P4 = gf.path.euler(radius=25, angle=45, p=0.5, use_eff=False)
    wg_trans = gf.path.extrude(P4, Xtrans)
    # WG_trans = P4.extrude(Xtrans)

    wg1_ref = c << wg1
    wg2_ref = c << wg2
    wgt_ref = c << wg_trans

    wgt_ref.connect("in2", wg1_ref.ports["out1"])
    wg2_ref.connect("in2", wgt_ref.ports["out1"])
    return c
def test_path_transitions():
    import gdsfactory as gf

    # Create our first CrossSection
    X1 = gf.CrossSection()
    X1.add(width=1.2, offset=0, layer=2, name="wg", ports=("o1", "o2"))
    X1.add(width=2.2, offset=0, layer=3, name="etch")
    X1.add(width=1.1, offset=3, layer=1, name="wg2")

    # Create the second CrossSection that we want to transition to
    X2 = gf.CrossSection()
    X2.add(width=1, offset=0, layer=2, name="wg", ports=("o1", "o2"))
    X2.add(width=3.5, offset=0, layer=3, name="etch")
    X2.add(width=3, offset=5, layer=1, name="wg2")

    # To show the cross-sections, let's create two Paths and
    # create Devices by extruding them
    P1 = gf.path.straight(length=5)
    P2 = gf.path.straight(length=5)
    wg1 = gf.path.extrude(P1, X1)
    wg2 = gf.path.extrude(P2, X2)

    # Place both cross-section Devices and quickplot them
    c = gf.Component()
    c << wg1
    wg2ref = c << wg2
    wg2ref.movex(7.5)

    # Create the transitional CrossSection
    Xtrans = gf.path.transition(cross_section1=X1, cross_section2=X2, width_type="sine")
    # Create a Path for the transitional CrossSection to follow
    P3 = gf.path.straight(length=15, npoints=100)

    # Use the transitional CrossSection to create a Component
    straight_transition = gf.path.extrude(P3, Xtrans)

    P4 = gf.path.euler(radius=25, angle=45, p=0.5, use_eff=False)
    wg_trans = gf.path.extrude(P4, Xtrans)

    c = gf.Component()
    wg1_ref = c << wg1  # First cross-section Component
    wg2_ref = c << wg2
    wgt_ref = c << wg_trans

    wgt_ref.connect("o1", wg1_ref.ports["o2"])
    wg2_ref.connect("o1", wgt_ref.ports["o2"])

    wg3 = c << straight_transition
    wg3.movey(10)
    return c
Exemple #3
0
def test_layers1():
    P = gf.path.straight(length=10.001)
    X = gf.CrossSection()
    X.add(width=0.5, offset=0, layer=gf.LAYER.SLAB90, ports=["in", "out"])
    c = gf.path.extrude(P, X, simplify=5e-3)
    assert c.ports["in"].layer == gf.LAYER.SLAB90
    assert c.ports["out"].position[0] == 10.001, c.ports["out"].position[0]
    return c
def test_path_transition_class():
    P = gf.path.straight(length=10, npoints=101)

    X1 = gf.CrossSection()
    X1.add(width=1, offset=0, layer=gf.LAYER.WG, name="core", ports=("o1", "o2"))
    X1.add(width=3, offset=0, layer=gf.LAYER.SLAB90)

    X2 = gf.CrossSection()
    X2.add(width=3, offset=0, layer=gf.LAYER.WG, name="core", ports=("o1", "o2"))

    T = gf.path.transition(X1, X2)
    c3 = gf.path.extrude(P, T)

    sections = {
        section["name"]: section for section in X1.sections if "name" in section
    }

    assert c3.ports["o1"].name == sections["core"]["ports"][0]
    assert c3.ports["o1"].layer == sections["core"]["layer"]
    assert c3.ports["o1"].orientation == 180
    assert c3.ports["o1"].port_type == sections["core"]["port_types"][0]
Exemple #5
0
def test_transition_unamed_fails():
    """raises error when transitioning un-named cross_sections"""
    with pytest.raises(ValueError):

        path = gf.Path()
        path.append(gf.path.arc(radius=10, angle=90))
        path.append(gf.path.straight(length=10))
        path.append(gf.path.euler(radius=3, angle=-90))
        path.append(gf.path.straight(length=40))
        path.append(gf.path.arc(radius=8, angle=-45))
        path.append(gf.path.straight(length=10))
        path.append(gf.path.arc(radius=8, angle=45))
        path.append(gf.path.straight(length=10))

        X = gf.CrossSection()
        X.add(width=1, offset=0, layer=0)

        x2 = gf.CrossSection()
        x2.add(width=2, offset=0, layer=0)

        transition(X, x2)
def bend_circular_heater(
    radius: float = 10,
    angle: int = 90,
    npoints: int = 720,
    heater_to_wg_distance: float = 1.2,
    heater_width: float = 0.5,
    layer_heater=TECH.layer.HEATER,
    cross_section: CrossSectionFactory = strip,
) -> Component:
    """Creates an arc of arclength ``theta`` starting at angle ``start_angle``

    Args:
        radius
        angle: angle of arc (degrees)
        npoints: Number of points used per 360 degrees
        heater_to_wg_distance:
        heater_width
        layer_heater
        cross_section:
    """
    x = cross_section()
    width = x.info["width"]
    cladding_offset = x.info["cladding_offset"]
    layers_cladding = x.info["layers_cladding"] or []
    layer = x.info["layer"]

    x = gf.CrossSection()
    x.add(width=width, offset=0, layer=layer, ports=["in", "out"])

    for layer_cladding in layers_cladding:
        x.add(width=width + 2 * cladding_offset,
              offset=0,
              layer=layer_cladding)

    offset = heater_to_wg_distance + width / 2
    x.add(
        width=heater_width,
        offset=+offset,
        layer=layer_heater,
    )
    x.add(
        width=heater_width,
        offset=-offset,
        layer=layer_heater,
    )
    p = arc(radius=radius, angle=angle, npoints=npoints)
    c = extrude(p, x)
    c.length = snap_to_grid(p.length())
    c.dx = abs(p.points[0][0] - p.points[-1][0])
    c.dy = abs(p.points[0][0] - p.points[-1][0])
    return c
Exemple #7
0
def rename():
    p = gf.path.arc()

    # Create a blank CrossSection
    X = gf.CrossSection()

    # Add a a few "sections" to the cross-section
    X.add(width=1, offset=0, layer=0, ports=("in", "out"))
    X.add(width=3, offset=2, layer=2)
    X.add(width=3, offset=-2, layer=2)

    # Combine the Path and the CrossSection
    straight = gf.path.extrude(p, cross_section=X)
    return straight
Exemple #8
0
def test_path_extrude_multiple_ports() -> gf.Component:
    X = gf.CrossSection()
    X.add(width=0.5, offset=0, layer=LAYER.SLAB90, ports=["o1", "o2"])
    X.add(
        width=2.0,
        offset=-4,
        layer=LAYER.HEATER,
        ports=["e1", "e2"],
        port_types=("electrical", "electrical"),
    )
    P = gf.path.straight(npoints=100, length=10)
    c = gf.path.extrude(P, X)
    assert c.ports["e1"].port_type == "electrical"
    assert c.ports["e2"].port_type == "electrical"
    assert c.ports["o1"].port_type == "optical"
    assert c.ports["o2"].port_type == "optical"
    return c
Exemple #9
0
def double_loop():
    # Create the path points
    P = gf.Path()
    P.append(gf.path.arc(radius=10, angle=90))
    P.append(gf.path.straight())
    P.append(gf.path.arc(radius=5, angle=-90))
    P.append(looploop(num_pts=1000))
    P.rotate(-45)

    # Create the crosssection
    X = gf.CrossSection()
    X.add(width=0.5, offset=2, layer=0)
    X.add(width=0.5, offset=4, layer=1)
    X.add(width=1.5, offset=0, layer=2, ports=["in", "out"])
    X.add(width=1, offset=0, layer=3)

    c = gf.path.extrude(P, X, simplify=0.3)
    return c
Exemple #10
0
def test_path():
    P = gf.Path()
    P.append(gf.path.arc(radius=10, angle=90))  # Circular arc
    P.append(gf.path.straight(length=10))  # Straight section
    P.append(gf.path.euler(radius=3, angle=-90,
                           p=1))  # Euler bend (aka "racetrack" curve)
    P.append(gf.path.straight(length=40))
    P.append(gf.path.arc(radius=8, angle=-45))
    P.append(gf.path.straight(length=10))
    P.append(gf.path.arc(radius=8, angle=45))
    P.append(gf.path.straight(length=10))
    P.length()
    P.length()
    assert np.isclose(P.length(), 107.69901058617913), P.length()

    X = gf.CrossSection()
    X.add(width=1, offset=0, layer=0)

    c = gf.path.extrude(P, X)
    return c
Exemple #11
0
def test_copy():
    X = gf.CrossSection()
    X.add(width=0.5, offset=0, layer=gf.LAYER.SLAB90, ports=["in", "out"])
    x2 = X.copy()
    assert x2