From 55210a1e2b9ae9e9e432b03f3ba51eac3dd06004 Mon Sep 17 00:00:00 2001 From: bsnyder Date: Sun, 25 Sep 2022 21:32:04 +0200 Subject: [PATCH] Added parabolic width_type to taper_cross_section --- gdsfactory/components/__init__.py | 2 ++ gdsfactory/components/taper_cross_section.py | 7 ++++++- gdsfactory/cross_section.py | 2 +- gdsfactory/path.py | 15 ++++++++++++++- gdsfactory/types.py | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gdsfactory/components/__init__.py b/gdsfactory/components/__init__.py index 4cad19ad14..216801bbf3 100644 --- a/gdsfactory/components/__init__.py +++ b/gdsfactory/components/__init__.py @@ -220,6 +220,7 @@ ) from gdsfactory.components.taper_cross_section import ( taper_cross_section_linear, + taper_cross_section_parabolic, taper_cross_section_sine, ) from gdsfactory.components.taper_from_csv import ( @@ -270,6 +271,7 @@ crossing45=crossing45, taper_cross_section_linear=taper_cross_section_linear, taper_cross_section_sine=taper_cross_section_sine, + taper_cross_section_parabolic=taper_cross_section_parabolic, taper=taper, taper2=taper2, taper_0p5_to_3_l36=taper_0p5_to_3_l36, diff --git a/gdsfactory/components/taper_cross_section.py b/gdsfactory/components/taper_cross_section.py index 55b721fa03..e969da462c 100644 --- a/gdsfactory/components/taper_cross_section.py +++ b/gdsfactory/components/taper_cross_section.py @@ -12,6 +12,7 @@ def taper_cross_section( length: float = 10, npoints: int = 100, linear: bool = False, + width_type: str = "sine", **kwargs ) -> Component: r"""Returns taper transition between cross_section1 and cross_section2. @@ -22,6 +23,7 @@ def taper_cross_section( length: transition length. npoints: number of points. linear: shape of the transition, sine when False. + width_type: shape of the transition ONLY IF linear is False kwargs: cross_section settings for section2. @@ -42,7 +44,7 @@ def taper_cross_section( transition = gf.path.transition( cross_section1=gf.get_cross_section(cross_section1), cross_section2=gf.get_cross_section(cross_section2, **kwargs), - width_type="linear" if linear else "sine", + width_type="linear" if linear else width_type, ) taper_path = gf.path.straight(length=length, npoints=npoints) @@ -54,6 +56,9 @@ def taper_cross_section( taper_cross_section_linear = gf.partial(taper_cross_section, linear=True, npoints=2) taper_cross_section_sine = gf.partial(taper_cross_section, linear=False, npoints=101) +taper_cross_section_parabolic = gf.partial( + taper_cross_section, linear=False, width_type="parabolic", npoints=101 +) if __name__ == "__main__": diff --git a/gdsfactory/cross_section.py b/gdsfactory/cross_section.py index e15db3f215..e2d7ff6baf 100644 --- a/gdsfactory/cross_section.py +++ b/gdsfactory/cross_section.py @@ -19,7 +19,7 @@ LAYER = TECH.layer Layer = Tuple[int, int] Layers = Tuple[Layer, ...] -WidthTypes = Literal["sine", "linear"] +WidthTypes = Literal["sine", "linear", "parabolic"] LayerSpec = Union[Layer, int, str, None] LayerSpecs = Union[List[LayerSpec], Tuple[LayerSpec, ...]] diff --git a/gdsfactory/path.py b/gdsfactory/path.py index 7911ade99c..cb19834a15 100644 --- a/gdsfactory/path.py +++ b/gdsfactory/path.py @@ -137,6 +137,15 @@ def sine(t): return sine +def _parabolic_transition(y1, y2): + dy = y2 - y1 + + def parabolic(t): + return y1 + np.sqrt(t) * dy + + return parabolic + + def _linear_transition(y1, y2): dy = y2 - y1 @@ -225,8 +234,12 @@ def transition( 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'}") + raise ValueError( + f"width_type={width_type!r} must be {'sine','linear','parabolic'}" + ) if section1.layer != section2.layer: hidden = True diff --git a/gdsfactory/types.py b/gdsfactory/types.py index 9aca6f5bd4..c22a30c804 100644 --- a/gdsfactory/types.py +++ b/gdsfactory/types.py @@ -58,7 +58,7 @@ ] Axis = Literal["x", "y"] NSEW = Literal["N", "S", "E", "W"] -WidthTypes = Literal["sine", "linear"] +WidthTypes = Literal["sine", "linear", "parabolic"] class Label(LabelPhidl):