-
Notifications
You must be signed in to change notification settings - Fork 69
fix(tidy3d): FXC-4563-use-2-d-intersections-for-adjoint-monitor-sizes-in-2-d-simulations #3096
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
fix(tidy3d): FXC-4563-use-2-d-intersections-for-adjoint-monitor-sizes-in-2-d-simulations #3096
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 1 comment
4c5b691 to
2ecf314
Compare
2ecf314 to
b1d5083
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 2 comments
1e0bc03 to
481b3fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, no comments
481b3fa to
bd8e561
Compare
yaugenst-flex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of an edge case but nice to have, thanks @marcorudolphflex
bd8e561 to
489b67d
Compare
…-in-2-d-simulations
489b67d to
119c999
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/structure.pyLines 332-343 332
333 intersections = geometry.intersections_plane(**{axis_char: plane_position})
334 bounds = [shape.bounds for shape in intersections if not shape.is_empty]
335 if len(bounds) == 0:
! 336 intersections = geom_box.intersections_plane(**{axis_char: plane_position})
! 337 bounds = [shape.bounds for shape in intersections if not shape.is_empty]
338 if len(bounds) == 0: # fallback
! 339 return geom_box
340
341 min_plane = (min(b[0] for b in bounds), min(b[1] for b in bounds))
342 max_plane = (max(b[2] for b in bounds), max(b[3] for b in bounds)) |
Previously, we just took the geometry bounds to construct adjoint monitors. This PR uses the plane intersection in 2D simulations.
Greptile Overview
Greptile Summary
This PR improves adjoint monitor sizing in 2D simulations by using planar geometry intersections instead of full bounding boxes. In 2D simulations (detected via
self.size.count(0.0) == 1), the code now callsgeometry.intersections_plane()to compute tight monitor bounds based on the actual geometry cross-section at the simulation plane.Key changes:
simulation.py:4887detects 2D simulations and passes plane info to structure monitor generationstructure.py:328-352implements_box_from_plane_intersection()that computes monitor bounds from plane intersections with multi-level fallback (geometry → bounding box → full bounding box)The implementation handles edge cases through a cascading fallback strategy and maintains backward compatibility for 3D simulations.
Confidence Score: 5/5
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant Sim as Simulation participant Struct as Structure participant Geom as Geometry participant BoxCls as Box Note over Sim: User calls _make_adjoint_monitors Sim->>Sim: Check if 2D via size.count(0.0) == 1 alt Is 2D simulation Sim->>Sim: sim_plane = self else Is 3D simulation Sim->>Sim: sim_plane = None end loop For each structure Sim->>Struct: _make_adjoint_monitors(freqs, index, field_keys, plane) alt plane is not None (2D case) Struct->>Struct: Call _box_from_plane_intersection Struct->>Geom: geometry.intersections_plane Geom-->>Struct: Return intersection shapes alt Intersections found Struct->>Struct: Compute union of bounds else No intersections Struct->>Geom: geom_box.intersections_plane alt Box intersections found Struct->>Struct: Compute union of bounds else Still no intersections Struct->>Struct: Use geom_box as fallback end end Struct->>BoxCls: Box.from_bounds(rmin, rmax) BoxCls-->>Struct: Return planar box else plane is None (3D case) Struct->>Struct: box = geom_box end Struct->>Struct: Create FieldMonitor with box Struct->>Struct: Create PermittivityMonitor with box Struct-->>Sim: Return monitors end Sim-->>Sim: Collect all monitorsNote
Improves adjoint monitor sizing for 2D simulations by cropping to the simulation plane’s geometry intersection; 3D behavior unchanged.
_make_adjoint_monitors; structures compute monitorBoxviageometry.intersections_plane(...)with robust fallbacksbounding_boxWritten by Cursor Bugbot for commit 119c999. This will update automatically on new commits. Configure here.