How do I set the mode polarization?

How do I set the mode polarization?#

Date

Category

2023-12-18 22:25:04

Mode Solver

After running the Tidy3D mode solver, the results are returned within a ModeSolverData object. The solver always computes the num_modes modes closest to the given target_neff. If filter_pol==None, they are simply sorted in order of decreasing effective index. If a polarization filter is selected, the modes are rearranged such that the first n_pol modes in the list are the ones with the selected polarization fraction larger than or equal to 0.5, while the next num_modes - n_pol modes are the ones where it is smaller than 0.5 (i.e. the opposite polarization fraction is larger than 0.5). The modes are still ordered within each polarization subset by decreasing the effective index.

The example below shows how to set the mode solver to return the TE modes first in the mode list.

import numpy as np
from tidy3d.plugins.mode import ModeSolver
from tidy3d.plugins.mode.web import run as run_mode_solver

# Define the waveguide.
waveguide = tidy3d.Structure(
    geometry=tidy3d.Box(size=(tidy3d.inf, 0.5, 0.22)),
    medium=tidy3d.Medium(permittivity=3.47**2),
)

# Build a simulation object including the waveguide.
sim = tidy3d.Simulation(
    size=(10, 2.5, 1.5),
    grid_spec=tidy3d.GridSpec.auto(min_steps_per_wvl=20, wavelength=1.55),
    structures=[waveguide],
    run_time=1e-12,
    boundary_spec=tidy3d.BoundarySpec.all_sides(boundary=tidy3d.PML()),
)

# Plane where we want to solve the modes.
plane = tidy3d.Box(center=(0, 0, 0), size=(0, 2.5, 1.5))

# Mode specification.
mode_spec = tidy3d.ModeSpec(
  num_modes=4,
  target_neff=3.47,
  filter_pol='te',
)

# Build the mode solver.
freq0 = tidy3d.C_0 / 1.55
mode_solver = ModeSolver(
  simulation=sim,
  plane=plane,
  mode_spec=mode_spec,
  freqs=[freq0],
)

# Run the server-side mode solver.
mode_data = run_mode_solver(mode_solver)

# Get the mode polarization fraction.
print("TE polarization fraction:")
print(np.asarray(mode_data.pol_fraction['te']).squeeze())