Skip to content

Commit 3257a0b

Browse files
comments
1 parent c95018a commit 3257a0b

File tree

3 files changed

+42
-75
lines changed

3 files changed

+42
-75
lines changed

schemas/TerminalComponentModeler.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11544,12 +11544,12 @@
1154411544
"type": "number"
1154511545
},
1154611546
"max_sampling_time": {
11547-
"default": 5,
11547+
"default": 5.0,
1154811548
"minimum": 0,
1154911549
"type": "number"
1155011550
},
1155111551
"min_sampling_time": {
11552-
"default": 1,
11552+
"default": 1.0,
1155311553
"minimum": 0,
1155411554
"type": "number"
1155511555
},

tidy3d/components/frequency_extrapolation.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,8 @@
99
from tidy3d.components.base import Tidy3dBaseModel
1010

1111

12-
class LowFrequencySmoothingSpec(Tidy3dBaseModel):
13-
"""Specifies the low frequency smoothing parameters for the terminal component simulation.
14-
The low frequency smoothing is performed by fitting a polynomial to the data in the trusted frequency range,
15-
defined by the minimum and maximum sampling times, and then using the polynomial to extrapolate
16-
the data outside of the trusted frequency range into lower frequencies.
17-
18-
Example
19-
-------
20-
>>> low_freq_smoothing = LowFrequencySmoothingSpec(
21-
... min_sampling_time=3,
22-
... max_sampling_time=6,
23-
... order=1,
24-
... max_deviation=0.5,
25-
... monitors=("monitor1", "monitor2"),
26-
... )
27-
"""
12+
class AbstractLowFrequencySmoothingSpec(Tidy3dBaseModel):
13+
"""Abstract base class for low frequency smoothing specifications."""
2814

2915
min_sampling_time: pydantic.NonNegativeFloat = pydantic.Field(
3016
1.0,
@@ -55,23 +41,40 @@ class LowFrequencySmoothingSpec(Tidy3dBaseModel):
5541
ge=0,
5642
)
5743

58-
monitors: tuple[str, ...] = pydantic.Field(
59-
...,
60-
title="Monitors",
61-
description="The monitors to use for the low frequency smoothing.",
62-
)
63-
6444
@pydantic.root_validator(skip_on_failure=True)
6545
def _validate_sampling_times(cls, values):
6646
min_sampling_time = values.get("min_sampling_time")
6747
max_sampling_time = values.get("max_sampling_time")
68-
if min_sampling_time is not None and max_sampling_time is not None:
69-
if min_sampling_time >= max_sampling_time:
70-
raise ValueError(
71-
"The minimum sampling time must be less than the maximum sampling time."
72-
)
48+
if min_sampling_time >= max_sampling_time:
49+
raise ValueError(
50+
"The minimum sampling time must be less than the maximum sampling time."
51+
)
7352
return values
7453

54+
55+
class LowFrequencySmoothingSpec(AbstractLowFrequencySmoothingSpec):
56+
"""Specifies the low frequency smoothing parameters for the simulation.
57+
This specification affects only results recorded in mode monitors. Specifically, the mode decomposition data
58+
for frequencies for which the total simulation time in units of the corresponding period (T = 1/f) is less than
59+
the specified minimum sampling time will be overridden by extrapolation from the data in the trusted frequency range.
60+
The trusted frequency range is defined in terms of minimum and maximum sampling times (the total simulation time divided by the corresponding period).
61+
Example
62+
-------
63+
>>> low_freq_smoothing = LowFrequencySmoothingSpec(
64+
... min_sampling_time=3,
65+
... max_sampling_time=6,
66+
... order=1,
67+
... max_deviation=0.5,
68+
... monitors=("monitor1", "monitor2"),
69+
... )
70+
"""
71+
72+
monitors: tuple[str, ...] = pydantic.Field(
73+
...,
74+
title="Monitors",
75+
description="The monitors to use for the low frequency smoothing.",
76+
)
77+
7578
@pydantic.validator("monitors", always=True)
7679
def _validate_monitors(cls, val, values):
7780
"""Validate the monitors list is not empty."""

