From 7131f842277e8342ec2c6f0f60c8c33b998c6d41 Mon Sep 17 00:00:00 2001 From: dbochkov-flexcompute Date: Wed, 30 Nov 2022 15:58:31 -0600 Subject: [PATCH] Shrink frequency range for broadband sources to +/- 1.5 * fwidth --- tests/test_components/test_source.py | 4 ++-- tidy3d/components/source.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_components/test_source.py b/tests/test_components/test_source.py index 90d813fd9..305ef7e15 100644 --- a/tests/test_components/test_source.py +++ b/tests/test_components/test_source.py @@ -5,7 +5,7 @@ import numpy as np import tidy3d as td from tidy3d.log import SetupError, DataError, ValidationError -from tidy3d.components.source import DirectionalSource +from tidy3d.components.source import DirectionalSource, CHEB_GRID_WIDTH _, AX = plt.subplots() @@ -156,7 +156,7 @@ def get_pol_dir(axis, pol_angle=0, angle_theta=0, angle_phi=0): def test_broadband_source(): g = td.GaussianPulse(freq0=1, fwidth=0.1) mode_spec = td.ModeSpec(num_modes=2) - fmin, fmax = g.frequency_range(num_fwidth=4) + fmin, fmax = g.frequency_range(num_fwidth=CHEB_GRID_WIDTH) fdiff = (fmax - fmin) / 2 fmean = (fmax + fmin) / 2 diff --git a/tidy3d/components/source.py b/tidy3d/components/source.py index 45acdc6dd..f4c1ed4f5 100644 --- a/tidy3d/components/source.py +++ b/tidy3d/components/source.py @@ -25,6 +25,8 @@ # when checking if custom data spans the source plane, allow for a small tolerance # due to numerical precision DATA_SPAN_TOL = 1e-8 +# width of Chebyshev grid used for broadband sources (in units of pulse width) +CHEB_GRID_WIDTH = 1.5 class SourceTime(ABC, Tidy3dBaseModel): @@ -475,7 +477,7 @@ class BroadbandSource(Source, ABC): @cached_property def frequency_grid(self) -> np.ndarray: """A Chebyshev grid used to approximate frequency dependence.""" - freq_min, freq_max = self.source_time.frequency_range(num_fwidth=4) + freq_min, freq_max = self.source_time.frequency_range(num_fwidth=CHEB_GRID_WIDTH) freq_avg = 0.5 * (freq_min + freq_max) freq_diff = 0.5 * (freq_max - freq_min) uni_points = (2 * np.arange(self.num_freqs) + 1) / (2 * self.num_freqs)