Fix bug in interpolation of epsilon grid from Meep to MPB#3163
Merged
stevengj merged 2 commits intoNanoComp:masterfrom Mar 7, 2026
Merged
Fix bug in interpolation of epsilon grid from Meep to MPB#3163stevengj merged 2 commits intoNanoComp:masterfrom
stevengj merged 2 commits intoNanoComp:masterfrom
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3163 +/- ##
==========================================
+ Coverage 73.81% 73.90% +0.09%
==========================================
Files 18 18
Lines 5423 5454 +31
==========================================
+ Hits 4003 4031 +28
- Misses 1420 1423 +3 🚀 New features to boost your workflow:
|
stevengj
reviewed
Mar 6, 2026
stevengj
reviewed
Mar 6, 2026
…et_chi1inv_at_pt for dispersive materials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1237.
Bug Analysis
The error "invalid dielectric function for MPB" is triggered by MPB's
check_maxwell_dielectric()(inmaxwell_eps.c:266), which validates that every grid point's inverse-epsilon tensor (eps_inv) is positive-definite.Root cause (in
mpb.cpp, the primary fix)The
meep_mpb_epscallback assembles a 3×3eps_invtensor at each MPB grid point by querying Meep'sget_chi1invfor 6 independent components. The diagonal components each come from their natural Yee grid positions (Ex grid forchi1inv_xx, Ey grid forchi1inv_yy, Ez grid forchi1inv_zz), which are spatially offset by half a pixel from each other. The off-diagonal components were queried from only one grid — e.g.,m01 = chi1inv(Ex, Y, p)used only the Ex grid.Near a curved material boundary (like a Cylinder), the Ex grid point may sit right at the interface where subpixel averaging produces a large off-diagonal
chi1inv_xy, while the Ey grid point (half a pixel away) is inside the high-epsilon material with a smallchi1inv_yy. The assembled tensor then hasm01² > m00 * m11, failing positive-definiteness.Fix: Average each off-diagonal component from both relevant Yee grids:
m01 = 0.5 * (chi1inv(Ex,Y,p) + chi1inv(Ey,X,p))m02 = 0.5 * (chi1inv(Ex,Z,p) + chi1inv(Ez,X,p))m12 = 0.5 * (chi1inv(Ey,Z,p) + chi1inv(Ez,Y,p))This produces off-diagonal values consistent with both corresponding diagonal values.
Secondary bug (in
monitor.cpp, defensive six)structure_chunk::get_chi1inv_at_pthas a frequency-dependent code path (entered wheneverfrequency != 0) that builds a full 3×3 chi1inv tensor usingchi1inv[comp_list[com_it]][dir_int][idx]for all three components — butidxwas computed viagv.index(c, iloc)for a single componentc. On the Yee grid, the same flat index refers to a different spatial location for each component, so this reads wrong data. For non-dispersive materials (no susceptibilities or conductivity), this tensor path is a no-op that only introduces errors.Fix: Skip the tensor assembly path when no frequency-dependent material properties exist, returning the direct
chi1inv[c][d][idx]value instead.