tidy3d/plugins/smatrix/component_modelers/terminal.py

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import numpy as np
88
import pydantic.v1 as pd
99

10-
from tidy3d.components.base import Tidy3dBaseModel, cached_property
10+
from tidy3d.components.base import cached_property
1111
from tidy3d.components.boundary import BroadbandModeABCSpec
12-
from tidy3d.components.frequency_extrapolation import LowFrequencySmoothingSpec
12+
from tidy3d.components.frequency_extrapolation import (
13+
AbstractLowFrequencySmoothingSpec,
14+
LowFrequencySmoothingSpec,
15+
)
1316
from tidy3d.components.geometry.utils_2d import snap_coordinate_to_grid
1417
from tidy3d.components.index import SimulationMap
1518
from tidy3d.components.monitor import DirectivityMonitor, ModeMonitor
@@ -33,11 +36,12 @@
3336
from tidy3d.plugins.smatrix.types import NetworkElement, NetworkIndex, SParamDef
3437

3538

36-
class ModelerLowFrequencySmoothingSpec(Tidy3dBaseModel):
39+
class ModelerLowFrequencySmoothingSpec(AbstractLowFrequencySmoothingSpec):
3740
"""Specifies the low frequency smoothing parameters for the terminal component simulation.
38-
The low frequency smoothing is performed by fitting a polynomial to the data in the trusted frequency range,
39-
defined by the minimum and maximum sampling times, and then using the polynomial to extrapolate
40-
the data outside of the trusted frequency range into lower frequencies.
41+
This specification affects only results at wave ports. Specifically, the mode decomposition data
42+
for frequencies for which the total simulation time in units of the corresponding period (T = 1/f) is less than
43+
the specified minimum sampling time will be overridden by extrapolation from the data in the trusted frequency range.
44+
The trusted frequency range is defined in terms of minimum and maximum sampling times (the total simulation time divided by the corresponding period).
4145
4246
Example
4347
-------
@@ -49,46 +53,6 @@ class ModelerLowFrequencySmoothingSpec(Tidy3dBaseModel):
4953
... )
5054
"""
5155

52-
min_sampling_time: pd.NonNegativeFloat = pd.Field(
53-
1,
54-
title="Minimum Sampling Time (periods)",
55-
description="The minimum simulation time in periods of the corresponding frequency for which frequency domain results will be used to fit the polynomial for the low frequency extrapolation. "
56-
"Results below this threshold will be completely discarded.",
57-
)
58-
59-
max_sampling_time: pd.NonNegativeFloat = pd.Field(
60-
5,
61-
title="Maximum Sampling Time (periods)",
62-
description="The maximum simulation time in periods of the corresponding frequency for which frequency domain results will be used to fit the polynomial for the low frequency extrapolation. "
63-
"Results above this threshold will be not be modified.",
64-
)
65-
66-
order: int = pd.Field(
67-
1,
68-
title="Extrapolation Order",
69-
description="The order of the polynomial to use for the low frequency extrapolation.",
70-
ge=0,
71-
le=3,
72-
)
73-
74-
max_deviation: Optional[float] = pd.Field(
75-
0.5,
76-
title="Maximum Deviation",
77-
description="The maximum deviation (in fraction of the trusted values) to allow for the low frequency smoothing.",
78-
ge=0,
79-
)
80-
81-
@pd.root_validator(skip_on_failure=True)
82-
def _validate_sampling_times(cls, values):
83-
min_sampling_time = values.get("min_sampling_time")
84-
max_sampling_time = values.get("max_sampling_time")
85-
if min_sampling_time is not None and max_sampling_time is not None:
86-
if min_sampling_time >= max_sampling_time:
87-
raise ValueError(
88-
"The minimum sampling time must be less than the maximum sampling time."
89-
)
90-
return values
91-
9256

9357
DEFAULT_LOW_FREQUENCY_SMOOTHING_SPEC = ModelerLowFrequencySmoothingSpec()
9458

0 commit comments

Comments
 (0)