Skip to content

Commit 837a080

Browse files
committed
add validator back to simulation for incorrect auto impedance mode spec
1 parent e320a18 commit 837a080

File tree

5 files changed

+490
-0
lines changed

5 files changed

+490
-0
lines changed

tests/test_components/test_microwave.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pydantic.v1 as pd
1111
import pytest
1212
import xarray as xr
13+
from shapely import LineString
1314

1415
import tidy3d as td
1516
import tidy3d.components.microwave.path_integrals.current_spec
@@ -22,6 +23,9 @@
2223
mutual_inductance_colinear_wire_segments,
2324
total_inductance_colinear_rectangular_wire_segments,
2425
)
26+
from tidy3d.components.microwave.path_integrals.mode_plane_analyzer import (
27+
ModePlaneAnalyzer,
28+
)
2529
from tidy3d.components.microwave.path_integrals.path_integral_factory import (
2630
make_current_integral,
2731
make_path_integrals,
@@ -466,6 +470,51 @@ def test_path_integral_creation():
466470
)
467471

468472

473+
def test_mode_plane_analyzer_errors():
474+
"""Check that the ModePlaneAnalyzer reports errors properly."""
475+
476+
path_spec_gen = ModePlaneAnalyzer(size=(0, 2, 2), field_data_colocated=False)
477+
478+
# First some quick sanity checks with the helper
479+
test_path = td.Box(center=(0, 0, 0), size=(0, 0.9, 0.1))
480+
test_shapely = [LineString([(-1, 0), (1, 0)])]
481+
assert path_spec_gen._check_box_intersects_with_conductors(test_shapely, test_path)
482+
483+
test_path = td.Box(center=(0, 0, 0), size=(0, 2.1, 0.1))
484+
test_shapely = [LineString([(-1, 0), (1, 0)])]
485+
assert not path_spec_gen._check_box_intersects_with_conductors(test_shapely, test_path)
486+
487+
sim = make_mw_sim(False, False, "microstrip")
488+
coax = td.GeometryGroup(
489+
geometries=(
490+
td.ClipOperation(
491+
operation="difference",
492+
geometry_a=td.Cylinder(axis=0, radius=2 * mm, center=(0, 0, 5 * mm), length=td.inf),
493+
geometry_b=td.Cylinder(
494+
axis=0, radius=1.4 * mm, center=(0, 0, 5 * mm), length=td.inf
495+
),
496+
),
497+
td.Cylinder(axis=0, radius=1 * mm, center=(0, 0, 5 * mm), length=td.inf),
498+
)
499+
)
500+
coax_struct = td.Structure(geometry=coax, medium=td.PEC)
501+
sim = sim.updated_copy(structures=[coax_struct])
502+
mode_monitor = sim.monitors[0]
503+
modal_plane = td.Box(center=mode_monitor.center, size=mode_monitor.size)
504+
path_spec_gen = ModePlaneAnalyzer(
505+
center=modal_plane.center,
506+
size=modal_plane.size,
507+
field_data_colocated=mode_monitor.colocate,
508+
)
509+
with pytest.raises(SetupError):
510+
path_spec_gen.get_conductor_bounding_boxes(
511+
sim.structures,
512+
sim.grid,
513+
sim.symmetry,
514+
sim.bounding_box,
515+
)
516+
517+
469518
def test_impedance_spec_validation():
470519
"""Check that the various allowed methods for supplying path specifications are validated."""
471520

tests/test_components/test_simulation.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,3 +3778,60 @@ def test_structures_per_medium(monkeypatch):
37783778
grid_spec=td.GridSpec.uniform(dl=0.02),
37793779
structures=structs,
37803780
)
3781+
3782+
3783+
def test_validate_microwave_mode_spec_generation():
3784+
"""Test that auto generation of path specs is correctly validated for currently unsupported structures."""
3785+
freq0 = 10e9
3786+
mm = 1e3
3787+
run_time_spec = td.RunTimeSpec(quality_factor=3.0)
3788+
size = (10 * mm, 10 * mm, 10 * mm)
3789+
size_mon = (0, 8 * mm, 8 * mm)
3790+
3791+
# Currently limited to generation of axis aligned boxes around conductors,
3792+
# so the path may intersect other nearby conductors, like in this coaxial cable
3793+
coaxial = td.Structure(
3794+
geometry=td.GeometryGroup(
3795+
geometries=(
3796+
td.ClipOperation(
3797+
operation="difference",
3798+
geometry_a=td.Cylinder(
3799+
axis=0, radius=2.5 * mm, center=(0, 0, 0), length=td.inf
3800+
),
3801+
geometry_b=td.Cylinder(
3802+
axis=0, radius=1.3 * mm, center=(0, 0, 0), length=td.inf
3803+
),
3804+
),
3805+
td.Cylinder(axis=0, radius=1 * mm, center=(0, 0, 0), length=td.inf),
3806+
)
3807+
),
3808+
medium=td.PEC,
3809+
)
3810+
mode_spec = td.ModeSpec(
3811+
num_modes=2,
3812+
target_neff=1.8,
3813+
microwave_spec=td.MicrowaveModeSpec(
3814+
impedance_specs=(td.AutoImpedanceSpec(), td.AutoImpedanceSpec())
3815+
),
3816+
)
3817+
3818+
mode_mon = td.ModeMonitor(
3819+
center=(0, 0, 0),
3820+
size=size_mon,
3821+
freqs=[freq0],
3822+
name="mode_1",
3823+
colocate=False,
3824+
mode_spec=mode_spec,
3825+
)
3826+
sim = td.Simulation(
3827+
run_time=run_time_spec,
3828+
size=size,
3829+
sources=[],
3830+
structures=[coaxial],
3831+
grid_spec=td.GridSpec.uniform(dl=0.1 * mm),
3832+
monitors=[mode_mon],
3833+
)
3834+
3835+
# check that validation error is caught
3836+
with pytest.raises(SetupError):
3837+
sim._validate_microwave_mode_specs()

0 commit comments

Comments
 (0)