-
Notifications
You must be signed in to change notification settings - Fork 66
fix(mode): fixed bug where mode solver was not respecting location of PEC #3030
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
base: develop
Are you sure you want to change the base?
fix(mode): fixed bug where mode solver was not respecting location of PEC #3030
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.
3 files reviewed, 1 comment
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/mode/mode_solver.pytidy3d/components/mode/solver.py |
f179f91 to
6bb0d8f
Compare
|
@greptileai another round |
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
d1ada2b to
3df4c17
Compare
I think it's quite common to have mode plane smaller than the simulation domain, and it'll be very useful to fix that too? Regarding closest grid boundary, i guess it should work in most cases, as it's expected to have the mode plane boundary to lie at the metal surface, and metal surface is snapped to grid. |
It's not really an issue though if the mode plane is smaller than the simulation domain. All that will happen is an extra cell will be added that is outside the monitor bounds. But since in the simulation there is no PEC boundary at the monitor bounds anyways, it is an accurate representation. A structure just outside/touching the monitor bounds will still be captured by the mode solver, and is the current workaround for this bug. |
caseyflex
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.
I think the warnings make sense if the boundary won’t be used.
the only unclear case is PML, which you don’t earn for just because it would be annoying. I guess that can be a separate discussion about unifying PML treatment
3df4c17 to
4384ea8
Compare
4359b2f to
c6e2d73
Compare
… PEC boundary conditions from the Simulation
c6e2d73 to
a436028
Compare
Greptile Overview
Greptile Summary
This PR fixes a bug where the mode solver grid would extend beyond simulation domain boundaries, causing incorrect PEC boundary condition application. The fix implements grid truncation at simulation boundaries and zero-pads fields outside the domain.
Key changes:
_sim_boundary_positionsmethod to detect PEC boundaries and determine where to truncate the computational gridcompute_modesthat clips coordinates, permittivity, permeability, and basis fields to simulation boundsThe implementation correctly handles the core issue, but there's a minor inconsistency in the boundary intersection detection logic that could cause edge cases.
Confidence Score: 4/5
np.isclosevsfp_epsthreshold) that could cause edge case failures. The core truncation and zero-padding logic appears soundtidy3d/components/mode/mode_solver.pyfor the boundary intersection logic inconsistencyImportant Files Changed
File Analysis
_sim_boundary_positionsmethod to detect PEC boundaries and determine truncation positions. Passes boundary positions to solver for grid truncation. Minor inconsistency in boundary checking logic_truncate_medium_datahelper methodSequence Diagram
sequenceDiagram participant MS as ModeSolver participant MSC as ModeSolver._solve_single_freq participant SBP as ModeSolver._sim_boundary_positions participant CM as compute_modes (solver.py) participant TMD as _truncate_medium_data MS->>MS: User calls .data property MS->>MSC: _solve_single_freq(freq, coords, symmetry) MSC->>SBP: Get PEC boundary positions SBP->>SBP: Check boundary types (PEC, PMC, etc.) SBP->>SBP: Determine if solver grid intersects boundaries SBP-->>MSC: Return (pos_min, pos_max) tuples MSC->>CM: compute_modes(eps_cross, coords, ..., sim_pec_pos_min, sim_pec_pos_max) CM->>CM: Calculate truncation indices from PEC positions CM->>CM: Check if truncation needed (trim_min != [0,0] or trim_max != [Nx,Ny]) alt Truncation needed CM->>CM: Truncate coords arrays CM->>TMD: Truncate eps_cross TMD-->>CM: Truncated eps CM->>TMD: Truncate mu_cross (if present) TMD-->>CM: Truncated mu CM->>CM: Truncate split_curl_scaling (if present) CM->>CM: Truncate solver_basis_fields (if present) end CM->>CM: Solve eigenvalue problem on truncated grid CM->>CM: Reshape fields to (2, 3, Nx_trunc, Ny_trunc, 1, num_modes) alt Truncation was applied CM->>CM: Zero-pad fields back to original size Note over CM: np.pad with trim_min/trim_max offsets end CM-->>MSC: Return (n_complex, fields, eps_spec) MSC-->>MS: Return mode data with correct boundary conditions