2727from gdsfactory .pdk import get_layer_stack
2828from gdsfactory .technology import LayerStack
2929from pydantic import NonNegativeFloat
30+ from tidy3d .components .geometry .base import from_shapely
3031from tidy3d .components .types import Symmetry
3132from tidy3d .plugins .smatrix import ComponentModeler , Port
3233
@@ -80,28 +81,26 @@ class Tidy3DComponent(LayeredComponentBase):
8081 reference_plane : Literal ["bottom" , "middle" , "top" ] = "middle"
8182
8283 @cached_property
83- def polyslabs (self ) -> dict [str , tuple [td .PolySlab , ...]]:
84+ def polyslabs (self ) -> dict [str , tuple [td .Geometry , ...]]:
8485 """Returns a dictionary of PolySlab instances for each layer in the component.
8586
8687 Returns:
8788 dict[str, tuple[td.PolySlab, ...]]: A dictionary mapping layer names to tuples of PolySlab instances.
8889 """
8990 slabs = {}
9091 layers = sort_layers (self .geometry_layers , sort_by = "mesh_order" , reverse = True )
91-
9292 for name , layer in layers .items ():
9393 bbox = self .get_layer_bbox (name )
94- slabs [name ] = tuple (
95- td .PolySlab (
96- vertices = v ,
97- axis = 2 ,
98- slab_bounds = (bbox [0 ][2 ], bbox [1 ][2 ]),
99- sidewall_angle = np .deg2rad (layer .sidewall_angle ),
100- reference_plane = self .reference_plane ,
101- dilation = self .dilation ,
102- )
103- for v in self .get_vertices (name )
94+ shape = self .polygons [name ].buffer (distance = 0.0 , join_style = "mitre" )
95+ geom = from_shapely (
96+ shape ,
97+ axis = 2 ,
98+ slab_bounds = (bbox [0 ][2 ], bbox [1 ][2 ]),
99+ dilation = self .dilation ,
100+ sidewall_angle = np .deg2rad (layer .sidewall_angle ),
101+ reference_plane = self .reference_plane ,
104102 )
103+ slabs [name ] = geom
105104
106105 return slabs
107106
@@ -113,19 +112,14 @@ def structures(self) -> list[td.Structure]:
113112 list[td.Structure]: A list of Structure instances.
114113 """
115114 structures = []
116- for name , polys in self .polyslabs .items ():
117- structures .extend (
118- [
119- td .Structure (
120- geometry = poly ,
121- medium = self .material_mapping [
122- self .geometry_layers [name ].material
123- ],
124- name = f"{ name } _{ idx } " ,
125- )
126- for idx , poly in enumerate (polys )
127- ]
115+ for name , poly in self .polyslabs .items ():
116+ structure = td .Structure (
117+ geometry = poly ,
118+ medium = self .material_mapping [self .geometry_layers [name ].material ],
119+ name = name ,
128120 )
121+ structures .append (structure )
122+
129123 return structures
130124
131125 def get_ports (
@@ -366,24 +360,23 @@ def plot_slice(
366360 for name , layer in layers .items ():
367361 if name not in self .polyslabs :
368362 continue
369- polys = self .polyslabs [name ]
370-
371- for idx , poly in enumerate (polys ):
372- axis , position = poly .parse_xyz_kwargs (x = x , y = y , z = z )
373- xlim , ylim = poly ._get_plot_limits (axis = axis , buffer = 0 )
374- xmin , xmax = min (xmin , xlim [0 ]), max (xmax , xlim [1 ])
375- ymin , ymax = min (ymin , ylim [0 ]), max (ymax , ylim [1 ])
376- for shape in poly .intersections_plane (x = x , y = y , z = z ):
377- _shape = td .Geometry .evaluate_inf_shape (shape )
378- patch = td .components .viz .polygon_patch (
379- _shape ,
380- facecolor = colors [name ],
381- edgecolor = "k" ,
382- linewidth = 0.5 ,
383- label = name if idx == 0 else None ,
384- zorder = order_map [layer .mesh_order ],
385- )
386- ax .add_artist (patch )
363+ poly = self .polyslabs [name ]
364+
365+ axis , position = poly .parse_xyz_kwargs (x = x , y = y , z = z )
366+ xlim , ylim = poly ._get_plot_limits (axis = axis , buffer = 0 )
367+ xmin , xmax = min (xmin , xlim [0 ]), max (xmax , xlim [1 ])
368+ ymin , ymax = min (ymin , ylim [0 ]), max (ymax , ylim [1 ])
369+ for idx , shape in enumerate (poly .intersections_plane (x = x , y = y , z = z )):
370+ _shape = td .Geometry .evaluate_inf_shape (shape )
371+ patch = td .components .viz .polygon_patch (
372+ _shape ,
373+ facecolor = colors [name ],
374+ edgecolor = "k" ,
375+ linewidth = 0.5 ,
376+ label = name if idx == 0 else None ,
377+ zorder = order_map [layer .mesh_order ],
378+ )
379+ ax .add_artist (patch )
387380
388381 size = list (self .size )
389382 cmin = list (self .bbox [0 ])
@@ -713,8 +706,8 @@ def write_sparameters_batch(
713706 center_z = "core" ,
714707 # plot_simulation_x=10,
715708 # plot_simulation_layer_name="core",
716- # plot_epsilon=True,
717- filepath = "straight2" ,
709+ plot_epsilon = True ,
710+ # filepath="straight2",
718711 # plot_mode_port_name="o1",
719712 # plot_mode_index=1,
720713 # mode_spec=mode_spec,
0 commit comments