tidy3d.ModeInterpSpec#

class ModeInterpSpec[source]#

Bases: Tidy3dBaseModel

Specification for mode frequency interpolation.

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

  • sampling_spec (Union[UniformSampling, ChebSampling, CustomSampling]) – Specification for frequency sampling points.

  • method (Literal['linear', 'cubic', 'poly'] = linear) – Method for interpolating mode data between computed frequencies. ‘linear’ uses linear interpolation (faster, requires 2+ points). ‘cubic’ uses cubic spline interpolation (smoother, more accurate, requires 4+ points). ‘poly’ uses polynomial interpolation with barycentric formula (optimal for Chebyshev nodes, requires 3+ points). For complex-valued data, real and imaginary parts are interpolated independently.

  • reduce_data (bool = False) – Applies only to ModeSolverData. If True, fields and quantities are only recorded at interpolation source frequency points. The data at requested frequencies can be obtained through interpolation. This can significantly reduce storage and computational costs for broadband simulations. Does not apply if the number of sampling points is greater than the number of monitor frequencies.

Notes

Allows computing modes at a reduced set of frequencies and interpolating to obtain results at all requested frequencies. This can significantly reduce computational cost for broadband simulations where modes vary smoothly with frequency.

Requires frequency tracking to be enabled (mode_spec.sort_spec.track_freq must not be None) to ensure mode ordering is consistent across frequencies.

Example

>>> # Uniform sampling with linear interpolation
>>> interp_spec = ModeInterpSpec(
...     method='linear',
...     sampling_spec=UniformSampling(num_points=10)
... )
>>> # Chebyshev sampling with polynomial interpolation
>>> interp_spec = ModeInterpSpec.cheb(num_points=10)
>>> # Custom sampling with cubic interpolation
>>> custom_freqs = [1e14, 1.5e14, 2e14, 2.5e14]
>>> interp_spec = ModeInterpSpec.custom(method='cubic', freqs=custom_freqs)

See also

ModeSolver

Mode solver that can use this specification for efficient broadband computation.

ModeSolverMonitor

Monitor that can use this specification to reduce mode computation cost.

ModeMonitor

Monitor that can use this specification to reduce mode computation cost.

Attributes

num_points

Number of sampling points.

attrs

Methods

cheb(num_points[, reduce_data])

Create a ModeInterpSpec with Chebyshev node sampling and polynomial interpolation.

custom(freqs[, method, reduce_data])

Create a ModeInterpSpec with custom frequency sampling.

sampling_points(freqs)

Compute frequency sampling points.

uniform(num_points[, method, reduce_data])

Create a ModeInterpSpec with uniform frequency sampling.

Inherited Common Usage

sampling_spec#
method#
reduce_data#
classmethod uniform(num_points, method='linear', reduce_data=False)[source]#

Create a ModeInterpSpec with uniform frequency sampling.

Parameters:
  • num_points (int) – Number of uniformly spaced sampling points.

  • method (Literal["linear", "cubic", "poly"]) – Interpolation method. Default is ‘linear’.

  • reduce_data (bool) – Whether to reduce data storage. Default is False.

Returns:

Interpolation specification with uniform sampling.

Return type:

ModeInterpSpec

Example

>>> interp_spec = ModeInterpSpec.uniform(num_points=10, method='cubic')
classmethod cheb(num_points, reduce_data=False)[source]#

Create a ModeInterpSpec with Chebyshev node sampling and polynomial interpolation.

Chebyshev nodes provide optimal sampling for polynomial interpolation, minimizing interpolation error for smooth functions.

Parameters:
  • num_points (int) – Number of Chebyshev nodes (minimum 3).

  • reduce_data (bool) – Whether to reduce data storage. Default is False.

Returns:

Interpolation specification with Chebyshev sampling and polynomial interpolation.

Return type:

ModeInterpSpec

Example

>>> interp_spec = ModeInterpSpec.cheb(num_points=10)
classmethod custom(freqs, method='linear', reduce_data=False)[source]#

Create a ModeInterpSpec with custom frequency sampling.

Parameters:
  • freqs (FreqArray) – Custom array of frequency sampling points.

  • method (Literal["linear", "cubic", "poly"]) – Interpolation method. Default is ‘linear’.

  • reduce_data (bool) – Whether to reduce data storage. Default is False.

Returns:

Interpolation specification with custom sampling.

Return type:

ModeInterpSpec

Example

>>> custom_freqs = [1e14, 1.5e14, 1.8e14, 2e14]
>>> interp_spec = ModeInterpSpec.custom(freqs=custom_freqs, method='cubic')
property num_points#

Number of sampling points.

sampling_points(freqs)[source]#

Compute frequency sampling points.

Parameters:

freqs (FreqArray) – Target frequency array.

Returns:

Array of frequency sampling points.

Return type:

FreqArray

Example

>>> import numpy as np
>>> freqs = np.linspace(1e14, 2e14, 100)
>>> interp_spec = ModeInterpSpec.cheb(num_points=10)
>>> sampling_freqs = interp_spec.sampling_points(freqs)
__hash__()#

Hash method.