tidy3d.plugins.mode.ModeSolver#

class ModeSolver[source]#

Bases: Tidy3dBaseModel

Interface for solving electromagnetic eigenmodes in a 2D plane with translational invariance in the third dimension.

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().

  • simulation (Simulation) – Simulation defining all structures and mediums.

  • plane (Box) – Cross-sectional plane in which the mode will be computed.

  • mode_spec (ModeSpec) – Container with specifications about the modes to be solved for.

  • freqs (Union[Tuple[float, ...], ArrayLike[dtype=float, ndim=1]]) – A list of frequencies at which to solve.

  • direction (Literal['+', '-'] = +) – Direction of waveguide mode propagation along the axis defined by its normal dimension.

  • colocate (bool = True) – Toggle whether fields should be colocated to grid cell boundaries (i.e. primal grid nodes). Default is True.

See also

ModeSource:

Injects current source to excite modal profile on finite extent plane.

Notebooks:
Lectures:

Attributes

data

ModeSolverData containing the field and effective index data.

data_raw

ModeSolverData containing the field and effective index on unexpanded grid.

grid_snapped

The solver grid snapped to the plane normal and to simulation 0-sized dims if any.

normal_axis

Axis normal to the mode plane.

reduced_simulation_copy

Strip objects not used by the mode solver from simulation object.

sim_data

SimulationData object containing the ModeSolverData for this object.

solver_symmetry

Get symmetry for solver for propagation along self.normal axis.

attrs

Methods

is_plane(val)

Raise validation error if not planar.

plane_in_sim_bounds(val, values)

Check that the plane is at least partially inside the simulation bounds.

plot([ax])

Plot the mode plane simulation's components.

plot_eps([freq, alpha, ax])

Plot the mode plane simulation's components.

plot_field(field_name[, val, scale, ...])

Plot the field for a ModeSolverData with Simulation plot overlaid.

plot_grid([ax])

Plot the mode plane cell boundaries as lines.

plot_pml([ax])

Plot the mode plane absorbing boundaries.

plot_structures_eps([freq, alpha, cbar, ...])

Plot the mode plane simulation's components.

sim_with_mode_solver_monitor(name)

Creates Simulation from a ModeSolver.

sim_with_monitor([freqs, name])

Creates Simulation from a ModeSolver.

sim_with_source(source_time[, direction, ...])

Creates Simulation from a ModeSolver.

solve()

ModeSolverData containing the field and effective index data.

to_mode_solver_monitor(name[, colocate])

Creates ModeSolverMonitor from a ModeSolver instance.

to_monitor([freqs, name])

Creates ModeMonitor from a ModeSolver instance plus additional specifications.

to_source(source_time[, direction, mode_index])

Creates ModeSource from a ModeSolver instance plus additional specifications.

validate_pre_upload([source_required])

Inherited Common Usage

simulation#
plane#
mode_spec#
freqs#
direction#
colocate#
classmethod is_plane(val)[source]#

Raise validation error if not planar.

classmethod plane_in_sim_bounds(val, values)[source]#

Check that the plane is at least partially inside the simulation bounds.

property normal_axis#

Axis normal to the mode plane.

property solver_symmetry#

Get symmetry for solver for propagation along self.normal axis.

solve()[source]#

ModeSolverData containing the field and effective index data.

Returns:

ModeSolverData object containing the effective index and mode fields.

Return type:

ModeSolverData

property grid_snapped#

The solver grid snapped to the plane normal and to simulation 0-sized dims if any.

property data_raw#

ModeSolverData containing the field and effective index on unexpanded grid.

Returns:

ModeSolverData object containing the effective index and mode fields.

Return type:

ModeSolverData

property data#

ModeSolverData containing the field and effective index data.

Returns:

ModeSolverData object containing the effective index and mode fields.

Return type:

ModeSolverData

property sim_data#

SimulationData object containing the ModeSolverData for this object.

Returns:

SimulationData object containing the effective index and mode fields.

Return type:

SimulationData

to_source(source_time, direction=None, mode_index=0)[source]#

Creates ModeSource from a ModeSolver instance plus additional specifications.

Parameters:
  • source_time (SourceTime) – Specification of the source time-dependence.

  • direction (Direction = None) – Whether source will inject in "+" or "-" direction relative to plane normal. If not specified, uses the direction from the mode solver.

  • mode_index (int = 0) – Index into the list of modes returned by mode solver to use in source.

Returns:

Mode source with specifications taken from the ModeSolver instance and the method inputs.

Return type:

ModeSource

to_monitor(freqs=None, name=None)[source]#

Creates ModeMonitor from a ModeSolver instance plus additional specifications.

Parameters:
  • freqs (List[float]) – Frequencies to include in Monitor (Hz). If not specified, passes self.freqs.

  • name (str) – Required name of monitor.

Returns:

Mode monitor with specifications taken from the ModeSolver instance and the method inputs.

Return type:

ModeMonitor

to_mode_solver_monitor(name, colocate=None)[source]#

Creates ModeSolverMonitor from a ModeSolver instance.

Parameters:
  • name (str) – Name of the monitor.

  • colocate (bool) – Whether to colocate fields or compute on the Yee grid. If not provided, the value set in the ModeSolver instance is used.

Returns:

Mode monitor with specifications taken from the ModeSolver instance and name.

Return type:

ModeSolverMonitor

sim_with_source(source_time, direction=None, mode_index=0)[source]#

