Self-intersecting PolySlab#

This tutorial shows how to use the ComplexPolySlab plugin in tidy3d to deal with self-intersecting polygon that occurs during extrusion in a slanted polyslab.

[1]:
import numpy as np
import matplotlib.pyplot as plt
import gdstk

import tidy3d as td

from tidy3d.plugins import ComplexPolySlab
[11:56:05] WARNING  This version of Tidy3D was pip installed from the         __init__.py:103
                    'tidy3d-beta' repository on PyPI. Future releases will be                
                    uploaded to the 'tidy3d' repository. From now on, please                 
                    use 'pip install tidy3d' instead.                                        
           INFO     Using client version: 1.9.0rc2                            __init__.py:121

Example 1: concave polygon on the top with positive sidewall angle#

Let’s consider a concave polygon as shown in the following figure. As we dilate the polygon, the length of the edge in the middle will approach 0, and the two vertices at the end of the edge can be degenerate. Further dilation will result in a self-intersecting polygon. The collapsing of the two neighboring vertices is known as one type of edge events. There are other types of edge events as well, while our plugin at the moment will focus on this type of edge event.

[2]:
vertices= ((0, 0), (1, 0), (1, 1), (0, 1), (0, 0.8), (0.5, 0.65), (0.5, 0.35), (0, 0.2))
s = td.PolySlab(
    vertices=vertices,
    slab_bounds=(0, 1),
    axis=2,
    sidewall_angle=0,
    reference_plane="top",
)
s.plot(z=0.5)
[2]:
<AxesSubplot:title={'center':'cross section at z=0.50'}, xlabel='x', ylabel='y'>
../_images/notebooks_Self_intersecting_polyslab_3_1.png

For a slanted polyslab where this polygon is at the top, self-intersection can occur as the polygon is extruded to the base when the sidewall angle is large. Since td.PolySlab only deals with simple polyslab, an error message will be displayed in this case.

[3]:
sidewall_angle = np.pi/4
try:
    s = td.PolySlab(
        vertices=vertices,
        slab_bounds=(0, 1),
        axis=2,
        sidewall_angle=sidewall_angle,
        reference_plane="top",
    )
except Exception as e:
    pass
           ERROR    Sidewall angle or structure thickness is so large that the      log.py:34
                    polygon is self-intersecting during extrusion. Please either             
                    reduce structure thickness to be < 2.016e-01, or use our plugin          
                    'ComplexPolySlab' to divide the complex polyslab into a list of          
                    simple polyslabs.                                                        

Dividing a complex polyslab into sub-polyslabs#

The plugin ComplexPolySlab can divide such a complex polyslab into a list of simple polyslabs. The procedure of setting up the object is the same as in td.PolySlab:

[4]:
s = ComplexPolySlab(
    vertices=vertices,
    slab_bounds=(0, 1),
    axis=2,
    sidewall_angle=sidewall_angle,
    reference_plane="top",
)

We can obtain the division result in the form of a list of simple polyslabs, or combined into a GeometryGroup. As shown below, the entire polyslab will be divided into 3 simple polyslabsl

[5]:
# To obtain the divided polyslabs, there are two approaches:
# 1) a list of divided polyslabs
sub_polyslabs = s.sub_polyslabs

# 2) geometry group containing the divided polyslabs
polyslabs_group = s.geometry_group

print(f"The number of sub-polyslabs in the list is {len(sub_polyslabs)}.")
print(f"The number of sub-polyslabs in geometry group is {len(polyslabs_group.geometries)}.")
The number of sub-polyslabs in the list is 3.
The number of sub-polyslabs in geometry group is 3.

Define a simulation#

Now let’s make a simple simulation with a ComplexPolySlab object.

[6]:
mat = td.Medium(permittivity=2)

# Three equivalent approaches
# 1) from sub-polyslabs
struct_list = [td.Structure(geometry=poly, medium=mat) for poly in s.sub_polyslabs]

# 2) from geometry group
struct_list = [td.Structure(geometry=s.geometry_group, medium=mat)]

# 3) directly obtain the structure with a user-specified medium
struct_list = [s.to_structure(mat)]
[7]:
sim = td.Simulation(
    run_time=1e-12,
    size=(4, 4, 2),
    center=(0.5,0.5,0.5),
    grid_spec=td.GridSpec.auto(wavelength=1.0),
    structures=struct_list,
)
           WARNING  'Simulation.boundary_spec' uses default value, which is simulation.py:227
                    'Periodic()' on all sides but will change to 'PML()' in                  
                    Tidy3D version 2.0. We recommend explicitly setting all                  
                    boundary conditions ahead of this release to avoid                       
                    unexpected results.                                                      
           WARNING  No sources in simulation.                               simulation.py:494

Visualization#

Three characteristic normal cross sections are illustrated below. The polygon near the top looks similar to the supplied polygon. Somewhere between \(z=0.75\) \(\mu\)m and \(z=0.95\) \(\mu\)m, a vertex-vertex crossing event happens, and the shape of the polygon changes. Between \(z=0.75\) \(\mu\)m and \(z=0.5\) \(\mu\)m, another event occurs, and the shape evolves to a simple box.

[8]:
fig, ax = plt.subplots(1, 3, figsize=(8,4),layout="tight")
sim.plot(z=0.95,ax=ax[0])
sim.plot(z=0.75,ax=ax[1])
sim.plot(z=0.5,ax=ax[2])
[8]:
<AxesSubplot:title={'center':'cross section at z=0.50'}, xlabel='x', ylabel='y'>
../_images/notebooks_Self_intersecting_polyslab_14_1.png

Example 2: GDS import#

Similar to PolySlab, a ComplexPolySlab can also be setup from a gdstk.Cell. To illustrate this, let’s make a GDS cell with the aforementioned concave polygon, and load it with .from_gds classmethod.

[9]:
# add the concave polygon to the gds cell

lib = gdstk.Library()
cell = lib.new_cell("SI")
poly = gdstk.Polygon(vertices,layer=0)
cell.add(poly)
[9]:
<gdstk.Cell at 0x7ff69ad72810>

Loading a GDS cell into ComplexPolySlab#

[10]:
# obtain a list of polyslabs
geo_list = ComplexPolySlab.from_gds(
    cell,
    gds_layer=0,
    axis=2,
    slab_bounds=(0, 1),
    sidewall_angle=np.pi/4,
    reference_plane="top",
)
[11]:
structure = td.Structure(
    geometry=td.GeometryGroup(geometries=geo_list),
    medium=mat,
)

sim = td.Simulation(
    run_time=1e-12,
    size=(4, 4, 2),
    center=(0.5,0.5,0.5),
    grid_spec=td.GridSpec.auto(wavelength=1.0),
    structures=[structure],
)
[11:56:06] WARNING  'Simulation.boundary_spec' uses default value, which is simulation.py:227
                    'Periodic()' on all sides but will change to 'PML()' in                  
                    Tidy3D version 2.0. We recommend explicitly setting all                  
                    boundary conditions ahead of this release to avoid                       
                    unexpected results.                                                      
           WARNING  No sources in simulation.                               simulation.py:494
[12]:
fig, ax = plt.subplots(1, 3, figsize=(8,4),layout="tight")
sim.plot(z=0.95,ax=ax[0])
sim.plot(z=0.75,ax=ax[1])
sim.plot(z=0.5,ax=ax[2])
[12]:
<AxesSubplot:title={'center':'cross section at z=0.50'}, xlabel='x', ylabel='y'>
../_images/notebooks_Self_intersecting_polyslab_20_1.png
[ ]: