Source code for tidy3d.plugins.smatrix.ports.modal
"""Class and custom data array for representing a scattering matrix port based on waveguide modes."""
from __future__ import annotations
import pydantic.v1 as pd
from tidy3d.components.data.data_array import DataArray
from tidy3d.components.geometry.base import Box
from tidy3d.components.mode_spec import ModeSpec
from tidy3d.components.types import Direction
from tidy3d.plugins.smatrix.ports.base import AbstractBasePort
class ModalPortDataArray(DataArray):
"""Port parameter matrix elements for modal ports.
Example
-------
>>> import numpy as np
>>> ports_in = ['port1', 'port2']
>>> ports_out = ['port1', 'port2']
>>> mode_index_in = [0, 1]
>>> mode_index_out = [0, 1]
>>> f = [2e14]
>>> coords = dict(
... port_in=ports_in,
... port_out=ports_out,
... mode_index_in=mode_index_in,
... mode_index_out=mode_index_out,
... f=f
... )
>>> fd = ModalPortDataArray((1 + 1j) * np.random.random((2, 2, 2, 2, 1)), coords=coords)
"""
__slots__ = ()
_dims = ("port_out", "mode_index_out", "port_in", "mode_index_in", "f")
_data_attrs = {"long_name": "modal port matrix element"}
[docs]
class Port(AbstractBasePort, Box):
"""Specifies a port for S-matrix calculation.
A port defines a location and a set of modes for which the S-matrix
is calculated.
"""
direction: Direction = pd.Field(
...,
title="Direction",
description="'+' or '-', defining which direction is considered 'input'.",
)
mode_spec: ModeSpec = pd.Field(
ModeSpec(),
title="Mode Specification",
description="Specifies how the mode solver will solve for the modes of the port.",
)