Creates Simulation from a ModeSolver. Creates a copy of the ModeSolver’s original simulation with a ModeSource added corresponding to the ModeSolver parameters.

Parameters:
  • source_time (SourceTime) – Specification of the source time-dependence.

  • direction (Direction = None) – Whether source will inject in "+" or "-" direction relative to plane normal. If not specified, uses the direction from the mode solver.

  • mode_index (int = 0) – Index into the list of modes returned by mode solver to use in source.

Returns:

Copy of the simulation with a ModeSource with specifications taken from the ModeSolver instance and the method inputs.

Return type:

Simulation

sim_with_monitor(freqs=None, name=None)[source]#

Creates Simulation from a ModeSolver. Creates a copy of the ModeSolver’s original simulation with a mode monitor added corresponding to the ModeSolver parameters.

Parameters:
  • freqs (List[float] = None) – Frequencies to include in Monitor (Hz). If not specified, uses the frequencies from the mode solver.

  • name (str) – Required name of monitor.

Returns:

Copy of the simulation with a ModeMonitor with specifications taken from the ModeSolver instance and the method inputs.

Return type:

Simulation

sim_with_mode_solver_monitor(name)[source]#

Creates Simulation from a ModeSolver. Creates a copy of the ModeSolver’s original simulation with a mode solver monitor added corresponding to the ModeSolver parameters.

Parameters:

name (str) – Name of the monitor.

Returns:

Copy of the simulation with a ModeSolverMonitor with specifications taken from the ModeSolver instance and name.

Return type:

Simulation

plot_field(field_name, val='real', scale='lin', eps_alpha=0.2, robust=True, vmin=None, vmax=None, ax=None, **sel_kwargs)[source]#

Plot the field for a ModeSolverData with Simulation plot overlaid.

Parameters:
  • field_name (str) – Name of field component to plot (eg. 'Ex'). Also accepts 'E' and 'H' to plot the vector magnitudes of the electric and magnetic fields, and 'S' for the Poynting vector.

  • val (Literal['real', 'imag', 'abs', 'abs^2', 'dB'] = 'real') – Which part of the field to plot.

  • eps_alpha (float = 0.2) – Opacity of the structure permittivity. Must be between 0 and 1 (inclusive).

  • robust (bool = True) – If True and vmin or vmax are absent, uses the 2nd and 98th percentiles of the data to compute the color limits. This helps in visualizing the field patterns especially in the presence of a source.

  • vmin (float = None) – The lower bound of data range that the colormap covers. If None, they are inferred from the data and other keyword arguments.

  • vmax (float = None) – The upper bound of data range that the colormap covers. If None, they are inferred from the data and other keyword arguments.

  • ax (matplotlib.axes._subplots.Axes = None) – matplotlib axes to plot on, if not specified, one is created.

  • sel_kwargs (keyword arguments used to perform .sel() selection in the monitor data.) – These kwargs can select over the spatial dimensions (x, y, z), frequency or time dimensions (f, t) or mode_index, if applicable. For the plotting to work appropriately, the resulting data after selection must contain only two coordinates with len > 1. Furthermore, these should be spatial coordinates (x, y, or z).

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

plot(ax=None, **patch_kwargs)[source]#

Plot the mode plane simulation’s components.

Parameters:

ax (matplotlib.axes._subplots.Axes = None) – Matplotlib axes to plot on, if not specified, one is created.

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

plot_eps(freq=None, alpha=None, ax=None)[source]#

Plot the mode plane simulation’s components. The permittivity is plotted in grayscale based on its value at the specified frequency.

Parameters:
  • freq (float = None) – Frequency to evaluate the relative permittivity of all mediums. If not specified, evaluates at infinite frequency.

  • alpha (float = None) – Opacity of the structures being plotted. Defaults to the structure default alpha.

  • ax (matplotlib.axes._subplots.Axes = None) – Matplotlib axes to plot on, if not specified, one is created.

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

plot_structures_eps(freq=None, alpha=None, cbar=True, reverse=False, ax=None)[source]#

Plot the mode plane simulation’s components. The permittivity is plotted in grayscale based on its value at the specified frequency.

Parameters:
  • freq (float = None) – Frequency to evaluate the relative permittivity of all mediums. If not specified, evaluates at infinite frequency.

  • alpha (float = None) – Opacity of the structures being plotted. Defaults to the structure default alpha.

  • cbar (bool = True) – Whether to plot a colorbar for the relative permittivity.

  • reverse (bool = False) – If False, the highest permittivity is plotted in black. If True, it is plotteed in white (suitable for black backgrounds).

  • ax (matplotlib.axes._subplots.Axes = None) – Matplotlib axes to plot on, if not specified, one is created.

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

plot_grid(ax=None, **kwargs)[source]#

Plot the mode plane cell boundaries as lines.

Parameters:
  • ax (matplotlib.axes._subplots.Axes = None) – Matplotlib axes to plot on, if not specified, one is created.

  • **kwargs – Optional keyword arguments passed to the matplotlib LineCollection. For details on accepted values, refer to Matplotlib’s documentation.

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

plot_pml(ax=None)[source]#

Plot the mode plane absorbing boundaries.

Parameters:

ax (matplotlib.axes._subplots.Axes = None) – Matplotlib axes to plot on, if not specified, one is created.

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

validate_pre_upload(source_required=True)[source]#
property reduced_simulation_copy#

Strip objects not used by the mode solver from simulation object. This might significantly reduce upload time in the presence of custom mediums.

__hash__()#

Hash method.