|
8 | 8 | import pydantic.v1 as pd |
9 | 9 |
|
10 | 10 | from tidy3d.components.autograd.constants import MAX_NUM_ADJOINT_PER_FWD |
11 | | -from tidy3d.components.base import Tidy3dBaseModel, cached_property |
| 11 | +from tidy3d.components.base import Tidy3dBaseModel, cached_property, skip_if_fields_missing |
12 | 12 | from tidy3d.components.geometry.utils import _shift_value_signed |
13 | 13 | from tidy3d.components.simulation import Simulation |
| 14 | +from tidy3d.components.source.time import SourceTimeType |
14 | 15 | from tidy3d.components.types import Complex, FreqArray |
15 | 16 | from tidy3d.components.validators import ( |
16 | 17 | assert_unique_names, |
@@ -94,6 +95,12 @@ class AbstractComponentModeler(ABC, Tidy3dBaseModel): |
94 | 95 | "matrix element. If all elements of a given column of the scattering matrix are defined " |
95 | 96 | "by ``element_mappings``, the simulation corresponding to this column is skipped automatically.", |
96 | 97 | ) |
| 98 | + custom_source_time: Optional[SourceTimeType] = pd.Field( |
| 99 | + None, |
| 100 | + title="Custom Source Time", |
| 101 | + description="If provided, this will be used as specification of the source time-dependence in simulations. " |
| 102 | + "Otherwise, a default source time will be constructed.", |
| 103 | + ) |
97 | 104 |
|
98 | 105 | @pd.validator("simulation", always=True) |
99 | 106 | def _sim_has_no_sources(cls, val): |
@@ -130,6 +137,21 @@ def _validate_element_mappings(cls, element_mappings, values): |
130 | 137 | _freqs_lower_bound = validate_freqs_min() |
131 | 138 | _freqs_unique = validate_freqs_unique() |
132 | 139 |
|
| 140 | + @pd.validator("custom_source_time", always=True) |
| 141 | + @skip_if_fields_missing(["freqs"]) |
| 142 | + def _freqs_in_custom_source_time(cls, val, values): |
| 143 | + """Make sure freqs is in the range of the custom source time.""" |
| 144 | + if val is None: |
| 145 | + return val |
| 146 | + freq_range = val._frequency_range_sigma_cached |
| 147 | + freqs = values["freqs"] |
| 148 | + |
| 149 | + if freq_range[0] > min(freqs) or max(freqs) > freq_range[1]: |
| 150 | + log.warning( |
| 151 | + "Custom source time does not cover all 'freqs'.", |
| 152 | + ) |
| 153 | + return val |
| 154 | + |
133 | 155 | @staticmethod |
134 | 156 | def get_task_name( |
135 | 157 | port: Port, mode_index: Optional[int] = None, format: Optional[TaskNameFormat] = "RF" |
|
0 commit comments