Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dbochkov-flexcompute committed Dec 9, 2024
1 parent a107cd8 commit 163804e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/test_components/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3067,7 +3067,7 @@ def test_fixed_angle_sim():
run_time=10 / fwidth,
)

# assert sim.i
assert sim._is_fixed_angle

with pytest.raises(pydantic.ValidationError):
_ = sim.updated_copy(
Expand Down
19 changes: 10 additions & 9 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2428,12 +2428,12 @@ def plane_wave_boundaries(cls, val, values):
num_bloch = sum(isinstance(bnd, BlochBoundary) for bnd in boundary)
if num_bloch > 0:
raise SetupError(
"Fixed angle plane wave sources ('FixedAngleSpec' and `angle_theta != 0`) do "
"Fixed angle plane wave sources ('FixedAngleSpec' and 'angle_theta' != 0) do "
f"not require the Bloch boundary along dimension {tan_dir}. "
"Either set the boundary conditions to 'Periodic' to proceed to simulate a plane "
"wave with frequency-independent propagation direction, or switch to "
"'FixedInPlaneKSpec' specification to simulate a plane wave with "
"frequency-dependent propagation direction."
"'FixedInPlaneKSpec' specification to simulate a plane wave with a fixed "
"in-plane Bloch vector (frequency-dependent propagation direction)."
)
else:
num_bloch = sum(isinstance(bnd, (Periodic, BlochBoundary)) for bnd in boundary)
Expand Down Expand Up @@ -2573,14 +2573,15 @@ def tfsf_with_symmetry(cls, val, values):
return val

@staticmethod
def _get_fixed_angle_sources(sources: Tuple[SourceType, ...]):
def _get_fixed_angle_sources(sources: Tuple[SourceType, ...]) -> Tuple[SourceType, ...]:
"""Get list of plane wave sources with ``FixedAngleSpec``."""

return [
source for source in sources if isinstance(source, PlaneWave) and source._is_fixed_angle
]

@pydantic.root_validator(skip_on_failure=True)
@pydantic.root_validator()
@skip_if_fields_missing(["sources", "structures", "medium", "monitors"], root=True)
def check_fixed_angle_components(cls, values):
"""Error if a fixed-angle plane wave is combined with other sources
or fully anisotropic mediums or gain mediums."""
Expand Down Expand Up @@ -3939,13 +3940,13 @@ def background_structure(self) -> Structure:
return self.scene.background_structure

@cached_property
def _fixed_angle_sources(self):
def _fixed_angle_sources(self) -> Tuple[SourceType, ...]:
"""List of plane wave sources with ``FixedAngleSpec``."""
return self._get_fixed_angle_sources(self.sources)

@cached_property
def _is_fixed_angle(self):
"""List of plane wave sources with ``FixedAngleSpec``."""
def _is_fixed_angle(self) -> bool:
"""Whether the simulation contains fixed angle sources."""
return len(self._fixed_angle_sources) > 0

# candidate for removal in 3.0
Expand Down Expand Up @@ -4373,7 +4374,7 @@ def plot_3d(self, width=800, height=800) -> None:
""" Discretization """

@cached_property
def _dt_fixed_angle_reduction_factor(self):
def _dt_fixed_angle_reduction_factor(self) -> float:
"""Reduction in time step due to plane wave source with ``FixedAngleSpec``."""
if self._is_fixed_angle:
theta = self._fixed_angle_sources[0].angle_theta
Expand Down

0 comments on commit 163804e

Please sign in to comment.