Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug where lumped elements were not being removed in Simulation.subsection #1995

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Significant speedup for field projection computations.
- Fix numerical precision issue in `FieldProjectionCartesianMonitor`.
- Bug where lumped elements in the `Simulation` were being overwritten by the `TerminalComponentModeler`.
- Bug in `Simulation.subsection` where lumped elements were not being correctly removed.

## [2.7.2] - 2024-08-07

Expand Down
5 changes: 4 additions & 1 deletion tests/test_components/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,11 +2407,14 @@ def test_to_gds(tmp_path):

@pytest.mark.parametrize("nz", [13, 1])
@pytest.mark.parametrize("unstructured", [True, False])
def test_sim_subsection(unstructured, nz):
def test_sim_subsection(unstructured, nz, log_capture):
region = td.Box(size=(0.3, 0.5, 0.7), center=(0.1, 0.05, 0.02))
region_xy = td.Box(size=(0.3, 0.5, 0), center=(0.1, 0.05, 0.02))

sim_red = SIM_FULL.subsection(region=region)
# Ensure that in this first test case the lumped element is safely excluded
_ = sim_red.volumetric_structures
assert_log_level(log_capture, "WARNING")
assert sim_red.structures != SIM_FULL.structures
sim_red = SIM_FULL.subsection(
region=region,
Expand Down
5 changes: 5 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ def make_custom_data(lims, unstructured):
freqs=[1e14, 2e14],
),
),
lumped_elements=[
td.LumpedResistor(
center=(2, 2, 0), size=(0.2, 0.2, 0), name="Resistor", resistance=42, voltage_axis=0
)
],
symmetry=(0, 0, 0),
boundary_spec=td.BoundarySpec(
x=td.Boundary(plus=td.PML(num_layers=20), minus=td.Absorber(num_layers=100)),
Expand Down
7 changes: 6 additions & 1 deletion tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,12 +1470,16 @@ def subsection(
# thus, recreate a box instance
new_box = Box.from_bounds(*new_bounds)

# inheritance of structures, sources, monitors, and boundary specs
# inheritance of structures, lumped elements, sources, monitors, and boundary specs
if remove_outside_structures:
new_structures = [strc for strc in self.structures if new_box.intersects(strc.geometry)]
else:
new_structures = self.structures

new_lumped_elements = [
elem for elem in self.lumped_elements if new_box.intersects(elem.to_structure.geometry)
]

if sources is None:
sources = [src for src in self.sources if new_box.intersects(src)]

Expand Down Expand Up @@ -1558,6 +1562,7 @@ def subsection(
sources=sources,
symmetry=symmetry,
structures=new_structures,
lumped_elements=new_lumped_elements,
**kwargs,
)

Expand Down
Loading