Skip to content

Commit 4abc665

Browse files
committed
rename auto patch spec to generator type name, fixed tests
1 parent 69b085f commit 4abc665

File tree

7 files changed

+27
-68
lines changed

7 files changed

+27
-68
lines changed

tests/test_components/test_microwave.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from shapely.geometry import LineString, Polygon
1313
from shapely.plotting import plot_line, plot_polygon
1414
from tidy3d.components.data.monitor_data import FreqDataArray
15-
from tidy3d.components.microwave.auto_path_spec import AutoPathSpec
1615
from tidy3d.components.microwave.formulas.circuit_parameters import (
1716
capacitance_colinear_cylindrical_wire_segments,
1817
capacitance_rectangular_sheets,
@@ -24,6 +23,7 @@
2423
make_current_integral,
2524
make_voltage_integral,
2625
)
26+
from tidy3d.components.microwave.path_spec_generator import PathSpecGenerator
2727
from tidy3d.components.types import Ax, Shapely
2828
from tidy3d.constants import EPSILON_0
2929
from tidy3d.exceptions import ValidationError
@@ -320,7 +320,7 @@ def test_auto_path_spec_canonical_shapes(colocate, tline_type):
320320
sim = make_mw_sim(False, colocate, tline_type)
321321
mode_monitor = sim.monitors[0]
322322
modal_plane = td.Box(center=mode_monitor.center, size=mode_monitor.size)
323-
comp_path_spec, geos = AutoPathSpec.create_current_path_specs(
323+
comp_path_spec, geos = PathSpecGenerator.create_current_path_specs(
324324
modal_plane,
325325
sim.structures,
326326
sim.grid,
@@ -380,7 +380,7 @@ def test_auto_path_spec_advanced(use_2D, symmetry):
380380
mode_monitor = sim.monitors[0]
381381

382382
modal_plane = td.Box(center=mode_monitor.center, size=mode_monitor.size)
383-
comp_path_spec, geos = AutoPathSpec.create_current_path_specs(
383+
comp_path_spec, geos = PathSpecGenerator.create_current_path_specs(
384384
modal_plane,
385385
sim.structures,
386386
sim.grid,
@@ -410,11 +410,11 @@ def test_auto_path_spec_validation():
410410
# First some quick sanity checks with the helper
411411
test_path = td.Box(center=(0, 0, 0), size=(0, 0.9, 0.1))
412412
test_shapely = [LineString([(-1, 0), (1, 0)])]
413-
assert AutoPathSpec._check_path_intersects_with_conductors(test_shapely, test_path)
413+
assert PathSpecGenerator._check_path_intersects_with_conductors(test_shapely, test_path)
414414

415415
test_path = td.Box(center=(0, 0, 0), size=(0, 2.1, 0.1))
416416
test_shapely = [LineString([(-1, 0), (1, 0)])]
417-
assert not AutoPathSpec._check_path_intersects_with_conductors(test_shapely, test_path)
417+
assert not PathSpecGenerator._check_path_intersects_with_conductors(test_shapely, test_path)
418418

419419
sim = make_mw_sim(False, False, "microstrip")
420420
coax = td.GeometryGroup(
@@ -434,7 +434,7 @@ def test_auto_path_spec_validation():
434434
mode_monitor = sim.monitors[0]
435435
modal_plane = td.Box(center=mode_monitor.center, size=mode_monitor.size)
436436
with pytest.raises(ValidationError):
437-
AutoPathSpec.create_current_path_specs(
437+
PathSpecGenerator.create_current_path_specs(
438438
modal_plane,
439439
sim.structures,
440440
sim.grid,

tidy3d/components/microwave/auto_path_spec.py renamed to tidy3d/components/microwave/path_spec_generator.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .path_spec import CompositeCurrentIntegralSpec, CurrentIntegralAxisAlignedSpec
2727

2828

29-
class AutoPathSpec(Tidy3dBaseModel):
29+
class PathSpecGenerator(Tidy3dBaseModel):
3030
"""Automatically determines current integration paths based on structure geometry.
3131
3232
This class analyzes the geometry of conductors in a simulation cross-section to determine
@@ -105,7 +105,7 @@ def bounding_box_from_shapely(geom: Shapely, normal_axis, normal_center):
105105
min_sym_bounds[dim] = sim_box.center[dim]
106106
sym_sim_bounds = (tuple(min_sym_bounds), max_sym_bounds)
107107

108-
conductor_polygons = AutoPathSpec._get_isolated_conductors_as_shapely(
108+
conductor_polygons = PathSpecGenerator._get_isolated_conductors_as_shapely(
109109
mode_plane, structures
110110
)
111111
normal_axis = mode_plane.size.index(0.0)
@@ -136,7 +136,9 @@ def bounding_box_from_shapely(geom: Shapely, normal_axis, normal_center):
136136
):
137137
continue
138138
box = Box.from_bounds(rmin=intersected_box[0], rmax=intersected_box[1])
139-
boxes = AutoPathSpec._apply_symmetry(symmetry, sim_box.center, normal_axis, box)
139+
boxes = PathSpecGenerator._apply_symmetry(
140+
symmetry, sim_box.center, normal_axis, box
141+
)
140142
for box in boxes:
141143
box_snapped = snap_box_to_grid(grid, box, snap_spec)
142144
path_spec = CurrentIntegralAxisAlignedSpec(
@@ -149,7 +151,9 @@ def bounding_box_from_shapely(geom: Shapely, normal_axis, normal_center):
149151
current_integral_specs.append(path_spec)
150152

151153
for path_spec in current_integral_specs:
152-
if AutoPathSpec._check_path_intersects_with_conductors(conductor_polygons, path_spec):
154+
if PathSpecGenerator._check_path_intersects_with_conductors(
155+
conductor_polygons, path_spec
156+
):
153157
raise ValidationError(
154158
"Failed to automatically setup path specification for impedance calculation. "
155159
"Please create a github issue so that the problem can be investigated. "
@@ -197,7 +201,7 @@ def _reflect_box(box: Box, axis: Axis, position: float) -> Box:
197201

198202
@staticmethod
199203
def _apply_symmetry_to_box(box: Box, axis: Axis, position: float) -> list[Box]:
200-
new_box = AutoPathSpec._reflect_box(box, axis, position)
204+
new_box = PathSpecGenerator._reflect_box(box, axis, position)
201205
if isclose(new_box.bounds[0][axis], box.bounds[1][axis]) or isclose(
202206
new_box.bounds[1][axis], box.bounds[0][axis]
203207
):
@@ -224,7 +228,8 @@ def _apply_symmetry(
224228
for dim, sym in zip(dims, symmetry):
225229
if sym != 0:
226230
tmp_list = [
227-
AutoPathSpec._apply_symmetry_to_box(box, dim, sim_center[dim]) for box in result
231+
PathSpecGenerator._apply_symmetry_to_box(box, dim, sim_center[dim])
232+
for box in result
228233
]
229234
result = list(chain.from_iterable(tmp_list))
230235
return result

tidy3d/components/mode/mode_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from ..geometry.base import Box
3333
from ..grid.grid import Coords, Grid
3434
from ..medium import FullyAnisotropicMedium, LossyMetalMedium
35-
from ..microwave.auto_path_spec import AutoPathSpec
35+
from ..microwave.path_spec_generator import PathSpecGenerator
3636
from ..microwave.terminal_spec import TerminalSpec
3737
from ..mode_spec import ModeSpec
3838
from ..monitor import ModeMonitor, ModeSolverMonitor
@@ -1270,7 +1270,7 @@ def _add_terminal_spec(self, mode_solver_data: ModeSolverData):
12701270
v_spec = self.mode_spec.terminal_spec.voltage_spec
12711271
i_spec = self.mode_spec.terminal_spec.current_spec
12721272
if v_spec is None and i_spec is None:
1273-
i_spec, _ = AutoPathSpec.create_current_path_specs(
1273+
i_spec, _ = PathSpecGenerator.create_current_path_specs(
12741274
self.plane,
12751275
self.simulation.structures,
12761276
self.simulation.grid,

tidy3d/components/simulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,8 +4120,8 @@ def _validate_freq_monitors_freq_range(self) -> None:
41204120

41214121
def _validate_terminal_specs(self) -> None:
41224122
"""Raise error if any terminal specificiations fail to instantiate path integrals."""
4123-
from .microwave.auto_path_spec import AutoPathSpec
41244123
from .microwave.path_integral_factory import make_current_integral, make_voltage_integral
4124+
from .microwave.path_spec_generator import PathSpecGenerator
41254125

41264126
for monitor in self.monitors:
41274127
if not isinstance(monitor, AbstractModeMonitor):
@@ -4133,7 +4133,7 @@ def _validate_terminal_specs(self) -> None:
41334133
v_spec = term_spec.voltage_spec
41344134
i_spec = term_spec.current_spec
41354135
if v_spec is None and i_spec is None:
4136-
i_spec, _ = AutoPathSpec.create_current_path_specs(
4136+
i_spec, _ = PathSpecGenerator.create_current_path_specs(
41374137
monitor.bounding_box,
41384138
self.structures,
41394139
self.grid,

tidy3d/plugins/microwave/custom_path_integrals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ...components.geometry.base import Geometry
1212
from ...components.microwave.path_spec import (
1313
CompositeCurrentIntegralSpec,
14+
CustomCurrentIntegral2DSpec,
1415
CustomPathIntegral2DSpec,
1516
CustomVoltageIntegral2DSpec,
1617
)
@@ -198,7 +199,7 @@ def compute_voltage(self, em_field: MonitorDataTypes) -> IntegralResultTypes:
198199
return voltage
199200

200201

201-
class CustomCurrentIntegral2D(CustomPathIntegral2D):
202+
class CustomCurrentIntegral2D(CustomPathIntegral2D, CustomCurrentIntegral2DSpec):
202203
"""Class for computing conduction current via Ampère's circuital law on a custom path.
203204
To compute the current flowing in the positive ``axis`` direction, the vertices should be
204205
ordered in a counterclockwise direction."""

tidy3d/plugins/microwave/path_integrals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
CurrentIntegralAxisAlignedSpec,
2424
VoltageIntegralAxisAlignedSpec,
2525
)
26-
from ...constants import AMP, VOLT
26+
from ...constants import AMP, VOLT, fp_eps
2727
from ...exceptions import DataError
2828

2929
MonitorDataTypes = Union[FieldData, FieldTimeData, ModeData, ModeSolverData]
@@ -259,10 +259,10 @@ def _to_path_integrals(
259259
) -> tuple[AxisAlignedPathIntegral, ...]:
260260
"""Returns four ``AxisAlignedPathIntegral`` instances, which represent a contour
261261
integral around the surface defined by ``self.size``."""
262-
from ...components.microwave.path_integral_factory import make_current_integral
263-
264262
path_specs = self._to_path_integral_specs(h_horizontal=h_horizontal, h_vertical=h_vertical)
265-
path_integrals = [make_current_integral(path_spec) for path_spec in path_specs]
263+
path_integrals = [
264+
AxisAlignedPathIntegral(**path_spec.dict(exclude={"type"})) for path_spec in path_specs
265+
]
266266
return tuple(path_integrals)
267267

268268
@staticmethod

tidy3d/plugins/microwave/viz.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,9 @@
55
from ...components.viz import PathPlotParams
66

77
""" Constants """
8-
VOLTAGE_COLOR = "red"
9-
CURRENT_COLOR = "blue"
108
LOBE_PEAK_COLOR = "tab:red"
119
LOBE_WIDTH_COLOR = "tab:orange"
1210
LOBE_FNBW_COLOR = "tab:blue"
13-
PATH_LINEWIDTH = 2
14-
ARROW_CURRENT = dict(
15-
arrowstyle="-|>",
16-
mutation_scale=32,
17-
linestyle="",
18-
lw=PATH_LINEWIDTH,
19-
color=CURRENT_COLOR,
20-
)
21-
22-
plot_params_voltage_path = PathPlotParams(
23-
alpha=1.0,
24-
zorder=inf,
25-
color=VOLTAGE_COLOR,
26-
linestyle="--",
27-
linewidth=PATH_LINEWIDTH,
28-
marker="o",
29-
markersize=10,
30-
markeredgecolor=VOLTAGE_COLOR,
31-
markerfacecolor="white",
32-
)
33-
34-
plot_params_voltage_plus = PathPlotParams(
35-
alpha=1.0,
36-
zorder=inf,
37-
color=VOLTAGE_COLOR,
38-
marker="+",
39-
markersize=6,
40-
)
41-
42-
plot_params_voltage_minus = PathPlotParams(
43-
alpha=1.0,
44-
zorder=inf,
45-
color=VOLTAGE_COLOR,
46-
marker="_",
47-
markersize=6,
48-
)
49-
50-
plot_params_current_path = PathPlotParams(
51-
alpha=1.0,
52-
zorder=inf,
53-
color=CURRENT_COLOR,
54-
linestyle="--",
55-
linewidth=PATH_LINEWIDTH,
56-
marker="",
57-
)
5811

5912
plot_params_lobe_peak = PathPlotParams(
6013
alpha=1.0,

0 commit comments

Comments
 (0)