Source code for tidy3d.plugins.smatrix.ports.base_terminal

"""Class and custom data array for representing a scattering-matrix port, which is defined by a pair of terminals."""

from __future__ import annotations

from abc import abstractmethod
from typing import TYPE_CHECKING, Any

from tidy3d.components.base import cached_property
from tidy3d.components.microwave.base import MicrowaveBaseModel
from tidy3d.log import log
from tidy3d.plugins.smatrix.ports.base import AbstractBasePort

if TYPE_CHECKING:
    from typing import Optional, Union

    from tidy3d.components.data.data_array import FreqDataArray
    from tidy3d.components.data.sim_data import SimulationData
    from tidy3d.components.grid.grid import Grid
    from tidy3d.components.monitor import FieldMonitor, ModeMonitor
    from tidy3d.components.source.base import Source
    from tidy3d.components.source.time import SourceTimeType
    from tidy3d.components.types import FreqArray


[docs] class AbstractTerminalPort(AbstractBasePort, MicrowaveBaseModel): """Class representing a single terminal-based port. All terminal ports must provide methods for computing voltage and current. These quantities represent the voltage between the terminals, and the current flowing from one terminal into the other. """ @cached_property @abstractmethod def injection_axis(self) -> None: """Injection axis of the port."""
[docs] @abstractmethod def to_source( self, source_time: SourceTimeType, snap_center: Optional[float] = None, grid: Optional[Grid] = None, **kwargs: Any, ) -> Source: """Create a current source from a terminal-based port."""
[docs] def to_field_monitors( self, freqs: FreqArray, snap_center: Optional[float] = None, grid: Optional[Grid] = None ) -> Union[list[FieldMonitor], list[ModeMonitor]]: """DEPRECATED: Monitors used to compute the port voltage and current.""" log.warning( "'to_field_monitors' method name is deprecated and will be removed in the future. Please use " "'to_monitors' for the same effect." ) return self.to_monitors(freqs=freqs, snap_center=snap_center, grid=grid)
[docs] @abstractmethod def to_monitors( self, freqs: FreqArray, snap_center: Optional[float] = None, grid: Optional[Grid] = None, **kwargs: Any, ) -> Union[list[FieldMonitor], list[ModeMonitor]]: """Monitors used to compute the port voltage and current."""
[docs] @abstractmethod def compute_voltage(self, sim_data: SimulationData) -> FreqDataArray: """Helper to compute voltage across the port."""
[docs] @abstractmethod def compute_current(self, sim_data: SimulationData) -> FreqDataArray: """Helper to compute current flowing into the port."""