tidy3d.plugins.mode.ModeSolverData#
- class ModeSolverData[source]#
Bases:
ModeDataData associated with a
ModeSolverMonitor: scalar components of E and H fields.- 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,
attrsare mutable. For example, the following is allowed for setting anattrobj.attrs['foo'] = bar. Also note that Tidy3D will raise aTypeErrorifattrscontain objects that can not be serialized. One can check ifattrsare serializable by callingobj.json().Ex (Optional[ScalarModeFieldDataArray] = None) – Spatial distribution of the x-component of the electric field of the mode.
Ey (Optional[ScalarModeFieldDataArray] = None) – Spatial distribution of the y-component of the electric field of the mode.
Ez (Optional[ScalarModeFieldDataArray] = None) – Spatial distribution of the z-component of the electric field of the mode.
Hx (Optional[ScalarModeFieldDataArray] = None) – Spatial distribution of the x-component of the magnetic field of the mode.
Hy (Optional[ScalarModeFieldDataArray] = None) – Spatial distribution of the y-component of the magnetic field of the mode.
Hz (Optional[ScalarModeFieldDataArray] = None) – Spatial distribution of the z-component of the magnetic field of the mode.
monitor (ModeSolverMonitor) – Mode solver monitor associated with the data.
symmetry (Tuple[Literal[0, -1, 1], Literal[0, -1, 1], Literal[0, -1, 1]] = (0, 0, 0)) – Symmetry eigenvalues of the original simulation in x, y, and z.
symmetry_center (Optional[Tuple[float, float, float]] = None) – Center of the symmetry planes of the original simulation in x, y, and z. Required only if any of the
symmetryfield are non-zero.grid_expanded (Optional[Grid] = None) –
Griddiscretization of the associated monitor in the simulation which created the data. Required if symmetries are present, as well as in order to use some functionalities like getting Poynting vector and flux.grid_primal_correction (Union[float, FreqDataArray, TimeDataArray, FreqModeDataArray, EMEFreqModeDataArray] = 1.0) – Correction factor that needs to be applied for data corresponding to a 2D monitor to take into account the finite grid in the normal direction in the simulation in which the data was computed. The factor is applied to fields defined on the primal grid locations along the normal direction.
grid_dual_correction (Union[float, FreqDataArray, TimeDataArray, FreqModeDataArray, EMEFreqModeDataArray] = 1.0) – Correction factor that needs to be applied for data corresponding to a 2D monitor to take into account the finite grid in the normal direction in the simulation in which the data was computed. The factor is applied to fields defined on the dual grid locations along the normal direction.
n_complex (ModeIndexDataArray) – Complex-valued effective propagation constants associated with the mode.
n_group_raw (Optional[GroupIndexDataArray] = None) – Index associated with group velocity of the mode.
dispersion_raw (Optional[ModeDispersionDataArray] = None) – [units = ps/(nm km)]. Dispersion parameter for the mode.
amps (Optional[ModeAmpsDataArray] = None) – Unused for ModeSolverData.
eps_spec (Optional[List[Literal['diagonal', 'tensorial_real', 'tensorial_complex']]] = None) – Characterization of the permittivity profile on the plane where modes are computed. Possible values are ‘diagonal’, ‘tensorial_real’, ‘tensorial_complex’.
grid_distances_primal (Union[tuple[float], tuple[float, float]] = (0.0,)) – Relative distances to the primal grid locations along the normal direction in the original simulation grid. Needed to recalculate grid corrections after interpolating in frequency.
grid_distances_dual (Union[tuple[float], tuple[float, float]] = (0.0,)) – Relative distances to the dual grid locations along the normal direction in the original simulation grid. Needed to recalculate grid corrections after interpolating in frequency.
Notes
The data is stored as a DataArray object using the xarray package.
Example
>>> from tidy3d import ModeSpec >>> from tidy3d import ScalarModeFieldDataArray, ModeIndexDataArray >>> x = [-1,1,3] >>> y = [-2,0] >>> z = [-3,-1,1,3,5] >>> f = [2e14, 3e14] >>> mode_index = np.arange(5) >>> grid = Grid(boundaries=Coords(x=x, y=y, z=z)) >>> field_coords = dict(x=x[:-1], y=y[:-1], z=z[:-1], f=f, mode_index=mode_index) >>> field = ScalarModeFieldDataArray((1+1j)*np.random.random((2,1,4,2,5)), coords=field_coords) >>> index_coords = dict(f=f, mode_index=mode_index) >>> index_data = ModeIndexDataArray((1+1j) * np.random.random((2,5)), coords=index_coords) >>> monitor = ModeSolverMonitor( ... size=(2,0,6), ... freqs=[2e14, 3e14], ... mode_spec=ModeSpec(num_modes=5), ... name='mode_solver', ... ) >>> data = ModeSolverData( ... monitor=monitor, ... Ex=field, ... Ey=field, ... Ez=field, ... Hx=field, ... Hy=field, ... Hz=field, ... n_complex=index_data, ... grid_expanded=grid ... )
Attributes
Return a copy of the data with interpolated fields.
Make a copy of the data with direction-reversed fields.
Methods
interp_in_freq(freqs[, method, renormalize, ...])Interpolate mode data to new frequency points.
normalize(source_spectrum_fn)Return copy of self after normalization is applied using source spectrum function.
Inherited Common Usage
- monitor#
- amps#
- grid_distances_primal#
- grid_distances_dual#
- normalize(source_spectrum_fn)[source]#
Return copy of self after normalization is applied using source spectrum function.
- interp_in_freq(freqs, method='linear', renormalize=True, recalculate_grid_correction=True, assume_sorted=False)[source]#
Interpolate mode data to new frequency points.
Interpolates all stored mode data (effective indices, field components, group indices, and dispersion) from the current frequency grid to a new set of frequencies. This is useful for obtaining mode data at many frequencies from computations at fewer frequencies, when modes vary smoothly with frequency.
- Parameters:
freqs (FreqArray) – New frequency points to interpolate to. Should generally span a similar range as the original frequencies to avoid extrapolation.
method (Literal["linear", "cubic", "poly"]) – Interpolation method.
"linear"for linear interpolation (requires 2+ source frequencies),"cubic"for cubic spline interpolation (requires 4+ source frequencies),"poly"for polynomial interpolation using barycentric formula (requires 3+ source frequencies). For complex-valued data, real and imaginary parts are interpolated independently.renormalize (bool = True) – Whether to renormalize the mode profiles to unity power after interpolation.
recalculate_grid_correction (bool = True) – Whether to recalculate the grid correction factors after interpolation or use interpolated grid corrections.
assume_sorted (bool = False,) – Whether to assume the frequency points are sorted.
- Returns:
New
ModeSolverDataobject with data interpolated to the requested frequencies.- Return type:
Note
Interpolation assumes modes vary smoothly with frequency. Results may be inaccurate near mode crossings or regions of rapid mode variation. Use frequency tracking (
mode_spec.sort_spec.track_freq) to help maintain mode ordering consistency.Example
>>> # Compute modes at 5 frequencies >>> import numpy as np >>> freqs_sparse = np.linspace(1e14, 2e14, 5) >>> # ... create mode_solver and compute modes ... >>> # mode_data = mode_solver.solve() >>> # Interpolate to 50 frequencies >>> freqs_dense = np.linspace(1e14, 2e14, 50) >>> # mode_data_interp = mode_data.interp(freqs=freqs_dense, method='linear')
- property interpolated_copy#
Return a copy of the data with interpolated fields.
- property time_reversed_copy#
Make a copy of the data with direction-reversed fields. In lossy or gyrotropic systems, the time-reversed fields will not be the same as the backward-propagating modes.
- __hash__()#
Hash method.
- eps_spec#
- Ex#
- Ey#
- Ez#
- Hx#
- Hy#
- Hz#
- n_complex#
- n_group_raw#
- dispersion_raw#
- grid_primal_correction#
- grid_dual_correction#
- symmetry#
- symmetry_center#
- grid_expanded#
- attrs#