tidy3d.ModeInterpSpec#
- class ModeInterpSpec[source]#
Bases:
Tidy3dBaseModelSpecification 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,
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().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. IfTrue, 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_freqmust not beNone) 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
ModeSolverMode solver that can use this specification for efficient broadband computation.
ModeSolverMonitorMonitor that can use this specification to reduce mode computation cost.
ModeMonitorMonitor that can use this specification to reduce mode computation cost.
Attributes
Number of sampling points.
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:
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:
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:
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.