Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink frequency range for broadband sources to +/- 1.5 * fwidth #585

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/test_components/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tidy3d/components/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down