tidy3d.plugins.smatrix.ModalComponentModeler#

class ModalComponentModeler[source]#

Bases: AbstractComponentModeler[tuple[str, NonNegativeInt], tuple[tuple[str, NonNegativeInt], tuple[str, NonNegativeInt]]]

A tool for modeling devices and computing scattering matrix elements.

Parameters:
  • attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields, attrs are mutable. For example, the following is allowed for setting an attr obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a TypeError if attrs contain objects that can not be serialized. One can check if attrs are serializable by calling obj.json().

  • name (str =) – simulation : Simulation Simulation describing the device without any sources present.

  • ports (Tuple[Port, ...] = ()) – Collection of ports describing the scattering matrix elements. For each input mode, one simulation will be run with a modal source.

  • freqs (Union[tuple[float, ...], ArrayLike[dtype=float, ndim=1]]) – [units = Hz]. Array or list of frequencies at which to compute port parameters.

  • remove_dc_component (bool = True) – Whether to remove the DC component in the Gaussian pulse spectrum. If True, the Gaussian pulse is modified at low frequencies to zero out the DC component, which is usually desirable so that the fields will decay. However, for broadband simulations, it may be better to have non-vanishing source power near zero frequency. Setting this to False results in an unmodified Gaussian pulse spectrum which can have a nonzero DC component.

  • run_only (Optional[Tuple[IndexType, ...]] = None) – Set of matrix indices that define the simulations to run. If None, simulations will be run for all indices in the scattering matrix. If a tuple is given, simulations will be run only for the given matrix indices.

  • element_mappings (Tuple[tuple[~ElementType, ~ElementType, Union[tidy3d.components.types.base.tidycomplex, tidy3d.components.types.base.ComplexNumber]], ...] = ()) – Tuple of S matrix element mappings, each described by a tuple of (input_element, output_element, coefficient), where the coefficient is the element_mapping coefficient describing the relationship between the input and output matrix element. If all elements of a given column of the scattering matrix are defined by element_mappings, the simulation corresponding to this column is skipped automatically.

  • to (This class orchestrates the process of running multiple simulations)

  • modal (derive the scattering matrix (S-matrix) of a component. It uses)

  • ports. (sources and monitors defined by a set of)

Attributes

matrix_indices_monitor

Returns a tuple of all possible matrix indices for monitoring.

max_mode_index

Returns the maximum mode indices for the in and out ports.

port_names

Returns lists of port names for inputs and outputs.

sim_dict

Generates all Simulation objects for the S-matrix calculation.

ports

attrs

Methods

plot_sim([x, y, z, ax])

Plots the simulation with all sources added for troubleshooting.

plot_sim_eps([x, y, z, ax])

Plots the permittivity of the simulation with all sources.

shift_port(port)

Generates a new port shifted slightly in the normal direction.

to_monitor(port)

Creates a mode monitor from a given port.

to_source(port, mode_index[, num_freqs])

Creates a mode source from a given port.

Inherited Common Usage

ports#
property sim_dict#

Generates all Simulation objects for the S-matrix calculation.

Returns:

A dictionary where keys are task names and values are the corresponding Simulation objects. Each simulation is configured to excite a specific mode at a specific port and includes all necessary monitors.

Return type:

Dict[str, Simulation]

property matrix_indices_monitor#

Returns a tuple of all possible matrix indices for monitoring.

Each matrix index is a tuple of (port_name, mode_index).

Returns:

A tuple of all possible matrix indices for the monitoring ports.

Return type:

Tuple[MatrixIndex, …]

property port_names#

Returns lists of port names for inputs and outputs.

Returns:

A tuple containing two lists: the first with the names of the output ports, and the second with the names of the input ports.

Return type:

Tuple[List[str], List[str]]

to_monitor(port)[source]#

Creates a mode monitor from a given port.

This monitor is used to measure the mode amplitudes at the port.

Parameters:

port (Port) – The port to convert into a monitor.

Returns:

A ModeMonitor configured to match the port’s properties.

Return type:

ModeMonitor

to_source(port, mode_index, num_freqs=1, **kwargs)[source]#

Creates a mode source from a given port.

This source is used to excite a specific mode at the port.

Parameters:
  • port (Port) – The port to convert into a source.

  • mode_index (int) – The index of the mode to excite.

  • num_freqs (int, optional) – The number of frequency points for the source, by default 1.

Returns:

A list containing a single ModeSource configured to excite the specified mode at the port.

Return type:

List[ModeSource]

shift_port(port)[source]#

Generates a new port shifted slightly in the normal direction.

This is to ensure that the source is placed just inside the simulation domain, away from the PML.

Parameters:

port (Port) – The port to shift.

Returns:

A new Port object with its center shifted.

Return type:

Port

plot_sim(x=None, y=None, z=None, ax=None)[source]#

Plots the simulation with all sources added for troubleshooting.

This method creates a temporary simulation with all mode sources activated to help visualize the setup.

Parameters:
  • x (float, optional) – The x-coordinate of the cross-section, by default None.

  • y (float, optional) – The y-coordinate of the cross-section, by default None.

  • z (float, optional) – The z-coordinate of the cross-section, by default None.

  • ax (Ax, optional) – The matplotlib axes to plot on, by default None.

Returns:

The matplotlib axes with the plot.

Return type:

Ax

plot_sim_eps(x=None, y=None, z=None, ax=None, **kwargs)[source]#

Plots the permittivity of the simulation with all sources.

This method is useful for visualizing the device geometry along with the placement of the sources.

Parameters:
  • x (float, optional) – The x-coordinate of the cross-section, by default None.

  • y (float, optional) – The y-coordinate of the cross-section, by default None.

  • z (float, optional) – The z-coordinate of the cross-section, by default None.

  • ax (Ax, optional) – The matplotlib axes to plot on, by default None.

  • **kwargs – Additional keyword arguments passed to the plotter.

Returns:

The matplotlib axes with the plot.

Return type:

Ax

property max_mode_index#

Returns the maximum mode indices for the in and out ports.

Returns:

A tuple containing the maximum mode index for the output ports and the maximum mode index for the input ports.

Return type:

Tuple[int, int]

__hash__()#

Hash method.